-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add support to use AZD as token credential provider #31728
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
base: dev
Are you sure you want to change the base?
Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
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.
Pull Request Overview
This PR adds support to use AZD as the token credential provider by enabling the AZ_USE_AZD_AUTH environment variable. It updates dependency versions in requirement files and setup.py and adds a new authentication path in _profile.py that leverages AzureDeveloperCliCredential.
- Added azure-identity dependency in Windows, Linux, and Darwin requirement files.
- Updated dependency version constraints in setup.py.
- Introduced AZD authentication flow in get_raw_token with a fallback to standard authentication.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/azure-cli/requirements.py3.*.txt | Add azure-identity version 1.15.0 dependency |
| src/azure-cli-core/setup.py | Update dependency version for azure-identity and msal[broker] |
| src/azure-cli-core/azure/cli/core/_profile.py | Add support for AZD authentication via the AZ_USE_AZD_AUTH env var |
Comments suppressed due to low confidence (2)
src/azure-cli-core/azure/cli/core/_profile.py:350
- Please ensure that the new AZD authentication flow (lines 350-387) is covered by tests, especially for handling token generation and fallback behavior when an exception occurs.
# Check if AZ_USE_AZD_AUTH environment variable is set
src/azure-cli-core/setup.py:48
- There is a potential inconsistency: the requirements files enforce azure-identity==1.15.0 while setup.py requires >=1.12.0. Consider aligning these versions to ensure consistent dependency resolution.
'azure-identity>=1.12.0',
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
|
This will be a HUGE improvement in the dev experience flow! Azure customers will appreciate this. |
|
Thanks @jiasli and @yonzhan for looking into this. This enhancement will significantly improve the experience for AZD users allowing them to seamlessly leverage AZD's authn in AZ. Also, the change appears to be well scoped and should not affect AZ's call flow unless the AZ_USE_AZD_AUTH environment variable is specifically set. Nice change @vhvb1989 |
|
|
||
| def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=None): | ||
| # Check if AZ_USE_AZD_AUTH environment variable is set | ||
| if os.environ.get('AZ_USE_AZD_AUTH'): |
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.
Only changing get_raw_token is far from enough.
get_raw_tokenis only designed for getting the raw token. It cannot be used with Python SDK. To invoke Python SDK, it is required to callget_login_credentialsto get the credential.- The account (returned by
az account show) containing the current subscription and tenant must also be set. This makesget_subscriptionwork, which is required byget_login_credentials:account = self.get_subscription(subscription_id)
| # Check if AZ_USE_AZD_AUTH environment variable is set | ||
| if os.environ.get('AZ_USE_AZD_AUTH'): | ||
| try: | ||
| from azure.identity import AzureDeveloperCliCredential |
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.
Azure CLI dropped the dependency on azure-identity in #22124 and has no plan to add it back, as azure-identity frequently causes dependency conflicts.
|
We currently don't want to introduce dependency on AZD or An alternative approach is for Azure CLI to support bring-your-own access token (#31575) and feed the access token into Azure CLI via environment variables. This will allow Azure CLI to use external credentials. I understand this may not be the best approach as the user will need to use AZD to get the access token and set the environment variable for Azure CLI. The user also needs to take scopes and token expiration into consideration while feeding the access token into Azure CLI. Or, we may reuse environment variables from #31575, and invoke Azure CLI with export AZURE_CLI_ACCESS_TOKEN=AZD # Use a special value for calling AzureDeveloperCliCredential
export AZURE_CLI_SUBSCRIPTION_ID=<subscription_id>
export AZURE_CLI_TENANT_ID=<tenant_id> |
This PR makes it possible to set
AZ_USE_AZD_AUTHenv var to makeazto useazdto generate the access tokens.By having this feature, AZD will be able to call AZ and set the ENV VAR as part of the process invocation, effectively re-using AZD's current authentication for AZ.
For example, using az inside azd's hooks would no longer require folks to login az and azd, enhancing the user experience.
This change should have no effect if the ENV VAR is not set.