-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Core] ADAL to MSAL migration #19853
Conversation
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/azure/cli/command_modules/vm/custom.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_app_service_environment_commands_thru_mock.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/azure/cli/core/_msal.py # src/azure-cli-core/azure/cli/core/_profile.py # src/azure-cli-core/azure/cli/core/tests/test_profile.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/azure/cli/core/_profile.py # src/azure-cli-core/azure/cli/core/adal_authentication.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
# Conflicts: # src/azure-cli-core/HISTORY.rst # src/azure-cli-core/azure/cli/core/__init__.py # src/azure-cli-core/azure/cli/core/_profile.py # src/azure-cli-core/azure/cli/core/adal_authentication.py # src/azure-cli-core/azure/cli/core/tests/test_profile.py # src/azure-cli-core/azure/cli/core/util.py # src/azure-cli-core/setup.py # src/azure-cli/HISTORY.rst # src/azure-cli/azure/cli/__main__.py # src/azure-cli/azure/cli/command_modules/vm/custom.py # src/azure-cli/requirements.py3.Darwin.txt # src/azure-cli/requirements.py3.Linux.txt # src/azure-cli/requirements.py3.windows.txt # src/azure-cli/setup.py
Credential locationIf you are curious, the token cache and service principal entries are saved under
⚠ They are private to Azure CLI. Please don’t decrypt or read from them in any way.We don’t use Azure Identity’s shared token cache Supported APIIf you are an Azure CLI command module or extension, you may
If you are another application or SDK, please follow https://docs.microsoft.com/en-us/cli/azure/msal-based-azure-cli |
Why Azure Identity is dropped in the migrationAzure Identity has several limitations: No logoutAzure Identity doesn't have a logout functionality which is required by No
|
Close #18944
Description
As ADAL has been deprecated, Azure CLI needs to be migrated from ADAL to MSAL.
How CLI authentication works
During initialization:
azure.cli.core.commands.client_factory._get_mgmt_service_client
callsazure.cli.core._profile.Profile.get_login_credentials
to get an instance ofCredentialAdaptor
._get_mgmt_service_client
feeds theCredentialAdaptor
instance into the SDK client.During invocation:
CredentialAdaptor
azure.core.pipeline.policies._authentication.BearerTokenCredentialPolicy
calls theget_token
method on theCredentialAdaptor
.msrest.pipeline.requests.RequestsCredentialsPolicy
calls thesigned_session
method on theCredentialAdaptor
,signed_session
callsget_token
.UserCredential
/ServicePrincipalCredential
Since Azure Identity has been dropped for User and Service Principal authentication, the MSAL integration is implemented in
src/azure-cli-core/azure/cli/core/auth/msal_authentication.py
.There are 2 kinds of credentials:
UserCredential
(inherit fromPublicClientApplication
)ServicePrincipalCredential
(inherit fromConfidentialClientApplication
)They all expose
get_token
so that they implementazure.core.credentials.TokenCredential
.Cross-tenant authentication
Cross-tenant authentication is implemented by simply adding header
x-ms-authorization-auxiliary
by_prepare_mgmt_client_kwargs_track2
.There were asks (Azure/azure-sdk-for-python#8313, Azure/azure-sdk-for-python#17764) on Python SDK to implement cross-tenant authentication but it hasn't been implemented.
Previously, CLI considered implementing a custom policy
ExternalAuthenticationPolicy
to achieve it, but is not implemented either due to its unnecessary complexity. Querying long-running operation result doesn't need auxiliary token, so no need to implement theget_token
callback.BREAKING CHANGES
az account show
/az ad sp create-for-rbac
:--sdk-auth
is removed ([Profile] Deprecate--sdk-auth
#19414).~/.azure/accessTokens.json
Changes on following objects are not considered breaking changes, but they may be used by end users or libraries:
azure.cli.core.adal_authentication
is removed, includingAdalAuthentication
_token_retriever
_external_tenant_token_retriever
If you depend on them, consider using public methods:
azure.cli.core._profile.Profile.get_raw_token
azure.cli.core._profile.Profile.get_login_credentials
Testing Guide
Test for different account types
Test for different SDK scenarios
Test for different clouds
References