{Profile} az account get-access-token: Show expiresOn for managed identity#20219
{Profile} az account get-access-token: Show expiresOn for managed identity#20219
az account get-access-token: Show expiresOn for managed identity#20219Conversation
|
Profile |
| 'tokenType': creds[0], | ||
| 'accessToken': creds[1], | ||
| # 'expires_on': creds[2].get('expires_on', None), | ||
| 'expiresOn': creds[2].get('expiresOn', None), |
There was a problem hiding this comment.
Why do you need to change this line?
There was a problem hiding this comment.
We need to guarantee that expiresOn always exists in creds[2] - CLI should fail if expiresOn is not set, instead of returning None which will cause more trouble.
| from .auth.util import scopes_to_resource | ||
| msi_creds = MsiAccountTypes.msi_auth_factory(identity_type, identity_id, | ||
| scopes_to_resource(scopes)) | ||
| sdk_token = msi_creds.get_token(*scopes) |
There was a problem hiding this comment.
The old implementation of ADAL-based Azure CLI returns token_entry containing inconsistent fields:
expires_onfor managed identityexpiresOnfor ADAL credential
They are unified later at command module level:
azure-cli/src/azure-cli/azure/cli/command_modules/profile/custom.py
Lines 82 to 85 in df737ed
We use get_token to unify them to epoch int expires_on in core instead.
There was a problem hiding this comment.
Just out of curiosity, will token_entry['expiresOn'] has its own value in some cases before it is overwritten by _fromtimestamp(int(token_entry['expires_on'])).strftime("%Y-%m-%d %H:%M:%S.%f")?
May I ask their values should be the same in all cases, but only in different formats, right?
There was a problem hiding this comment.
No. get_token only returns AccessToken which must have int epoch expires_on.
|
any update on when this issue will be merged and released? getting similar issue when trying to use azure app service with custom container. |
az account get-access-token show expiresOn for managed identityaz account get-access-token: Show expiresOn for managed identity
|
@waylew-lexis your issue has been resolved by #20215 and will be released in Azure CLI 2.31.0. |
# Conflicts: # src/azure-cli-core/azure/cli/core/tests/test_profile.py
| self.object_id = kwargs.get('object_id') | ||
| self.msi_res_id = kwargs.get('msi_res_id') | ||
| self.resource = kwargs.get('resource') | ||
| MSRestAzureAuthStub.return_value = self |
There was a problem hiding this comment.
Don't save the instance as class attribute so that tests won't interfere with each other.
| msi_creds.set_token() | ||
| token_entry = msi_creds.token | ||
| creds = (token_entry['token_type'], token_entry['access_token'], token_entry) | ||
| raise CLIError("Tenant shouldn't be specified for managed identity account") |
There was a problem hiding this comment.
Could we use a specific error type (such as ArgumentUsageError) instead of CLIError?
There was a problem hiding this comment.
There are so many places in core that don't comply with the error handling rule. Let's refine them together later.
|
Hello, do you know when this merged modification will be integrated to a release ?
That should be fixed with this modification ;) Regards Marc. |
|
Build to Cloud Shell: 12/03/2021 Official Release: 12/07/2021 |
Fix #20211
Fix getporter/azure-plugins#39
Fix microsoft/AzureTRE#1067
Fix Azure/azure-cli-extensions#4076
Description
Issue: During the migration to MSAL, for managed identity, the
expiresOnproperty inaz account get-access-token's output is lost.This is due to the complexity and inconsistency of
expiresOn/expires_onproperties across different services and tools.There are 4 forms of
expiresOn/expires_on:"expires_on": "1605238724""expires_on": 1605238724"expiresOn": "2020-11-12 13:50:47.114324""expires_on": "11/05/2021 15:18:31 +00:00"This PR unified these 4 types:
expires_onis returned.expires_onis unified to epoch int ([App Service] Support managed identity in App Service container #20215).get_raw_tokenreturnsexpiresOn: datetime string for backward compatibility, like"2020-11-12 13:50:47.114324"expires_on: epoch int, like1605238724(az account get-access-token: Use epochexpiresOn/expires_on#19700)Testing Guide