Skip to content

Commit

Permalink
Access for find-moj-data github actions
Browse files Browse the repository at this point in the history
We want to schedule Datahub ingestions using github actions.
(ministryofjustice/data-catalogue#123)

To do this, Github actions needs to be able to assume a role via OIDC.
See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_oidc.html

This role needs read only access to the bucket that contains CaDeT
outputs.
  • Loading branch information
MatMoore committed May 28, 2024
1 parent 4d49ae8 commit a7d272a
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ resource "aws_iam_policy" "datahub_read_cadet_bucket" {
policy = data.aws_iam_policy_document.datahub_read_cadet_bucket.json
}

# Allow Github actions to assume a role via OIDC.
# So that scheduled jobs in the find-moj-data repo can access the CaDeT bucket.
data "aws_iam_policy_document" "data_catalogue_ingestion_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]

principals {
type = "Federated"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/token.actions.githubusercontent.com"]
}
condition {
test = "StringEquals"
values = ["sts.amazonaws.com"]
variable = "token.actions.githubusercontent.com:aud"
}
condition {
test = "StringLike"
values = ["repo:ministryofjustice/find-moj-data:*"]
variable = "token.actions.githubusercontent.com:sub"
}
}
}

resource "aws_iam_role" "data_catalogue_ingestion_role" {
name = "ci-ingestion"
assume_role_policy = data.aws_iam_policy_document.data_catalogue_ingestion_role.json
}

resource "aws_iam_role_policy_attachment" "data_catalogue_ingestion_role" {
policy_arn = aws_iam_policy_document.datahub_read_cadet_bucket.arn
role = aws_iam_role.data_catalogue_ingestion_role.name
}

#trivy:ignore:avd-aws-0057:sensitive action 'glue:GetDatabases' on wildcarded resource
data "aws_iam_policy_document" "datahub_ingest_glue_datasets" {
statement {
Expand Down

0 comments on commit a7d272a

Please sign in to comment.