Skip to content

Commit 6ffea76

Browse files
committed
fix: Restrict E2E workflow on PR target to privileged users
- Removed the `labeled` event type from `pull_request_target` triggers for the E2E workflow. - The E2E workflow will now run on `pull_request_target` events (opened, reopened, synchronize) only if the actor who triggered the event possessed write or admin permissions to the repository. - This replaced the previous mechanism where an 'e2e' label on a pull request would trigger the workflow. - The primary goal was to enhance security for `pull_request_target` workflows, preventing untrusted users from running them with potentially elevated permissions via labels. - Adjusted conditional logic in E2E test execution steps to align with these new permission-based job triggers, removing obsolete label checks. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 03788d6 commit 6ffea76

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

.github/workflows/e2e.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ on:
1616
required: false
1717
pull_request_target:
1818
types:
19-
- labeled
2019
- opened
2120
- reopened
2221
- synchronize
@@ -27,11 +26,12 @@ on:
2726

2827
jobs:
2928
e2e-tests:
30-
# Only run if it's a scheduled run, manual dispatch, or has e2e label
29+
# Run on schedule, unconditional workflow_dispatch,
30+
# or pull_request_target if the actor has write/admin permissions.
3131
if: >
32-
github.event_name == 'schedule' ||
33-
github.event_name == 'workflow_dispatch' ||
34-
(github.event_name == 'pull_request_target' && (github.event.label.name == 'e2e' || contains(github.event.pull_request.labels.*.name, 'e2e')))
32+
github.event_name == 'schedule' ||
33+
github.event_name == 'workflow_dispatch' ||
34+
(github.event_name == 'pull_request_target' && (github.actor == github.triggering_actor && (github.event.repository.permissions.write == true || github.event.repository.permissions.admin == true)))
3535
3636
concurrency:
3737
group: ${{ github.workflow }}-${{ matrix.provider }}-${{ github.event.pull_request.number || github.ref_name }}
@@ -122,8 +122,11 @@ jobs:
122122
run: |
123123
./hack/gh-workflow-ci.sh create_second_github_app_controller_on_ghe
124124
125+
# Adjusted step-level conditions based on the new job-level logic
125126
- name: Run E2E Tests
126-
if: ${{ github.event_name != 'schedule' || github.event.label.name == 'e2e' || contains(github.event.pull_request.labels.*.name, 'e2e') }}
127+
# This step runs for schedule, PR target (if job started), or workflow_dispatch (if job started)
128+
# Remove the old label check which is no longer relevant for triggering.
129+
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request_target' }}
127130
env:
128131
TEST_PROVIDER: ${{ matrix.provider }}
129132
TEST_BITBUCKET_CLOUD_TOKEN: ${{ secrets.BITBUCKET_CLOUD_TOKEN }}
@@ -140,6 +143,7 @@ jobs:
140143
./hack/gh-workflow-ci.sh run_e2e_tests
141144
142145
- name: Run E2E Tests on nightly
146+
# This step still runs specifically for schedule or workflow_dispatch
143147
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
144148
env:
145149
NIGHTLY_E2E_TEST: "true"

.tekton/e2e-label.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ metadata:
55
name: e2e-label.yaml
66
annotations:
77
pipelinesascode.tekton.dev/max-keep-runs: "2"
8-
pipelinesascode.tekton.dev/cancel-in-progress: "true"
9-
pipelinesascode.tekton.dev/on-event: "pull_request"
10-
pipelinesascode.tekton.dev/on-target-branch: "main"
11-
pipelinesascode.tekton.dev/on-path-change: "[**/*.go, .github/workflows/*l, test/**]"
8+
pipelinesascode.tekton.dev/on-comment: "^/e2e"
129
spec:
1310
pipelineSpec:
1411
tasks:

0 commit comments

Comments
 (0)