cdk-pipelines: Setting CrossAccountKeys with custom bootstrap role causes an error #21973
Labels
@aws-cdk/aws-kms
Related to AWS Key Management
@aws-cdk/pipelines
CDK Pipelines library
bug
This issue is a bug.
effort/medium
Medium work item – several days of effort
p2
Describe the bug
When CrossAccountKeys is set when creating a cdk-pipelines:CodePipeline construct, and launching the stack with a bootstrapped CDK role that doesn't have Admin privileges, the stack will not launch.
Expected Behavior
The following code should create a CodePipeline and a KMS key later used to encrypt pipeline assets even with a non-default CDK bootstrap role:
Current Behavior
When we run the code above, we get the error "The new key policy will not allow you to update the key policy in the future."
The generated CFN template is:
The error can be avoided by including CDK bootstrap role as a Principal in the Key Policy, or by giving the CDK bootstrap role Admin privileges, but there is no way to affect the principals in the Key Policy through the CodePipeline class.
Reproduction Steps
Place the code above in a CDK app (any repo can be used), build. Re-bootstrap your environment with a role that doesn't include Admin (it can include AWSKeyManagementServicePowerUser).
The deployment will fail with the policy error.
Possible Solution
As the only to affect this KMS Key and its policy through CodePipeline class is the boolean CrossAccountKeys property, there is no way to pass a key, role or policy into CodePipeline to avoid this error. Short of submitting a PR to aws-cdk, our only path forward seems to be loosening the policy in the CDK Bootstrap Role.
Am I missing another solution?
Additional Information/Context
No response
CDK CLI Version
2.37.0
Framework Version
2.37.0
Node.js Version
16.15.0
OS
iOS
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: