1- # Gate before e2e jobs that use repository secrets.
2- # Must be a separate job: secrets are sent to the runner when that job starts.
1+ # Gate before e2e jobs that use repository secrets (separate job so secrets are not sent if skipped).
2+ #
3+ # Uses the same collaborator permission API GitHub uses for push/merge access on
4+ # this repository (org base permissions, teams, and direct grants).
35name : Authorize E2E secrets access
46
57on :
68 workflow_call :
79 outputs :
810 authorized :
9- description : true if e2e may run with repository secrets
1011 value : ${{ jobs.authorize.outputs.authorized }}
1112
1213jobs :
1314 authorize :
1415 name : Check repository owner or member
1516 runs-on : ubuntu-latest
16- timeout-minutes : 2
17+ timeout-minutes : 1
1718 if : github.event.action != 'labeled' || github.event.label.name == 'ok-to-test'
18- permissions :
19- contents : read
19+ # Do not set permissions: contents: read — it blocks reading collaborator permissions.
2020 outputs :
2121 authorized : ${{ steps.check.outputs.authorized }}
2222 steps :
@@ -26,49 +26,45 @@ jobs:
2626 GH_TOKEN : ${{ github.token }}
2727 EVENT_NAME : ${{ github.event_name }}
2828 EVENT_ACTION : ${{ github.event.action }}
29+ IS_FORK : ${{ github.event.repository.fork }}
30+ # PR author for merge-rights check (not github.actor — see dependabot hardening).
2931 USER : ${{ github.event.pull_request.user.login || github.actor }}
3032 ACTOR : ${{ github.actor }}
33+ REPO_OWNER : ${{ github.repository_owner }}
3134 REPOSITORY : ${{ github.repository }}
3235 run : |
3336 set -euo pipefail
34-
3537 allow() { echo "$1"; echo "authorized=true" >> "$GITHUB_OUTPUT"; exit 0; }
3638 deny() { echo "::warning::$1"; echo "authorized=false" >> "$GITHUB_OUTPUT"; exit 0; }
3739
38- encode() { jq -nr --arg u "$1" '$u|@uri'; }
39-
40- repo_permission() {
41- gh api "repos/${REPOSITORY}/collaborators/$(encode "$1")/permission" \
40+ permission_of() {
41+ gh api "repos/${REPOSITORY}/collaborators/$(jq -nr --arg u "$1" '$u|@uri')/permission" \
4242 --jq .permission 2>/dev/null || echo none
4343 }
4444
45- # Any non-none permission means the user is on this repository.
46- is_repo_owner_or_member() {
47- case "$(repo_permission "$1")" in
48- admin|maintain|write|triage|read) return 0 ;;
49- *) return 1 ;;
50- esac
51- }
45+ [ "$EVENT_NAME" = "schedule" ] && allow "Scheduled run."
5246
53- is_repo_owner() {
54- [ "$(repo_permission "$1")" = "admin" ]
55- }
47+ echo "user=${USER} actor=${ACTOR} event=${EVENT_NAME}/${EVENT_ACTION:-none} fork=${IS_FORK}"
5648
57- [ "$EVENT_NAME" = "schedule" ] && allow "Scheduled run."
49+ # Push to upstream: only users with push (merge) rights can push here.
50+ [ "$EVENT_NAME" = "push" ] && [ "$IS_FORK" != "true" ] && allow "Push to upstream repository."
51+
52+ # Push to your own fork.
53+ [ "$EVENT_NAME" = "push" ] && [ "$ACTOR" = "$REPO_OWNER" ] && allow "Push by fork owner."
5854
59- USER_PERM=$(repo_permission "$USER")
60- echo "executor=$USER permission=$USER_PERM"
61- if is_repo_owner_or_member "$USER"; then
62- allow "$USER is an owner or member of ${REPOSITORY}."
63- fi
55+ USER_PERM=$(permission_of "$USER")
56+ echo "user_permission=${USER_PERM}"
57+ case "$USER_PERM" in
58+ admin|maintain|write|triage|read)
59+ allow "${USER} has repository access (${USER_PERM}, same source as merge rights)."
60+ ;;
61+ esac
6462
65- # Outsiders: only when an owner adds ok-to-test on this event .
66- [ "$EVENT_ACTION" = "labeled" ] || deny "$USER is not an owner or member of ${REPOSITORY} ."
63+ # Outsider PR: repository owner added ok-to-test on this run .
64+ [ "$EVENT_ACTION" = "labeled" ] || deny "${ USER} has no repository access ."
6765
68- LABELER_PERM=$(repo_permission "$ACTOR")
69- echo "ok-to-test labeler=$ACTOR permission=$LABELER_PERM"
70- if is_repo_owner "$ACTOR"; then
71- allow "Owner $ACTOR added ok-to-test."
72- fi
66+ LABELER_PERM=$(permission_of "$ACTOR")
67+ echo "ok-to-test labeler=${ACTOR} permission=${LABELER_PERM}"
68+ [ "$LABELER_PERM" = "admin" ] && allow "Repository owner ${ACTOR} added ok-to-test."
7369
74- deny "ok-to-test must be added by a repository owner."
70+ deny "ok-to-test must be added by a repository owner (admin) ."
0 commit comments