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

Use us-gov-west-1 for global APIs in aws-us-gov #9947

Merged
merged 4 commits into from
Sep 26, 2020

Conversation

bluekeyes
Copy link
Contributor

Certain partition-global AWS services, like IAM, seem to require specific regions. In the regular 'aws' partition, this is us-east-1. In the 'aws-us-gov' partition, this is us-gov-west-1. Providing us-gov-east-1 returns an error from AWS:

SignatureDoesNotMatch: Credential should be scoped to a valid region, not 'us-gov-east-1'.

This resolves a problem where AWS authentication could randomly fail depending on the value cached by Vault at startup.

Fixes #9935.

Certain partition-global AWS services, like IAM, seem to require
specific regions. In the regular 'aws' partition, this is us-east-1. In
the 'aws-us-gov' partition, this is us-gov-west-1. Providing
us-gov-east-1 returns an error from AWS:

  SignatureDoesNotMatch: Credential should be scoped to a valid region, not 'us-gov-east-1'.

This resolves a problem where AWS authentication could randomly fail
depending on the value cached by Vault at startup.
@hashicorp-cla
Copy link

hashicorp-cla commented Sep 14, 2020

CLA assistant check
All committers have signed the CLA.

@kalafut
Copy link
Contributor

kalafut commented Sep 18, 2020

@bluekeyes Thanks for this! Do you have a link to AWS docs which references the specialness of "us-gov-west-1" that you could add to the code comment?

To confirm, were you able to test this out in the us gov partition? Running such a test is a little more challenging for us so 💯 if you've verified it.

@bluekeyes
Copy link
Contributor Author

I wish I could find this fact in the docs, but I've spent a while looking and can't find this called out in either the IAM docs or the region and endpoint docs.

The closest reference I have is that both botocore and aws-go-sdk set the credential scope for IAM to us-gov-west-1 in the us-gov partition, while the definitions for other services either set the region to match the endpoint or don't set a region at all. This value is used to set the "signing region" when resolving the IAM endpoint, which suggests there could be a way to remove Vault's region cache completely, but that would be a more involved change.

For testing, I haven't tried deploying a binary with this change to our GovCloud environment yet (although I have reproduced the original issue multiple times.) I can test this out and report back if it will help.

@bluekeyes
Copy link
Contributor Author

bluekeyes commented Sep 19, 2020

I deployed a custom Vault binary with this patch in our staging GovCloud environment and it solves the problem. I was able to step down Vault 15 times while simultaneously authenticating from another host without any failures.

For comparison, when I first connected to the environment, authentication was broken and I had to step down Vault four times before it cached the correct region and fixed authentication.

Copy link
Contributor

@kalafut kalafut left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@kalafut kalafut added this to the 1.5.5 milestone Sep 25, 2020
@kalafut
Copy link
Contributor

kalafut commented Sep 25, 2020

@bluekeyes Reading the original issue prompted an additional test. Is it possible for you to run this within us-gov-east-1 and verify that there are no issues with the hard-coded us-gov-west-1?

@bluekeyes
Copy link
Contributor Author

@kalafut I launched a Vault server built from my fork in us-gov-east-1, configured the AWS auth backend in a similar way to what we use in us-gov-west-1, and was able to authenticate with IAM from an instance in us-gov-east-1, so I believe this will work fine in both regions.

@kalafut
Copy link
Contributor

kalafut commented Sep 26, 2020

@bluekeyes Thanks for the extra test!

// because it is always enabled (and enabled for STS) by default.
// However, there are a few exceptions:
//
// For "aws", choose "us-east-1" because it is always enabled (and
Copy link
Contributor

Choose a reason for hiding this comment

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

Really appreciate the extended comments in here!

@kalafut kalafut merged commit 8cb39fb into hashicorp:master Sep 26, 2020
kalafut pushed a commit that referenced this pull request Sep 26, 2020
* Use us-gov-west-1 for global APIs in aws-us-gov

Certain partition-global AWS services, like IAM, seem to require
specific regions. In the regular 'aws' partition, this is us-east-1. In
the 'aws-us-gov' partition, this is us-gov-west-1. Providing
us-gov-east-1 returns an error from AWS:

  SignatureDoesNotMatch: Credential should be scoped to a valid region, not 'us-gov-east-1'.

This resolves a problem where AWS authentication could randomly fail
depending on the value cached by Vault at startup.
kalafut pushed a commit that referenced this pull request Sep 29, 2020
* Use us-gov-west-1 for global APIs in aws-us-gov

Certain partition-global AWS services, like IAM, seem to require
specific regions. In the regular 'aws' partition, this is us-east-1. In
the 'aws-us-gov' partition, this is us-gov-west-1. Providing
us-gov-east-1 returns an error from AWS:

  SignatureDoesNotMatch: Credential should be scoped to a valid region, not 'us-gov-east-1'.

This resolves a problem where AWS authentication could randomly fail
depending on the value cached by Vault at startup.

Co-authored-by: Billy Keyes <[email protected]>
@bluekeyes bluekeyes deleted the bkeyes/fix-govcloud-region branch September 30, 2020 05:30
@matt14483
Copy link

Is this still an issue for us-iso and us-isob? It appears that this fix doesn't resolve this issue for other non-commercial partitions.

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.

Cached regions break IAM role lookups during AWS auth in GovCloud
5 participants