-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Closed
Closed
Copy link
Labels
@aws-cdk/aws-s3-deploymentbugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp1
Description
Describe the bug
When initialising the toolkit stack with --bootstrap-kms-key-id the bucket deployment fails.
Expected Behavior
Bucket deployment copies the ressources to the desired destination
Current Behavior
The deployment fails and the logs read:
download failed: s3://cdk-<qualifier>-assets-<account>-<region>/<asset-hash>.zip to <tmp-folder> An error occurred (AccessDenied) when calling the GetObject operation: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access.
Reproduction Steps
Bootstrap with KMS:
npx cdk bootstrap aws://$AWS_ACCOUNT_ID/$AWS_REGION --bootstrap-kms-key-id $KMS_KEY_IDcreate a stack with a bucket deployment
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
export class MyStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create an S3 bucket
const bucket = new s3.Bucket(this, 'MyBucket', {
bucketName: 'my-bucket-name'
});
// Deploy a text file to the bucket using BucketDeployment
new s3deploy.BucketDeployment(this, 'DeployTextFile', {
sources: [s3deploy.Source.asset('./path/to/text/file.txt')],
destinationBucket: bucket,
destinationKeyPrefix: 'path/to/deployed/text/file.txt'
});
}
}
Possible Solution
The handlerRole of the BucketDeployment construct needs to have something like this:
Key.fromKeyArn(this, 'cdk-toolkit-encryption-key', Stack.of(this).formatArn({
region: Aws.REGION,
service: 'kms',
account: Aws.ACCOUNT_ID,
resource: 'key',
resourceName: Fn.importValue(`CdkBootstrap-${this.node.tryGetContext('@aws-cdk/core:bootstrapQualifier')}-FileAssetKeyArn`),
}))
// @ts-ignore
.grantEncryptDecrypt(bucketDeployment.handlerRole);
Additional Information/Context
Bootstrap Stack is updated to the most recent version
CDK CLI Version
2.73.0
Framework Version
No response
Node.js Version
16.20.0
OS
macos 13.2.1
Language
Typescript
Language Version
4.9.5
Other information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-s3-deploymentbugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp1