Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from MeteoGroup/restrict_read_prefix
Browse files Browse the repository at this point in the history
Restrict read prefix
  • Loading branch information
Peter Lohmann authored Dec 16, 2019
2 parents b95c91b + 3cce33a commit 8c05fae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
26 changes: 17 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,23 @@ data "aws_iam_policy_document" "bucket_policy_read" {
count = local.enable_read_accounts ? 1 : 0

statement {
sid = "AllowCrossAccountRead"
resources = [
local.bucket_arn,
"${local.bucket_arn}/*",
]
actions = [
"s3:Get*",
"s3:List*",
]
sid = "AllowCrossAccountList"
resources = [local.bucket_arn]
actions = ["s3:List*"]
principals {
type = "AWS"
identifiers = var.read_accounts
}
condition {
test = "StringLike"
variable = "s3:prefix"
values = ["${var.read_prefix}*"]
}
}
statement {
sid = "AllowCrossAccountGet"
resources = ["${local.bucket_arn}/${var.read_prefix}*",]
actions = ["s3:Get*"]
principals {
type = "AWS"
identifiers = var.read_accounts
Expand Down
Empty file modified outputs.tf
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ variable "read_accounts" {
default = []
}

variable "read_prefix" {
description = "Prefix of object keys to restrict cross-account reads to"
type = string
default = ""
}

variable "write_accounts" {
description = "List of other AWS accounts which should get write access to the bucket"
type = list(string)
Expand Down

0 comments on commit 8c05fae

Please sign in to comment.