Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roles for our pathogen-repo-build GitHub Actions workflow #6

Closed
wants to merge 2 commits into from

Conversation

tsibley
Copy link
Member

@tsibley tsibley commented May 15, 2024

See commits.

Resolves: #4
Related-to: nextstrain/.github#81

Checklist

  • Checks pass

@tsibley tsibley requested a review from joverlee521 May 15, 2024 21:28
@tsibley
Copy link
Member Author

tsibley commented May 15, 2024

@joverlee521 Not finished, but I'd appreciate some earlier-than-later 👀 on this from you.

Copy link
Contributor

@joverlee521 joverlee521 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of questions, but we'll probably want to revisit the whole idea again based on your commment.

@@ -21,7 +21,7 @@ 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": "repo:nextstrain/*:*:job_workflow_ref:nextstrain/.github/.github/workflows/pathogen-repo-build.yaml@refs/heads/*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would @refs/heads/* prevent the use of specific commit hashes, e.g. pathogen-repo-build.yaml@e48956bb5eb0b1db1ba3d614ede9d1a6275b72ec?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would… and that was kinda intentional. I was worried that forks could get a specific commit id accessible in workflow calls. Reason is that GitHub (roughly speaking) stores all forks in the same Git storage backend, which means you can do things like view commits in forks via the forked repo, e.g. nextstrain/test-github-actions@0d1fee0 which really comes from https://github.com/tsibley/test-github-actions.

However, GitHub's protected against such attacks:

image

(In hindsight, of course they have, but they've also had other oversights in Actions before, so I don't think I was wrong to be wary.)

Comment on lines +35 to +36
# Builds inside the AWS Batch runtime need access to the jobs bucket.
aws_iam_policy.NextstrainJobsAccessToBucket.arn,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this. Why does the build require access to the jobs bucket? I thought that was handled by the Nextstrain CLI?

Edit: OH duh, it's the workdir for the Batch job so the build needs to be able to write to bucket.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. That permission is provided by default by our Batch job role, but that role doesn't apply if you pass in your own credentials. In my ideal world we'd be able to take the union of the default job role + any additional creds passed in, but that's non-trivial in my understanding.

}

resource "github_actions_repository_oidc_subject_claim_customization_template" "nextstrain" {
for_each = toset(data.github_repositories.nextstrain.names)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I understanding this correctly that this is for existing Nextstrain repos? For any new repos, we'd have to re-deploy the Terraform plan?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. No code changes required, but a new plan and apply cycle would be needed. (We could run that periodically on automation…)

Will let us manage (and self-document) our GitHub organization and repo
settings via this Terraform configuration.
@tsibley tsibley force-pushed the trs/pathogen-repo-build-workflow branch 3 times, most recently from ffe1302 to 8d33863 Compare May 17, 2024 18:54
Static role permissions policies which are expected to be
narrowed/scoped-down by an inline session policy set by the
pathogen-repo-build workflow.

Problems with this approach noted in review commentary:

  - <nextstrain/.github#81 (comment)>
  - <nextstrain/.github#81 (comment)>

Resolves: <#4>
Related-to: <nextstrain/.github#81>
@tsibley tsibley force-pushed the trs/pathogen-repo-build-workflow branch from 8d33863 to 3225f90 Compare May 17, 2024 18:57
@tsibley tsibley closed this May 17, 2024
@tsibley
Copy link
Member Author

tsibley commented May 17, 2024

The approach here was static role permissions policies which are expected to be narrowed/scoped-down by an inline session policy set by the pathogen-repo-build workflow.

But problems with this approach noted in review commentary:

tsibley added a commit that referenced this pull request May 20, 2024
tsibley added a commit that referenced this pull request May 20, 2024
tsibley added a commit that referenced this pull request May 20, 2024
tsibley added a commit that referenced this pull request May 20, 2024
tsibley added a commit that referenced this pull request May 21, 2024
A collection of templated repo-specific roles for inside a Nextstrain
runtime and one role for the GitHub Actions job itself, i.e. outside the
runtime.

The inside-the-runtime roles are given pathogen-specific permissions
necessary for the ingest and phylogenetic workflows of a pathogen repo.

The outside-the-runtime role is only necessary/used at the moment for
access to AWS Batch.

The roles can only be assumed by specific repos when performed by our
centralized pathogen-repo-build workflow.  While this doesn't completely
prevent off-label use by other GitHub Actions workflows launched from a
pathogen repo, it does make it more involved to do so, hopefully to the
point of discouragement.  The associated GitHub repository configuration
is managed by Terraform now as well since the customization of the "sub"
claim in GitHub Action's OIDC token is tightly coupled to our AWS role
trust policies.

Resolves: <#4>
Related-to: <nextstrain/private#96>,
            <nextstrain/.github#81>
Supersedes: <#6>,
            <#7>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create new role for GH Action access to S3
2 participants