-
Notifications
You must be signed in to change notification settings - Fork 905
GODRIVER-2728: Implement automatic Azure token acquisition callback #1703
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 82 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
a47681f
GODRIVER-2911: Initial attempted to untie the Gordian not, this will …
pmeredit 279635a
GODRIVER-2911: We're going to have to go this way and implement some …
pmeredit 9170d50
GODRIVER-2911: Ok, not great, but this will work
pmeredit 590662d
GODRIVER-2911: Renaming oidc sasl
pmeredit 171204c
GODRIVER-2911: Implement Operation based private sasl conversation fo…
pmeredit dbc5699
GODRIVER-2911: Privitize all the oidc sasl api, move AuthConfig up so…
pmeredit ff73302
GODRIVER-2911: Move things as necessary for authentication registration
pmeredit 0db7c3e
GODRIVER-2911: Let's use a bit better naming
pmeredit be99139
GODRIVER-2911: Add Reauth to Authenticators
pmeredit f400d18
GODRIVER-2911: Check point
pmeredit eed3dd5
GODRIVER-2911: Initial plumbing, the Client Authenticator is going to…
pmeredit 2ee93cc
GODRIVER-2911: Set authenticator in topology
pmeredit f6def8d
GODRIVER-2911: Set authenticator from Command to Operation
pmeredit bd5c9f2
GODRIVER-2911: Remove authenticator so we can readd it programmatically
pmeredit 36ba008
GODRIVER-2911: Remove authenticator so we can readd it programmatically
pmeredit a2a4029
GODRIVER-2911: Remove authenticator so we can readd it programatically
pmeredit d2c75f1
GODRIVER-2911: Add all that authenticator plumbing programmatically s…
pmeredit 4070d06
GODRIVER-2911: Thread through Authenticator
pmeredit 4a44090
GODRIVER-2911: Move OIDC back to auth package, yay
pmeredit 4ea9b9c
GODRIVER-2911: Move Config = AuthConfig to top of the file
pmeredit 2b5cde6
GODRIVER-2911: Update comment
pmeredit 368cedd
GODRIVER-2911: Some implementation
pmeredit e00e057
GODRIVER-2911: Add OIDCTokenGenID to Connection interface
pmeredit 1666c6c
GODRIVER-2911: Add OIDCTokenGenID to Connection interface for types i…
pmeredit d90ee3f
GODRIVER-2911: Actually add the oidc file, whoops
pmeredit 19ed261
GODRIVER-2911: Fix nil pointer error
pmeredit 4112208
GODRIVER-2911: Fix fmt
pmeredit 03c4c08
GODRIVER-2911: Fix build failure
pmeredit dac0468
GODRIVER-2911: well, that was silly
pmeredit 651af66
GODRIVER-2911: Add licenses and fix comment
pmeredit 6b16e91
GODRIVER-2911: Fix receiver names and remove authenticator field from…
pmeredit 26412ae
GODRIVER-2911: Fix many lints. Linter not running for me locally
pmeredit 98e8cbe
GODRIVER-2911: Fix lints
pmeredit 78fa217
GODRIVER-2911: Fix spelling error
pmeredit 46fa6f3
GODRIVER-2911: Testing checkpoint
pmeredit c6d23de
GODRIVER-2911: Fix config, fix spec auth
pmeredit c137399
GODRIVER-2911: Checkpoint
pmeredit 1be9498
GODRIVER-2911: OIDC working
pmeredit 8542f76
GODRIVER-2911: add machine_1_2
pmeredit 286525f
GODRIVER-2911: add machine_1_2, actually helps to call it
pmeredit 4013ccb
GODRIVER-2911: Remove unneeded debugging
pmeredit 83ffaa7
GODRIVER-2911: Add more tests
pmeredit f33dca7
GODRIVER-2911: Updates
pmeredit 3c00307
GODRIVER-2911: Change to using errors
pmeredit 590a3c8
GODRIVER-2911: Add more tests that do not require fail points
pmeredit e88ebe7
GODRIVER-2911: See if it fails with 10 tries
pmeredit 58f0f42
GODRIVER-2911: Not sure how to get fail points working
pmeredit 1be1e13
GODRIVER-2911: Appease linter
pmeredit 6e1fd3a
GODRIVER-2911: Appease linter
pmeredit 640907d
GODRIVER-2911: Change 3_3 to use fail on find, add 4_1
pmeredit 4d30705
GODRIVER-2911: Manually create fail points
pmeredit 9dd40c9
GODRIVER-2911: This is working except 3_3 seems to be hanging
pmeredit b343ebb
GODRIVER-2911: Tests all passing
pmeredit 5240a91
GODRIVER-2911: Appease linter
pmeredit 0cdd7a2
GODRIVER-2911: Remove test func that is unneeded
pmeredit 4613c5f
Update x/mongo/driver/auth/oidc.go
pmeredit 40998b6
SQL-1937: Remove spurious authenticators, move mutex
pmeredit 2d09cc5
SQL-1937: Change Reauth interface
pmeredit d45c7e4
Update Makefile
pmeredit ae9c34f
GODRIVER-2911: Apply httpclient patch
pmeredit 1d86914
GODRIVER-2911: Fix races
pmeredit 30ed4c4
GODRIVER-2911: Back out changes to sasl, add comment, remove Println …
pmeredit 519205c
GODRIVER-2911: Move public OIDC configuration types into public, non-…
pmeredit 5f0c68d
GODRIVER-2911: Improve comment
pmeredit 6410109
GODRIVER-2728: Add azurecallback support
pmeredit 7dc89cb
GODRIVER-2728: Update test framework
pmeredit b84cc12
GODRIVER-2728: No idea what this incredibly unhelpful shellscript fai…
pmeredit 6a3af5a
GODRIVER-2911: Update script comment
pmeredit 386389d
GODRIVER-2728: cp
pmeredit 7340ddd
GODRIVER-2911: Use conversion functions instead of type redeclarations
pmeredit 902bb9b
Merge branch 'GODRIVER-2911' into GODRIVER-2728
pmeredit e86b80b
GODRIVER-2728: Appears to be working once I can figure out the json side
pmeredit 9878c73
GODRIVER-2728: Should work now
pmeredit aa887de
GODRIVER-2728: Working, remove debugging
pmeredit 39d045b
GODRIVER-2728: Cleanup
pmeredit c48ffec
Merge branch 'v1' into GODRIVER-2728
pmeredit 0a4c641
GODRIVER-2728: Merge v1
pmeredit ac1782b
GODRIVER-2728: Merge v1
pmeredit 95c22f3
GODRIVER-2728: Merge v1
pmeredit f081162
GODRIVER-2728: Check error
pmeredit 1bcf07e
Update x/mongo/driver/auth/oidc.go
pmeredit d825e33
GODRIVER-2728: Fix spelling
pmeredit 4450d5f
Update x/mongo/driver/auth/oidc.go
pmeredit 8735082
GODRIVE-2728: Use auto deserialize conversion
pmeredit c9990a2
Merge branch 'v1' into GODRIVER-2728
pmeredit 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ export TEST_AUTH_OIDC=1 | |
export COVERAGE=1 | ||
export AUTH="auth" | ||
|
||
make -s evg-test-oidc-auth | ||
$1 |
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 |
---|---|---|
|
@@ -8,8 +8,11 @@ package auth | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
@@ -166,10 +169,15 @@ func (oa *OIDCAuthenticator) providerCallback() (OIDCCallback, error) { | |
} | ||
|
||
switch env { | ||
// TODO GODRIVER-2728: Automatic token acquisition for Azure Identity Provider | ||
case azureEnvironmentValue: | ||
resource, ok := oa.AuthMechanismProperties[resourceProp] | ||
if !ok { | ||
return nil, newAuthError("resource must be specified for Azure OIDC", nil) | ||
pmeredit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return getAzureOIDCCallback(oa.userName, resource, oa.httpClient), nil | ||
// TODO GODRIVER-2806: Automatic token acquisition for GCP Identity Provider | ||
// This is here just to pass the linter, it will be fixed in one of the above tickets. | ||
case azureEnvironmentValue, gcpEnvironmentValue: | ||
case gcpEnvironmentValue: | ||
return func(ctx context.Context, args *OIDCArgs) (*OIDCCredential, error) { | ||
return nil, fmt.Errorf("automatic token acquisition for %q not implemented yet", env) | ||
}, fmt.Errorf("automatic token acquisition for %q not implemented yet", env) | ||
|
@@ -178,6 +186,53 @@ func (oa *OIDCAuthenticator) providerCallback() (OIDCCallback, error) { | |
return nil, fmt.Errorf("%q %q not supported for MONGODB-OIDC", environmentProp, env) | ||
} | ||
|
||
// getAzureOIDCCallback returns the callback for the Azure Identity Provider. | ||
func getAzureOIDCCallback(clientID string, resource string, httpClient *http.Client) OIDCCallback { | ||
// return the callback parameterized by the clientID and resource, also passing in the user | ||
// configured httpClient. | ||
return func(ctx context.Context, args *OIDCArgs) (*OIDCCredential, error) { | ||
resource = url.QueryEscape(resource) | ||
var uri string | ||
if clientID != "" { | ||
uri = fmt.Sprintf("http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=%s&client_id=%s", resource, clientID) | ||
} else { | ||
uri = fmt.Sprintf("http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=%s", resource) | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) | ||
if err != nil { | ||
return nil, newAuthError("error creating http request to Azure Identity Provider", err) | ||
} | ||
req.Header.Add("Metadata", "true") | ||
req.Header.Add("Accept", "application/json") | ||
resp, err := httpClient.Do(req) | ||
if err != nil { | ||
return nil, newAuthError("error getting access token from Azure Identity Provider", err) | ||
} | ||
defer resp.Body.Close() | ||
var azureResp struct { | ||
AccessToken string `json:"access_token"` | ||
ExpiresOn string `json:"expires_on"` | ||
} | ||
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. Optional: You can skip the separate integer parsing step by using the E.g. var azureResp struct {
AccessToken string `json:"access_token"`
ExpiresOn int64 `json:"expires_on,string"`
} 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. Oh, cool! |
||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, newAuthError(fmt.Sprintf("failed to get a valid response from Azure Identity Provider, http code: %d", resp.StatusCode), nil) | ||
} | ||
err = json.NewDecoder(resp.Body).Decode(&azureResp) | ||
if err != nil { | ||
return nil, newAuthError("failed parsing result from Azure Identity Provider", err) | ||
} | ||
expiresOn, err := strconv.ParseInt(azureResp.ExpiresOn, 10, 64) | ||
if err != nil { | ||
return nil, newAuthError("failed converting expiration field from Azure Identity Provider to int64", err) | ||
} | ||
expiresAt := time.Unix(expiresOn, 0) | ||
return &OIDCCredential{ | ||
AccessToken: azureResp.AccessToken, | ||
ExpiresAt: &expiresAt, | ||
}, nil | ||
} | ||
} | ||
|
||
func (oa *OIDCAuthenticator) getAccessToken( | ||
ctx context.Context, | ||
conn driver.Connection, | ||
|
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.
the test is compiled ahead of time and just the compiled exe is ran on the azure vm. This matters more for gcp vm which is far slower, but it's good to be consistent