Skip to content

Commit a807319

Browse files
authored
Merge pull request #413 from NHSDigital/bugfix/eja-fixing-tagging-permissions
eli-413 adding tagging permissions and workaround for limit to s3 tags
2 parents 77b124a + 23ad76c commit a807319

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

infrastructure/stacks/api-layer/truststore_s3_bucket.tf

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ resource "aws_s3_bucket_policy" "truststore" {
1313
}
1414

1515
data "aws_iam_policy_document" "truststore_api_gateway" {
16-
# Deny non-SSL
17-
statement {
18-
sid = "AllowSslRequestsOnly"
19-
actions = ["s3:*"]
20-
effect = "Deny"
21-
resources = [
22-
module.s3_truststore_bucket.storage_bucket_arn,
23-
"${module.s3_truststore_bucket.storage_bucket_arn}/*"
16+
# Deny non-SSL
17+
statement {
18+
sid = "AllowSslRequestsOnly"
19+
actions = ["s3:*"]
20+
effect = "Deny"
21+
resources = [
22+
module.s3_truststore_bucket.storage_bucket_arn,
23+
"${module.s3_truststore_bucket.storage_bucket_arn}/*"
2424
]
2525
principals {
2626
type = "*"
@@ -55,4 +55,11 @@ resource "aws_s3_object" "pem_file" {
5555
content = local.pem_file_content
5656

5757
acl = "private"
58+
59+
# Explicitly set empty tags to override default_tags due to S3 object 10-tag limit
60+
tags = {}
61+
62+
lifecycle {
63+
ignore_changes = [tags_all]
64+
}
5865
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ resource "aws_iam_policy" "dynamodb_management" {
104104
"dynamodb:DeleteTable",
105105
"dynamodb:CreateTable",
106106
"dynamodb:TagResource",
107+
"dynamodb:UntagResource",
107108
"dynamodb:ListTagsOfResource",
108109
"dynamodb:UpdateTable",
109110
],
@@ -178,7 +179,8 @@ resource "aws_iam_policy" "s3_management" {
178179
"s3:PutBucketLogging",
179180
"s3:GetObjectTagging",
180181
"s3:PutObjectTagging",
181-
"s3:GetObjectVersion"
182+
"s3:GetObjectVersion",
183+
"s3:PutBucketTagging",
182184
],
183185
Resource = [
184186
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-eli-rules",
@@ -299,9 +301,11 @@ resource "aws_iam_policy" "api_infrastructure" {
299301
"logs:AssociateKmsKey",
300302
"logs:CreateLogGroup",
301303
"logs:PutMetricFilter",
304+
"logs:TagResource",
302305

303306
# EC2 permissions
304307
"ec2:CreateTags",
308+
"ec2:DeleteTags",
305309
"ec2:CreateNetworkAclEntry",
306310
"ec2:CreateNetworkAcl",
307311
"ec2:AssociateRouteTable",
@@ -357,6 +361,7 @@ resource "aws_iam_policy" "api_infrastructure" {
357361
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/vpc/*",
358362
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/*",
359363
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/apigateway/*",
364+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/eligibility-signposting-api-${var.environment}-audit/*",
360365
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:NHSDAudit_trail_log_group*",
361366
"arn:aws:ssm:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.environment}/*",
362367
"arn:aws:ssm:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:parameter/splunk/*",
@@ -411,6 +416,7 @@ resource "aws_iam_policy" "kms_creation" {
411416
"kms:UpdateKeyDescription",
412417
"kms:CreateGrant",
413418
"kms:TagResource",
419+
"kms:UntagResource",
414420
"kms:EnableKeyRotation",
415421
"kms:ScheduleKeyDeletion",
416422
"kms:PutKeyPolicy",
@@ -459,6 +465,7 @@ resource "aws_iam_policy" "iam_management" {
459465
"iam:TagRole",
460466
"iam:PassRole",
461467
"iam:TagPolicy",
468+
"iam:UntagPolicy",
462469
],
463470
Resource = [
464471
# Lambda role
@@ -564,6 +571,8 @@ resource "aws_iam_policy" "cloudwatch_management" {
564571
"logs:ListTagsForResource",
565572
"logs:DescribeLogGroups",
566573
"logs:PutRetentionPolicy",
574+
"logs:TagResource",
575+
"logs:UntagResource",
567576

568577
"cloudwatch:PutMetricAlarm",
569578
"cloudwatch:DeleteAlarms",
@@ -589,7 +598,8 @@ resource "aws_iam_policy" "cloudwatch_management" {
589598
Resource = [
590599
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/*",
591600
"arn:aws:cloudwatch:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:alarm:*",
592-
"arn:aws:sns:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:cloudwatch-security-alarms*"
601+
"arn:aws:sns:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:cloudwatch-security-alarms*",
602+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/apigateway/default-eligibility-signposting-api*",
593603
]
594604
}
595605
]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ data "aws_iam_policy_document" "permissions_boundary" {
3535
"dynamodb:DeleteTable",
3636
"dynamodb:CreateTable",
3737
"dynamodb:TagResource",
38+
"dynamodb:UntagResource",
3839
"dynamodb:ListTagsOfResource",
3940
"dynamodb:UpdateTable",
4041

4142
# EC2 - networking infrastructure
4243
"ec2:Describe*",
4344
"ec2:ModifyVpcBlockPublicAccessOptions",
4445
"ec2:CreateTags",
46+
"ec2:DeleteTags",
4547
"ec2:CreateNetworkAclEntry",
4648
"ec2:CreateNetworkAcl",
4749
"ec2:AssociateRouteTable",
@@ -105,6 +107,7 @@ data "aws_iam_policy_document" "permissions_boundary" {
105107
"iam:CreatePolicy",
106108
"iam:CreatePolicyVersion",
107109
"iam:TagRole",
110+
"iam:UntagPolicy",
108111
"iam:PassRole",
109112
"iam:TagPolicy",
110113

@@ -123,6 +126,7 @@ data "aws_iam_policy_document" "permissions_boundary" {
123126
"kms:UpdateKeyDescription",
124127
"kms:CreateGrant",
125128
"kms:TagResource",
129+
"kms:UntagResource",
126130
"kms:EnableKeyRotation",
127131
"kms:ScheduleKeyDeletion",
128132
"kms:PutKeyPolicy",
@@ -167,6 +171,8 @@ data "aws_iam_policy_document" "permissions_boundary" {
167171
"logs:DescribeLogStreams",
168172
"logs:Describe*",
169173
"logs:ListTagsForResource",
174+
"logs:TagResource",
175+
"logs:UntagResource",
170176
"logs:PutRetentionPolicy",
171177
"logs:AssociateKmsKey",
172178
"logs:PutMetricFilter",
@@ -204,6 +210,7 @@ data "aws_iam_policy_document" "permissions_boundary" {
204210
"s3:GetObjectTagging",
205211
"s3:PutObjectTagging",
206212
"s3:GetObjectVersion",
213+
"s3:PutBucketTagging",
207214

208215
# SNS - notification management
209216
"sns:CreateTopic",

0 commit comments

Comments
 (0)