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

migrate danger CI job to GHA #8477

Merged
merged 4 commits into from
Jan 10, 2023
Merged

migrate danger CI job to GHA #8477

merged 4 commits into from
Jan 10, 2023

Conversation

chris48s
Copy link
Member

@chris48s chris48s commented Oct 4, 2022

This PR migrates the danger CI job from Circle CI to GHA.

@chris48s chris48s added the developer-experience Dev tooling, test framework, and CI label Oct 4, 2022
@shields-cd shields-cd temporarily deployed to shields-pr-8477 October 4, 2022 20:12 Inactive
@shields-cd shields-cd temporarily deployed to shields-pr-8477 October 4, 2022 20:18 Inactive
@shields-cd shields-cd temporarily deployed to shields-pr-8477 October 4, 2022 20:36 Inactive
@shields-cd shields-cd temporarily deployed to shields-pr-8477 October 4, 2022 20:37 Inactive
@shields-cd shields-cd temporarily deployed to shields-pr-8477 October 4, 2022 20:47 Inactive
@shields-cd shields-cd temporarily deployed to shields-pr-8477 October 4, 2022 20:50 Inactive
@@ -0,0 +1,27 @@
name: Danger
on: pull_request_target
Copy link
Member Author

Choose a reason for hiding this comment

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

This is really the crucial line in this PR and needs some explanation. From the docs:

This event runs in the context of the base of the pull request, rather than in the context of the merge commit, as the pull_request event does. This prevents execution of unsafe code from the head of the pull request that could alter your repository or steal any secrets you use in your workflow. This event allows your workflow to do things like label or comment on pull requests from forks. Avoid using this event if you need to build or run code from the pull request.

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target

This means:

On balance, I think this is the right approach for us.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds reasonable, so long as we've got the permissions properly configured in the repository settings (wouldn't want to rely on the in-file permission definition approach)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds reasonable, so long as we've got the permissions properly configured in the repository settings (wouldn't want to rely on the in-file permission definition approach)

This is a bit fiddly, so I just want to try and clarify this a bit more. Apologies if I am re-stating what you've already understood.


If an action runs

on: pull_request

no secrets are available to the build.
There is nothing we can change in the repo settings.
There is nothing we can change in any workflow file.
They are just not exposed to the build.

The code that gets checked out (to lint, or test, or whatever) is whatever the user submitting the PR pushed to the tip of their branch.

This means that even if the user submitting the PR pushes changes to their branch that exfiltrate your secrets, it doesn't matter. They're not exposed.


If an action runs

on: pull_request_target

our secrets are available to the build
BUT
The code that gets checked out is whatever is on our default branch, not whatever the user submitting the PR pushed to the tip of their branch.

This means if we have a on: pull_request_target workflow:

  • even if the user pushes code that tries to exfiltrate your secrets, it doesn't matter that your secrets are available to the build because the code that is checked out is our code, not theirs (unless you go and explicitly check out their code in the build).
  • if we run tests or lint checks or whatever, what we're actually checking is the code on the default branch, not the code in the pull request

The reason why this works OK for this case is because danger isn't looking at what is checked out in the workflow environment - it is just using the GitHub API to look at what files changed in the PR, match patterns in the PR diff, etc so we can look at what has changed in the PR without having the user code checked out or executed.

@chris48s chris48s changed the title WIP migrate danger CI job to GHA migrate danger CI job to GHA Oct 4, 2022
@chris48s chris48s marked this pull request as ready for review October 4, 2022 21:18
@chris48s
Copy link
Member Author

Thinking about this in the context of #8535 I am hoping that the combination of

pull_request_target:
types: [opened, edited, reopened, synchronize]

and

if: github.actor != 'dependabot[bot]'

should keep things in check.

We might consider tweaking https://github.com/badges/shields/blob/master/dangerfile.js#L104 down slightly as that means a PR modifying 100 files can now eat 10% of our rate limit, as opposed to just 2%.

@chris48s chris48s merged commit f1d151e into master Jan 10, 2023
@chris48s chris48s deleted the danger-gha branch January 10, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience Dev tooling, test framework, and CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants