|
3 | 3 |
|
4 | 4 | // S3 read only access policy |
5 | 5 | data "aws_iam_policy_document" "read_only_s3_department_access" { |
| 6 | + # Include CloudTrail bucket access for data-and-insight department |
| 7 | + source_policy_documents = local.department_identifier == "data-and-insight" && var.cloudtrail_bucket != null ? [ |
| 8 | + data.aws_iam_policy_document.cloudtrail_access[0].json |
| 9 | + ] : [] |
| 10 | + |
6 | 11 | statement { |
7 | 12 | sid = "ListAllS3AndKmsKeys" |
8 | 13 | effect = "Allow" |
@@ -32,6 +37,8 @@ data "aws_iam_policy_document" "read_only_s3_department_access" { |
32 | 37 | ] |
33 | 38 | } |
34 | 39 |
|
| 40 | + |
| 41 | + |
35 | 42 | dynamic "statement" { |
36 | 43 | for_each = var.additional_s3_access |
37 | 44 | iterator = additional_access_item |
@@ -90,6 +97,8 @@ data "aws_iam_policy_document" "read_only_s3_department_access" { |
90 | 97 | ] |
91 | 98 | } |
92 | 99 |
|
| 100 | + |
| 101 | + |
93 | 102 | dynamic "statement" { |
94 | 103 | for_each = var.additional_s3_access |
95 | 104 | iterator = additional_access_item |
@@ -180,6 +189,11 @@ resource "aws_iam_policy" "read_only_glue_access" { |
180 | 189 |
|
181 | 190 | // Full departmental S3 access policy |
182 | 191 | data "aws_iam_policy_document" "s3_department_access" { |
| 192 | + # Include CloudTrail bucket access for data-and-insight department |
| 193 | + source_policy_documents = local.department_identifier == "data-and-insight" && var.cloudtrail_bucket != null ? [ |
| 194 | + data.aws_iam_policy_document.cloudtrail_access[0].json |
| 195 | + ] : [] |
| 196 | + |
183 | 197 | statement { |
184 | 198 | sid = "ListAllS3AndKmsKeys" |
185 | 199 | effect = "Allow" |
@@ -215,6 +229,8 @@ data "aws_iam_policy_document" "s3_department_access" { |
215 | 229 | ] |
216 | 230 | } |
217 | 231 |
|
| 232 | + |
| 233 | + |
218 | 234 | dynamic "statement" { |
219 | 235 | for_each = var.additional_s3_access |
220 | 236 | iterator = additional_access_item |
@@ -277,10 +293,12 @@ data "aws_iam_policy_document" "s3_department_access" { |
277 | 293 | var.mwaa_etl_scripts_bucket_arn, |
278 | 294 | "${var.mwaa_etl_scripts_bucket_arn}/${replace(local.department_identifier, "-", "_")}/*", |
279 | 295 | "${var.mwaa_etl_scripts_bucket_arn}/unrestricted/*", |
280 | | - "${var.mwaa_etl_scripts_bucket_arn}/shared/*", |
| 296 | + "${var.mwaa_etl_scripts_bucket_arn}/shared/*" |
281 | 297 | ] |
282 | 298 | } |
283 | 299 |
|
| 300 | + |
| 301 | + |
284 | 302 | dynamic "statement" { |
285 | 303 | for_each = var.additional_s3_access |
286 | 304 | iterator = additional_access_item |
@@ -1079,3 +1097,40 @@ resource "aws_iam_policy" "mtfh_access_policy" { |
1079 | 1097 | description = "Allows ${local.department_identifier} department access for ecs tasks to mtfh/ subdirectory in landing zone" |
1080 | 1098 | policy = data.aws_iam_policy_document.mtfh_access[0].json |
1081 | 1099 | } |
| 1100 | + |
| 1101 | +// Read-only CloudTrail access for Data and Insight department only |
| 1102 | +data "aws_iam_policy_document" "cloudtrail_access" { |
| 1103 | + count = local.department_identifier == "data-and-insight" && var.cloudtrail_bucket != null ? 1 : 0 |
| 1104 | + |
| 1105 | + statement { |
| 1106 | + sid = "CloudTrailKmsReadAccess" |
| 1107 | + effect = "Allow" |
| 1108 | + actions = [ |
| 1109 | + "kms:Decrypt", |
| 1110 | + "kms:GenerateDataKey*", |
| 1111 | + "kms:DescribeKey" |
| 1112 | + ] |
| 1113 | + resources = [var.cloudtrail_bucket.kms_key_arn] |
| 1114 | + } |
| 1115 | + |
| 1116 | + statement { |
| 1117 | + sid = "CloudTrailS3ReadAccess" |
| 1118 | + effect = "Allow" |
| 1119 | + actions = [ |
| 1120 | + "s3:GetObject", |
| 1121 | + "s3:GetObjectVersion", |
| 1122 | + "s3:ListBucket" |
| 1123 | + ] |
| 1124 | + resources = [ |
| 1125 | + var.cloudtrail_bucket.bucket_arn, |
| 1126 | + "${var.cloudtrail_bucket.bucket_arn}/*" |
| 1127 | + ] |
| 1128 | + } |
| 1129 | +} |
| 1130 | + |
| 1131 | +resource "aws_iam_policy" "cloudtrail_access_policy" { |
| 1132 | + count = local.department_identifier == "data-and-insight" && var.cloudtrail_bucket != null ? 1 : 0 |
| 1133 | + name = lower("${var.identifier_prefix}-${local.department_identifier}-cloudtrail-access-policy") |
| 1134 | + description = "Allows ${local.department_identifier} department read-only access to CloudTrail bucket" |
| 1135 | + policy = data.aws_iam_policy_document.cloudtrail_access[0].json |
| 1136 | +} |
0 commit comments