Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow account reset codebuild access to custom nuke config bucket #issue409 #412

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.33.9
- Allow account reset codebuild access to custom nuke config bucket

## v0.33.8
- Upgrade the Swagger UI dependency to remove a very dangerous vulnerability (upgrade Swagger UI to v3.51.2).

Expand Down
91 changes: 50 additions & 41 deletions modules/reset_codebuild.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,51 +151,60 @@ EOF
tags = var.global_tags
}

# Configure IAM Policy for CodeBuild
# Configure IAM Role for CodeBuild
resource "aws_iam_role_policy" "codebuild_reset" {
role = aws_iam_role.codebuild_reset.name
name = "account-reset-codebuild-${var.namespace}"
role = aws_iam_role.codebuild_reset.name
name = "account-reset-codebuild-${var.namespace}"
policy = data.aws_iam_policy_document.codebuild_reset_policy_document.json
}

policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
"*"
],
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"sts:AssumeRole",
"ssm:GetParameter",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:Query",
"dynamodb:UpdateItem",
"sns:Publish"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:GetBucketAcl",
"s3:GetBucketLocation"
],
"Resource": [
"${aws_s3_bucket.artifacts.arn}",
"${aws_s3_bucket.artifacts.arn}/*"
]
}
]
# Configure IAM Policy for CodeBuild
data "aws_iam_policy_document" "codebuild_reset_policy_document" {
override_json = var.reset_nuke_template_bucket == "STUB" ? null : data.aws_iam_policy_document.custom_nuke_config[0].json
statement {
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"sts:AssumeRole",
"ssm:GetParameter",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:Query",
"dynamodb:UpdateItem",
"sns:Publish"
]
resources = ["*"]
}
statement {
actions = [
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:GetBucketAcl",
"s3:GetBucketLocation"
]
resources = [
"${aws_s3_bucket.artifacts.arn}",
"${aws_s3_bucket.artifacts.arn}/*"
]
}
}
POLICY

data "aws_iam_policy_document" "custom_nuke_config" {
count = var.reset_nuke_template_bucket == "STUB" ? 0 : 1
statement {
sid = "allowCustomNukeConfig"
# only put this statement if reset_nuke_template_bucket has been set by the user
actions = [
"s3:ListBucket",
"s3:GetObject"
]
resources = [
"arn:aws:s3:::${var.reset_nuke_template_bucket}",
"arn:aws:s3:::${var.reset_nuke_template_bucket}/${var.reset_nuke_template_key}",
]
}
}

# Cloudwatch alarm, for Reset CodeBuild failure
Expand Down