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

aws/credential: Increase credential_process provider default buffer size #2329

Merged
merged 2 commits into from
Dec 6, 2018
Merged

aws/credential: Increase credential_process provider default buffer size #2329

merged 2 commits into from
Dec 6, 2018

Conversation

bodhi
Copy link
Contributor

@bodhi bodhi commented Dec 5, 2018

Thanks @YakDriver and everyone who got #2217 merged!

I tried out this feature with our internal auth delegation tool, but it didn't work out of the box, even though the AWS CLI works fine, because the session token returned by the AWS API is much longer (at 560 bytes) than the code expects.

I note that DefaultBufSize is exported, so it could be set larger in client code, but it seems a bit unfriendly to me that the default size doesn't accept data that is being returned from the AWS API.

Copy of commit message:

The default buffer size of 512 bytes is not long enough to contain credentials with long session tokens, like those returned by sts.STS.AssumeRoleWithWebIdentity, which appears to return session tokens of ~560 bytes.

Using 560 bytes as a starting point, with the rest of the credential data being ~160-170 bytes, 1024 bytes will fit these, without being excessive.

The default buffer size of 512 bytes is not long enough to contain
credentials with long session tokens, like those returned by
`sts.STS.AssumeRoleWithWebIdentity`, which appears to return session
tokens of ~560 bytes.

Using 560 bytes as a starting point, with the rest of the credential
data being ~160-170 bytes, 1024 bytes will fit these, without being
excessive.
@jasdel
Copy link
Contributor

jasdel commented Dec 5, 2018

Thanks for the feedback @bodhi. A 1024 default buffer seems reasonable. We can do more research and see if there is a more appropriate size.

@bodhi
Copy link
Contributor Author

bodhi commented Dec 5, 2018

@jasdel thanks!

I note that DefaultBufSize is exported, so it could be set larger in client code

One of my team-mates just pointed out to me that DefaultBufSize is const, not var 🙀 .

@YakDriver
Copy link
Contributor

YakDriver commented Dec 5, 2018

@jasdel 512 is ultra conservative 😞 . In my opinion, even 2048 would be safe and accommodate most situations.

@bodhi DefaultBufSize is a const, as it should be because it's a default. However, MaxBufSize is exported and can be set programmatically for an individual ProcessProvider. (This doesn't help much if, like us, there's a layer or two between you and the aws-sdk-go and you need it to work out of the box.)

    creds := processcreds.NewCredentials(
        "/path/to/command",
        func(opt *ProcessProvider) {
            opt.Timeout = time.Duration(2) * time.Minute
            opt.Duration = time.Duration(60) * time.Minute
            opt.MaxBufSize = 2048
        })

@@ -8,3 +8,6 @@ credential_process = cat ./testdata/nonexpire.json
aws_access_key_id = notFromCredProcAccess
aws_secret_access_key = notFromCredProcSecret
credential_process = cat ./testdata/verybad.json

[profile long_session_token]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shared config has been tested already so no need to add another profile.

@@ -8,3 +8,6 @@ credential_process = type .\testdata\nonexpire.json
aws_access_key_id = notFromCredProcAccess
aws_secret_access_key = notFromCredProcSecret
credential_process = type .\testdata\verybad.json

[profile long_session_token]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shared config has been tested already so no need to add another profile.

oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)

os.Setenv("AWS_PROFILE", "long_session_token")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using a profile and shared config file, this can be tested more directly:

creds := processcreds.NewCredentials(
		fmt.Sprintf(
			"%s %s",
			getOSCat(),
			strings.Join(
				[]string{"testdata", "longsessiontoken.json"},
				string(os.PathSeparator))))
	_, err := creds.Get()
	if err != nil {
		t.Errorf("expected %v, got %v", "no error", err)
	}

This way you can get rid of the two changes to the shared config files.

@mikkeloscar
Copy link

I also hit this issue now when testing with https://github.com/mikkeloscar/kube-aws-iam-controller

There's no need to go via a profile in the shared config, this
behaviour can be tested directly against
`processcreds.ProcessProvider`.
@bodhi
Copy link
Contributor Author

bodhi commented Dec 5, 2018

@YakDriver I just updated the tests to not use the profile configuration. It's done as a separate commit, but I'm fine to squash them if that's preferred.

@jasdel
Copy link
Contributor

jasdel commented Dec 5, 2018

Separate commit is fine, the PR will be squashed when its merged into master so no worries about the separate commits in the PR.

Copy link
Contributor

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@jasdel
Copy link
Contributor

jasdel commented Dec 6, 2018

Thanks for putting this fix together. The change looks good.

@jasdel jasdel merged commit 89ebd3a into aws:master Dec 6, 2018
@diehlaws diehlaws added needs-review This issue or pull request needs review from a core team member. and removed review-needed labels Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review This issue or pull request needs review from a core team member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants