Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
#2890 resolved #2672 with a source_json and override_json field which enables layering of AWS policies. We leverage this mechanism to merge S3 bucket policies from a library of policies, since a bucket can only have one policy (cf #409).
Unfortunately, only two policies can be combined at a time (one each as source_json and override_json), leading to multi-step merges with temporary intermediate policies. You also have to know the name of a statement in the override_json policy in order to insert a dummy statement field, since the statement field is required even if you're combining other policies.
I propose:
- make the
statement field optional
- change
source_json and override_json to accept arrays, where priority for duplicate statements is given to later elements in the array
This makes it easy to merge any number of policies.
Affected Resource
Potential Terraform Configuration
Current:
data "aws_iam_policy_document" "tmp_merge" {
source_json = "${data.aws_iam_policy_document.DenyIncorrectEncryptionHeader.json}"
override_json = "${data.aws_iam_policy_document.DenyUnencryptedObjectUploads.json}"
statement {
sid = "DenyUnencryptedObjectUploads" # will be overridden
}
}
data "aws_iam_policy_document" "secure_bucket" {
policy_id = "SecureBucketPolicy"
source_json = "${data.aws_iam_policy_document.tmp_merge.json}"
override_json = "${data.aws_iam_policy_document.DenyUnencryptedConnections.json}"
statement {
sid = "DenyUnencryptedConnections" # will be overridden
}
}
Proposed:
data "aws_iam_policy_document" "secure_bucket" {
policy_id = "SecureBucketPolicy"
source_json = [
"${data.aws_iam_policy_document.DenyIncorrectEncryptionHeader.json}",
"${data.aws_iam_policy_document.DenyUnencryptedObjectUploads.json}",
"${data.aws_iam_policy_document.DenyUnencryptedConnections.json}",
}
}
References
Community Note
Description
#2890 resolved #2672 with a
source_jsonandoverride_jsonfield which enables layering of AWS policies. We leverage this mechanism to merge S3 bucket policies from a library of policies, since a bucket can only have one policy (cf #409).Unfortunately, only two policies can be combined at a time (one each as
source_jsonandoverride_json), leading to multi-step merges with temporary intermediate policies. You also have to know the name of a statement in theoverride_jsonpolicy in order to insert a dummystatementfield, since thestatementfield is required even if you're combining other policies.I propose:
statementfield optionalsource_jsonandoverride_jsonto accept arrays, where priority for duplicate statements is given to later elements in the arrayThis makes it easy to merge any number of policies.
Affected Resource
Potential Terraform Configuration
Current:
Proposed:
References