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

Don't read AWS env vars #5974

Merged
merged 3 commits into from
Jan 4, 2019
Merged

Don't read AWS env vars #5974

merged 3 commits into from
Jan 4, 2019

Conversation

jefferai
Copy link
Member

Let AWS SDK env cred chain provider do it for us

Fixes #5965

k.accessKey = accessKey
}
// Check and set AWS access key, secret key, and session token
var accessKey, secretKey, sessionToken string
Copy link
Contributor

Choose a reason for hiding this comment

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

My code editor complains that these aren't actually read below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fails to make for me with:

Stderr: # github.com/hashicorp/vault/vault/seal/awskms
../../../../../GO/src/github.com/hashicorp/vault/vault/seal/awskms/awskms.go:103:6: accessKey declared and not used
../../../../../GO/src/github.com/hashicorp/vault/vault/seal/awskms/awskms.go:103:17: secretKey declared and not used
../../../../../GO/src/github.com/hashicorp/vault/vault/seal/awskms/awskms.go:103:28: sessionToken declared and not used```

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

}
// Check and set AWS access key, secret key, and session token
var accessKey, secretKey, sessionToken string
if os.Getenv("AWS_ACCESS_KEY_ID") == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that since we use credsConfig.GenerateCredentialChain() below, and that includes adding an Env cred provider if the AWS key is unset, we can just do away with all fussing with pulling AWS environment variables here and let the Env provider do the right thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the Env provider supports pulling specifically the access key, secret key, and session token, but nothing else.

secretKey = conf["secret_key"]
}
sessionToken := os.Getenv("AWS_SESSION_TOKEN")
if sessionToken == "" {
if os.Getenv("AWS_SESSION_TOKEN") == "" {
Copy link
Contributor

@tyrannosaurus-becks tyrannosaurus-becks Dec 19, 2018

Choose a reason for hiding this comment

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

We should just drop pulling all three of these here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

The point of keeping it there was so that if you overrode the config with env vars we'd prioritize the env vars -- note that awsutil has the ordering static, env, shared, iam. Whether this is the right thing to do or not is debatable, but it's also how it's worked up to this point so I'm not sure changing them is the right move.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see! Maybe it would be nice to add a comment to that effect, then. But yes, I looked through the code in GenerateCredentialChain and I see why you're doing that but still using the method, that method does a lot of work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I've been trying to think about whether we should change this. I'm starting to think we should.

Copy link
Contributor

@tyrannosaurus-becks tyrannosaurus-becks left a comment

Choose a reason for hiding this comment

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

This code looks good as-is, up to you whether to add a comment explaining why the env vars are checked. I do note there's a test failure on the code but the failure is on master too, so it's unrelated to this change. Just posting it as an FYI.

--- FAIL: TestAWSKMSSeal (0.00s)
    awskms_test.go:22: expected error when AWSKMSSeal key ID is not provided

@tyrannosaurus-becks tyrannosaurus-becks self-assigned this Dec 20, 2018
Let AWS SDK env cred chain provider do it for us

Fixes #5965
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