Skip to content

Commit

Permalink
fix: attach bucket access policy to content bucket instead of assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
jsterner30 committed Apr 10, 2024
1 parent 93e82fc commit 710346e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 48 deletions.
32 changes: 32 additions & 0 deletions iac/modules/app/content-bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,35 @@ resource "aws_s3_bucket_versioning" "bucket_versioning" {
status = "Enabled"
}
}

resource "aws_s3_bucket_policy" "allow_builder_access" {
bucket = aws_s3_bucket.CdnContentBucket.id
policy = data.aws_iam_policy.CdnContentBucketAllowBuilderUpdates.arn
}


data "aws_iam_policy" "CdnContentBucketAllowBuilderUpdates" {
name = "CdnContentBucketAllowBuilderUpdates"
description = "Allows assembler to access s3 content bucket"
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"s3:ListBucket",
"s3:PutBucketWebsite",
"s3:Get*"
],
"Resource" : "arn:aws:s3:::${aws_s3_bucket.CdnContentBucket.id}"
},
{
"Effect" : "Allow",
"Action" : [
"s3:*",
],
"Resource" :"arn:aws:s3:::${aws_s3_bucket.CdnContentBucket.id}/*"
}
]
})
}
48 changes: 0 additions & 48 deletions iac/modules/app/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,6 @@ resource "aws_iam_policy" "AllowCloudFrontInvalidation" {
})
}

resource "aws_iam_policy" "CdnContentBucketAllowBuilderUpdates" {
name = "CdnContentBucketAllowBuilderUpdates"
description = "Allows S3 Access From Assembler"
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"s3:ListBucket",
"s3:PutBucketWebsite",
"s3:Get*"
],
"Resource" : "arn:aws:s3:::${aws_s3_bucket.CdnContentBucket.id}"
}
]
})
}

resource "aws_iam_policy" "S3ObjectAccess" {
name = "S3ObjectAccess"
description = "Allows S3 Object Access From Assembler"
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"s3:*",
],
"Resource" : "arn:aws:s3:::${aws_s3_bucket.CdnContentBucket.id}/*"
}
]
})
}

data "aws_ecr_repository" "assembler_ecr_repo" {
name = "${var.cdn_name}-assembler"
}
Expand Down Expand Up @@ -144,18 +108,6 @@ resource "aws_iam_role_policy_attachment" "AllowAssemblerImageAccessAttachment"
policy_arn = aws_iam_policy.AllowAssemblerImageAccess.arn
}

resource "aws_iam_role_policy_attachment" "S3ObjectAccess" {
depends_on = [aws_iam_policy.S3ObjectAccess, aws_iam_role.CdnBuilderRole]
role = aws_iam_role.CdnBuilderRole.name
policy_arn = aws_iam_policy.S3ObjectAccess.arn
}

resource "aws_iam_role_policy_attachment" "CdnContentBucketAllowBuilderUpdates" {
depends_on = [aws_iam_policy.CdnContentBucketAllowBuilderUpdates, aws_iam_role.CdnBuilderRole]
role = aws_iam_role.CdnBuilderRole.name
policy_arn = aws_iam_policy.CdnContentBucketAllowBuilderUpdates.arn
}

data "aws_iam_policy_document" "ecs_invokation_policy" {
version = "2012-10-17"
statement {
Expand Down

0 comments on commit 710346e

Please sign in to comment.