Skip to content

Commit

Permalink
[Profile] Drop support for old-style managed identity account (Azure#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli authored Nov 20, 2024
1 parent b639c9d commit 14084ad
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 81 deletions.
25 changes: 14 additions & 11 deletions src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def get_login_credentials(self, resource=None, subscription_id=None, aux_subscri

account = self.get_subscription(subscription_id)

managed_identity_type, managed_identity_id = Profile._try_parse_msi_account_name(account)
managed_identity_type, managed_identity_id = Profile._parse_managed_identity_account(account)

if in_cloud_console() and account[_USER_ENTITY].get(_CLOUD_SHELL_ID):
# Cloud Shell
Expand Down Expand Up @@ -436,7 +436,7 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No

account = self.get_subscription(subscription)

managed_identity_type, managed_identity_id = Profile._try_parse_msi_account_name(account)
managed_identity_type, managed_identity_id = Profile._parse_managed_identity_account(account)

if in_cloud_console() and account[_USER_ENTITY].get(_CLOUD_SHELL_ID):
# Cloud Shell
Expand Down Expand Up @@ -642,15 +642,18 @@ def get_subscription_id(self, subscription=None): # take id or name
return self.get_subscription(subscription)[_SUBSCRIPTION_ID]

@staticmethod
def _try_parse_msi_account_name(account):
msi_info, user = account[_USER_ENTITY].get(_ASSIGNED_IDENTITY_INFO), account[_USER_ENTITY].get(_USER_NAME)

if user in [_SYSTEM_ASSIGNED_IDENTITY, _USER_ASSIGNED_IDENTITY]:
if not msi_info:
msi_info = account[_SUBSCRIPTION_NAME] # fall back to old persisting way
parts = msi_info.split('-', 1)
if parts[0] in MsiAccountTypes.valid_msi_account_types():
return parts[0], (None if len(parts) <= 1 else parts[1])
def _parse_managed_identity_account(account):
user_name = account[_USER_ENTITY][_USER_NAME]
if user_name == _SYSTEM_ASSIGNED_IDENTITY:
# The account contains:
# "assignedIdentityInfo": "MSI",
# "name": "systemAssignedIdentity",
return MsiAccountTypes.system_assigned, None
if user_name == _USER_ASSIGNED_IDENTITY:
# The account contains:
# "assignedIdentityInfo": "MSIClient-xxx"/"MSIObject-xxx"/"MSIResource-xxx",
# "name": "userAssignedIdentity",
return tuple(account[_USER_ENTITY][_ASSIGNED_IDENTITY_INFO].split('-', maxsplit=1))
return None, None

def _create_credential(self, account, tenant_id=None, client_id=None):
Expand Down
Loading

0 comments on commit 14084ad

Please sign in to comment.