Skip to content

Commit e592877

Browse files
authored
[tooling] Fix contribution message workflow permission issue on PR from fork (#224)
Problem: * `pull_request` trigger type is forced for PRs that **come from forks** to only have `read` permission for all scopes regardless of what we set explicitly in the workflow -> results in permission issue in contribution comment Source: https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflows-in-forked-repositories Proposed solution: * Use `pull_request_target` with restricted scope for GITHUB_TOKEN * Checkout to base repository default branch instead of the HEAD of the forked repository for security reasons (ensures we only run safe and trusted code in the main branch) Source: https://www.linkedin.com/pulse/how-access-secrets-running-tests-forked-pull-requests-kylee-fields-7vcne/ Note: this change will only take effect for PRs that appear AFTER this PR is merged. Alternative solution: * more complicated flow where we have a `pull_request` trigger that builds relevant artifacts (if needed), then use `workflow_runs` trigger to comment to github (see more here: https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/)
1 parent 8c007cd commit e592877

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

.github/workflows/contribution-message.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: Post contribution message in pull request
22
on:
3-
pull_request:
3+
pull_request_target:
44
types: [opened, reopened]
55

66
permissions:
7-
contents: write
7+
# Only scope GITHUB_TOKEN to write for pull requests, others set to none (by default) for security reasons since we are using pull_request_target trigger
88
pull-requests: write
99

1010
jobs:
1111
post_contribution_message:
1212
runs-on: ubuntu-latest
1313
steps:
14+
# DO NOT CHECKOUT TO HEAD UNSAFE (will checkout to head of the fork for pull_request_target trigger)
1415
- name: Checkout repository
1516
uses: actions/checkout@v6
1617

0 commit comments

Comments
 (0)