Skip to content

Commit 1718314

Browse files
committed
github-ci: fix new authors check
Shortly after minimizing the new authors check to one workflow, github released an action update that required more permissions due to an attack scenario, which didn't really apply to us as we didn't run code from the remotes fork. However, to avoid extending permissions, rework the authors check to pull the OISF repo, checkout the PR fork as history, then do the new authors check. This safely allows the check to run in the context of our repo without the fork being able to inject code execution.
1 parent 0f56783 commit 1718314

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

.github/workflows/authors.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ name: New Authors Check
44
# for fork PRs, allowing us to post a comment directly without the artifact
55
# hand-off to a second workflow_run workflow.
66
#
7-
# Only git history is read here — no PR code is built or executed — so
8-
# checking out the PR head SHA is safe under pull_request_target.
7+
# Only git history is read here. Avoid checking out fork PR files in the
8+
# pull_request_target trust context; the job checks out the trusted base ref and
9+
# fetches the PR head ref only for git-log inspection.
910
on:
1011
pull_request_target:
1112

1213
permissions:
14+
contents: read
1315
pull-requests: write
1416

1517
concurrency:
@@ -21,16 +23,24 @@ jobs:
2123
name: New Author Check
2224
runs-on: ubuntu-latest
2325
steps:
24-
- name: Checkout PR code
26+
- name: Checkout trusted base branch
2527
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
2628
with:
27-
ref: ${{ github.event.pull_request.head.sha }}
2829
fetch-depth: 0
30+
persist-credentials: false
2931
- run: sudo apt -y install git
32+
- name: Fetch PR head for history inspection
33+
env:
34+
PR_NUMBER: ${{ github.event.pull_request.number }}
35+
run: |
36+
git fetch --no-tags --no-recurse-submodules origin \
37+
"+refs/pull/${PR_NUMBER}/head:refs/remotes/pull-request/head"
3038
- name: Export known authors from main branch
3139
run: git log --format="%an <%ae>" origin/main | sort | uniq > authors.txt
3240
- name: Export authors from new commits
33-
run: git log --format="%an <%ae>" ${{ github.event.pull_request.base.sha }}... | sort | uniq > commit-authors.txt
41+
env:
42+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
43+
run: git log --format="%an <%ae>" "${BASE_SHA}..refs/remotes/pull-request/head" | sort | uniq > commit-authors.txt
3444
- name: Check new authors
3545
run: |
3646
touch new-authors.txt

0 commit comments

Comments
 (0)