-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 support for multiple credential providers via aws-sdk-go #1049
Conversation
This looks good to me.
I'm not sure this is an issue, since Terraform currently supports both. If a user supplies either of the variable names in the environment, Terraform should pick those up and populate If neither are supplied, it would fall into the |
Yeah, that was the point - both = the deprecated ones too. But I'm ok with only supporting new ones and force people to start using the new convention as long as you guys (as maintainers) are ok with that. That said, I still think there should be a logic for both |
I think we should just maintain backwards compatibility with the old ones. We can do a simple But otherwise this LGTM. |
1254017
to
85a2bec
Compare
Rebased latest commits from master + added the compatibility layer as mentioned. I misread the source code of https://github.com/awslabs/aws-sdk-go/blob/master/aws/auth.go#L90-98 last time, so I didn't notice that both |
0bd3505
to
4be64da
Compare
|
||
// Get the auth and region. This can fail if keys/regions were not | ||
// specified and we're attempting to use the environment. | ||
var errs []error | ||
log.Println("[INFO] Building AWS auth structure") | ||
log.Println("[INFO] Building AWS auth structure via goamz") | ||
auth, err := c.AWSAuth() |
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.
Hmm, might there be a problem using ec2
/elb
functionality if credentials are loaded from the auth file? It looks like you could end up in a situation where ec2
is using one set of credentials from the env, and s3
is using a different set loaded from the config file. Maybe getCredentialsProvider()
could update Config.AccessKey
and Config.SecretKey
like AWSAuth()
does?
I've been playing around with this branch, and I've noticed that the only way to have credentials sourced from the config file is to specify blank versions in the AWS provider block. For example:
Using a simple
When I run
After setting the
The
I'm guessing that the On the one hand it seems counterintuitive to require these options be set to such a "magic value", but on the other having the provider require an explicit option to use the default credentials could prevent someone from unintentionally running terraform against the wrong account. |
Good point, although that was so far the way to work around this if you wanted credentials to be autoloaded (not really an excuse for that behavior, just an explanation where it comes from).
That is an interesting thought. Generally it's not just about wrong account (that could be solved via #1063) but also about set of credentials with different permissions to the same account. We could have config option provider "aws" {
source = "detect"
}
provider "aws" {
source = "file_config"
config_path = "~/.aws/credentials"
} Running TF against wrong account or with different keys is pain, the first can be prevented as mentioned, but the other one? Would you recognise any difference between two keys if you'd see them? I wouldn't. To make it even more obvious for user, we could be printing to console where did the credentials come from to allow user panicking sooner & doing last-minute |
After playing around with the master branch, it seems that a by-product of this line is that terraform has always supported loading credentials from |
I think you're right, although the implementation in Generally I agree that there should be probably more systematic approach to this which will make these things more explicit rather than implicit and it should all be documented. What do you think about the suggested config options above? |
Apologies, GH didn't load your reply when I was submitting mine!
Thanks, I had a look through the issue list but missed that as it's already closed. Glad to see it's already fixed!
Thanks, that sounds like a much better fix for that particular problem.
That sounds interesting, I hadn't considered that using the credentials with the wrong permissions could leave you in an inconsistent state. That's definitely something to avoid.
That sounds like it could be very helpful, especially for people who're joining an existing terraform project; my only comment would be that I'm not sure if the schema allows for the
Hmmm, I'm just re-reading all the code and it seems that
Definitely! 👍 |
After thinking about it one solution that springs to mind is to move the detection of credentials from the
Thoughts? |
I was merely replying to your sentence about config-loading (= it does not support loading token from file). Token is something you send along with access_key + secret_key to the API. At the end it's all about API requests. Only the tool (TF in this case) cares how you give it the token - either via ENV variable - which was supported in
I like the idea of using schema's
Will all respect, 👎 on that. I think if the ENV variable can be replaced with provider config option, it should be. So far TF only has two ENV variables ( |
Gotcha, thanks for explaining that.
I completely agree. I should've been clearer with my explanation, by
I meant calling it in
Not quite sure what you mean by this?
I agree that it's not pretty, it's just an easy way to preserve interactive prompting of unset variables while allowing people to opt into loading config from a file. If there's an alternative way to do this I'd much prefer that. |
I wanted to rebase this + try implementing all the suggestions, but I think I'll rather hold off until Clint deals with the last bits of goamz -> aws-sdk-go conversion. This mid-stage is just creating way too many edge cases that would be hard to work around. |
Just thinking about this... it will be probably best to move the whole logic for building credentials provider into |
9b8d1cd
to
1654242
Compare
ef8aae9
to
044f3c9
Compare
33c4f00
to
ef071da
Compare
d16d321
to
b7806f9
Compare
fb31c61
to
82d0b58
Compare
Ping! This no longer applies to master in a sensible way, and I'd really really like to see this get merged, as multi-account support is pretty essential to our workflow at Yelp. @radeksimko - do you have time / inclination to get this updated to merge cleanly again, or even better finished off so the interface suits @mitchellh 's demo requirements? I'm happy to try to help out if you're busy! TIA |
@bobtfish I'll be happy to update it, but @catsby is working on some further aws refactoring (switching back to AWS' upstream library), so I'd rather do it after he finishes that, so we don't step on each other's toes. Either way, some help would be appreciated in https://github.com/hashicorp/terraform/issues/1255 |
c893f68
to
aa45b02
Compare
Let's look at this again and solve any UX issues left. |
First UX issues need to be solved. Have a look at #1311 where I tried to demonstrate (and fix) the problem. |
@radeksimko I think we get all this for free now from aws-go, can you verify? There is still #1311 but the core issue here I think is fixed. Let me know if I'm wrong. |
I don't think it is entirely fixed, but it's just because the original title+purpose of this PR is wrong (too wide). TL;DR: My point (and the missing feature) is ability to choose one specific provider (one of them being "detect"). |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
The new library already brings in the functionality, so I just took the advantage of it and gave it a higher priority as in the current state
goamz
was loading everything the same old way and then passing these credentials as static intoaws-sdk-go
.I first wanted to write some tests for this, but I'm finding it really hard to mock the calls of remote API in
aws-sdk-go
as it doesn't have any similar argument for passing mocked http client instance like each API part has.Either way, I guess we may want to maintain the "backward compatibility" with the way
goamz
loads credentials, especially because the new library doesn't support following (so far):AWS_CREDENTIAL_FILE
- we could pass a filename intoProfileCreds
and use that one insteadDetectCreds
if the variable existsAWS_PROFILE
- same solution,profile
parameterAWS_ACCESS_KEY
AWS_SECRET_KEY
AWS_SECURITY_TOKEN
Both
AWS_CREDENTIAL_FILE
&AWS_PROFILE
should probably be raised as an issue and/or pull request in theaws-sdk-go
library as well in the meantime I guess as it's pretty standard variable used by some other tools like AWS CLI.I can add that compatibility layer into this PR too, I just first want to know what your thoughts are and if you actually want such layer there.
cc @catsby
Related to:
#866 #266 #801