Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Skip get_all_tokens for managed identity
  • Loading branch information
jiasli committed Feb 22, 2021
commit b6cedae85a2f22cbe37192ce17607a473be84d6e
5 changes: 5 additions & 0 deletions src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def get_login_credentials(self, resource=None, subscription_id=None, aux_subscri

identity_type, identity_id = Profile._try_parse_msi_account_name(account)

# Make sure external_tenants_info only contains real external tenant (no current tenant).
external_tenants_info = []
if aux_tenants:
external_tenants_info = [tenant for tenant in aux_tenants if tenant != account[_TENANT_ID]]
Expand All @@ -573,6 +574,10 @@ def get_login_credentials(self, resource=None, subscription_id=None, aux_subscri
if sub[_TENANT_ID] != account[_TENANT_ID]:
external_tenants_info.append(sub[_TENANT_ID])

if external_tenants_info and (identity_type or in_cloud_console()):
raise CLIError("Cross-tenant authentication is not supported by managed identity and Cloud Shell. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLIError is deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is difficult to classify.

"Please run `az login` with a user account or a service principal.")

if identity_type is None:
def _retrieve_token(sdk_resource=None):
# When called by
Expand Down
11 changes: 4 additions & 7 deletions src/azure-cli-core/azure/cli/core/commands/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,11 @@ def _get_mgmt_service_client(cli_ctx,
# https://github.com/Azure/azure-sdk-for-python/issues/8313
# As a temporary workaround, manually add external tokens to 'x-ms-authorization-auxiliary' header.
# https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/authenticate-multi-tenant
if aux_subscriptions or aux_tenants:
if getattr(cred, "_external_tenant_token_retriever", None):
_, _, _, external_tenant_tokens = cred.get_all_tokens(*resource_to_scopes(resource))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is *

Copy link
Member Author

@jiasli jiasli Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# external_tenant_tokens can be [] if no external tenant is involved.
if external_tenant_tokens:
# Hard-code scheme to 'Bearer' as _BearerTokenCredentialPolicyBase._update_headers does.
client_kwargs['headers']['x-ms-authorization-auxiliary'] = \
', '.join("Bearer {}".format(t[1]) for t in external_tenant_tokens)
# Hard-code scheme to 'Bearer' as _BearerTokenCredentialPolicyBase._update_headers does.
client_kwargs['headers']['x-ms-authorization-auxiliary'] = \
', '.join("Bearer {}".format(t[1]) for t in external_tenant_tokens)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a pipeline support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a new policy and add it to the pipeline in the future, utilizing Azure/azure-sdk-for-python#17340.


if subscription_bound:
client = client_type(cred, subscription_id, **client_kwargs)
Expand Down