-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Complete azure-identity prototype #5547
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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9720536
complete azure-identity prototype
chlowell 4531606
add long_description_content_type
chlowell 0a80886
use list constructor
chlowell 3ff29b6
test_credentials -> test_identity
chlowell 2d27280
more descriptive error messages
chlowell 19ce84b
let's call this 1.0
chlowell 50d2bdd
add tests and make EnvironmentCredential clearer
chlowell 71d6e4c
remove thumbprint
chlowell 46944fb
AZURE_PRIVATE_KEY_FILE -> AZURE_CLIENT_CERTIFICATE_PATH
chlowell 856cc22
cert credential inits take path to cert file
chlowell fd289df
todo re the other clouds in our sky
chlowell a3dde9e
this release is minor
chlowell 1d630a8
broaden quotation
chlowell da5ddd2
follow IMDS retry guidance
chlowell 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See LICENSE.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from msal.oauth2cli import JwtSigner | ||
|
|
||
| from .constants import OAUTH_ENDPOINT | ||
|
|
||
| try: | ||
| from typing import TYPE_CHECKING | ||
| except ImportError: | ||
| TYPE_CHECKING = False | ||
|
|
||
| if TYPE_CHECKING: | ||
| # pylint:disable=unused-import | ||
| from typing import Any, Mapping | ||
|
|
||
|
|
||
| class ClientSecretCredentialBase(object): | ||
| def __init__(self, client_id, secret, tenant_id, **kwargs): | ||
| # type: (str, str, str, Mapping[str, Any]) -> None | ||
| if not client_id: | ||
| raise ValueError("client_id should be the id of an Azure Active Directory application") | ||
| if not secret: | ||
| raise ValueError("secret should be an Azure Active Directory application's client secret") | ||
| if not tenant_id: | ||
| raise ValueError("tenant_id should be an Azure Active Directory tenant's id (also called its 'directory id')") | ||
| self._form_data = {"client_id": client_id, "client_secret": secret, "grant_type": "client_credentials"} | ||
| super(ClientSecretCredentialBase, self).__init__() | ||
|
|
||
|
|
||
| class CertificateCredentialBase(object): | ||
| def __init__(self, client_id, tenant_id, certificate_path, **kwargs): | ||
| # type: (str, str, str, Mapping[str, Any]) -> None | ||
| if not certificate_path: | ||
| # TODO: support PFX | ||
| raise ValueError("certificate_path must be the path to a PEM-encoded private key file") | ||
|
|
||
| super(CertificateCredentialBase, self).__init__() | ||
| auth_url = OAUTH_ENDPOINT.format(tenant_id) | ||
|
|
||
| with open(certificate_path) as pem: | ||
| private_key = pem.read() | ||
| signer = JwtSigner(private_key, "RS256") | ||
| client_assertion = signer.sign_assertion(audience=auth_url, issuer=client_id) | ||
| self._form_data = { | ||
| "client_assertion": client_assertion, | ||
| "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", | ||
| "client_id": client_id, | ||
| "grant_type": "client_credentials", | ||
| } |
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
Oops, something went wrong.
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.
Why are you retrying on 404?
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.
Right? According to the IMDS docs the endpoint returns 404 when it's updating, and clients should retry.
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'm not a big fan of having to create a list with >100 items. There are some things we can do to improve. Just off the top of my head, something like:
It does bastardize the eq method, though, so another version would be to change the simple
incheck in the retry policy to understand ranges as well...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.
Per the linked documentation (great find, btw :)), we should make sure our retry policy follows the suggested timeouts by default. We are trying to make sure that our libraries "do the right thing" (tm).
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.
Have done. I put #5628 on the backlog to track retry code range support.