-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[AwsCustomResource]: (assumeRoleArn defined in non-opt-in region while assume in opt-in region cause permission issue) #26562
Comments
I am afraid this is related to JS SDK rather than CDK. Which opt-in region is that in your case? Let me rephrase it. Account A in an opt-in region was deploying a CDK custom resource that assumes to another role from Account B which does not opt-in this region, and the custom resource just failed with lambda log as you provided above. Is it correct? |
Are you sure you are using CDK 2.1.4 ? Can you confirm your CDK version? |
Stack trace indicates this is using SDK v2: |
Yes. the opt-in region we tested is ap-east-1 and me-south-1 This can be either CDK problem or SDK issue, if we want to force(hardcode) the assume region to be Account B non-opt-in region, it will be an SDK issue, but this may be an issue for some special case. If we want to provide the override option for assumeRole region in this case, CDK also needs some update to support. Not sure about the decision from CDK team for AwsCustomResource |
Actually, we are using "aws-cdk-lib": 2.73.0, |
Exact SDK version is: |
In the latest SDK, it provide the override option for region:
The sdk V2 also provide the override option:
Is it possible to expose this stsRegion Option to AwsCustomResourceProps. it is blocking one of our prod region build. |
Is there a timeline for fixing this bug? It is blocking our region build and we have another opt-in region build coming this week. |
So, to be clear @chensy-aws, you're asking for a new feature that hasn't been supported in this custom resource previously? You want to be able to set the region with which the SDK client is initiated? Can you not achieve this using environment variables? |
HI, I am not an expert of CustomResource, Both interface here did not provide easy way to setup the ENV VAR in cdk, am I miss anything here?
Yes, If this situation is something AwsCustomResource did not consider before. |
To summarize the discussion: We are using this construct: From our CDK code,
The Role we are trying to assume As far as we understand, there are 2 ways to solve this issue.
|
So, in the
However, in the more opinionated aws-cdk/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/runtime/aws-sdk-v2-handler.ts Lines 120 to 123 in 0fc33d9
The ask is to honor the context flag |
So the v3 sdk uses the sts regional endpoints by default. I don't think regional endpoints are the issue here. The client needs to instantiate the sts client using a non opt-in region, I guess it doesn't matter which one, as long as it's one that is enabled in the account where the role being assumed is defined. According to the docs, you can't assume a role using an opt-in regional endpoint, unless the account with that role defined also has that opt-in region enabled. Also tokens granted using the global endpoint are not compatible with opt-in regions by default. You can make them compatible but you have to set a flag within the IAM console for your account. Basically I think this means we shouldn't use the global endpoint. Relevant docs: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html |
#26593
The main issue is sts assumeRole using the default region (which is opt-in), while use the provided As I mentioned earlier, either we use the same region for sts and service/action, or expose the sts region as a parameter. |
@chensy-aws yeah I think we are in agreement, my message was with regards to the usage of I think using the same region as the aws api call in the |
I had to think about this a lot, but in the end I came up with this diagram and it basically confirms what @MrArnoldPalmer was already saying 🤣
I was wondering whether this would work, but it should: Lambda will be using regional opt-in credentials, but they should be valid in Account A to perform the AssumeRole call in the non-opt-in region (since Account A has the opt-in region opted-in, otherwise the Lambda couldn't be running there). And then afterwards, those credentials are valid in the non-opt-in region. |
Yes, that should definitely work in our case. |
…26917) Currently, the region parameter in `AwsCustomResource` only controls where the action is performed. If a role needs to be assumed, the `assumeRole` call is made from the region the stack is deployed into. This presents a problem if the stack is deployed into an opt-in region, and the role being assumed lives in a separate stack in an account without the opt-in region enabled. This change makes the `assumeRole` call and the sdk call performed in the same region. Therefore, to solve the above problem, pass any region that is enabled for the account that owns the role to be assumed. Closes #26562. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
…26917) Currently, the region parameter in `AwsCustomResource` only controls where the action is performed. If a role needs to be assumed, the `assumeRole` call is made from the region the stack is deployed into. This presents a problem if the stack is deployed into an opt-in region, and the role being assumed lives in a separate stack in an account without the opt-in region enabled. This change makes the `assumeRole` call and the sdk call performed in the same region. Therefore, to solve the above problem, pass any region that is enabled for the account that owns the role to be assumed. Closes #26562. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Describe the bug
for AwsCustomResource, the AwsSdkCall have assumeRoleArn that we can assume to proceed the SdkCall.
But the default sts endpoint is set to regional, and default region in our case an opt-in region. However, the role is created/defined under a root account in non-opt-in region(we cannot enable all opt-in region for that account). With the incorrect sts endpint point the assumeRole failed with permission issue.
Expected Behavior
sts Assume Role success and AwsSdkCall can proceed with success response.
Current Behavior
Reproduction Steps
Create an AwsCustomResource in opt-in region to assume a Role define in an account which did not enable this opt-in region.
Possible Solution
We tried all combinations of region vs stsEndpoint:
case 1, default region(opt-in region) with global sts endpoint. -> FAILED
case 2, non opt-in region with global sts endpoint. -> SUCCEED
case 3, default region(opt-in region) with regional sts endpoint. -> FAILED
case 4, non opt-in region with regional sts endpoint. -> SUCCEED
So in either cases, we need to override the default region to a non-opt-in region!! So requesting to expose this sts region option to the user. the AwsSdkCall do have a region option, but the region is NOT used for sts assume role.
Additional Information/Context
No response
CDK CLI Version
2.73.0
Framework Version
No response
Node.js Version
18
OS
AL2
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: