diff --git a/aws/components/s3/setup.ftl b/aws/components/s3/setup.ftl index 01aa1464..84d7f90b 100644 --- a/aws/components/s3/setup.ftl +++ b/aws/components/s3/setup.ftl @@ -37,6 +37,7 @@ [#local replicationCrossAccount = false ] [#local replicationDestinationAccountId = "" ] [#local replicationExternalPolicy = []] + [#local replicationKMSKey = ""] [#local backupTags = {} ] @@ -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" ] @@ -394,7 +402,10 @@ solution.Replication.Enabled, prefix, replicateEncryptedData, - kmsKeyId, + replicationKMSKey?has_content?then( + replicationKMSKey, + kmsKeyId + ), replicationDestinationAccountId )]] [/#list] diff --git a/aws/services/kms/policy.ftl b/aws/services/kms/policy.ftl index 5cf45b2f..11f049a5 100644 --- a/aws/services/kms/policy.ftl +++ b/aws/services/kms/policy.ftl @@ -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("*") + ) } } ) diff --git a/aws/services/s3/policy.ftl b/aws/services/s3/policy.ftl index 5eadf76c..c524b90b 100644 --- a/aws/services/s3/policy.ftl +++ b/aws/services/s3/policy.ftl @@ -243,6 +243,7 @@ [#return getS3Statement( [ + "s3:PutObject", "s3:ReplicateObject", "s3:ReplicateDelete", "s3:ObjectOwnerOverrideToBucketOwner",