Skip to content

Commit c6558c2

Browse files
author
Radovan Fuchs
committed
fix
1 parent 6328782 commit c6558c2

5 files changed

Lines changed: 31 additions & 43 deletions

File tree

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
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).
35
name: Authorize E2E secrets access
46

57
on:
68
workflow_call:
79
outputs:
810
authorized:
9-
description: true if e2e may run with repository secrets
1011
value: ${{ jobs.authorize.outputs.authorized }}
1112

1213
jobs:
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)."

.github/workflows/e2e_tests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
# Own job so repository secrets are never sent to a runner unless this passes.
1111
authorize:
1212
uses: ./.github/workflows/e2e_authorize.yaml
13-
permissions:
14-
contents: read
1513

1614
e2e_tests:
1715
needs: authorize

.github/workflows/e2e_tests_lightspeed_evaluation.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ jobs:
99
# Own job so repository secrets are never sent to a runner unless this passes.
1010
authorize:
1111
uses: ./.github/workflows/e2e_authorize.yaml
12-
permissions:
13-
contents: read
1412

1513
e2e_tests:
1614
needs: authorize

.github/workflows/e2e_tests_providers.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
# Own job so repository secrets are never sent to a runner unless this passes.
1111
authorize:
1212
uses: ./.github/workflows/e2e_authorize.yaml
13-
permissions:
14-
contents: read
1513

1614
e2e_tests:
1715
needs: authorize

.github/workflows/e2e_tests_rhaiis.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
# Own job so repository secrets are never sent to a runner unless this passes.
1212
authorize:
1313
uses: ./.github/workflows/e2e_authorize.yaml
14-
permissions:
15-
contents: read
1614

1715
e2e_tests:
1816
needs: authorize

0 commit comments

Comments
 (0)