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

ci(repo): Use pull_request_target event by triggering actor permissions #4692

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Dec 2, 2024

Description

#4702 needs to be merged first

This PR ensures that when a new untrusted PR is submitted, it verifies the triggering actor permissions, to proceed with the next steps that rely on repository secrets.

Context

Currently, CI steps that rely on secrets get skipped once it detects that it's an external fork. It's also using pull_request event which doesn't provide access to secrets. This is bringing a ton of friction to merge external contributions.

Security considerations with pull_request_target

Any automated processing of PRs from an external fork is potentially dangerous and such PRs should be treated like untrusted input. Malicious changes could be such as:

  • make or powershell files or redefine the build script in the package.json file
  • npm packages may have custom preinstall and postinstall scripts, so running npm install would already trigger any malicious code if the attackers added a new package reference

With the pull_request event, as per the documentation, with the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository.

On the other hand, workflows triggered via pull_request_targe have write permission to the target repository. They also have access to target repository secrets.

pull_request_target + checking trigger actor permissions

GitHub Actions provides a triggering actor field that lets you know who ran (or re-ran) a workflow. This allows maintainers to check the changes manually, and proceed by re-running the jobs.

The workflow is:

  1. Check permissions
  2. Checkout code
  3. Run CI with secrets

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Dec 2, 2024

🦋 Changeset detected

Latest commit: ceb4277

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2024 7:26pm

@LauraBeatris LauraBeatris self-assigned this Dec 2, 2024
@LauraBeatris LauraBeatris temporarily deployed to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Inactive
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris temporarily deployed to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Inactive
@LauraBeatris LauraBeatris temporarily deployed to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Inactive
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:49 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Failure
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Failure
@LauraBeatris LauraBeatris temporarily deployed to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Inactive
@LauraBeatris LauraBeatris temporarily deployed to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Inactive
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Failure
@LauraBeatris LauraBeatris temporarily deployed to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Inactive
@LauraBeatris LauraBeatris had a problem deploying to Run CI for external contribution December 2, 2024 19:53 — with GitHub Actions Failure
@LauraBeatris LauraBeatris changed the title ci(repo): Use environment protection rule to secure secrets from external forks ci(repo): Use pull_request_target event by checking user permissions Dec 3, 2024
@LauraBeatris LauraBeatris marked this pull request as ready for review December 3, 2024 14:27
@LauraBeatris LauraBeatris force-pushed the laura/gh-env-rule-ci branch 2 times, most recently from f8f0d1f to 753f3fd Compare December 3, 2024 14:30
@LauraBeatris LauraBeatris changed the title ci(repo): Use pull_request_target event by checking user permissions ci(repo): Use pull_request_target event by triggering actor permissions Dec 3, 2024
@LauraBeatris LauraBeatris removed the request for review from BRKalow December 3, 2024 14:37
@@ -2,13 +2,9 @@ name: CI

on:
workflow_dispatch:
inputs:
run_integration_tests:
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 wasn't being used at all, it was introduced in a previous PR with the attempt to continue using pull_request event with workflow_run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants