Skip to content

fix: use pull_request_target to enable E2E tests for Dependabot PRs#156

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-ci-failure-dependabot-pr
Draft

fix: use pull_request_target to enable E2E tests for Dependabot PRs#156
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-ci-failure-dependabot-pr

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

Dependabot PRs run with Dependabot-scoped secrets only and cannot access regular repository secrets under the pull_request event, causing the E2E job to always fail with E2E_RESOURCE_GROUP: Set E2E_RESOURCE_GROUP in environment or .env.

Change

Switch the E2E workflow trigger from pull_request to pull_request_target, which runs in the base-branch context and has full access to repository secrets even for Dependabot PRs. The checkout step is explicitly pinned to github.event.pull_request.head.sha so the actual PR code is tested rather than the base-branch code:

on:
  pull_request_target:
    branches: [main, dev]
    types: [opened, synchronize, reopened]

steps:
  - name: Checkout code
    uses: actions/checkout@v4
    with:
      ref: ${{ github.event.pull_request.head.sha }}

A job-level if guard is added to prevent the known pull_request_target security risk where arbitrary fork PRs could execute untrusted code with repository secrets. Only PRs from within the same repository or from dependabot[bot] are allowed to run:

if: |
  github.event_name != 'pull_request_target' ||
  github.event.pull_request.head.repo.full_name == github.repository ||
  github.actor == 'dependabot[bot]'

This allows Dependabot PRs and internal team PRs to run E2E tests with the required Azure credentials, while external fork PRs are skipped and never receive repository secrets.

Copilot AI linked an issue Apr 27, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix CI failure for Dependabot PR fix: skip E2E tests for Dependabot PRs Apr 27, 2026
Copilot AI requested a review from bcho April 27, 2026 21:49
Copilot finished work on behalf of bcho April 27, 2026 21:49
Copy link
Copy Markdown
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do want dependabot's PRs to run with e2e tests

Copy link
Copy Markdown
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address latest comment

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 27, 2026

we do want dependabot's PRs to run with e2e tests

Addressed in commit 2e69fbd. The fix changes the trigger from pull_request to pull_request_target. The pull_request_target event runs in the base-branch context and has full access to repository secrets (including E2E_RESOURCE_GROUP, AZURE_SUBSCRIPTION_ID, etc.) even for Dependabot PRs. The checkout step is explicitly pinned to github.event.pull_request.head.sha so the actual PR code is tested rather than the base-branch code.

Copilot AI changed the title fix: skip E2E tests for Dependabot PRs fix: use pull_request_target to enable E2E tests for Dependabot PRs Apr 27, 2026
Copilot AI requested a review from bcho April 27, 2026 21:55
Copilot finished work on behalf of bcho April 27, 2026 21:55
Copilot finished work on behalf of bcho April 27, 2026 22:14
Copy link
Copy Markdown
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot does it allow ad-hoc users to run from their fork with our cred?

Copy link
Copy Markdown
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot review latest comment

Add an `if` condition on the e2e job so that when triggered by
pull_request_target only PRs from the same repository or from
dependabot[bot] run with repository secrets.  External fork PRs are
skipped, preventing arbitrary users from exfiltrating credentials.

Agent-Logs-Url: https://github.com/Azure/AKSFlexNode/sessions/15f8caea-8942-44c2-93e8-f3b77db9ae9c

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 27, 2026

@copilot does it allow ad-hoc users to run from their fork with our cred?

Yes — that was a real risk with the original pull_request_target approach. A malicious fork PR could have checked out and run arbitrary code with full repository secrets.

Fixed in c17cb79 by adding a job-level if guard:

if: |
  github.event_name != 'pull_request_target' ||
  github.event.pull_request.head.repo.full_name == github.repository ||
  github.actor == 'dependabot[bot]'

This means:

  • workflow_dispatch / push tag triggers: always run (no restriction)
  • pull_request_target: only runs for PRs from within this repository (team members) or from dependabot[bot] — external fork PRs are skipped and never receive secrets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix ci failure for dependabot pr

2 participants