Closed jiasli closed 4 months ago
az login with MSI
add to S170
Is this still and issue. I'm observing this behavior still.
Azure CLI still uses msrestazure
for managed identity login. We will fix this issue after we migrate to MSAL (https://github.com/Azure/azure-cli/issues/18944).
With #18944 being complete, any word on this issue? Our example is a requirement on both user and system assigned identities assigned but we want to default to user assigned.
With #18944 being complete, any word on this issue?
Apologize for the delay as we don't have enough bandwidth revisiting this historical issue for now. 😥
Our example is a requirement on both user and system assigned identities assigned but we want to default to user assigned.
I don't think this is possible. When both system and user assigned identity are available, managed identity endpoint will return system assigned one by default.
Recommendation is to explicitly declare a user assigned identity and use its client id.
Do not rely on the system choosing the "only 1" identity. It is a brittle experience, which will break the moment a new user assigned identity or a system assigned identity is broken.
We (SDK and service teams) are actively looking for how to deprecate this behavior.
@jiasli - please close this as "won't fix"
More context provided by MSAL developer @rayluo:
That is the underlying behavior baked into Azure VM's endpoint (but not on any other flavors of Managed Identities). I left a trace here in MSAL code base, which points to Azure VM's official documentation. We do not like it or advertise it, but, that behavior on the endpoint layer will probably stay forever, until/unless we drop that endpoint and switch to Managed Identity v2 in the future.
With our programming model of encouraging/enforcing the choice between SAMI and UAMI, we at least conceptually guide app developers to make that decision upfront. So, when app developer wants to use the only UAMI on their VM, they are expected to create a UAMI with its client_id
. They are not supposed to use SAMI. There is no DefaultManagedIdentity
concept here. There will be no ambiguity in this usage pattern. Of course, nothing stops app developer from knowing #1
and then purposely (ab)use our SAMI interface to get a token that is actually for the UAMI. But we (MSAL) did our part.
Symptom
When using a single user assigned identity for
az login --identity
, it says the logged inuser
is a system assigned identity.The default identity is the identity returned when the
client_id
,object_id
andmi_res_id
parameters are not provided to IMDS. This will be the system assigned identity when present but can also be a user assigned identity ifaz login
is assuming the default identity used is a system assigned even if it is a user assigned.The system identity is off since the creation of the VM, but each time I use the command I got the following:
Explanation
In the current implementation, identity type is deduced from whether
identity_id
is provided. When you runaz login --identity
without--username
, CLI will assume it is a system assigned identity, instead of confirming from the response.https://github.com/Azure/azure-cli/blob/764332b65bd8758696df36921084c033d82e5ff9/src/azure-cli-core/azure/cli/core/_profile.py#L357
Solution
Extract the resource ID of managed identity from the access token's
xms_mirid
property to decide the correct type of managed identity.Get the access token with
Then decode the access token with https://jwt.ms/.
System assigned identity:
User assigned identity:
Additional information
Email: az login on VM indicating system assigned when the identity is user assigned