Skip to content

Use STS regional endpoints for STS calls from resource providers #22022

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

Closed
2 tasks
willyg302 opened this issue Sep 13, 2022 · 4 comments · Fixed by #22370
Closed
2 tasks

Use STS regional endpoints for STS calls from resource providers #22022

willyg302 opened this issue Sep 13, 2022 · 4 comments · Fixed by #22370
Assignees
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@willyg302
Copy link

Describe the feature

Per the STS docs:

Session tokens from Regional AWS STS endpoints are valid in all AWS Regions. Session tokens from the global STS endpoint are valid only in AWS Regions that are enabled by default.

Use Case

When attempting to use CrossAccountZoneDelegationRecord, we discovered that the cross-account assume role did not work from an opt-in region, failing with:

Received response status [FAILED] from custom resource. Message returned: AccessDenied: User: <provider Lambda execution role> is not authorized to perform: sts:AssumeRole on resource: <delegationRole>

In our case, this was due to our use of a global service principal in the delegation role's trust policy, and opt-in accounts are not visible in such a service principal. One possible workaround is to add either regional service principals or opt-in account IDs directly to the trust policy, but this is not desirable as it requires updating the delegation role for each new opt-in region.

Proposed Solution

This can be done by updating the following:

  • Where instantiating an STS client directly, e.g. here, switch to new STS({ stsRegionalEndpoints: 'regional' })
  • Where using chainable temporary credentials, e.g. here, switch to new AWS.ChainableTemporaryCredentials({ params, stsConfig: { stsRegionalEndpoints: 'regional' } })

Other Information

I would submit a PR myself, but am unclear on whether there are any downsides to defaulting to the regional endpoints (i.e. whether these changes can be hardcoded or should be behind a flag). At least in our team's experience, switching to the regional endpoints has caused no issues.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

v1

Environment details (OS name and version, etc.)

N/A

@willyg302 willyg302 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 13, 2022
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Sep 13, 2022
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Sep 13, 2022

Thanks for the request @willyg302!

I would submit a PR myself, but am unclear on whether there are any downsides to defaulting to the regional endpoints

I'm also unclear on this myself, maybe someone else on the team would know. @TheRealAmazonKendra this may be interesting to you

Though, I don't see why we wouldn't at the least be able to include an option for this that isn't enabled by default

@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 13, 2022
@mtrspringer
Copy link

@peterwoodworth I believe the absence of this optional also prevents the custom resource from being used in private subnets that rely on an AWS Interface Endpoint for STS access, since the InterfaceVpcEndpointAwsService class creates a regional endpoint.

The EKS cluster resource provider has regional STS endpoints enabled by default via the AWS_STS_REGIONAL_ENDPOINTS environment variable: link.

A simple solution to enable STS regional endpoints without touching the existing handler code would be to make the function environment configurable via a new AwsCustomResourceProps option: functionEnvironment?: { [string]: string }.

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 5, 2022

I took your fix. Thanks!

rix0rrr added a commit that referenced this issue Oct 5, 2022
By default, the STS client is using the global STS endpoint, and tokens
it returns are not valid in opt-in regions.

Fixes #22022.
@mergify mergify bot closed this as completed in #22370 Oct 10, 2022
mergify bot pushed a commit that referenced this issue Oct 10, 2022
By default, the STS client is using the global STS endpoint, and tokens it returns are not valid in opt-in regions.

Affects EKS, Route53, AwsCustomResource.

Fixes #22022.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants