Skip to content

Commit 8aa599d

Browse files
ELI-545 - permission boundary and github action policies
1 parent eebb040 commit 8aa599d

3 files changed

Lines changed: 87 additions & 2 deletions

File tree

infrastructure/stacks/api-layer/service_account.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ resource "aws_iam_user_policy" "tableau_athena_policy" {
4747
]
4848
Resource = [
4949
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:catalog",
50-
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:database/elid_db",
51-
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:table/elid_db/cohort_metrics"
50+
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:database/elid_dq",
51+
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:table/elid_dq/cohort_metrics"
5252
]
5353
},
5454
{

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ resource "aws_iam_policy" "s3_management" {
235235
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-dq-metrics/*",
236236
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-dq-metrics-access-logs",
237237
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-dq-metrics-access-logs/*",
238+
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-athena-stage",
239+
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-athena-stage/*",
240+
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-athena-stage-access-logs",
241+
"arn:aws:s3:::*eligibility-signposting-api-${var.environment}-athena-stage-access-logs/*",
238242
]
239243
}
240244
]
@@ -743,6 +747,65 @@ resource "aws_iam_policy" "cloudwatch_management" {
743747
tags = merge(local.tags, { Name = "cloudwatch-management" })
744748
}
745749

750+
# Athena/Glue Infrastructure Management Policy for GitHub Actions
751+
resource "aws_iam_policy" "athena_glue_management" {
752+
name = "athena-glue-management"
753+
description = "Allows GitHub Actions to create and manage Athena/Glue resources"
754+
path = "/service-policies/"
755+
756+
policy = jsonencode({
757+
Version = "2012-10-17",
758+
Statement = [
759+
{
760+
# 1. Permission to manage the Glue Metadata (The "Athena Database/Table")
761+
Effect = "Allow",
762+
Action = [
763+
"glue:CreateDatabase",
764+
"glue:DeleteDatabase",
765+
"glue:GetDatabase",
766+
"glue:UpdateDatabase",
767+
"glue:CreateTable",
768+
"glue:DeleteTable",
769+
"glue:UpdateTable",
770+
"glue:GetTable",
771+
"glue:GetTables",
772+
"glue:BatchCreatePartition",
773+
"glue:CreatePartition",
774+
"glue:DeletePartition",
775+
"glue:GetPartitions"
776+
],
777+
Resource = [
778+
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:catalog",
779+
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:database/elid_dq",
780+
"arn:aws:glue:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:table/elid_dq/*"
781+
]
782+
},
783+
{
784+
# 2. Permission to manage Athena Workgroups or Named Queries
785+
Effect = "Allow",
786+
Action = [
787+
"athena:CreateWorkGroup",
788+
"athena:DeleteWorkGroup",
789+
"athena:UpdateWorkGroup",
790+
"athena:GetWorkGroup",
791+
"athena:CreateNamedQuery",
792+
"athena:DeleteNamedQuery",
793+
"athena:GetNamedQuery",
794+
"athena:ListDataCatalogs",
795+
"athena:CreateDataCatalog",
796+
"athena:DeleteDataCatalog"
797+
],
798+
Resource = [
799+
"arn:aws:athena:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:workgroup/*",
800+
"arn:aws:athena:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:datacatalog/*"
801+
]
802+
}
803+
]
804+
})
805+
806+
tags = merge(local.tags, { Name = "athena-glue-management" })
807+
}
808+
746809
# Attach the policies to the role
747810
resource "aws_iam_role_policy_attachment" "terraform_state" {
748811
role = aws_iam_role.github_actions.name
@@ -788,3 +851,8 @@ resource "aws_iam_role_policy_attachment" "cloudwatch_management" {
788851
role = aws_iam_role.github_actions.name
789852
policy_arn = aws_iam_policy.cloudwatch_management.arn
790853
}
854+
855+
resource "aws_iam_role_policy_attachment" "athena_glue_management" {
856+
role = aws_iam_role.github_actions.name
857+
policy_arn = aws_iam_policy.athena_glue_management.arn
858+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ data "aws_iam_policy_document" "permissions_boundary" {
221221
"states:CreateStateMachine",
222222
"states:TagResource",
223223
"states:UpdateStateMachine",
224+
225+
# Athena
226+
"athena:CreateWorkGroup",
227+
"athena:UpdateWorkGroup",
228+
"athena:GetQueryExecution",
229+
"athena:GetQueryResults",
230+
"athena:StartQueryExecution",
231+
"athena:GetWorkGroup",
232+
"athena:StopQueryExecution",
233+
"athena:GetDataCatalog",
234+
235+
# Glue
236+
"glue:CreateDatabase",
237+
"glue:GetDatabase",
238+
"glue:GetTable",
239+
"glue:GetTables",
240+
"glue:GetDatabases"
224241
]
225242

226243
resources = ["*"]

0 commit comments

Comments
 (0)