Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
feat(syncer): update bucket policy to require ssl (#3342)
Browse files Browse the repository at this point in the history
feat: update bucket policy to require ssl
  • Loading branch information
sgtoj authored Jul 10, 2023
1 parent 41a74ec commit 7a3d825
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions modules/runner-binaries-syncer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -79,38 +79,52 @@ resource "aws_s3_bucket_versioning" "action_dist" {
}
}

data "aws_iam_policy_document" "action_dist_sse_policy" {
count = try(var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default, null) != null ? 1 : 0

data "aws_iam_policy_document" "action_dist_bucket_policy" {
statement {
effect = "Deny"
sid = "ForceSSLOnlyAccess"
effect = "Deny"
actions = ["s3:*"]
resources = [aws_s3_bucket.action_dist.arn, "${aws_s3_bucket.action_dist.arn}/*"]

principals {
type = "AWS"
identifiers = ["*"]
type = "*"
}

identifiers = [
"*",
]
condition {
test = "Bool"
values = ["false"]
variable = "aws:SecureTransport"
}
}

dynamic "statement" {
for_each = try(var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default, null) != null ? [true] : []

actions = [
"s3:PutObject",
]
content {
sid = "ForceSSE"
effect = "Deny"
actions = ["s3:PutObject"]
resources = ["${aws_s3_bucket.action_dist.arn}/*"]

resources = [
"${aws_s3_bucket.action_dist.arn}/*",
]
principals {
type = "AWS"

condition {
test = "StringNotEquals"
variable = "s3:x-amz-server-side-encryption"
values = [var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default.sse_algorithm]
identifiers = [
"*",
]
}

condition {
test = "StringNotEquals"
variable = "s3:x-amz-server-side-encryption"
values = [var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default.sse_algorithm]
}
}
}
}

resource "aws_s3_bucket_policy" "action_dist_sse_policy" {
count = try(var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default, null) != null ? 1 : 0
resource "aws_s3_bucket_policy" "action_dist_bucket_policy" {
bucket = aws_s3_bucket.action_dist.id
policy = data.aws_iam_policy_document.action_dist_sse_policy[0].json
policy = data.aws_iam_policy_document.action_dist_bucket_policy.json
}

0 comments on commit 7a3d825

Please sign in to comment.