chore(ci): give new workspace comment workflow correct perms#2606
chore(ci): give new workspace comment workflow correct perms#2606hopehadfield wants to merge 1 commit intoredhat-developer:mainfrom
Conversation
Signed-off-by: Hope Hadfield <hhadfiel@redhat.com>
Review Summary by QodoUpdate workspace PR comment workflow with elevated permissions
WalkthroughsDescription• Changed trigger from pull_request to pull_request_target for elevated permissions • Added persist-credentials: false to checkout step for security • Enables workflow to write comments on PRs from external contributors Diagramflowchart LR
A["pull_request trigger"] -->|"Change to"| B["pull_request_target trigger"]
B -->|"Enables"| C["Write permissions for PR comments"]
D["Checkout step"] -->|"Add security flag"| E["persist-credentials: false"]
File Changes1. .github/workflows/new-workspace-pr-comment.yml
|
Code Review by Qodo
1. Privileged checkout of PR
|
|
|
|
||
| on: | ||
| pull_request: | ||
| pull_request_target: |
There was a problem hiding this comment.
1. Privileged checkout of pr 🐞 Bug ⛨ Security
The workflow now runs on pull_request_target with write permissions, but still checks out the PR head SHA, making attacker-controlled repository content available in a privileged job context. This creates a critical token/permission abuse vector if any step (now or in the future) executes or sources code from the checked-out workspace.
Agent Prompt
### Issue description
`pull_request_target` runs with base-repo context and a write-capable token. Checking out the PR head SHA in that job makes attacker-controlled code/content available, which is a known GitHub Actions security anti-pattern.
### Issue Context
The workflow only needs to detect whether `workspaces/` gained new top-level directories and then post a comment.
### Fix Focus Areas
- .github/workflows/new-workspace-pr-comment.yml[1-40]
### Suggested fix
- Do **not** check out `github.event.pull_request.head.sha` in a `pull_request_target` job.
- Prefer one of:
1) Checkout the base (`ref: ${{ github.event.pull_request.base.sha }}`) and then `git fetch` the PR head into a separate ref and use `git ls-tree <sha>:workspaces` without checking out the PR content into the working tree; or
2) Avoid checkout entirely and use GitHub API to compare tree contents (read-only operations) while keeping write permissions only for the comment step.
- If you must access PR content, only check out the minimal paths needed (similar to `validate-codeowners.yml`’s `git checkout pr-head -- <path>` pattern).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Hey, I just made a Pull Request!
This should provide the correct permissions for the new workspace PR comment workflow. The test run failed because workflows triggered by
pull_requestreceive a read-only GITHUB_TOKEN.✔️ Checklist