awslabs / awslabs/aws-deployment-framework
[Bug]: DeploymentFrameworkRegionalKMSKey "Allow use of the key" missing permissions for cross-account
- Dominant language
- Python
- Stars
- 699
- Forks
- 235
- Avg merge
- 20h 53m
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Cross-account pipeline deploy actions fail with an error due to missing KMS key resource-based policy permissions for non-admin principals.
### Expected Behavior
Cross-region + cross-account deployment actions succeed.
### Current Behavior
Cross-account pipeline deploy actions fail with error:
```
Replication of artifact '' failed: Failed replicating artifact from in to in : Check source and destination artifact buckets exist and has permission to access it.
```
### Steps To Reproduce
_No response_
### Possible Solution
After troubleshooting, narrowed down issue to [the removal of the following permissions from `DeploymentFrameworkRegionalKMSKey`'s "Allow use of the key" statement](https://github.com/sbkok/aws-deployment-framework/commit/112dd6cf68c8c892f19d87fd32db5e132dbec04f#diff-13105c72ebd071b7bb125b564b6902870b2470711bceb109b9370f9b6cc6b4eaR104):
```
- kms:Encrypt
- kms:GenerateDataKey*
- kms:ReEncrypt*
```
CodePipeline cross-account actions need to allow these permissions on the artifact bucket's KMS key resource based policy for general usage. From [Create a pipeline in CodePipeline that uses resources from another AWS account - Prerequisite: Create an AWS KMS encryption key](https://docs.aws.amazon.com/codepipeline/latest/userguide/pipelines-create-cross-account.html#pipelines-create-cross-account-create-key), step 6 walks through creating the KMS key using the console:
> In Define Key Usage Permissions, under This Account, select the name of the service role for the pipeline (for example, CodePipeline_Service_Role). Under Other AWS accounts, choose Add another AWS account. Enter the account ID for AccountB to complete the ARN, and then choose Next.
This step will generate the following statement in the key's policy:
```
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam:::root"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*"
}
```
And later under subheading ["Configure policies and roles in the account that owns the AWS resource (AccountB)"](https://docs.aws.amazon.com/codepipeline/latest/userguide/pipelines-create-cross-account.html#pipelines-create-cross-account-setup-accountb), these permissions are added to the cross-account role. So for key usage, we need the `kms:Encrypt`, `kms:GenerateDataKey*`, and `kms:ReEncrypt*` added back.
### Additional Information/Context
_No response_
### ADF Version
4.0.0
### Contributing a fix?
- [X] Yes, I am working on a fix to resolve this issue
```[tasklist]
### Tasks
- [ ] https://github.com/awslabs/aws-deployment-framework/pull/757
```
Contributor guide
Research direction
Inspect the DeploymentFrameworkRegionalKMSKey "Allow use of the key" statement and the linked commit diff, then review PR 757 because the issue says a fix is already in progress. Done means the key policy supports the documented cross-account CodePipeline permissions and cross-region, cross-account deployment actions succeed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud, devops, security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 20/100