Skip to content

Commit bfc7a1e

Browse files
[SEC-17144] Restrict access to Agentless S3 Bucket (#172)
1 parent b519e9b commit bfc7a1e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

modules/agentless-s3-bucket/main.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ resource "aws_s3_bucket_lifecycle_configuration" "bucket_lifecycle" {
3636
}
3737

3838
data "aws_iam_policy_document" "bucket_access_policy_document" {
39-
# TODO: add statement to deny access to everyone except the scanner roles
4039
statement {
4140
sid = "DatadogAgentlessScannerBucketPolicy"
4241
effect = "Allow"
@@ -92,6 +91,32 @@ data "aws_iam_policy_document" "bucket_access_policy_document" {
9291
]
9392
}
9493
}
94+
95+
statement {
96+
sid = "DenyAllOtherAccess"
97+
effect = "Deny"
98+
actions = [
99+
"s3:GetObject*",
100+
"s3:ListBucket",
101+
"s3:PutObject*",
102+
]
103+
resources = [
104+
aws_s3_bucket.bucket.arn,
105+
"${aws_s3_bucket.bucket.arn}/*",
106+
]
107+
principals {
108+
type = "AWS"
109+
identifiers = ["*"]
110+
}
111+
condition {
112+
test = "ArnNotEquals"
113+
variable = "aws:PrincipalArn"
114+
values = [
115+
var.iam_delegate_role_arn,
116+
var.rds_service_role_arn,
117+
]
118+
}
119+
}
95120
}
96121

97122
resource "aws_s3_bucket_policy" "bucket_access_policy" {

0 commit comments

Comments
 (0)