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

WIP: Allow jobs to upload to S3 buckets #252

Open
wants to merge 4 commits into
base: main
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
54 changes: 41 additions & 13 deletions s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,28 @@ data "aws_iam_policy_document" "bucket-policy" {
"${aws_s3_bucket.this.arn}/*",
]
}

dynamic "statement" {
for_each = var.config.additional_access_role != null ? [1] : []

content {
actions = ["s3:PutObject"]
effect = "Allow"

principals {
type = "AWS"
identifiers = [var.config.additional_access_role]
}

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

resource "aws_s3_bucket_policy" "bucket-policy" {
count = var.config.serve_static_content ? 0 : 1

bucket = aws_s3_bucket.this.id
policy = data.aws_iam_policy_document.bucket-policy.json
}
Expand Down Expand Up @@ -82,26 +99,37 @@ resource "aws_s3_bucket_lifecycle_configuration" "lifecycle-configuration" {
}

resource "aws_kms_key" "kms-key" {
count = var.config.serve_static_content ? 0 : 1

# checkov:skip=CKV_AWS_7:We are not currently rotating the keys
description = "KMS Key for S3 encryption"
tags = local.tags
}

resource "aws_kms_key_policy" "kms-key-policy" {
count = var.config.additional_access_role && var.config.serve_static_content ? 1 : 0

key_id = aws_kms_key.kms-key.id
policy = jsonencode({
Id = "key-default-1"
Version = "2012-10-17"
Id = "key-default-1"
Statement = [
{
"Sid" : "Enable IAM User Permissions",
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
Sid = "Enable IAM User Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
"Action" : "kms:*",
"Resource" : "*"
}
Action = "kms:*"
Resource = "*"
}, {
Sid = "Allow cross account S3 uploads",
Effect = "Allow",
Principal = {
AWS = var.config.additional_access_role
},
Action = "kms:GenerateDataKey"
Resource = "*"
}
]
Version = "2012-10-17"
})
}

Expand Down
1 change: 1 addition & 0 deletions s3/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ variable "vpc_name" {
variable "config" {
type = object({
bucket_name = string
additional_access_role = optional(string)
versioning = optional(bool)
retention_policy = optional(object({
mode = string
Expand Down
Loading