Authenticating to a Private Azure Container Registry is limited to just a handfull of options
Bicep version 0.17.1 + 0.18.4 + 0.19.5
Describe the bug I tried to authenticate to my Azure Container Registry (ACR) from VSCode with the Bicep Extension enabled through the following scenario's (with each scenario I only configured the credentialPrecedence to a single value like AzureCLI or AzurePowerShell):
- Logged in through the Azure CLI with my account on the same tenant as my ACR is located. This seems to be working perfectly.
- Logged in through the Azure CLI with my account on a different tenant where my ACR is not located. Next I login to the ACR based on a token (generated from the ACR) trying to authenticate to my ACR and calling my BICEP Modules. Resulting in UNAUTHORIZED.
- Logged in through the Azure PowerShell with my account on the same tenant where my ACR is located. Resulting in Unhandled exception: Azure.Identity.AuthenticationFailedException: The ChainedTokenCredential failed due to an unhandled exception: AzurePowerShellCredential authentication failed: String '7/28/2023 1:59:43 PM +00:00' was not recognized as a valid DateTime. I tried it with the Az.Accounts 2.12*, Az.ContainerRegistry 3.* + 4.* modules and configured .NET Framework with 4.7.2 and higher (different combinations).
- Logged in through the Azure PowerShell with my account on a different tenant where my ACR is not located. Next I login to the ACR based on a token (generated from the ACR) trying to authenticate to my ACR and calling my BICEP Modules. Resulting in Unhandled exception: Azure.Identity.AuthenticationFailedException: The ChainedTokenCredential failed due to an unhandled exception: AzurePowerShellCredential authentication failed: String '7/28/2023 1:59:43 PM +00:00' was not recognized as a valid DateTime. I tried it with the Az.Accounts 2.12*, Az.ContainerRegistry 3.* + 4.* modules and configured .NET Framework with 4.7.2 and higher (different combinations).
To Reproduce Steps to reproduce the behavior:
- Create a Private Azure Container Registry
- Create a token
- Create an account with AcrPull permissions
- Authenticate based on the scenario's I provided above with the several versions of BICEP and PSModules
Additional context Perhaps I am missing something so feel free to contact me regarding the information above.
Also the authentication option VisualStudioCode is used but without success. Here I configured the Azure Account extension with the account where my ACR is located in. UNAUTHORIZED is the result.
I also noticed that the display in VSCode stays faulty even when authenticated in the working scenario. So the module keeps saying error UNAUTHORIZED while I am authorized. Perhaps something to keep in mind aswell, something is going wrong there?
This seems to be related to an issue in the Azure.Identity library that we are using for authentication: https://github.com/Azure/azure-sdk-for-net/issues/22638
I'm reaching out to the owners of Azure.Identity internally to find out more...
Tagging @christothes to take a look
@buys-stash - It appears that this is happening due to a mismatch of the cultures between the process running Azure.Identity and the one running Pwsh. Could you describe what your environment is like with regard to locales?
@buys-stash Would you be able to answer @christothes's question?
This should be fixed in the latest Azure.Identity (1.10.0)
Hi @buys-stash, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! :smile: :mechanical_arm:
Hi @buys-stash, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! :smile: :mechanical_arm:
Hi @buys-stash, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! :smile: :mechanical_arm:
@buys-stash - It appears that this is happening due to a mismatch of the cultures between the process running Azure.Identity and the one running Pwsh. Could you describe what your environment is like with regard to locales?
My apologies for the delay, I will send you how my environment looks like in a couple of days. I am on leave right now.
I'm having the same issues, seems like not a lot of people are using the ACR with token. I have a public ACR but want to use the scope maps for bicep deployments and just as @ronald-heijn-buys said it seems impossible to authenticate. I tried powershell, az cli and docker login and none seem to work. Although login is a succes but restoring the modules doesn't work.
Edit: Error BCP192: Unable to restore the module with reference "br:{URL}.azurecr.io/virtual-network:v1": Service request failed. Status: 401 (Unauthorized)
Content: {"errors":[{"code":"UNAUTHORIZED","message":"authentication required, visit https://aka.ms/acr/authorization for more information."}]}
Headers: Server: openresty Date: Wed, 20 Sep 2023 18:09:26 GMT Connection: keep-alive X-Ms-Correlation-Request-Id: a1a8cdd5-6aa4-4e63-b92a-1f52c01e3a5d x-ms-ratelimit-remaining-calls-per-second: 166.633333 Strict-Transport-Security: REDACTED Content-Type: text/plain; charset=utf-8 Content-Length: 134