-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3467 OIDC: Automatic token acquisition for Azure Identity Provider #1443
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
112 commits
Select commit
Hold shift + click to select a range
d7265bf
PYTHON-3845 OIDC: Implement Machine Callback Mechanism
blink1073 cc838c5
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 4c22587
run unified tests in oidc test
blink1073 0485e82
fix path handling
blink1073 ae77133
debug
blink1073 e5b31cb
fix path handling
blink1073 fee9cf4
handle db_ip
blink1073 e11865a
handle srv hosts
blink1073 fb7470d
PYTHON-3845 OIDC: Implement Machine Callback Mechanism
blink1073 131de6a
undo test comment out
blink1073 1d7011f
change name to custom_token_callback
blink1073 36d6c8b
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 9c961e9
simplify custom callback and start prose tests
blink1073 c0eed02
fix placeholder handling
blink1073 65e47a1
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 f26c60a
wip implement OIDC tests
blink1073 7897053
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 a95479c
Use callback class and update tests
blink1073 e55d34e
Fix typing and test
blink1073 480a648
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 c085b50
fix tests
blink1073 07b8c6d
fix default port
blink1073 5b991c3
lint
blink1073 2cd3aa7
add reauth succeeds prose test for machine
blink1073 e221ebf
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 5c0f770
use dataclasses in callbacks
blink1073 dae8124
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 e563840
update for spec changes
blink1073 9a4d6b0
add updated spec tests
blink1073 789a55c
fix test and typing
blink1073 ac8e90e
PYTHON-3467 OIDC: Automatic token acquisition for Azure Identity Prov…
blink1073 f35a316
wip
blink1073 45ba0af
fix handling of oidc admin user
blink1073 d6e8df6
fix uri
blink1073 ce8527c
fix handling of token aud
blink1073 abcc9b6
try using parse uri
blink1073 d9e6d85
fix lookup
blink1073 744a24e
try with token client
blink1073 7b92310
add azure support in unified tests
blink1073 7ecbf61
fix provider name
blink1073 d591efe
fix auth mech name
blink1073 c63c795
fix response handling
blink1073 ddcc27b
skip prose tests for now
blink1073 fded240
add debug print
blink1073 39a26bc
fix aud
blink1073 c522503
add human tests back
blink1073 d30d099
add test for multiple client_ids
blink1073 fa0839a
update prose test
blink1073 30b1230
fixes
blink1073 9bf112a
updates based on spec discussion
blink1073 6f315ce
try with another &&
blink1073 10319dd
debug
blink1073 51955e6
make sure files are up to date
blink1073 4026097
fix delay logic
blink1073 9519880
enable oidc auth mech
blink1073 d0b8575
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 385b1d1
wip implement prose tests
blink1073 b0b5ee5
update azure handling
blink1073 59c31ff
fix handling of azure username
blink1073 0caba87
add debug info
blink1073 df8a069
clear username and pwd
blink1073 317bb44
try with username
blink1073 4dbcafc
force the username
blink1073 0e6f0e1
fix username
blink1073 a6f5211
clean up
blink1073 908d367
debug
blink1073 8f719d5
cleanup
blink1073 cf8c7a4
fix test
blink1073 966145a
Update connection string tests
blink1073 1daaf8c
fix typing
blink1073 ea46340
fix handling of username and passwd
blink1073 bd4d320
fix token name
blink1073 c2e6749
update typings
blink1073 770124e
fix token handling
blink1073 14da786
consolidate callbacks and update mech property names
blink1073 e7b9208
cleanup
blink1073 b5c16de
fix test
blink1073 93960c8
add new unified test
blink1073 7e1d685
update prose tests
blink1073 5ff9c05
fix azure vm teardown
blink1073 0dec6b3
Update unified tests
blink1073 528f9e1
Cleanup
blink1073 53ae91f
update for spec changes
blink1073 88bea64
more updates for spec changes
blink1073 ea75285
wip oidc updates
blink1073 b8b31a1
Refactor auth logic
blink1073 80713b4
more refactor
blink1073 7a7ce6f
more refactor and prose implementation
blink1073 ac8c6ae
more refactor and prose implementation
blink1073 70707c0
update based on discussion today
blink1073 b72d0ab
more cleanup
blink1073 b81f405
simplify spec auth
blink1073 1bb217f
address failing tests
blink1073 64022c7
more updates
blink1073 6866f64
try pinning pyopenssl
blink1073 1b043a4
try pinning service_identity
blink1073 9eb2d40
update prose tests
blink1073 c9e3d98
update for spec changes
blink1073 4776a1d
update for spec changes
blink1073 f012dd4
Fix test
blink1073 93620d4
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 3624a8f
undo resync-specs change
blink1073 dc5a239
undo change to oscp reqs
blink1073 55ee678
restore GSSAPI tests
blink1073 170272b
undo changes to specs
blink1073 7040640
fix typing
blink1073 87151bf
Update pymongo/auth_oidc.py
blink1073 b3decdd
Update test/auth_oidc/test_auth_oidc.py
blink1073 23ae825
Update test/auth_oidc/test_auth_oidc.py
blink1073 2051aad
Update test/auth_oidc/test_auth_oidc.py
blink1073 586f67a
Update test/auth_oidc/test_auth_oidc.py
blink1073 628bd03
address review
blink1073 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,56 @@ | ||
# Copyright 2023-present MongoDB, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Azure helpers.""" | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import Any, Optional | ||
from urllib.request import Request, urlopen | ||
|
||
|
||
def _get_azure_response( | ||
resource: str, object_id: Optional[str] = None, timeout: float = 5 | ||
) -> dict[str, Any]: | ||
url = "http://169.254.169.254/metadata/identity/oauth2/token" | ||
url += "?api-version=2018-02-01" | ||
url += f"&resource={resource}" | ||
if object_id: | ||
url += f"&object_id={object_id}" | ||
headers = {"Metadata": "true", "Accept": "application/json"} | ||
request = Request(url, headers=headers) # noqa: S310 | ||
print("fetching url", url) # noqa: T201 | ||
try: | ||
with urlopen(request, timeout=timeout) as response: # noqa: S310 | ||
status = response.status | ||
body = response.read().decode("utf8") | ||
except Exception as e: | ||
msg = "Failed to acquire IMDS access token: %s" % e | ||
raise ValueError(msg) from None | ||
|
||
if status != 200: | ||
msg = "Failed to acquire IMDS access token." | ||
raise ValueError(msg) | ||
try: | ||
data = json.loads(body) | ||
except Exception: | ||
raise ValueError("Azure IMDS response must be in JSON format.") from None | ||
|
||
for key in ["access_token", "expires_in"]: | ||
if not data.get(key): | ||
msg = "Azure IMDS response must contain %s, but was %s." | ||
msg = msg % (key, body) | ||
raise ValueError(msg) | ||
|
||
return data |
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.
Humor me if this is a silly question. Is the
${PREPARE_SHELL}
command responsible for adding in the new files for the commit?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, it sets up common env variables.