fix(ci): support fork PRs in e2e-brev workflow#1860
Conversation
workflow_dispatch with pr_number resolved the branch name, but fork branches don't exist in the base repo. Use refs/pull/<N>/head instead, which GitHub creates for all open PRs regardless of origin.
📝 WalkthroughWalkthroughA GitHub Actions workflow configuration update that introduces a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/e2e-brev.yaml:
- Around line 118-124: The workflow is currently unconditionally setting PR_REF
to refs/pull/${{ inputs.pr_number }}/head and then checking it out
(actions/checkout@v6), which allows fork PRs to run code in jobs that have
secrets (BREV_API_TOKEN, NVIDIA_API_KEY); change the logic that sets or uses
PR_REF so fork PR refs are only used for trusted/internal PRs or explicit
maintainer opt-in: detect whether the PR head repo matches the repository owner
(e.g., compare github.event.pull_request.head.repo.full_name or
head.repo.owner.login to github.repository or github.repository_owner) and only
set PR_REF / perform the checkout of refs/pull/... when that check passes
(otherwise fall back to inputs.branch or 'main'), or gate the checkout behind an
explicit input like inputs.trust_pr_from_fork that must be true and approved by
a maintainer before exposing secrets. Ensure the checkout step
(actions/checkout@v6) uses the guarded PR_REF value so secrets are never exposed
to untrusted fork refs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4ac8ecb9-7fc9-4bfd-8e94-b3199c832450
📒 Files selected for processing (1)
.github/workflows/e2e-brev.yaml
| # Use the PR head ref for checkout — works for both fork and non-fork PRs. | ||
| echo "PR_REF=refs/pull/${{ inputs.pr_number }}/head" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Checkout target branch | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ env.RESOLVED_BRANCH || inputs.branch || 'main' }} | ||
| ref: ${{ env.PR_REF || inputs.branch || 'main' }} |
There was a problem hiding this comment.
Block untrusted fork PR refs before secret-backed checkout.
Line 119 and Line 124 now enable running fork PR code (refs/pull/<N>/head) in a job that later exposes BREV_API_TOKEN and NVIDIA_API_KEY. That is a secret-exfiltration path unless you gate fork PRs by trust level (or explicit maintainer opt-in).
🔒 Suggested guard before setting PR_REF
- name: Resolve branch from PR number
if: inputs.pr_number != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
BRANCH=$(gh pr view ${{ inputs.pr_number }} --repo ${{ github.repository }} --json headRefName -q .headRefName)
+ IS_FORK=$(gh pr view ${{ inputs.pr_number }} --repo ${{ github.repository }} --json isCrossRepository -q .isCrossRepository)
+ AUTHOR_ASSOC=$(gh pr view ${{ inputs.pr_number }} --repo ${{ github.repository }} --json authorAssociation -q .authorAssociation)
+ if [ "$IS_FORK" = "true" ] && ! echo "$AUTHOR_ASSOC" | grep -Eq '^(OWNER|MEMBER|COLLABORATOR)$'; then
+ echo "::error::Refusing to run secret-backed e2e for untrusted fork PR #${{ inputs.pr_number }} (authorAssociation=$AUTHOR_ASSOC)."
+ exit 1
+ fi
echo "Resolved PR #${{ inputs.pr_number }} → branch: $BRANCH"
echo "RESOLVED_BRANCH=$BRANCH" >> "$GITHUB_ENV"
# Use the PR head ref for checkout — works for both fork and non-fork PRs.
echo "PR_REF=refs/pull/${{ inputs.pr_number }}/head" >> "$GITHUB_ENV"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/e2e-brev.yaml around lines 118 - 124, The workflow is
currently unconditionally setting PR_REF to refs/pull/${{ inputs.pr_number
}}/head and then checking it out (actions/checkout@v6), which allows fork PRs to
run code in jobs that have secrets (BREV_API_TOKEN, NVIDIA_API_KEY); change the
logic that sets or uses PR_REF so fork PR refs are only used for
trusted/internal PRs or explicit maintainer opt-in: detect whether the PR head
repo matches the repository owner (e.g., compare
github.event.pull_request.head.repo.full_name or head.repo.owner.login to
github.repository or github.repository_owner) and only set PR_REF / perform the
checkout of refs/pull/... when that check passes (otherwise fall back to
inputs.branch or 'main'), or gate the checkout behind an explicit input like
inputs.trust_pr_from_fork that must be true and approved by a maintainer before
exposing secrets. Ensure the checkout step (actions/checkout@v6) uses the
guarded PR_REF value so secrets are never exposed to untrusted fork refs.
Summary
refs/pull/<N>/headinstead of resolving the branch name for checkout whenpr_numberis providedgit fetch exit code 1refs/pull/<N>/headis created by GitHub for all open PRs regardless of originTest plan
e2e-brevworkflow with a fork PR number (e.g. PR feat(security): add tamper-evident audit chain logger #892) and confirm checkout succeedse2e-brevworkflow with a non-fork PR number and confirm it still workse2e-brevworkflow withbranchinput (nopr_number) and confirm fallback worksSummary by CodeRabbit