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

2256 encrypt cloudtrail logs #2257

Merged
merged 3 commits into from
Sep 28, 2023
Merged
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: 35 additions & 19 deletions infrastructure/cloudtrail.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resource "aws_cloudtrail" "all-events" {
name = "all-events"
s3_bucket_name = var.cloudtrail_bucket_name
kms_key_id = aws_kms_key.key.arn
cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.cloudtrail.arn}:*"
cloud_watch_logs_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.cloudtrail_role_name}"
tags = {
Expand Down Expand Up @@ -71,24 +72,22 @@ resource "aws_s3_bucket_policy" "cloudtrail_bucket" {
}

resource "aws_iam_role" "cloudtrail_role" {
name = var.cloudtrail_role_name
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": [
"cloudtrail.amazonaws.com"
]
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
name = var.cloudtrail_role_name
assume_role_policy = jsonencode({
Version : "2012-10-17",
Statement : [
{
Action : "sts:AssumeRole",
Principal : {
Service : [
"cloudtrail.amazonaws.com"
]
},
Effect : "Allow",
Sid : "CloudTrailServiceRole"
}
]
})
tags = {
Project = var.project
Stage = var.stage
Expand All @@ -104,7 +103,7 @@ data "template_file" "cloudtrail_bucket_policy" {
}

# Attach policies to the IAM role allowing access to the S3 bucket and Cloudwatch
resource "aws_iam_role_policy" "cloudtrail_policy" {
resource "aws_iam_role_policy" "cloudtrail_s3_policy" {
name_prefix = "crossfeed-cloudtrail-s3-${var.stage}"
role = aws_iam_role.cloudtrail_role.id
policy = jsonencode({
Expand Down Expand Up @@ -139,4 +138,21 @@ resource "aws_iam_role_policy" "cloudtrail_cloudwatch_policy" {
Resource = "arn:aws:logs:*"
}]
})
}

resource "aws_iam_role_policy" "cloudtrail_kms_policy" {
name_prefix = "crossfeed-cloudtrail-kms-${var.stage}"
role = aws_iam_role.cloudtrail_role.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Action = [
"kms:GenerateDataKey*",
"kms:Decrypt*",
"kms:DescribeKey"
],
Effect = "Allow",
Resource = aws_kms_key.key.arn
}]
})
}
Loading