Skip to content

Commit 3c3514f

Browse files
revert broken SSO policy changes (#2500)
Reverts commits: - f8d1a5c Fix policy length (#2499) - e84e303 Fix glue database visibility (#2498) - 7996f9f add GetTags action (#2496) - ed4f4fe add GetPartition(s) actions (#2495) - 31d991a add required actions to additional databases (#2494) - 1dd0562 add GetDatabases to Glue Catalog permissions (#2493) - 26d3805 update glue policies (#2491)
1 parent f8d1a5c commit 3c3514f

File tree

5 files changed

+27
-139
lines changed

5 files changed

+27
-139
lines changed

terraform/core/05-departments.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ module "department_parking" {
7373
departmental_airflow_user = true
7474
mwaa_etl_scripts_bucket_arn = aws_s3_bucket.mwaa_etl_scripts_bucket.arn
7575
mwaa_key_arn = aws_kms_key.mwaa_key.arn
76-
additional_glue_database_access = [
77-
{
78-
database_name = "${local.identifier_prefix}-liberator-raw-zone"
79-
actions = ["glue:GetTable", "glue:GetTables"]
80-
},
81-
{
82-
database_name = "${local.identifier_prefix}-liberator-refined-zone"
83-
actions = ["glue:GetTable", "glue:GetTables"]
84-
},
85-
{
86-
database_name = "${local.identifier_prefix}-liberator-trusted-zone"
87-
actions = ["glue:GetTable", "glue:GetTables"]
88-
},
89-
{
90-
database_name = "${local.identifier_prefix}-raw-zone-unrestricted-address-api"
91-
actions = ["glue:GetTable", "glue:GetTables"]
92-
},
93-
]
9476
}
9577

9678
module "department_finance" {

terraform/modules/department/02-inputs-optional.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ variable "additional_glue_database_access" {
7272
description = <<EOF
7373
Additional Glue database access to grant to the department.
7474
Allows specifying specific databases and the actions that can be performed on them.
75-
76-
Note: The actions 'glue:GetDatabase', 'glue:GetDatabases', 'glue:GetPartition' and 'glue:GetPartitions' are automatically
77-
appended to the actions list to ensure databases appear in SQL editors and can be
78-
accessed. You only need to specify additional actions like table operations:
79-
- glue:GetTable, glue:GetTables
80-
- glue:CreateTable, glue:UpdateTable, glue:DeleteTable (for write access)
81-
- glue:CreatePartition, glue:UpdatePartition, glue:DeletePartition (for write access)
8275
EOF
8376
type = list(object({
8477
database_name = string

terraform/modules/department/50-aws-iam-policies.tf

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ data "aws_iam_policy_document" "read_only_glue_access" {
167167

168168
// Glue Access - Catalog level operations
169169
statement {
170-
sid = "GlueCatalogReadOnlyAccess"
170+
sid = "GlueCatalogAccess"
171171
actions = [
172172
"glue:GetCatalogImportStatus",
173173
"glue:GetDataCatalogEncryptionSettings",
@@ -179,10 +179,9 @@ data "aws_iam_policy_document" "read_only_glue_access" {
179179

180180
// Glue Access - Department database and table operations
181181
statement {
182-
sid = "GlueDepartmentDatabaseReadOnlyAccess"
182+
sid = "GlueDepartmentDatabaseAccess"
183183
actions = [
184184
"glue:GetDatabase",
185-
"glue:GetDatabases",
186185
"glue:GetTable",
187186
"glue:GetTables",
188187
"glue:GetTableVersion",
@@ -202,10 +201,6 @@ data "aws_iam_policy_document" "read_only_glue_access" {
202201
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${aws_glue_catalog_database.raw_zone_catalog_database.name}/*",
203202
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${aws_glue_catalog_database.refined_zone_catalog_database.name}/*",
204203
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${aws_glue_catalog_database.trusted_zone_catalog_database.name}/*",
205-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/unrestricted-raw-zone/*",
206-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/unrestricted-refined-zone/*",
207-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/unrestricted-trusted-zone/*",
208-
209204
]
210205
}
211206

@@ -227,7 +222,6 @@ data "aws_iam_policy_document" "read_only_glue_access" {
227222
"glue:GetWorkflowRun",
228223
"glue:GetWorkflowRuns",
229224
"glue:ListWorkflows",
230-
"glue:GetTags",
231225
"glue:CheckSchemaVersionValidity",
232226
]
233227
resources = ["*"]
@@ -237,18 +231,9 @@ data "aws_iam_policy_document" "read_only_glue_access" {
237231
for_each = var.additional_glue_database_access
238232
iterator = additional_db_access
239233
content {
240-
sid = "AdditionalGlueDatabaseAccess${replace(additional_db_access.value.database_name, "/[^a-zA-Z0-9]/", "")}"
241-
effect = "Allow"
242-
# Auto-append essential actions for database listing and access
243-
actions = distinct(concat(
244-
additional_db_access.value.actions,
245-
[
246-
"glue:GetDatabase", # Required for specific database access
247-
"glue:GetDatabases", # Required for SQL editor database listing
248-
"glue:GetPartition",
249-
"glue:GetPartitions",
250-
]
251-
))
234+
sid = "AdditionalGlueDatabaseAccess${replace(additional_db_access.value.database_name, "/[^a-zA-Z0-9]/", "")}"
235+
effect = "Allow"
236+
actions = additional_db_access.value.actions
252237
resources = [
253238
"arn:aws:glue:eu-west-2:${data.aws_caller_identity.current.account_id}:catalog",
254239
"arn:aws:glue:eu-west-2:${data.aws_caller_identity.current.account_id}:database/${additional_db_access.value.database_name}",
@@ -273,7 +258,7 @@ data "aws_iam_policy_document" "s3_department_access" {
273258
] : []
274259

275260
statement {
276-
sid = "ListAllS3AndKmsKeysFullAccess"
261+
sid = "ListAllS3AndKmsKeys"
277262
effect = "Allow"
278263
actions = [
279264
"s3:ListAllMyBuckets",
@@ -283,7 +268,7 @@ data "aws_iam_policy_document" "s3_department_access" {
283268
}
284269

285270
statement {
286-
sid = "KmsKeyFullAccessForS3"
271+
sid = "KmsKeyFullAccess"
287272
effect = "Allow"
288273
actions = [
289274
"kms:Encrypt",
@@ -545,7 +530,7 @@ data "aws_iam_policy_document" "glue_access" {
545530

546531
// Glue Access - Catalog level operations
547532
statement {
548-
sid = "GlueCatalogFullAccess"
533+
sid = "GlueCatalogAccess"
549534
actions = [
550535
"glue:GetCatalogImportStatus",
551536
"glue:GetDataCatalogEncryptionSettings",
@@ -557,10 +542,9 @@ data "aws_iam_policy_document" "glue_access" {
557542

558543
// Glue Access - Department database and table operations (read, write, delete)
559544
statement {
560-
sid = "GlueDepartmentDatabaseFullAccess"
545+
sid = "GlueDepartmentDatabaseAccess"
561546
actions = [
562547
"glue:GetDatabase",
563-
"glue:GetDatabases",
564548
"glue:GetTable",
565549
"glue:GetTables",
566550
"glue:GetTableVersion",
@@ -589,9 +573,6 @@ data "aws_iam_policy_document" "glue_access" {
589573
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${aws_glue_catalog_database.raw_zone_catalog_database.name}/*",
590574
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${aws_glue_catalog_database.refined_zone_catalog_database.name}/*",
591575
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${aws_glue_catalog_database.trusted_zone_catalog_database.name}/*",
592-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/unrestricted-raw-zone/*",
593-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/unrestricted-refined-zone/*",
594-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/unrestricted-trusted-zone/*",
595576
]
596577
}
597578

@@ -628,7 +609,6 @@ data "aws_iam_policy_document" "glue_access" {
628609
"glue:StopCrawlerSchedule",
629610
"glue:StopTrigger",
630611
"glue:StopWorkflowRun",
631-
"glue:GetTags",
632612
"glue:TagResource",
633613
"glue:UpdateDevEndpoint",
634614
"glue:UpdateJob",
@@ -639,30 +619,6 @@ data "aws_iam_policy_document" "glue_access" {
639619
]
640620
resources = ["*"]
641621
}
642-
643-
dynamic "statement" {
644-
for_each = var.additional_glue_database_access
645-
iterator = additional_db_access
646-
content {
647-
sid = "AdditionalGlueDatabaseFullAccess${replace(additional_db_access.value.database_name, "/[^a-zA-Z0-9]/", "")}"
648-
effect = "Allow"
649-
# Auto-append essential actions for database listing and access
650-
actions = distinct(concat(
651-
additional_db_access.value.actions,
652-
[
653-
"glue:GetDatabase", # Required for specific database access
654-
"glue:GetDatabases", # Required for SQL editor database listing
655-
"glue:GetPartition",
656-
"glue:GetPartitions",
657-
]
658-
))
659-
resources = [
660-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:catalog",
661-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:database/${additional_db_access.value.database_name}",
662-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${additional_db_access.value.database_name}/*"
663-
]
664-
}
665-
}
666622
}
667623

668624
resource "aws_iam_policy" "glue_access" {

terraform/modules/department/50-aws-iam-roles.tf

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
data "aws_iam_policy_document" "sso_staging_additional_with_notebook" {
2-
count = local.create_notebook ? 1 : 0
3-
4-
override_policy_documents = [
1+
// User Role for staging account - This role is a combination of policies ready to be applied to SSO
2+
data "aws_iam_policy_document" "sso_staging_user_policy" {
3+
override_policy_documents = local.create_notebook ? [
4+
data.aws_iam_policy_document.s3_department_access.json,
5+
data.aws_iam_policy_document.glue_access.json,
6+
data.aws_iam_policy_document.secrets_manager_read_only.json,
57
data.aws_iam_policy_document.redshift_department_read_access.json,
68
data.aws_iam_policy_document.notebook_access[0].json
7-
]
8-
}
9-
10-
data "aws_iam_policy_document" "sso_staging_additional" {
11-
count = local.create_notebook ? 0 : 1
12-
13-
override_policy_documents = [
9+
] : [
10+
data.aws_iam_policy_document.s3_department_access.json,
11+
data.aws_iam_policy_document.glue_access.json,
12+
data.aws_iam_policy_document.secrets_manager_read_only.json,
1413
data.aws_iam_policy_document.redshift_department_read_access.json,
1514
data.aws_iam_policy_document.mwaa_department_web_server_access.json
1615
]
1716
}
1817

19-
data "aws_iam_policy_document" "sso_production_additional" {
18+
// User Role for production account - This role is a combination of policies ready to be applied to SSO
19+
data "aws_iam_policy_document" "sso_production_user_policy" {
2020
override_policy_documents = [
21-
data.aws_iam_policy_document.athena_can_write_to_s3.json,
22-
data.aws_iam_policy_document.redshift_department_read_access.json
21+
data.aws_iam_policy_document.read_only_s3_department_access.json,
22+
data.aws_iam_policy_document.read_only_glue_access.json,
23+
data.aws_iam_policy_document.secrets_manager_read_only.json,
24+
data.aws_iam_policy_document.athena_can_write_to_s3.json
2325
]
2426
}
2527

terraform/modules/department/60-aws-sso.tf

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,14 @@ resource "aws_ssoadmin_permission_set" "department" {
1515
tags = var.tags
1616
}
1717

18-
resource "aws_ssoadmin_managed_policy_attachment" "department_s3" {
18+
resource "aws_ssoadmin_permission_set_inline_policy" "department" {
1919
count = local.deploy_sso ? 1 : 0
2020

2121
provider = aws.aws_hackit_account
2222

23+
inline_policy = var.environment == "stg" ? data.aws_iam_policy_document.sso_staging_user_policy.json : data.aws_iam_policy_document.sso_production_user_policy.json
2324
instance_arn = var.sso_instance_arn
2425
permission_set_arn = aws_ssoadmin_permission_set.department[0].arn
25-
managed_policy_arn = var.environment == "stg" ? aws_iam_policy.s3_access.arn : aws_iam_policy.read_only_s3_access.arn
26-
}
27-
28-
resource "aws_ssoadmin_managed_policy_attachment" "department_glue" {
29-
count = local.deploy_sso ? 1 : 0
30-
31-
provider = aws.aws_hackit_account
32-
33-
instance_arn = var.sso_instance_arn
34-
permission_set_arn = aws_ssoadmin_permission_set.department[0].arn
35-
managed_policy_arn = var.environment == "stg" ? aws_iam_policy.glue_access.arn : aws_iam_policy.read_only_glue_access.arn
36-
}
37-
38-
resource "aws_ssoadmin_managed_policy_attachment" "department_secrets" {
39-
count = local.deploy_sso ? 1 : 0
40-
41-
provider = aws.aws_hackit_account
42-
43-
instance_arn = var.sso_instance_arn
44-
permission_set_arn = aws_ssoadmin_permission_set.department[0].arn
45-
managed_policy_arn = aws_iam_policy.secrets_manager_read_only.arn
46-
}
47-
48-
resource "aws_iam_policy" "sso_department_additional_policy" {
49-
count = local.deploy_sso ? 1 : 0
50-
51-
name = lower("${var.identifier_prefix}-${local.department_identifier}-sso-additional-policy")
52-
description = "Additional SSO policy for ${local.department_identifier} department in ${var.environment} environment"
53-
policy = var.environment == "stg" ? (
54-
local.create_notebook ?
55-
data.aws_iam_policy_document.sso_staging_additional_with_notebook[0].json :
56-
data.aws_iam_policy_document.sso_staging_additional[0].json
57-
) : (
58-
data.aws_iam_policy_document.sso_production_additional.json
59-
)
60-
tags = var.tags
61-
}
62-
63-
resource "aws_ssoadmin_managed_policy_attachment" "department_additional" {
64-
count = local.deploy_sso ? 1 : 0
65-
66-
provider = aws.aws_hackit_account
67-
68-
instance_arn = var.sso_instance_arn
69-
permission_set_arn = aws_ssoadmin_permission_set.department[0].arn
70-
managed_policy_arn = aws_iam_policy.sso_department_additional_policy[0].arn
7126
}
7227

7328
data "aws_identitystore_group" "department" {

0 commit comments

Comments
 (0)