Skip to content

Commit

Permalink
enforcing ssl access only on s3 buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert committed Feb 20, 2019
1 parent 53d7c40 commit a69047e
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions terraform/s3.tf
Expand Up @@ -53,6 +53,39 @@ resource "aws_s3_bucket" "binaryalert_log_bucket" {
force_destroy = "${var.force_destroy}"
}

// Policy for log bucket that forces ssl only access
data "aws_iam_policy_document" "force_ssl_only_access" {
# Force SSL access only
statement {
sid = "ForceSSLOnlyAccess"

effect = "Deny"

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

actions = ["s3:*"]

resources = [
"${aws_s3_bucket.binaryalert_log_bucket.arn}",
"${aws_s3_bucket.binaryalert_log_bucket.arn}/*",
]

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

resource "aws_s3_bucket_policy" "force_ssl_only_access" {
bucket = "${aws_s3_bucket.binaryalert_log_bucket.id}"
policy = "${data.aws_iam_policy_document.force_ssl_only_access.json}"
}

// Source S3 bucket: binaries uploaded here will be automatically analyzed.
resource "aws_s3_bucket" "binaryalert_binaries" {
bucket = "${replace(var.name_prefix, "_", ".")}.binaryalert-binaries.${var.aws_region}"
Expand Down Expand Up @@ -146,6 +179,31 @@ data "aws_iam_policy_document" "allow_inventory" {
values = ["${aws_s3_bucket.binaryalert_binaries.arn}"]
}
}

# Force SSL access only
statement {
sid = "ForceSSLOnlyAccess"

effect = "Deny"

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

actions = ["s3:*"]

resources = [
"${aws_s3_bucket.binaryalert_binaries.arn}",
"${aws_s3_bucket.binaryalert_binaries.arn}/*",
]

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

resource "aws_s3_bucket_policy" "allow_inventory" {
Expand Down

0 comments on commit a69047e

Please sign in to comment.