Skip to content

Conversation

kpcraig
Copy link
Contributor

@kpcraig kpcraig commented Apr 21, 2025

This PR should resolve an issue with certain secrets/aws configurations where we weren't properly handling default values, and additionally where we weren't handling GovCloud iam endpoints.

This change will allow the config.Region setting to flow through as the default in all cases for IAM, and when no stsRegion is set for STS. The fallback values (AWS_REGION, etc) will show up in fewer cases.

In the GovCloud case, it's possible that one might be able to work around the existing issue by setting the AWS_REGION environment variable and explicitly setting the iam_endpoint value.

Areas of Concern:
I tested this to work on all permutations of IAM and STS endpoints, regions, etc, that I could think of, but

  1. We don't have access to GovCloud, so I can't definitively verify that it works there
  2. A lot of the behavior of secrets/aws (and AWS in general, frankly) are the result of cascading settings and backwards compatible conventions, and there's just a lot of interlocking space for situations I didn't think of.

TODO only if you're a HashiCorp employee

  • Backport Labels: If this fix needs to be backported, use the appropriate backport/ label that matches the desired release branch. Note that in the CE repo, the latest release branch will look like backport/x.x.x, but older release branches will be backport/ent/x.x.x+ent.

We weren't handling config.Region values in some high-default
environments, and not handling gov-cloud iam values correctly. Reflow
how default values propagate through the code and attempt to fix the
region/endpoint values at the end. Also try to fix the slices if they
end up mismatched, and ensure we have explicit value setting escape
hatches in case we forgot something.
@kpcraig kpcraig requested a review from a team as a code owner April 21, 2025 21:12
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Apr 21, 2025
@kpcraig kpcraig requested a review from a team as a code owner April 21, 2025 21:14
@kpcraig kpcraig requested a review from tom-pang April 21, 2025 21:14
Copy link

github-actions bot commented Apr 21, 2025

CI Results:
All Go tests succeeded! ✅

Copy link

github-actions bot commented Apr 21, 2025

Build Results:
All builds succeeded! ✅

@kpcraig kpcraig requested review from lursu and tomcf-hcp April 22, 2025 15:29
t.Fatalf("got %d configs, but expected 1", len(cfgs))
}

if *(cfgs[0].Endpoint) != "" {
Copy link
Contributor Author

@kpcraig kpcraig Apr 22, 2025

Choose a reason for hiding this comment

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

The reason why we need the endpoint to be held blank is that in official AWS IAM, the endpoint being set seems to fail the client setup, even if the endpoint matches what is specified on the AWS Endpoints list[1]. Apparently it needs to be blank (or some value I haven't been able to find.)

[1] https://docs.aws.amazon.com/general/latest/gr/iam-service.html

@@ -24,8 +24,6 @@ import (
"github.com/hashicorp/vault/sdk/logical"
)

const fallbackEndpoint = "https://sts.amazonaws.com" // this is not regionally distributed; all requests go to us-east-1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was unused, so I removed it.

@@ -81,13 +79,19 @@ func (b *backend) getRootConfigs(ctx context.Context, s logical.Storage, clientT
credsConfig.HTTPClient = cleanhttp.DefaultClient()
credsConfig.Logger = logger

if config.Region != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (probably) was the bug that was causing gov-cloud issues - we weren't pre-setting the region defined in the config, so it was getting lost.

endpoints = append(endpoints, matchingSTSEndpoint(fallbackRegion))
case "iam":
endpoints = append(endpoints, "https://iam.amazonaws.com") // see https://docs.aws.amazon.com/general/latest/gr/iam-service.html
if len(endpoints) == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is possible for no endpoint to be supplied even if a region was - in particular in the IAM case, which expects no endpoint unless a third-party reimplementer of IAM is being used.

robmonte
robmonte previously approved these changes Apr 24, 2025
Copy link
Member

@robmonte robmonte left a comment

Choose a reason for hiding this comment

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

Looks good, the region and endpoint logic makes sense to me and also is a little cleaner than its current state which is a plus. Only a few tiny comments.

@kpcraig kpcraig merged commit 8a84d13 into main Apr 28, 2025
92 checks passed
@kpcraig kpcraig deleted the VAULT-35407/aws-gov-cloud branch April 28, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed pr/no-milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants