AWS cdk medium security documentation change
Summary
Added new sections addressing Security Hub findings related to bootstrap template IAM policies, provided remediation steps for KMS.2 finding, and restructured legacy/modern bootstrap template comparison
Security assessment
The change explicitly addresses AWS Security Hub findings (KMS.2) related to IAM policies with wildcard resources in bootstrap templates. It explains why these findings can be safely ignored due to conditional restrictions, but also provides step-by-step instructions to harden permissions by replacing wildcards with specific ARNs. This directly documents security implications of bootstrap configurations.
Diff
diff --git a/cdk/v2/guide/bootstrapping-env.md b/cdk/v2/guide/bootstrapping-env.md index 4080128f7..774aa0730 100644 --- a//cdk/v2/guide/bootstrapping-env.md +++ b//cdk/v2/guide/bootstrapping-env.md @@ -5 +5 @@ -How to bootstrap your environmentWhen to bootstrap your environmentDefault resources created during bootstrappingPermissions to use when bootstrapping your environmentCustomize bootstrappingBootstrapping with CDK PipelinesBootstrap template version history +How to bootstrap your environmentWhen to bootstrap your environmentDefault resources created during bootstrappingPermissions to use when bootstrapping your environmentCustomize bootstrappingBootstrapping with CDK PipelinesBootstrap template version historyUpgrade from legacy to modern bootstrap templateAddress Security Hub FindingsConsiderations @@ -323 +323 @@ Template version | AWS CDK version | Changes -**30** | 2.1034.0 | Add permissions to describe stack events to the deployment role, to be able to show CloudFormation Early Validation errors accurately. For more information on this change, see `aws-cdk-cli` PR [#970](https://github.com/aws/aws-cdk-cli/pull/970). [#bootstrapping-template] == Upgrade from legacy to modern bootstrap template The AWS CDK v1 supported two bootstrapping templates, legacy and modern. CDK v2 supports only the modern template. For reference, here are the high-level differences between these two templates. [cols="1h,1,1", options="header"] +**30** | 2.1034.0 | Add permissions to describe stack events to the deployment role, to be able to show CloudFormation Early Validation errors accurately. For more information on this change, see `aws-cdk-cli` PR [#970](https://github.com/aws/aws-cdk-cli/pull/970). @@ -325 +325 @@ Template version | AWS CDK version | Changes -| Feature | Legacy (v1 only) | Modern (v1 and v2) +## Upgrade from legacy to modern bootstrap template @@ -327 +327 @@ Template version | AWS CDK version | Changes -|Cross-account deployments |Not allowed |Allowed +The AWS CDK v1 supported two bootstrapping templates, legacy and modern. CDK v2 supports only the modern template. For reference, here are the high-level differences between these two templates. @@ -329 +329,12 @@ Template version | AWS CDK version | Changes -|AWS CloudFormation Permissions |Deploys using current user’s permissions (determined by AWS profile, environment variables, etc.) |Deploys using the permissions specified when the bootstrap stack was provisioned (for example, by using `--trust`) +Feature | Legacy (v1 only) | Modern (v1 and v2) +---|---|--- +**Cross-account deployments** | Not allowed | Allowed +**AWS CloudFormation Permissions** | Deploys using current user’s permissions (determined by AWS profile, environment variables, etc.) | Deploys using the permissions specified when the bootstrap stack was provisioned (for example, by using `--trust`) +**Versioning** | Only one version of bootstrap stack is available | Bootstrap stack is versioned; new resources can be added in future versions, and AWS CDK apps can require a minimum version +**Resources*** | Amazon S3 bucket | + + * Amazon S3 bucket + * AWS KMS key + * IAM roles + * Amazon ECR repository + * SSM parameter for versioning @@ -331 +341,0 @@ Template version | AWS CDK version | Changes -|Versioning |Only one version of bootstrap stack is available |Bootstrap stack is versioned; new resources can be added in future versions, and AWS CDK apps can require a minimum version @@ -333 +343,3 @@ Template version | AWS CDK version | Changes -|Resources* |Amazon S3 bucket a| +**AWS KMS key** | IAM roles | Amazon ECR repository +**Resource naming** | Automatically generated | Deterministic +**Bucket encryption** | Default key | AWS managed key by default. You can customize to use a customer managed key. @@ -335 +347 @@ Template version | AWS CDK version | Changes - * Amazon S3 bucket + * _We will add additional resources to the bootstrap template as needed._ @@ -337 +348,0 @@ Template version | AWS CDK version | Changes - * AWS KMS key @@ -339 +349,0 @@ Template version | AWS CDK version | Changes - * IAM roles @@ -341 +350,0 @@ Template version | AWS CDK version | Changes - * Amazon ECR repository @@ -343 +352,57 @@ Template version | AWS CDK version | Changes - * SSM parameter for versioning +An environment that was bootstrapped using the legacy template must be upgraded to use the modern template for CDK v2 by re-bootstrapping. Re-deploy all AWS CDK applications in the environment at least once before deleting the legacy bucket. + +## Address Security Hub Findings + +If you are using AWS Security Hub, you may see findings reported on some of the resources created by the AWS CDK bootstrapping process. Security Hub findings help you find resource configurations you should double-check for accuracy and safety. We have reviewed these specific resource configurations with AWS Security and are confident they do not constitute a security problem. + +**[KMS.2] IAM principals should not have IAM inline policies that allow decryption actions on all KMS keys** + + +The _deploy role_ (`DeploymentActionRole`) grants permission to read encrypted data, which is necessary for cross-account deployments with CDK Pipelines. Policies in this role do not grant permission to all data. It only grants permission to read encrypted data from Amazon S3 and AWS KMS, and only when those resources allow it through their bucket or key policy. + +The following is a snippet of these two statements in the _deploy role_ from the bootstrap template: + + + DeploymentActionRole: + Type: AWS::IAM::Role + Properties: + ... + Policies: + - PolicyDocument: + Statement: + ... + - Sid: PipelineCrossAccountArtifactsBucket + Effect: Allow + Action: + - s3:GetObject* + - s3:GetBucket* + - s3:List* + - s3:Abort* + - s3:DeleteObject* + - s3:PutObject* + Resource: "*" + Condition: + StringNotEquals: + s3:ResourceAccount: + Ref: AWS::AccountId + - Sid: PipelineCrossAccountArtifactsKey + Effect: Allow + Action: + - kms:Decrypt + - kms:DescribeKey + - kms:Encrypt + - kms:ReEncrypt* + - kms:GenerateDataKey* + Resource: "*" + Condition: + StringEquals: + kms:ViaService: + Fn::Sub: s3.${AWS::Region}.amazonaws.com + ... + +**Why does Security Hub flag this?** + + +The policies contain a `Resource: *` combined with a `Condition` clause. Security Hub flags the `*` wildcard. This wildcard is used because at the time the account is bootstrapped, the AWS KMS key created by CDK Pipelines for the CodePipeline artifact bucket does not exist yet, and therefore, can’t be referenced on the bootstrap template by ARN. In addition, Security Hub does not consider the `Condition` clause when raising this flag. This `Condition` restricts `Resource: *` to requests made from the same AWS account of the AWS KMS key. These requests must come from Amazon S3 in the same AWS Region as the AWS KMS key. + +**Do I need to fix this finding?** @@ -345,0 +411,37 @@ Template version | AWS CDK version | Changes +As long as you have not modified the AWS KMS key on your bootstrap template to be overly permissive, the _deploy role_ does not allow more access than it needs. Therefore, it is not necessary to fix this finding. + +**What if I want to fix this finding?** + + +How you fix this finding depends on whether or not you will be using CDK Pipelines for cross-account deployments. + +**To fix the Security Hub finding and use CDK Pipelines for cross-account deployments** + + + 1. If you have not done so, deploy the CDK bootstrap stack using the `cdk bootstrap` command. + + 2. If you have not done so, create and deploy your CDK Pipeline. For instructions, see [Continuous integration and delivery (CI/CD) using CDK Pipelines](./cdk-pipeline.html). + + 3. Obtain the AWS KMS key ARN of the CodePipeline artifact bucket. This resource is created during pipeline creation. + + 4. Obtain a copy of the CDK bootstrap template to modify it. The following is an example, using the AWS CDK CLI: + + $ cdk bootstrap --show-template > bootstrap-template.yaml + + 5. Modify the template by replacing `Resource: *` of the `PipelineCrossAccountArtifactsKey` statement with your ARN value. + + 6. Deploy the template to update your bootstrap stack. The following is an example, using the CDK CLI: + + $ cdk bootstrap aws://<account-id>/<region> --template bootstrap-template.yaml + + + + +**To fix the Security Hub finding if you’re not using CDK Pipelines for cross-account deployments** + + + 1. Obtain a copy of the CDK bootstrap template to modify it. The following is an example, using the CDK CLI: + + $ cdk bootstrap --show-template > bootstrap-template.yaml + + 2. Delete the `PipelineCrossAccountArtifactsBucket` and `PipelineCrossAccountArtifactsKey` statements from the template. @@ -346,0 +449 @@ Template version | AWS CDK version | Changes + 3. Deploy the template to update your bootstrap stack. The following is an example, using the CDK CLI: @@ -348 +451 @@ Template version | AWS CDK version | Changes -|AWS KMS key |IAM roles |Amazon ECR repository + $ cdk bootstrap aws://<account-id>/<region> --template bootstrap-template.yaml @@ -350 +452,0 @@ Template version | AWS CDK version | Changes -|Resource naming |Automatically generated |Deterministic @@ -352 +453,0 @@ Template version | AWS CDK version | Changes -|Bucket encryption |Default key |AWS managed key by default. You can customize to use a customer managed key. @@ -354,2 +454,0 @@ Template version | AWS CDK version | Changes -* _We will add additional resources to the bootstrap template as needed._ An environment that was bootstrapped using the legacy template must be upgraded to use the modern template for CDK v2 by re-bootstrapping. Re-deploy all AWS CDK applications in the environment at least once before deleting the legacy bucket. [#bootstrapping-securityhub] == Address Security Hub Findings If you are using AWS Security Hub, you may see findings reported on some of the resources created by the AWS CDK bootstrapping process. Security Hub findings help you find resource configurations you should double-check for accuracy and safety. We have reviewed these specific resource configurations with AWS Security and are confident they do not constitute a security problem. [#bootstrapping-securityhub-kms2] **[KMS.2] IAM principals should not have IAM inline policies that allow decryption actions on all KMS keys** :: \+ The _deploy role_ (`DeploymentActionRole`) grants permission to read encrypted data, which is necessary for cross-account deployments with CDK Pipelines. Policies in this role do not grant permission to all data. It only grants permission to read encrypted data from Amazon S3 and AWS KMS, and only when those resources allow it through their bucket or key policy. \+ The following is a snippet of these two statements in the _deploy role_ from the bootstrap template: \+ [source,yaml,subs="verbatim,attributes"] \---- DeploymentActionRole: Type: AWS::IAM::Role Properties: … Policies: \- PolicyDocument: Statement: … \- Sid: PipelineCrossAccountArtifactsBucket Effect: Allow Action: \- s3:GetObject* \- s3:GetBucket* \- s3:List* \- s3:Abort* \- s3:DeleteObject* \- s3:PutObject* Resource: "**" Condition: StringNotEquals: s3:ResourceAccount: Ref: AWS::AccountId \- Sid: PipelineCrossAccountArtifactsKey Effect: Allow Action: \- kms:Decrypt \- kms:DescribeKey \- kms:Encrypt \- kms:ReEncrypt** \- kms:GenerateDataKey* Resource: "**" Condition: StringEquals: kms:ViaService: Fn::Sub: s3.${AWS::Region}.amazonaws.com … \---- \+ [#bootstrapping-securityhub-kms2-why] *Why does Security Hub flag this?**::: \+ The policies contain a `Resource: *` combined with a `Condition` clause. Security Hub flags the `*` wildcard. This wildcard is used because at the time the account is bootstrapped, the AWS KMS key created by CDK Pipelines for the CodePipeline artifact bucket does not exist yet, and therefore, can’t be referenced on the bootstrap template by ARN. In addition, Security Hub does not consider the `Condition` clause when raising this flag. This `Condition` restricts `Resource: ****` to requests made from the same AWS account of the AWS KMS key. These requests must come from Amazon S3 in the same AWS Region as the AWS KMS key. \+ [#bootstrapping-securityhub-kms2-decide] *Do I need to fix this finding?::: \+ As long as you have not modified the AWS KMS key on your bootstrap template to be overly permissive, the _deploy role_ does not allow more access than it needs. Therefore, it is not necessary to fix this finding. \+ [#bootstrapping-securityhub-kms2-fix] **What if I want to fix this finding?** ::: \+ How you fix this finding depends on whether or not you will be using CDK Pipelines for cross-account deployments. \+ **To fix the Security Hub finding and use CDK Pipelines for cross-account deployments** :::: \+ . If you have not done so, deploy the CDK bootstrap stack using the `cdk bootstrap` command. . If you have not done so, create and deploy your CDK Pipeline. For instructions, see [Continuous integration and delivery (CI/CD) using CDK Pipelines](./cdk-pipeline.html). . Obtain the AWS KMS key ARN of the CodePipeline artifact bucket. This resource is created during pipeline creation. . Obtain a copy of the CDK bootstrap template to modify it. The following is an example, using the AWS CDK CLI: \+ [source,bash,subs="verbatim,attributes"] \---- $ cdk bootstrap --show-template bootstrap-template.yaml \---- . Modify the template by replacing `Resource: ****` of the `PipelineCrossAccountArtifactsKey` statement with your ARN value. . Deploy the template to update your bootstrap stack. The following is an example, using the CDK CLI: \+ [source,bash,subs="verbatim,attributes"] \---- $ cdk bootstrap aws://account-id/region --template bootstrap-template.yaml \---- + *To fix the Security Hub finding if you’re not using CDK Pipelines for cross-account deployments:::: \+ . Obtain a copy of the CDK bootstrap template to modify it. The following is an example, using the CDK CLI: \+ [source,bash,subs="verbatim,attributes"] \---- $ cdk bootstrap --show-template bootstrap-template.yaml \---- . Delete the `PipelineCrossAccountArtifactsBucket` and `PipelineCrossAccountArtifactsKey` statements from the template. . Deploy the template to update your bootstrap stack. The following is an example, using the CDK CLI: \+ [source,bash,subs="verbatim,attributes"] \---- $ cdk bootstrap aws://account-id/region --template bootstrap-template.yaml \---- ---- @@ -357 +456 @@ Template version | AWS CDK version | Changes -[#bootstrapping-env-considerations] == Considerations +## Considerations @@ -369 +468 @@ Configure CDK CLI telemetry -Develop AWS CDK applications +Customize bootstrapping