Skip to content

better AWS policy layering #5047

@tvald

Description

@tvald

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:

  1. make the statement field optional
  2. 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

  • aws_iam_policy_document

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

Metadata

Metadata

Assignees

Labels

enhancementRequests to existing resources that expand the functionality or scope.service/iamIssues and PRs that pertain to the iam service.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions