Skip to content

Commit

Permalink
wip! repo-specific permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Feb 17, 2024
1 parent 6f45b37 commit b1ceb76
Showing 1 changed file with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
locals {
# XXX FIXME: define in external file instead
pathogens = [
{
"name": "mpox",
"repo": "nextstrain/mpox",
"prefix": "mpox_"
},
{
"name": "rsv",
"repo": "nextstrain/rsv",
"prefix": "rsv_"
},
{
"name": "seasonal-flu",
"repo": "nextstrain/seasonal-flu",
"prefix": "flu_seasonal_"
},
# XXX FIXME: ncov, ncov-ingest, forecasts-ncov
]
}

import {
to = aws_iam_role.GitHubActionsRoleNextstrainBatchJobs
id = "GitHubActionsRoleNextstrainBatchJobs"
Expand All @@ -21,7 +43,12 @@ resource "aws_iam_role" "GitHubActionsRoleNextstrainBatchJobs" {
"Condition": {
"StringLike": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:nextstrain/.github:*"
"token.actions.githubusercontent.com:sub": concat(
[for repo in local.pathogens[*].repo: "repo:${repo}:*"],

# For testing our pathogen-repo-build.yaml workflow
["repo:nextstrain/.github:*"],
)
}
},
}
Expand All @@ -33,5 +60,68 @@ resource "aws_iam_role" "GitHubActionsRoleNextstrainBatchJobs" {
aws_iam_policy.NextstrainJobsAccessToBucket.arn,
aws_iam_policy.NextstrainJobsAccessToLogs.arn,
]
inline_policy {}
dynamic "inline_policy" {
for_each = local.pathogens
iterator = pathogen
content {
name = pathogen.value.name
policy = jsonencode({
"Version": "2012-10-17",
"Statement": [
# Technically this whole statement (ListPublicData) is unnecessary
# since the nextstrain-data and nextstrain-staging buckets already
# allow a superset of this with their bucket policies, but it's good to
# be explicit about what permissions we require?
# -trs, 16 Feb 2024
{
"Sid": "ListPublicData",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::nextstrain-data",
"arn:aws:s3:::nextstrain-staging",
],
"Condition": {
"StringLike": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:${pathogen.value.repo}:*",
"s3:prefix": [
"files/workflows/${pathogen.value.name}/*",
"files/datasets/${pathogen.value.name}/*",
"${pathogen.value.prefix}*.json",
]
}
}
},
{
"Sid": "ReadWritePublicData",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::nextstrain-data/files/workflows/${pathogen.value.name}/*",
"arn:aws:s3:::nextstrain-data/files/datasets/${pathogen.value.name}/*",
"arn:aws:s3:::nextstrain-data/${pathogen.value.prefix}*.json",
"arn:aws:s3:::nextstrain-staging/files/workflows/${pathogen.value.name}/*",
"arn:aws:s3:::nextstrain-staging/files/datasets/${pathogen.value.name}/*",
"arn:aws:s3:::nextstrain-staging/${pathogen.value.prefix}*.json",
"arn:aws:s3:::nextstrain-staging/trial_*_${pathogen.value.prefix}*.json"
],
"Condition": {
"StringLike": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:${pathogen.value.repo}:*",
}
}
},
# XXX FIXME: add general statements for nextstrain-data-private
# XXX FIXME: add custom statements for ncov, ncov-ingest, forecasts-ncov
]
})
}
}
}

0 comments on commit b1ceb76

Please sign in to comment.