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

Add sso session and token provider support #4885

Merged
merged 43 commits into from
Jul 6, 2023
Merged

Conversation

wty-Bryant
Copy link
Contributor

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 generated, 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 cached token

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

Tianyi Wang and others added 30 commits May 23, 2023 17:56
# Conflicts:
#	CHANGELOG_PENDING.md
Tianyi Wang and others added 8 commits May 31, 2023 15:32
sync main to feat-sso-session
* Merge logic of resolving sso section in shared config file

* Modify and Merge shared config unit test case

* Modify and Merge logic of shared config loaded from files

---------

Co-authored-by: Tianyi Wang <wty@amazon.com>
sync main into current branch
sync main branch into current branch
* Update and Merge logic of sso credential provider to support token provider

* Add and Merge sso credential provider unit test data

* Modify and Merge sso credential provider's token provider field and unit test

* Modify and Merge sso credential provider's token provider and unit test

* Modify and Merge sso credential provider's unit test

---------

Co-authored-by: Tianyi Wang <wty@amazon.com>
sync main into current branch
Copy link
Contributor

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

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

Looks good. I pulled it down and played with it locally and it works as expected.

Housekeeping notes:

  • Be sure to squash when you merge and update the commit description and comment to be something meaningful (GH will default to all commit messages which is not useful).
  • Remember to get a second reviewer before merging.

@@ -3,3 +3,5 @@
### SDK Enhancements

### SDK Bugs
* `aws/credentials/ssocreds`: Implement SSO token provider to support for `sso-session` in AWS shared config.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "Implement SSO token provider to support for ..."

"time"
)

type Token struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: did your IDE not complain about no comment/documentation here? this is a public type, so it should have some documentation here.

aws/credentials/ssocreds/provider_test.go Show resolved Hide resolved
}

// Expired returns if the token's Expires time is before or equal to the time
// provided. If CanExpires is false, Expired will always return false.
Copy link

Choose a reason for hiding this comment

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

Suggested change
// provided. If CanExpires is false, Expired will always return false.
// provided. If CanExpire is false, Expired will always return false.


return p.Response()
}

func (m mockClient) GetRoleCredentialsWithContext(ctx aws.Context, params *sso.GetRoleCredentialsInput, _ ...request.Option) (*sso.GetRoleCredentialsOutput, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i know this is not part of your changeset. so this is just a comment for the future. but i dont think we should be including the Go testing framework object in the mocked client.

when validating the errors in the mocked client, it shouldnt directly invoke the testing object framework, but we should actually mock the returned errors, and then catch those in the test case execution

return bearer.Token{}, fmt.Errorf("mock token provider return error")
},
},
AccountID: "012345678901",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: whats the purpose of AccountID Region RoleName, and StartURL? removing them doesnt change the outcome of the test, and the mocked token provider doesnt seem to be reacting to them at all.

Copy link
Contributor Author

@wty-Bryant wty-Bryant Jul 6, 2023

Choose a reason for hiding this comment

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

StartURL will be used to get legacy ssoToken while token provider is unavailable, AccountID and RoleName will be checked with expected value in mock SSO Client while calling GetRoleCredentialsWithContext. But some error case won't reach that step so I will just remove their fields. Additionally Region is not used in all cases so I will remove it from test case struct.

UnknownFields map[string]interface{} `json:"-"`
}

func (t cachedToken) MarshalJSON() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some documentation for this function and func (t *cachedToken) UnmarshalJSON on why we need a custom marshaller/unmarshaller? we need documentation on public functions, and its not immediately obvious why the standard Go marshaller doesnt suffice.

Copy link
Contributor

Choose a reason for hiding this comment

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

i see your added documentation now. and i think i get it. but the documentation as is isnt very clear. how about this:

MarshalJSON provides custom marshalling because the standard library Go marshaller ignores unknown/unspecified fields when marshalling from a struct. 
https://pkg.go.dev/encoding/json#Marshal
This function adds some extra validation to the known fields and captures unknown fields.

fix this and UnmarshalJSON and then ship it.

@@ -507,6 +528,15 @@ func TestLoadSharedConfigFromFile(t *testing.T) {
S3UseARNRegion: true,
},
},
{
Profile: "sso-session-success",
Copy link
Contributor

Choose a reason for hiding this comment

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

whats the difference between this test and the other test above that tests sso-session-success?

UnknownFields map[string]interface{} `json:"-"`
}

func (t cachedToken) MarshalJSON() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i see your added documentation now. and i think i get it. but the documentation as is isnt very clear. how about this:

MarshalJSON provides custom marshalling because the standard library Go marshaller ignores unknown/unspecified fields when marshalling from a struct. 
https://pkg.go.dev/encoding/json#Marshal
This function adds some extra validation to the known fields and captures unknown fields.

fix this and UnmarshalJSON and then ship it.

fields[key] = value
}

// UnmarshalJSON decode cachedToken known/unknown fields from json format
Copy link
Contributor

@isaiahvita isaiahvita Jul 6, 2023

Choose a reason for hiding this comment

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

i see your added documentation now. and i think i get it. but the documentation as is isnt very clear. how about this:

UnmarshalJSON provides custom unmarshalling because the standard library Go unmarshaller ignores unknown/unspecified fields when unmarshalling from a struct. 
https://pkg.go.dev/encoding/json#Unmarshal
This function adds some extra validation to the known fields and captures unknown fields.

fix this and MarshalJSON and ship it

@wty-Bryant wty-Bryant merged commit d744468 into main Jul 6, 2023
62 checks passed
@wty-Bryant wty-Bryant deleted the feat-sso-session branch July 6, 2023 19:44
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.

aws-sdk-go doens't support new sso-session in a shared config
4 participants