Skip to content

Commit

Permalink
feat: add support for kms replication of objects
Browse files Browse the repository at this point in the history
- When doing cross account replications for items that are encrypted
at rest using SSE-KMS you need to provide a new key in the S3 account
that can be used
- This update covers the extra permissions and processes that we do
  • Loading branch information
roleyfoley committed Oct 26, 2023
1 parent e81a478 commit 7b8dd54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
15 changes: 13 additions & 2 deletions aws/components/s3/setup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[#local replicationCrossAccount = false ]
[#local replicationDestinationAccountId = "" ]
[#local replicationExternalPolicy = []]
[#local replicationKMSKey = ""]

[#local backupTags = {} ]

Expand Down Expand Up @@ -296,9 +297,16 @@
[#local replicationEnabled = true]
[#local versioningEnabled = true]

[#local replicationDestinationAccountId = linkTargetAttributes["ACCOUNT_ID"]!"" ]
[#local replicationDestinationAccountId = (linkTargetAttributes["ACCOUNT_ID"])!"" ]
[#local replicationExternalPolicy += s3ReplicaDestinationPermission( linkTargetAttributes["ARN"] ) ]
[#local replicationBucket = linkTargetAttributes["ARN"]]
[#local replicationKMSKey = (linkTargetAttributes["KMS_KEY_ARN"])!""]
[#local replicationKMSKeyARN = (linkTargetAttributes["KMS_KEY_REGION"])!""]

[#if replicationKMSKey?has_content ]
[#local replicationExternalPolicy += s3EncryptionAllPermission(replicationKMSKey, replicationBucket, "*", replicationKMSKeyARN)]
[/#if]

[#break]

[#case "save" ]
Expand Down Expand Up @@ -394,7 +402,10 @@
solution.Replication.Enabled,
prefix,
replicateEncryptedData,
kmsKeyId,
replicationKMSKey?has_content?then(
replicationKMSKey,
kmsKeyId
),
replicationDestinationAccountId
)]]
[/#list]
Expand Down
8 changes: 7 additions & 1 deletion aws/services/kms/policy.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@
"",
{
"StringLike" : {
"kms:EncryptionContext:aws:s3:arn" : "arn:aws:s3:::" + formatRelativePath(bucketName, bucketPrefix?ensure_ends_with("*") )
"kms:EncryptionContext:aws:s3:arn" : formatRelativePath(
bucketName?is_string?then(
bucketName?ensure_starts_with("arn:aws:s3:::"),
bucketName
),
bucketPrefix?ensure_ends_with("*")
)
}
}
)
Expand Down
1 change: 1 addition & 0 deletions aws/services/s3/policy.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
[#return
getS3Statement(
[
"s3:PutObject",
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ObjectOwnerOverrideToBucketOwner",
Expand Down

0 comments on commit 7b8dd54

Please sign in to comment.