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: Use new STS endpoint to validate creds #6536

Merged

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented May 8, 2016

We were historically using iam:GetUser API for validating credentials, which however doesn't work on EC2 instances with IAM instance profiles (assumed roles) nor with other assumed roles for humans (via SAML/OpenID). In addition to that any credentials generated via sts:GetFederationToken cannot call any STS or IAM endpoints.

We originally avoided the mentioned limitations just by silently ignoring certain error codes coming from iam:GetUser. We don't have to do this anymore since the new STS endpoint was introduced (sts:GetCallerIdentity).

I was originally afraid that it will be yet another half-working method for validation with dozens of exceptions across different environments - e.g. STS can be disabled per regions. It however looks like the sts:GetCallerIdentity can be used even when explicitly denied via IAM policy (Deny for sts:*) and in region which has STS disabled. It can also be used (surprisingly) on EC2 instances. 🎉

WIP: I approached AWS support as I want them to confirm that the inability to "disable" this API endpoint is intention and not a bug which would be fixed later on. I'm currently awaiting response from them.

Fixes #6523

@radeksimko
Copy link
Member Author

I just received confirmation from AWS that sts:GetCallerIdentity will work no matter if STS is disabled in that region or IAM policy explicitly denies that action. This PR is therefore ready for review.

@radeksimko radeksimko changed the title [WIP] aws: Use new STS endpoint to validate creds aws: Use new STS endpoint to validate creds May 9, 2016
@brianantonelli
Copy link
Contributor

Has this fix been verified? I just built TF from master and it still errors out:

Get a token and then set env vars and call terraform plan

aws sts get-session-token > ./foo

export AWS_ACCESS_KEY_ID=$(cat foo | jq -r ".Credentials.AccessKeyId")
export AWS_SECRET_ACCESS_KEY=$(cat foo | jq -r ".Credentials.SecretAccessKey")
export AWS_SESSION_TOKEN=$(cat foo | jq -r ".Credentials.SessionToken")

terraform plan

Errors:

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be persisted to local or remote state storage.

Error refreshing state: 1 error(s) occurred:

* 1 error(s) occurred:

* InvalidClientTokenId: The security token included in the request is invalid
    status code: 403, request id: a45de91c-3188-11e6-8867-21f1b377912d

Here's my aws provider:

provider "aws" {
    region     = "${var.region}"
}

@brianantonelli
Copy link
Contributor

Ahh, looks like you have to pass the session token as AWS_SECURITY_TOKEN

@catsby
Copy link
Contributor

catsby commented Jun 20, 2016

LGTM! Thanks @radeksimko

@radeksimko radeksimko merged commit 6fed5eb into hashicorp:master Jun 20, 2016
@radeksimko radeksimko deleted the f-aws-creds-check-via-sts branch June 20, 2016 22:14
@waltervargas
Copy link

@radeksimko Thank you for this PR; it enables Okta credentials and remote state in S3.

@ghost
Copy link

ghost commented Apr 8, 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 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.

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform fails to authenticate using STS temporary credentials - InvalidClientTokenId
4 participants