Skip to content

Commit 858bae5

Browse files
authored
Merge pull request #15 from ONS-Innovation/credential-refactor-and-key-rotation
KEH 1706 & 1708: Credential Refactor and Key Rotation
2 parents 44a33d9 + d0c3192 commit 858bae5

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

checkov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
skip-check:
2+
- CKV_AWS_273 # IAM user required for local development
3+
- CKV_AWS_149 # AWS-managed key encryption is sufficient and CMK not required for this service
4+
- CKV2_AWS_57 # Key rotation is already provisioned by external module

terraform/batch/main.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,46 @@ resource "aws_iam_role_policy_attachment" "s3_policy_attachment" {
7070
role = split("/", module.batch_eventbridge.batch_job_role_arn)[1]
7171
policy_arn = aws_iam_policy.s3_access.arn
7272
}
73+
74+
# IAM User Group
75+
resource "aws_iam_group" "group" {
76+
name = "${var.domain}-${var.service_subdomain}-user-group"
77+
path = "/"
78+
}
79+
80+
# Attach S3 policy to group
81+
resource "aws_iam_group_policy_attachment" "group_s3_access_attachment" {
82+
group = aws_iam_group.group.name
83+
policy_arn = aws_iam_policy.s3_access.arn
84+
}
85+
86+
# Attach Secrets Manager policy to group
87+
resource "aws_iam_group_policy_attachment" "group_secrets_attachment" {
88+
group = aws_iam_group.group.name
89+
policy_arn = aws_iam_policy.secrets_access.arn
90+
}
91+
92+
# IAM User
93+
resource "aws_iam_user" "user" {
94+
name = "${var.domain}-${var.service_subdomain}"
95+
path = "/"
96+
}
97+
98+
# Assign IAM User to group
99+
resource "aws_iam_user_group_membership" "user_group_attach" {
100+
user = aws_iam_user.user.name
101+
102+
groups = [
103+
aws_iam_group.group.name
104+
]
105+
}
106+
107+
# IAM Key Rotation Module
108+
module "iam_key_rotation" {
109+
source = "git::https://github.com/ONS-Innovation/keh-aws-iam-key-rotation.git?ref=v0.1.0"
110+
111+
iam_username = aws_iam_user.user.name
112+
access_key_secret_arn = aws_secretsmanager_secret.access_key.arn
113+
secret_key_secret_arn = aws_secretsmanager_secret.secret_key.arn
114+
rotation_in_days = 90
115+
}

terraform/batch/secrets.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Secrets Manager resources for IAM user access keys
2+
3+
resource "aws_secretsmanager_secret" "access_key" {
4+
name = "${var.domain}-${var.service_subdomain}-access-key"
5+
description = "Access Key ID for github statistics scraper IAM user"
6+
recovery_window_in_days = 0 // Secret will be deleted immediately
7+
force_overwrite_replica_secret = true // Allow overwriting the secret in case of changes
8+
}
9+
10+
resource "aws_secretsmanager_secret" "secret_key" {
11+
name = "${var.domain}-${var.service_subdomain}-secret-key"
12+
description = "Secret Access Key for github stastics scraper IAM user"
13+
recovery_window_in_days = 0 // Secret will be deleted immediately
14+
force_overwrite_replica_secret = true // Allow overwriting the secret in case of changes
15+
}

0 commit comments

Comments
 (0)