Skip to content

Commit e73905a

Browse files
authored
Merge pull request #283 from NHSDigital/feature/eja-eli-385-remove-wildcard-resource-and-passrole-permissions
eli-385 finessing github permissions
2 parents fb56e51 + 7c1c332 commit e73905a

File tree

3 files changed

+318
-74
lines changed

3 files changed

+318
-74
lines changed

infrastructure/stacks/api-layer/assumed_role_permissions_boundary.tf

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,53 @@ data "aws_iam_policy_document" "assumed_role_permissions_boundary" {
66
effect = "Allow"
77

88
actions = [
9-
"acm:*",
10-
"application-autoscaling:*",
11-
"apigateway:*",
12-
"cloudtrail:*",
13-
"cloudwatch:*",
14-
"config:*",
15-
"dynamodb:*",
16-
"ec2:*",
17-
"events:*",
18-
"firehose:*",
19-
"glue:*",
20-
"health:*",
21-
"iam:*",
22-
"kms:*",
23-
"lambda:*",
24-
"logs:*",
25-
"network-firewall:*",
26-
"pipes:*",
27-
"s3:*",
28-
"schemas:*",
29-
"sns:*",
30-
"servicequotas:*",
31-
"ssm:*",
32-
"states:*",
33-
"support:*",
34-
"sqs:*",
35-
"tag:*",
36-
"trustedadvisor:*",
37-
"xray:*"
9+
# DynamoDB - table operations for Lambda and external write roles
10+
"dynamodb:GetItem",
11+
"dynamodb:Query",
12+
"dynamodb:Scan",
13+
"dynamodb:PutItem",
14+
"dynamodb:UpdateItem",
15+
"dynamodb:DeleteItem",
16+
"dynamodb:BatchWriteItem",
17+
18+
# S3 - bucket and object operations for Lambda and Firehose
19+
"s3:GetObject",
20+
"s3:ListBucket",
21+
"s3:PutObject",
22+
"s3:PutObjectAcl",
23+
"s3:AbortMultipartUpload",
24+
"s3:GetBucketLocation",
25+
"s3:ListBucketMultipartUploads",
26+
27+
# KMS - encryption/decryption for DynamoDB and S3
28+
"kms:Encrypt",
29+
"kms:Decrypt",
30+
"kms:ReEncrypt*",
31+
"kms:GenerateDataKey",
32+
"kms:GenerateDataKey*",
33+
"kms:DescribeKey",
34+
35+
# CloudWatch Logs - Lambda execution and Firehose logging
36+
"logs:CreateLogGroup",
37+
"logs:CreateLogStream",
38+
"logs:PutLogEvents",
39+
"logs:DescribeLogGroups",
40+
"logs:DescribeLogStreams",
41+
42+
# EC2 - VPC access for Lambda (from AWSLambdaVPCAccessExecutionRole)
43+
"ec2:CreateNetworkInterface",
44+
"ec2:DescribeNetworkInterfaces",
45+
"ec2:DeleteNetworkInterface",
46+
"ec2:AttachNetworkInterface",
47+
"ec2:DetachNetworkInterface",
48+
49+
# Kinesis Firehose - Lambda writing audit data
50+
"firehose:PutRecord",
51+
"firehose:PutRecordBatch",
52+
53+
# X-Ray - Lambda tracing
54+
"xray:PutTraceSegments",
55+
"xray:PutTelemetryRecords"
3856
]
3957

4058
resources = ["*"]

infrastructure/stacks/iams-developer-roles/github_actions_policies.tf

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ resource "aws_iam_policy" "s3_management" {
163163
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-truststore/*",
164164
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-truststore-access-logs",
165165
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-truststore-access-logs/*",
166+
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-eli-splunk-backup",
167+
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-eli-splunk-backup/*"
166168
]
167169
}
168170
]
@@ -196,20 +198,62 @@ resource "aws_iam_policy" "api_infrastructure" {
196198
# ACM for certs
197199
"acm:DescribeCertificate",
198200
"acm:GetCertificate",
199-
"acm:ListCertificates",
200-
# S3 for mTLS truststore
201-
"s3:GetObject",
202-
# CloudWatch Logs for logging
203-
"logs:CreateLogGroup",
204-
"logs:CreateLogStream",
205-
"logs:PutLogEvents",
206-
# IAM PassRole for logging role association (if needed)
207-
"iam:PassRole"
201+
"acm:ListCertificates"
208202

209203
],
210204
Resource = "*"
211205
#checkov:skip=CKV_AWS_289: Actions require wildcard resource
212206
},
207+
{
208+
Effect = "Allow",
209+
Action = [
210+
# CloudWatch Logs creation and management
211+
"logs:CreateLogGroup",
212+
"logs:CreateLogStream",
213+
"logs:PutLogEvents"
214+
],
215+
Resource = [
216+
# VPC Flow Logs
217+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/vpc/*",
218+
# Lambda function logs
219+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/*",
220+
# API Gateway logs
221+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/apigateway/*",
222+
# Kinesis Firehose logs
223+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/*"
224+
]
225+
},
226+
{
227+
Effect = "Allow",
228+
Action = [
229+
# IAM PassRole for specific service roles only
230+
"iam:PassRole"
231+
],
232+
Resource = [
233+
# Lambda execution roles
234+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/eligibility_lambda-role*",
235+
# API Gateway CloudWatch logging role
236+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/*-api-gateway-*-role",
237+
# VPC Flow Logs role
238+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/vpc-flow-logs-role*",
239+
# EventBridge to Firehose role
240+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/eventbridge-firehose-role*",
241+
# Kinesis Firehose S3 backup roles
242+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/*firehose*role*",
243+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/splunk-firehose-assume-role*"
244+
],
245+
Condition = {
246+
StringEquals = {
247+
"iam:PassedToService" = [
248+
"lambda.amazonaws.com",
249+
"apigateway.amazonaws.com",
250+
"vpc-flow-logs.amazonaws.com",
251+
"events.amazonaws.com",
252+
"firehose.amazonaws.com"
253+
]
254+
}
255+
}
256+
},
213257
{
214258
Effect = "Allow",
215259
Action = [
@@ -299,24 +343,22 @@ resource "aws_iam_policy" "kms_creation" {
299343
{
300344
Effect = "Allow",
301345
Action = [
346+
# Key creation and listing actions require wildcard resource
302347
"kms:CreateKey",
303-
"kms:DescribeKey",
304348
"kms:CreateAlias",
305349
"kms:List*",
306-
"kms:ListAliases",
307-
"kms:Decrypt",
308-
"kms:Encrypt",
309-
"kms:ReEncrypt*",
350+
"kms:ListAliases"
310351
],
311352
Resource = "*"
312353
},
313354
{
314355
Effect = "Allow",
315356
Action = [
357+
# Key management actions on account-specific keys only
358+
"kms:DescribeKey",
316359
"kms:Describe*",
317360
"kms:GetKeyPolicy*",
318361
"kms:GetKeyRotationStatus",
319-
"kms:Decrypt*",
320362
"kms:DeleteAlias",
321363
"kms:UpdateKeyDescription",
322364
"kms:CreateGrant",
@@ -325,8 +367,9 @@ resource "aws_iam_policy" "kms_creation" {
325367
"kms:ScheduleKeyDeletion",
326368
"kms:PutKeyPolicy",
327369
"kms:Encrypt",
328-
"kms:TagResource",
329-
"kms:GenerateDataKey",
370+
"kms:Decrypt",
371+
"kms:ReEncrypt*",
372+
"kms:GenerateDataKey"
330373
],
331374
Resource = [
332375
"arn:aws:kms:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:key/*",

0 commit comments

Comments
 (0)