Refuse all fork pull requests on IUCLabs runners (#593)

A pull_request job from a fork runs the fork's own workflow, Makefile and pre-commit config on the self-hosted runners before review. Fork PRs authored by members or collaborators were still allowed through.

- job-started hook refuses every pull_request whose head repo differs from the base repo, regardless of author association
- hook tests expect member fork PRs to be refused on default and infra runners

Reviewed-on: #593
Co-authored-by: unkin-agent <unkin-agent@unkin.net>
Co-committed-by: unkin-agent <unkin-agent@unkin.net>
This commit was merged in pull request #593.
This commit is contained in:
2026-11-21 14:51:06 +11:00
committed by BenVincent
parent e1241811c9
commit b65f86b53c
2 changed files with 5 additions and 8 deletions
+3 -7
View File
@@ -33,13 +33,9 @@ esac
case "${event}" in
push | workflow_dispatch | schedule | merge_group | release) ;;
pull_request)
trusted=$(jq -r '
.pull_request.head.repo.full_name as $head
| if $head == null then false
elif $head == .repository.full_name then true
else (.pull_request.author_association | IN("OWNER", "MEMBER", "COLLABORATOR"))
end' "${GITHUB_EVENT_PATH}") || refuse "event payload unreadable"
[ "${trusted}" = true ] || refuse "pull request from untrusted fork"
same=$(jq -r '.pull_request.head.repo.full_name != null
and .pull_request.head.repo.full_name == .repository.full_name' "${GITHUB_EVENT_PATH}") || refuse "event payload unreadable"
[ "${same}" = true ] || refuse "pull request from a fork"
;;
*) refuse "event not allowed on self-hosted runners" ;;
esac
+2 -1
View File
@@ -29,7 +29,7 @@ done
for e in push workflow_dispatch schedule merge_group release; do
check 0 default "$e" push.json
done
check 0 default pull_request pr-member.json
check 1 default pull_request pr-member.json
check 0 default pull_request pr-same-repo.json
check 1 default pull_request pr-fork-none.json
check 1 default pull_request pr-fork-spoofed.json
@@ -62,6 +62,7 @@ for r in terraform-git terraform-vault terraform-artifactapi terraform-authentik
check 0 infra push push.json "IUCLabs/$r"
check 0 infra pull_request pr-same-repo.json "IUCLabs/$r"
check 1 infra pull_request pr-fork-none.json "IUCLabs/$r"
check 1 infra pull_request pr-member.json "IUCLabs/$r"
check 1 infra issue_comment issue-comment.json "IUCLabs/$r"
done
for r in IUCLabs/app IUCLabs/terraform-netbox iuclabs/terraform-git evil/terraform-git IUCLabs/terraform-git-x "IUCLabs/terraform-git "; do