Hello Brandon Gilbert,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Regarding your scenario and explanation, there are couple of a few things you will need to resolve the issue:
- First confirm that system-assigned managed identity is enabled on your Azure resource by using this bash command:
az vm show --resource-group <your-resource-group> --name <your-vm-name> --query identity --output json
Use this link for more info - https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview - Configure Azure Key Vault Access Policy for access to your application using bash command:
az keyvault set-policy --name <your-key-vault-name> --object-id <managed-identity-object-id> --secret-permissions get list
For more info - https://docs.microsoft.com/azure/key-vault/general/assign-access-policy - In your Docker, you will need to set environment variable as
and use:`IDENTITY_ENDPOINT` `IMDS_ENDPOINT`
docker run -it --rm -e IDENTITY_ENDPOINT=http://169.254.169.254/metadata/identity/oauth2/token -e IMDS_ENDPOINT=http://169.254.169.254/metadata/instance -v C:\azuretest:C:\azuretest --name my-app-container mcr.microsoft.com/windows/nanoserver:ltsc2022 cmd
- Make sure your application is using
DefaultAzureCredential
correctly.
For more info: https://docs.microsoft.com/dotnet/api/overview/azure/identity-readmeusing Azure.Identity; using Azure.Security.KeyVault.Secrets; // Create a secret client var client = new SecretClient(new Uri("https://<your-key-vault-name>.vault.azure.net/"), new DefaultAzureCredential()); // Get a secret KeyVaultSecret secret = await client.GetSecretAsync("<your-secret-name>");
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.