Azure / Azure/azure-powershell
Connect-AzAccount support for Azure Arc managed identities
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
## Description of the new feature
Today, you can use `Connect-AzAccount -Identity` on an Azure VM to request a token for the system-assigned managed identity from the Instance Metadata Service (IMDS) and use that identity for your AzPS context. Azure Arc enabled servers has introduced a managed identity for on-premises and multicloud servers. Due to a slightly different IMDS implementation, the existing behavior doesn't work on hybrid servers.
This issue proposes changes to `Connect-AzAccount -Identity` to support both Azure VMs and Arc enabled servers.
## Proposed implementation details (optional)
There are two changes to how the hybrid IMDS works on an Arc enabled server:
1. The IMDS server is exposed at http://localhost:40342/ instead of http://169.254.169.254. On Windows, you can query the `IDENTITY_ENDPOINT` environment variable to get the base URL for the token endpoint. Today, it will always return `http://localhost:40342/metadata/identity/oauth2/token`. There is not an equivalent on Linux, nor are there plans to support other ports at this time.
2. Hybrid IMDS requires that callers prove they are administrators to access the AAD token. To achieve this, there is an additional challenge-response mechanism added to the token request. A successful flow goes as follows:
1. Make the initial request to Hybrid IMDS for the access token
2. HIMDS will return a 403 response, with a "Www-Authenticate" header that contains a file path. This file contains randomly generated content in a directory restricted to administrator access.
3. The code should read the contents of that file (proving it has admin privileges) and include it in the access token request again with an authentication header: `Authentication: Basic `. HIMDS will return the access token per usual after verifying the authentication header.
The code should always try Azure IMDS before Hybrid IMDS in case an Arc server has been migrated to Azure without removing the HIMDS agent first.
Contributor guide
Assessment
This issue has not been assessed yet.