Skip to content

Commit e18d117

Browse files
committed
NRL-853 disallow http requests in s3 buckets
1 parent 87b7316 commit e18d117

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

terraform/account-wide-infrastructure/dev/aws-backups.tf

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ locals {
3030
destination_account_id = data.aws_secretsmanager_secret_version.destination_account_id.secret_string
3131
}
3232

33-
# First, we create an S3 bucket for compliance reports. You may already have a module for creating
34-
# S3 buckets with more refined access rules, which you may prefer to use.
35-
33+
# First, we create an S3 bucket for compliance reports.
3634
resource "aws_s3_bucket" "backup_reports" {
3735
bucket_prefix = "${local.project_name}-backup-reports"
3836
}
@@ -55,7 +53,33 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "backup_reports" {
5553
}
5654
}
5755
}
58-
# Now we have to configure access to the report bucket.
56+
57+
resource "aws_s3_bucket_policy" "backup_reports_bucket_policy" {
58+
bucket = aws_s3_bucket.backup_reports.id
59+
60+
policy = jsonencode({
61+
Version = "2012-10-17"
62+
Id = "backup_reports_bucket_policy"
63+
Statement = [
64+
{
65+
Sid = "HTTPSOnly"
66+
Effect = "Deny"
67+
Principal = "*"
68+
Action = "s3:*"
69+
Resource = [
70+
aws_s3_bucket.backup_reports.arn,
71+
"${aws_s3_bucket.backup_reports.arn}/*",
72+
]
73+
Condition = {
74+
Bool = {
75+
"aws:SecureTransport" = "false"
76+
}
77+
}
78+
},
79+
]
80+
})
81+
}
82+
5983

6084
resource "aws_s3_bucket_ownership_controls" "backup_reports" {
6185
bucket = aws_s3_bucket.backup_reports.id

terraform/account-wide-infrastructure/modules/permissions-store-bucket/s3.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "authorization-sto
2727
}
2828
}
2929

30+
resource "aws_s3_bucket_policy" "authorization_store_bucket_policy" {
31+
bucket = aws_s3_bucket.authorization-store.id
32+
33+
policy = jsonencode({
34+
Version = "2012-10-17"
35+
Id = "authorization_store_bucket_policy"
36+
Statement = [
37+
{
38+
Sid = "HTTPSOnly"
39+
Effect = "Deny"
40+
Principal = "*"
41+
Action = "s3:*"
42+
Resource = [
43+
aws_s3_bucket.authorization-store.arn,
44+
"${aws_s3_bucket.authorization-store.arn}/*",
45+
]
46+
Condition = {
47+
Bool = {
48+
"aws:SecureTransport" = "false"
49+
}
50+
}
51+
},
52+
]
53+
})
54+
}
55+
3056
resource "aws_s3_bucket_versioning" "authorization-store" {
3157
bucket = aws_s3_bucket.authorization-store.id
3258
versioning_configuration {

0 commit comments

Comments
 (0)