Azure Key Vault Access from Azure Arc Host

Richard Long 391 Reputation points
2025-09-15T21:15:11.1933333+00:00

We've onboarded a Windows server into Azure Arc and granted it access to an Azure Key Vault. I confirmed I am able to access secrets in the vault via Azure CLI, however, we're trying to use an IIS Application Pool to access secrets in the vault, but are unable to. It seems like most of the documentation we're finding is geared towards Azure native VMs. Is there a different method required to access the secrets from an Azure Arc enabled host?

Azure Key Vault
Azure Key Vault

An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.

0 comments No comments

Answer accepted by question author
Marcin Policht 113.2K Reputation points MVP Volunteer Moderator
2025-09-15T21:55:24.0166667+00:00

Every Azure Arc–enabled server automatically has a system-assigned managed identity created when it's onboarded. The Connected Machine agent (HIMDS) on Arc exposes a local IMDS-style endpoint (by default http://localhost:40342) and sets environment variables like IDENTITY_ENDPOINT and IMDS_ENDPOINT. Workloads use this to request tokens. On Windows, only local Administrators or members of the Hybrid agent extension applications local group can complete the HIMDS challenge and retrieve tokens. By default, an IIS app pool identity won't have access.

When you use Azure CLI as an admin, you can read the HIMDS challenge and get a token. The IIS worker process, running under its own low-privilege identity, usually cannot — so the token request fails and your app can't access Key Vault.

To fix this, try the following:

  1. Confirm the Arc machine identity
       az connectedmachine show --name MyMachine --resource-group MyRG --query identity -o json
    
    This shows the managed identity's principal ID.
  2. Grant the Arc identity access to Key Vault
    • RBAC (recommended):
           az role assignment create \
             --assignee <principalId> \
             --role "Key Vault Secrets User" \
             --scope /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.KeyVault/vaults/<vaultName>
      
    • Or with an access policy:
           az keyvault set-policy --name <vaultName> --object-id <principalId> --secret-permissions get list
      
  3. Check the local identity endpoint on the server
       $env:IDENTITY_ENDPOINT
       $env:IMDS_ENDPOINT
    
    You can also try a token request:
       Invoke-WebRequest -Uri "$env:IDENTITY_ENDPOINT?api-version=2018-02-01&resource=https://vault.azure.net" -Headers @{Metadata='true'}
    
  4. Allow IIS to use HIMDS Add the IIS app pool identity (or its service account) to the Hybrid agent extension applications local group:
       Add-LocalGroupMember -Group "Hybrid agent extension applications" -Member "CONTOSO\svc-iis-app"
    
    Then recycle the app pool or restart IIS.
  5. Use the Azure SDK in your app In .NET, for example:
       var client = new Azure.Security.KeyVault.Secrets.SecretClient(
           new Uri("https://<your-kv>.vault.azure.net/"),
           new DefaultAzureCredential());
    
       var secret = await client.GetSecretAsync("MySecret");
    
    Make sure you're using a recent version of the Azure.Identity library.

If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

hth

Marcin

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.