-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[Profile] BREAKING CHANGE: az login
: --password
no longer accepts service principal certificate
#30092
[Profile] BREAKING CHANGE: az login
: --password
no longer accepts service principal certificate
#30092
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,20 +264,10 @@ def test_service_principal_auth_client_assertion(self): | |
assert client_credential == {'client_assertion': 'test_jwt'} | ||
|
||
def test_build_credential(self): | ||
# secret | ||
cred = ServicePrincipalAuth.build_credential(secret_or_certificate="test_secret") | ||
# client_secret | ||
cred = ServicePrincipalAuth.build_credential(client_secret="test_secret") | ||
assert cred == {"client_secret": "test_secret"} | ||
|
||
# secret with '~', which is preserved as-is | ||
cred = ServicePrincipalAuth.build_credential(secret_or_certificate="~test_secret") | ||
assert cred == {"client_secret": "~test_secret"} | ||
Comment on lines
-271
to
-273
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. The secret is no longer expanded, so this check is meaningless. |
||
|
||
# certificate as password (deprecated) | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
test_cert_file = os.path.join(current_dir, 'sp_cert.pem') | ||
cred = ServicePrincipalAuth.build_credential(secret_or_certificate=test_cert_file) | ||
assert cred == {'certificate': test_cert_file} | ||
|
||
# certificate | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
test_cert_file = os.path.join(current_dir, 'sp_cert.pem') | ||
|
@@ -297,7 +287,7 @@ def test_build_credential(self): | |
cred = ServicePrincipalAuth.build_credential(certificate=test_cert_file, use_cert_sn_issuer=True) | ||
assert cred == {'certificate': test_cert_file, 'use_cert_sn_issuer': True} | ||
|
||
# client assertion | ||
# client_assertion | ||
cred = ServicePrincipalAuth.build_credential(client_assertion="test_jwt") | ||
assert cred == {"client_assertion": "test_jwt"} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,12 @@ | |
AccessToken = namedtuple("AccessToken", ["token", "expires_on"]) | ||
|
||
|
||
PASSWORD_CERTIFICATE_WARNING = ( | ||
"The error may be caused by passing a service principal certificate with --password. " | ||
"Please note that --password no longer accepts a service principal certificate. " | ||
"To pass a service principal certificate, use --certificate instead.") | ||
|
||
|
||
def aad_error_handler(error, **kwargs): | ||
""" Handle the error from AAD server returned by ADAL or MSAL. """ | ||
|
||
|
@@ -30,17 +36,21 @@ def aad_error_handler(error, **kwargs): | |
"below, please mention the hostname '%s'", socket.gethostname()) | ||
|
||
error_description = error.get('error_description') | ||
error_codes = error.get('error_codes') | ||
|
||
# Build recommendation message | ||
login_command = _generate_login_command(**kwargs) | ||
login_message = ( | ||
# Cloud Shell uses IMDS-like interface for implicit login. If getting token/cert failed, | ||
# we let the user explicitly log in to AAD with MSAL. | ||
"Please explicitly log in with:\n{}" if error.get('error') == 'broker_error' | ||
else "Interactive authentication is needed. Please run:\n{}").format(login_command) | ||
if error_codes and 7000215 in error_codes: | ||
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. What's the full message of 7000215? 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. It is in the PR description:
|
||
recommendation = PASSWORD_CERTIFICATE_WARNING | ||
else: | ||
login_command = _generate_login_command(**kwargs) | ||
recommendation = ( | ||
# Cloud Shell uses IMDS-like interface for implicit login. If getting token/cert failed, | ||
# we let the user explicitly log in to AAD with MSAL. | ||
"Please explicitly log in with:\n{}" if error.get('error') == 'broker_error' | ||
else "Interactive authentication is needed. Please run:\n{}").format(login_command) | ||
|
||
from azure.cli.core.azclierror import AuthenticationError | ||
raise AuthenticationError(error_description, msal_error=error, recommendation=login_message) | ||
raise AuthenticationError(error_description, msal_error=error, recommendation=recommendation) | ||
|
||
|
||
def _generate_login_command(scopes=None, claims=None): | ||
|
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.
ConfidentialClientApplication
'sclient_credential
is a keyword argument. #29439 passes a positional argument, breaking tests such asazure.cli.core.auth.tests.test_identity.TestIdentity.test_login_with_service_principal_certificate
.Also see Azure/azure-cli-dev-tools#318