-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Profile] az login: Add --certificate for authenticating with service principal certificate
#30091
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ | |
| For more details, see https://go.microsoft.com/fwlink/?linkid=2276314 | ||
|
|
||
|
|
||
| [WARNING] Passing the service principal certificate with `--password` is deprecated and will be removed | ||
| by version 2.74. Please use `--certificate` instead. | ||
|
|
||
|
|
||
| To log in with a service principal, specify --service-principal. | ||
|
|
||
|
|
||
|
|
@@ -35,8 +39,8 @@ | |
| text: az login -u [email protected] -p VerySecret | ||
| - name: Log in with a service principal using client secret. Use -p=secret if the first character of the password is '-'. | ||
| text: az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p VerySecret --tenant contoso.onmicrosoft.com | ||
| - name: Log in with a service principal using client certificate. | ||
| text: az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p ~/mycertfile.pem --tenant contoso.onmicrosoft.com | ||
| - name: Log in with a service principal using certificate. | ||
| text: az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 --certificate ~/mycertfile.pem --tenant contoso.onmicrosoft.com | ||
| - name: Log in with a system-assigned managed identity. | ||
| text: az login --identity | ||
| - name: Log in with a user-assigned managed identity. You must specify the client ID, object ID or resource ID of the user-assigned managed identity with --username. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,7 @@ def login(cmd, username=None, password=None, tenant=None, scopes=None, allow_no_ | |
| # Device code flow | ||
| use_device_code=False, | ||
| # Service principal | ||
| service_principal=None, use_cert_sn_issuer=None, client_assertion=None, | ||
| service_principal=None, certificate=None, use_cert_sn_issuer=None, client_assertion=None, | ||
| # Managed identity | ||
| identity=False): | ||
| """Log in to access Azure subscriptions""" | ||
|
|
@@ -148,7 +148,7 @@ def login(cmd, username=None, password=None, tenant=None, scopes=None, allow_no_ | |
| logger.warning(_CLOUD_CONSOLE_LOGIN_WARNING) | ||
|
|
||
| if username: | ||
| if not (password or client_assertion): | ||
| if not (password or client_assertion or certificate): | ||
| try: | ||
| password = prompt_pass('Password: ') | ||
| except NoTTYException: | ||
|
|
@@ -158,7 +158,10 @@ def login(cmd, username=None, password=None, tenant=None, scopes=None, allow_no_ | |
|
|
||
| if service_principal: | ||
| from azure.cli.core.auth.identity import ServicePrincipalAuth | ||
| password = ServicePrincipalAuth.build_credential(password, client_assertion, use_cert_sn_issuer) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing keyword arguments as positional arguments is fragile and may break unexpectedly.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, I am not a big fan of positional arguments in general. |
||
| password = ServicePrincipalAuth.build_credential( | ||
| secret_or_certificate=password, | ||
| certificate=certificate, use_cert_sn_issuer=use_cert_sn_issuer, | ||
| client_assertion=client_assertion) | ||
|
|
||
| login_experience_v2 = cmd.cli_ctx.config.getboolean('core', 'login_experience_v2', fallback=True) | ||
| # Send login_experience_v2 config to telemetry | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shall we also add certificate check in
azure-cli/src/azure-cli/azure/cli/command_modules/profile/custom.py
Lines 123 to 126 in 6c32c4d
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, as missing all 3 types of credentials will result in prompting for secrets.
Uh oh!
There was an error while loading. Please reload this page.
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.
I mean, if user pass in
--certificatetogether with--identity/--use-device-code, we should raise error as well, right?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.
--certificatewill be discarded in that case. As you can see,client_assertionis not checked either. We can do that in a separate PR.