Skip to content

Commit

Permalink
chore(ci): verify triggering actor on pull request from fork
Browse files Browse the repository at this point in the history
If a contributor that open a Pull Request from a fork is not part
of the repository collaborators, then the workflow using
check_triggering_actor subworkflowwill exit with a failure.
It could be re-run later by a collaborator who has a write access.

This allows reviewers to read the code proposition before running
the CI, ensuring no secrets are leaked outside the repository.
  • Loading branch information
soonum committed Dec 18, 2024
1 parent bda8ab0 commit 9195753
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/aws_tfhe_fast_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ on:
pull_request_target:

jobs:
check-user-permission:
if: github.event_name == 'pull_request_target'
uses: ./.github/workflows/check_triggering_actor.yml
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

should-run:
runs-on: ubuntu-latest
needs: check-user-permission
if: github.event_name != 'pull_request_target' ||
needs.check-user-permission.result == 'success'
permissions:
pull-requests: write
outputs:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/check_triggering_actor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Check if triggering actor is a collaborator and has write access
name: Check Triggering Actor

on:
workflow_call:
secrets:
GITHUB_TOKEN:
required: true

jobs:
check-actor-permission:
runs-on: ubuntu-latest
steps:
- name: Get User Permission
id: check-access
uses: actions-cool/check-user-permission@956b2e73cdfe3bcb819bb7225e490cb3b18fd76e # v2.2.1
with:
require: write
username: ${{ github.triggering_actor }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check User Permission
if: steps.check-access.outputs.require-result == 'false'
run: |
echo "${{ github.triggering_actor }} does not have permissions on this repo."
echo "Current permission level is ${{ steps.check-access.outputs.user-permission }}"
echo "Job originally triggered by ${{ github.actor }}"
exit 1

0 comments on commit 9195753

Please sign in to comment.