-
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
aws-iam: Updating CDK version removes SQS IAM policy #33577
Comments
Looking into it. |
const user = iam.User.fromUserName(this,'user','SandboxCaminoReadWrite') Is the IAM User from the same account of the stack? |
This is related to #30023 by changing how the principalAccount property is set in the Before public readonly principalAccount = Aws.ACCOUNT_ID; After public readonly principalAccount = Stack.of(scope).splitArn(attrs.userArn, ArnFormat.SLASH_RESOURCE_NAME).account; This change ensures that the The fix was implemented in CDK version 2.142.1, but it seems there might be a regression in how it's applied to SQS permissions specifically. Users experiencing this issue should update to the latest CDK version, and if the issue persists, they may need to explicitly specify the account ID when importing the user. This issue highlights the importance of correctly handling cross-account permissions in CDK constructs, especially when using imported resources from other accounts. What's happening:
The root cause:The issue appears to be in the In the
However, it seems that after the fix to correctly identify cross-account principals, the logic for adding permissions to the resource is not working correctly for SQS queues, resulting in the removal of the queue policy. This is why you're seeing:
To properly fix this, the CDK would need to ensure that when a principal is identified as being from a different account:
This appears to be a regression that was introduced when fixing the principalAccount property, and would require another fix to ensure that cross-account permissions are handled correctly for SQS queues. |
It's not using cross-account for deployment. The user I'm using is in the same account as the SQS queue. I checked again with command line |
OK after further investigation. I think this is an expected behavior. In 2.141.0 before #30023 public readonly principalAccount = Aws.ACCOUNT_ID; This won't be available in cdk synth time as this is pseudo parameter reference, which will only be resolved in cloudformation deployment time. Starting 2.142.0 public readonly principalAccount = Stack.of(scope).splitArn(attrs.userArn, ArnFormat.SLASH_RESOURCE_NAME).account; This ensures the Now, when aws-cdk/packages/aws-cdk-lib/aws-iam/lib/grant.ts Lines 141 to 143 in f9252ab
Now, given the principal policy is successfully added and the iam.User and sqs.Queue are actually from the "same account", it won't add resource policy anymore as only principal policy is required. This explains why you are seeing the removal of resource-based policy starting 2.142.0. So this is expected. Not a regression. You should still have required permissions to access this queue with the iam.User. Let me know if you still have any issue. |
Thanks I do see the user policy now. I'm fine closing this ticket. Thanks! |
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
When updating CDK from 2.141.0 to a version beyond 2.142.1 it removes the IAM policy of a user setup to read the SQS queue from a user created outside of the CDK project connected using fromUserName or fromUserArn.
Regression Issue
Last Known Working CDK Version
2.141.0
Expected Behavior
When running with CDK version 2.141.0 it behaves as expected for changes:
Current Behavior
When using a version of the CDK beyond 2.142.1 it takes away the permissions that were expected.
Reproduction Steps
Can recreate with a basic example
and
With package.json changing
aws-cdk
andaws-cdk-lib
from2.141.0
to2.142.1
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.142.1 (build ed4e152)
Framework Version
No response
Node.js Version
v18.19.0
OS
Mac 15.3.1
Language
TypeScript
Language Version
Typescript 5.6.3
Other information
No response
The text was updated successfully, but these errors were encountered: