From 9195753273dbb0bef493bc861b17d2160ae7421b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Test=C3=A9?= Date: Wed, 18 Dec 2024 18:00:18 +0100 Subject: [PATCH] chore(ci): verify triggering actor on pull request from fork 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. --- .github/workflows/aws_tfhe_fast_tests.yml | 9 ++++++ .github/workflows/check_triggering_actor.yml | 29 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/check_triggering_actor.yml diff --git a/.github/workflows/aws_tfhe_fast_tests.yml b/.github/workflows/aws_tfhe_fast_tests.yml index c49aa69d4b..2c82e6b264 100644 --- a/.github/workflows/aws_tfhe_fast_tests.yml +++ b/.github/workflows/aws_tfhe_fast_tests.yml @@ -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: diff --git a/.github/workflows/check_triggering_actor.yml b/.github/workflows/check_triggering_actor.yml new file mode 100644 index 0000000000..6afcdba5f7 --- /dev/null +++ b/.github/workflows/check_triggering_actor.yml @@ -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