Skip to content

Commit a916061

Browse files
authored
Merge pull request #118 from NHSDigital/feature/eja-eli-238-address-checkov-flagged-issues
Feature/eja eli 238 address checkov flagged issues
2 parents af21a9b + 0c63d71 commit a916061

File tree

28 files changed

+282
-28
lines changed

28 files changed

+282
-28
lines changed

.github/workflows/stage-1-commit.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ jobs:
9797
uses: bridgecrewio/checkov-action@v12
9898
with:
9999
directory: infrastructure/
100-
soft_fail: true
100+
soft_fail: false
101101
output_format: sarif
102102
output_file_path: checkov-report.sarif
103+
- name: Upload Checkov results to GitHub Security tab
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: checkov_results
107+
path: checkov-report.sarif
103108
count-lines-of-code:
104109
name: "Count lines of code"
105110
runs-on: ubuntu-latest

infrastructure/modules/api_gateway/cloudwatch.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "aws_cloudwatch_log_group" "api_gateway" {
22
name = "/aws/apigateway/${var.workspace}-${var.api_gateway_name}"
3-
retention_in_days = 14
3+
retention_in_days = 365
44
tags = var.tags
55
kms_key_id = aws_kms_key.api_gateway.arn
66

infrastructure/modules/api_gateway/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data "aws_iam_policy_document" "api_gateway_logging" {
2727
"logs:GetLogEvents",
2828
"logs:FilterLogEvents"
2929
]
30-
resources = ["*"]
30+
resources = [aws_cloudwatch_log_group.api_gateway.arn]
3131
}
3232
}
3333

infrastructure/modules/api_gateway/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ output "logging_policy_attachment" {
2525
output "iam_role_name" {
2626
value = aws_iam_role.api_gateway.name
2727
}
28+
29+
output "kms_key_arn" {
30+
value = aws_kms_key.api_gateway.arn
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "current" {}

infrastructure/modules/bootstrap/tfstate/kms.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,21 @@ resource "aws_kms_alias" "terraform_state_bucket_cmk" {
1010
name = "alias/${var.project_name}-tfstate_bucket_cmk"
1111
target_key_id = aws_kms_key.terraform_state_bucket_cmk.key_id
1212
}
13+
14+
resource "aws_kms_key_policy" "terraform_state_bucket_cmk" {
15+
key_id = aws_kms_key.terraform_state_bucket_cmk.id
16+
policy = data.aws_iam_policy_document.terraform_state_bucket_cmk.json
17+
}
18+
19+
data "aws_iam_policy_document" "terraform_state_bucket_cmk" {
20+
statement {
21+
sid = "Enable IAM User Permissions for s3 buckets"
22+
effect = "Allow"
23+
principals {
24+
type = "AWS"
25+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
26+
}
27+
actions = ["kms:*"]
28+
resources = [aws_kms_key.terraform_state_bucket_cmk.arn]
29+
}
30+
}

infrastructure/modules/bootstrap/tfstate/s3.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Main state bucket
22
resource "aws_s3_bucket" "tfstate_bucket" {
3+
#checkov:skip=CKV_AWS_144: We don't want to replicate outside our region
4+
#checkov:skip=CKV2_AWS_62: We won't enable event notifications for this bucket, yet
35
bucket = "${var.project_name}-${var.environment}-tfstate"
46
tags = {
57
Stack = "Bootstrap"
@@ -95,6 +97,9 @@ resource "aws_s3_bucket_lifecycle_configuration" "tfstate_bucket" {
9597
# Logging
9698

9799
resource "aws_s3_bucket" "tfstate_s3_access_logs" {
100+
#checkov:skip=CKV_AWS_144: We don't want to replicate outside our region
101+
#checkov:skip=CKV2_AWS_62: We won't enable event notifications for this bucket, yet
102+
#checkov:skip=CKV_AWS_21: Versioning not needed given short lifecycle of logs
98103
bucket = "${var.project_name}-${var.environment}-tfstate-access-logs"
99104
}
100105

@@ -109,7 +114,8 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "tfstate_s3_access
109114

110115
rule {
111116
apply_server_side_encryption_by_default {
112-
sse_algorithm = "AES256"
117+
sse_algorithm = "aws:kms"
118+
kms_master_key_id = aws_kms_key.terraform_state_bucket_cmk.arn
113119
}
114120
}
115121
}
@@ -131,6 +137,16 @@ resource "aws_s3_bucket_lifecycle_configuration" "tfstate_s3_access_logs_object_
131137
noncurrent_days = var.log_retention_in_days
132138
}
133139
}
140+
rule {
141+
id = "StateBucketLogsMultipartUploadExpiration"
142+
status = "Enabled"
143+
filter {
144+
prefix = ""
145+
}
146+
abort_incomplete_multipart_upload {
147+
days_after_initiation = 7
148+
}
149+
}
134150
}
135151

136152
resource "aws_s3_bucket_public_access_block" "s3logs" {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "current" {}

infrastructure/modules/dynamodb/dynamodb.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ resource "aws_dynamodb_table" "dynamodb_table" {
2323
kms_key_arn = aws_kms_key.dynamodb_cmk.arn
2424
}
2525

26+
#checkov:skip=CKV_AWS_28: Point-in-time recovery is enabled only for production environments
27+
point_in_time_recovery {
28+
enabled = var.environment == "prod"
29+
}
30+
2631
tags = var.tags
2732
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "current" {}

0 commit comments

Comments
 (0)