Fix contribution message workflow permission issue on PR from fork#224
Conversation
| - name: Checkout repository # Checks out to base repository default branch (for pull_request_target trigger) | ||
| uses: actions/checkout@v6 # DO NOT CHECKOUT TO HEAD UNSAFE (will checkout to head of the fork) |
There was a problem hiding this comment.
What's the purpose of these comments if there's no changes to the behavior? I would remove them since they don't really add anything. If you want to add a comment to not checkout to HEAD, add it as a line above the - name
There was a problem hiding this comment.
@woojiahao There is a difference in behaviour if we are using pull_request_target vs. pull_request trigger.
pull_request checks out to the forks repo (since it is run in safer environment)
pull_request_target checks out to the base repo (that's why the updated gh action can only run after we merge this into main)
I'm adding this here as additional documentation why I made this change, but I can add it above -name
There was a problem hiding this comment.
Oh no I get the difference between the triggers, I was just wondering why new comments were added
woojiahao
left a comment
There was a problem hiding this comment.
Verified against the documentation. The values of the fields should not change
Problem:
pull_requesttrigger type is forced for PRs that come from forks to only havereadpermission for all scopes regardless of what we set explicitly in the workflow -> results in permission issue in contribution commentSource: https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflows-in-forked-repositories
Proposed solution:
pull_request_targetwith restricted scope for GITHUB_TOKENSource: 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:
pull_requesttrigger that builds relevant artifacts (if needed), then useworkflow_runstrigger to comment to github (see more here: https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/)