aws-cdk: (aws-cdk): IAM role created by CDK Bootstrap is not following AWS best practices
What is the problem?
Security Hub best practices suggest that IAM roles should not be given encrypt/decrypt permissions to all KMS keys (source).
The deployment role created by CDK bootstrap does not meet this criteria.
Reproduction Steps
Run cdk bootstrap and check the role policy on the deployment role (cdk-hnb659fds-deploy-role-787743944430-eu-west-1).
What did you expect to happen?
The bootstrap process should generate roles which conform to AWS best practices.
What actually happened?
The CDK bootstrap creates an IAM policy which contains a statement which looks like the following:
{
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.eu-west-1.amazonaws.com"
}
},
"Action": [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*"
],
"Resource": "*",
"Effect": "Allow",
"Sid": "PipelineCrossAccountArtifactsKey"
},
This is therefore not following the best practice control guidelines within Security Hub which are proposed by AWS.
CDK CLI Version
2.15.0 (build 151055e)
Framework Version
No response
Node.js Version
16.13.1
OS
Ubuntu
Language
Typescript, Python, .NET, Java, Go
Language Version
No response
Other information
Based on the template file (packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml) I believe that this can be resolved by changing the PipelineCrossAccountArtifactsKey statement in the DeploymentActionRole to use a single KMS resource instead of *.
For example:
- Sid: PipelineCrossAccountArtifactsKey
# Use keys only for the purposes of reading encrypted files from S3.
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
could be updated to:
- Sid: PipelineCrossAccountArtifactsKey
# Use keys only for the purposes of reading encrypted files from S3.
Effect: Allow
Action:
- kms:Decrypt
- kms:DescribeKey
- kms:Encrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
Resource: "arn:aws:kms:*:*:alias/SOME_ALIAS_NAME"
Condition:
StringEquals:
kms:ViaService:
Fn::Sub: s3.${AWS::Region}.amazonaws.com
However, I do not know enough about the internal working of the CDK pipelines to understand if this could use an alias. Perhaps there’s another way to achieve this?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 13
- Comments: 15 (4 by maintainers)
Commits related to this issue
- fix(bootstrap): bootstrap doesn't work in non-aws partitions anymore (revert security hub finding fix) (#25540) **NOTE**: This PR bumps the version of the bootstrap stack to 18, but there is no need ... — committed to aws/aws-cdk by kaizencc 4 years ago
- fix(bootstrap): bootstrap doesn't work in non-aws partitions anymore (revert security hub finding fix) (#25540) **NOTE**: This PR bumps the version of the bootstrap stack to 18, but there is no need ... — committed to aws/aws-cdk by kaizencc 4 years ago
- Update dependency Amazon.CDK.Lib to v2.80.0 (#749) [](https://renovatebot.com) This PR contains the following updates: | Package | Typ... — committed to cythral/brighid-commands by renovate[bot] 4 years ago
- Update dependency Amazon.CDK.Lib to v2.80.0 (#1052) [](https://renovatebot.com) This PR contains the following updates: | Package | Ty... — committed to cythral/brighid-discord-adapter by renovate[bot] 4 years ago
- Update all non-major dependencies (#254) [](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update... — committed to SvenKirschbaum/share.kirschbaum.cloud by renovate[bot] 4 years ago
- Update all non-major dependencies (#6) [](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update |... — committed to SvenKirschbaum/aws-utils by renovate[bot] 3 years ago
You’re right. Security Hub is often a little over jealous in it’s assessments and it often misses additional information like the conditions. However, I think currently that key could be used to encrypt data in any S3 bucket within the account. It wouldn’t be hard for someone to use it incorrectly on another bucket.
Definitely not a huge security risk but it’s not ideal having every account using the CDK being non-compliant with the foundational checks in Security Hub.