-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Honor scopes specified by Track 2 SDK #15184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Core |
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| n.token_credential, _, _ = profile.get_login_credentials( | ||
| resource="https://storage.azure.com", subscription_id=n._subscription) | ||
| n.token_credential, _, _ = profile.get_login_credentials(subscription_id=n._subscription) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scope is now managed by Track 2 Storage SDK (azure/multiapi/storagev2/blob/v2019_12_12/_shared/constants.py:25):
STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"|
Unfortunately, due an incorrect
|
| # Deal with an old Track 2 SDK issue where the default credential_scopes is extended with | ||
| # custom credential_scopes. Instead, credential_scopes should be replaced by custom credential_scopes. | ||
| # https://github.com/Azure/azure-sdk-for-python/issues/12947 | ||
| # We simply remove the first one if there are multiple scopes provided. | ||
| if len(scopes) > 1: | ||
| scopes = scopes[1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a patch to handle issue Azure/azure-sdk-for-python#12947 in old Track 2 SDKs.
# Conflicts: # src/azure-cli-core/azure/cli/core/adal_authentication.py
| :rtype: str | ||
| """ | ||
| scope = scopes[0] | ||
| if scope.endswith(".default"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if scope.endswith(".default"): [](start = 4, length = 30)
Do we need make this case insensitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. .default is the only supported form. See The /.default scope.
|
|
||
| # Trim extra ending slashes. https://datalake.azure.net// -> https://datalake.azure.net/ | ||
| scope = scope.rstrip('/') + '/' | ||
| return scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that "scope" is https://management.core.windows.net/ or it should be https://management.core.windows.net?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. See
| active_directory_resource_id='https://management.core.windows.net/', |
| :return: The ADAL resource | ||
| :rtype: str | ||
| """ | ||
| scope = scopes[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we only support one scope now as it is a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scopes must all be from a single resource, along with OIDC scopes (profile, openid, email)
| :param resource: The ADAL resource ID | ||
| :return: A list of scopes | ||
| """ | ||
| if 'datalake' in resource or 'batch' in resource or 'database' in resource: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that we move this tricky logic from core to module level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Currently resource_to_scopes is only called by _get_mgmt_service_client. We should actually remove this tricky logic totally from this function. Will do in a separate PR.
jsntcy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
Fix #15179
Issue
In
scopes(resource) is managed by Azure CLIscopes(resource) is managed by SDKFor example, for Track 2 SDK mgmt-plane
SubscriptionClientConfiguration:For Track 2 SDK data-plane
AzureAppConfigurationClient:But in
AdalAuthentication.get_token,scopesis not honored (discarded), resulting in getting a token for a wrongscopes(ARMhttps://management.core.windows.net/by default):azure-cli/src/azure-cli-core/azure/cli/core/adal_authentication.py
Lines 61 to 67 in c2b9a2c
Fix
This PR fixes the issue by honoring the
scopesspecified by Track 2 SDK.Testing Guide
User Identity
Managed Identity