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 aws_provider_credentials data source #10694

Closed
wants to merge 1 commit into from
Closed

add aws_provider_credentials data source #10694

wants to merge 1 commit into from

Conversation

twang817
Copy link

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

This allows local-exec provisioners to be able to retrieve the
credentials that the aws provider is using.

Ex:

provider "aws" {
    version = "~> v2.33.1" # to use local copy of terraform-provider-aws
}

data "aws_provider_credentials" "current" {}

resource "null_resource" "my_resource" {
  provisioner "local-exec" {
    command = "echo $AWS_ACCESS_KEY_ID - $AWS_SECRET_ACCESS_KEY - $AWS_SESSION_TOKEN"
    environment = {
      AWS_ACCESS_KEY_ID = "${data.aws_provider_credentials.current.access_key}"
      AWS_SECRET_ACCESS_KEY = "${data.aws_provider_credentials.current.secret_key}"
      AWS_SESSION_TOKEN = "${data.aws_provider_credentials.current.session_token}"
    }
  }
}

Closes #8242

Release note for CHANGELOG:

Allows credentials (access_key, secret_key, and session_token) to be fetched from new data source aws_provider_credentials to be used within local-exec provisioners.

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

I was not able to run acceptance testing as I don't have access to a personal AWS account. I did run make tests.

@twang817 twang817 requested a review from a team October 31, 2019 04:57
@ghost ghost added size/M Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 31, 2019
@twang817
Copy link
Author

twang817 commented Oct 31, 2019

Supersedes #8517

@twang817
Copy link
Author

Question: Is there a maintenance branch for v0.11 support?

I suspect there are lots of people out there that are stuck on v0.11.x and would appreciate a backport to support this feature.

@bflad
Copy link
Contributor

bflad commented Nov 1, 2019

Question: Is there a maintenance branch for v0.11 support?

I suspect there are lots of people out there that are stuck on v0.11.x and would appreciate a backport to support this feature.

@twang817 all versions of the Terraform AWS Provider including the most recent released today support Terraform CLI 0.11. The only restriction at the moment is Terraform CLI 0.12 requires Terraform AWS Provider version 2.7.0 or higher. We will be deprecating Terraform CLI 0.11 and earlier support at some point in the coming months, but the timing and announcement have not yet occurred.


Regarding the content of this pull request, I think its best that we are upfront with saying that we would be hesitant to make it easy to exfiltrate active AWS credentials from a Terraform run. There are valid use cases within Terraform as shown above, but those credentials may be then used completely outside of Terraform's context (e.g. if they are visible to CI logging then anyone with CI log access can see and use them locally). While this is opt-in, setting up controls/policies to block its usage is also opt-in and has to be known, so even having this ability within an officially released Terraform AWS Provider binary may not be acceptable in many organizations.

@twang817
Copy link
Author

twang817 commented Nov 1, 2019

Being closely involved in security at organization, I wholly understand and appreciate the feedback. It is largely why I have let this PR languish for so long.

We have internally worked around this problem by providing credentials to both Terraform and any local-exec provisioners in a consistent manner. This moves credentials management out of Terraform. It is ugly, and it's not DRY, but it solves the issue and allows us to move forward. Even if this PR is indeed merged, I couldn't say with confidence that our organization would opt in to using the data source, despite the fact that we don't have any long term-credentials, use encrypted state buckets, etc.

I only recently picked this up as there seemed to be some activity and interest on #8517.

Perhaps we can take this opportunity to start a dialog and search for alternative solutions. The set of problems that this solves is relatively common and I suspect there are many who are in more relaxed security contexts and are eager to find a solution.

@zopanix
Copy link
Contributor

zopanix commented Nov 1, 2019

Hey, thanks for opening this PR. I also am concerned security whise but it's my best solution to keep things inside terraform. My use case is that EKS is really poorly implemented. For EKS to work you need specific tags on the subnets in which you deploy it. Which is easy enough to do when you're managing the subnets within you terraform code. Unfortunately, VPC infrastructure is handled in a seperate account in my case by another team which leads to the conclusion. I have to partially handle the subnet resources (which is also ugly). Now since the credentials that we use in terraform are temporary (max 1h) I don't mind it being stored in the statefile. In addition, only the terraform credentials are allowed to read the statefile in our case, nobody else has access. I would really appreciate this being resolved becasue without it. I would need to generate additionnal creds outside of terraform and pass these as variables. But in my current use case we use modules a lot. In fact those credentials would the be passed as parameters to 4 modules becasue of dependency handling.

I agree there should be a huge warning sign whether to use this or not and the risks it can bring. But I'm strill convinced that this is still better that working around the problem in another manner.

@bflad
Copy link
Contributor

bflad commented Nov 1, 2019

Hi @zopanix 👋 Would either/both of these EC2 tagging improvements help in your situation?

@bflad
Copy link
Contributor

bflad commented Jan 17, 2020

Hi again 👋 There hasn't been any additional comments on this functionality for awhile now and the maintainers are still extremely hesitant to merge this in (see #10694 (comment) above), so rather than keeping this pull request open when its not likely to be merged, I'm going to close this. Thanks again for contributing this and please create a new GitHub issue if you wish to discuss this functionality further.

@bflad bflad closed this Jan 17, 2020
@ghost
Copy link

ghost commented Mar 27, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
provider Pertains to the provider itself, rather than any interaction with AWS. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass credentials to local-exec OR extract credentials via properties
3 participants