Skip to content
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

Update sso credential provider to support token provider #4875

Merged
merged 8 commits into from
Jun 15, 2023

Conversation

wty-Bryant
Copy link
Contributor

@wty-Bryant wty-Bryant commented Jun 7, 2023

Update sso credential provider logic to support both sso token provider and legacy sso config.
The manual test of sso-session section support in shared config file follows steps below:

  • running the sso login flow with the AWS CLI
  • using the access token, calling S3 List Buckets on the configured AWS account
  • when the access token expires, re-calling S3 List buckets and see it succeed with an updated expiration in the SSO cache

This PR will resolve #4649 with prvious PRs on the same branch.


// Used by the SSOCredentialProvider if a token configuration
// profile is used in the shared config
SSOTokenProvider *SSOTokenProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aajtodd @lucix-aws i am curious about your opinion here.

in my V2 implementation i did this same thing.

at the time, not knowing Go that well (or the Go SDK), this seemed fine to me. but i think i prob should have used the TokenProvider interface rather than the SSOTokenProvider struct implementation. this is because our use of it doesnt seem to depend on anything specific to the SSOTokenProvider: its just calling RetrieveBearerToken. also, another benefit as @wty-Bryant pointed out in a conversation I had with him, if this were an interface we can more easily unit test it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance I think that's ok if you want to go down that route.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will try to implement the interface route

@isaiahvita isaiahvita requested a review from a team June 12, 2023 14:30

// Used by the SSOCredentialProvider if a token configuration
// profile is used in the shared config
SSOTokenProvider *SSOTokenProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance I think that's ok if you want to go down that route.

isaiahvita
isaiahvita previously approved these changes Jun 13, 2023
@isaiahvita isaiahvita dismissed their stale review June 13, 2023 19:20

accidentally approved, while still reviewing it. need to finish my review.

@@ -64,9 +65,12 @@ type Provider struct {
// parameter will be ignored.
CachedTokenFilepath string

// Used by the SSOCredentialProvider to judge if TokenProvider is configured
HasTokenProvider bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? bearer.TokenProvider is an interface, you can check if it's nil as you were before.

@@ -187,7 +187,8 @@ func resolveSSOCredentials(cfg *aws.Config, sharedCfg sharedConfig, handlers req
oidcClient := ssooidc.New(mySession, cfgCopy)
tokenProvider := ssocreds.NewSSOTokenProvider(oidcClient, cachedPath)
optFns = append(optFns, func(p *ssocreds.Provider) {
p.SSOTokenProvider = tokenProvider
p.HasTokenProvider = true
p.TokenProvider = *tokenProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we dereferencing here? This doesn't look right. The methods should probably be pointer receivers (looks like they are value receivers currently).

}, nil
},
},
HasTokenProvider: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasnt this field removed in the source code? why is it still in the test data?


// Used by the SSOCredentialProvider if a token configuration
// profile is used in the shared config
TokenProvider bearer.TokenProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: id like to discuss this as a team. my understanding is that this can be optional. and my understanding of Go is that the best way to signal optionality is via pointer types? but im wondering if thats only the case for primitive types and not object types?

Copy link
Contributor Author

@wty-Bryant wty-Bryant Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bear.TokenProvider is an interface so it can be nil which I think can mark it is optional? Interface doesn't support pointer receiver afaik

@wty-Bryant wty-Bryant merged commit bce0677 into feat-sso-session Jun 15, 2023
@wty-Bryant wty-Bryant deleted the feat-sso-session-cred-provider branch June 15, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants