Open Cloud-Architekt opened 8 months ago
This issue also is present when using Azure Automation. Workaround by @Cloud-Architekt works there as well but should be fixed in the codebase
$Uri = "$($env:IDENTITY_ENDPOINT)?api-version=2018-02-01&client_id=$ClientId&resource=$ClientId"
$AzToken = Invoke-WebRequest -Uri $Uri -Method GET -Headers @{ Metadata = "true" } | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty access_token
@msJinLei could you help look into this? Thanks.
@isra-fel , @msJinLei: Are there any updates on this issue?
@Cloud-Architekt You don't need to specify -Resource
when you run Get-AzAccessToken
except you want to get a data plane token.
Description
Request of access token in scope of the (User-Assigned) Managed Identity Client ID is not working anymore. This scope is required to sign-in as federated identity credentials in AWS by using a Managed Identity. The issue is independent from the Azure Resource type (affects Automation Accounts but also Virtual Machines).
The issue seems to exist since module version 2.15.1 of Az.Accounts.
Used cmdlets: Connect-AzAccount -identity -AccountId
Get-AzAccessToken -resource
Error message: Get-AzAccessToken: ManagedIdentityCredential authentication failed: API does not accept client id as a user-provided scope. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot
Current workaround: Request access token from IMDS by using Invoke-WebRequest:
$response = Invoke-WebRequest -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&client_id=<ClientId>&resource=<ClientId>' -Method GET -Headers @{Metadata="true"} $content = $response.Content | ConvertFrom-Json $ArmToken = $content.access_token
Issue script & Debug output
Environment data
Module versions
Error output