Skip to content

ci(flyte-binary-v2): use pull_request_target so fork PRs can access DEPOT_PROJECT_ID#7320

Merged
pingsutw merged 8 commits intomainfrom
test-2
Apr 30, 2026
Merged

ci(flyte-binary-v2): use pull_request_target so fork PRs can access DEPOT_PROJECT_ID#7320
pingsutw merged 8 commits intomainfrom
test-2

Conversation

@pingsutw
Copy link
Copy Markdown
Member

@pingsutw pingsutw commented Apr 30, 2026

Why

The Build & Push Flyte Single Binary Images v2 workflow validates and uses vars.DEPOT_PROJECT_ID to drive Depot builds. GitHub does not pass repository variables (or secrets) to workflows triggered by pull_request events from forks. As a result, every PR opened from a fork (e.g. pingsutw/flyte) failed the Validate Depot project id step with:

##[error]DEPOT_PROJECT_ID repo variable is not set.

Branches in flyteorg/flyte worked fine; only fork PRs failed. We want fork PRs to run the same build verification as in-repo branches.

What changed

  • pull_requestpull_request_target for this workflow. pull_request_target runs in the base repo context, so vars.DEPOT_PROJECT_ID (and any non-secret config) is available even for fork PRs.
  • All actions/checkout@v4 steps now explicitly check out github.event.pull_request.head.sha || github.sha. By default pull_request_target checks out the base ref, which would test the wrong code; this makes the workflow actually build the PR's contents.
  • PUSH_IMAGES tightened: now requires pull_request_target and head.repo.full_name == github.repository and the test-push-image label. Fork PRs can never trigger an image push, so secrets.FLYTE_BOT_PAT is never reachable from fork-controlled code.
  • Added a SECURITY comment at the top of on: documenting the tradeoff.

Security considerations

pull_request_target + checking out the PR head means fork-authored code (Dockerfile, Makefile, build scripts) executes with access to whatever the base-repo job exposes. Mitigations applied:

  • No repo secrets are referenced in any step that runs for fork PRs.
  • Image push / GHCR login are gated to base-repo branches only.
  • The only base-repo value exposed to fork code is vars.DEPOT_PROJECT_ID, which is a public Depot project identifier (not a credential). Auth to Depot uses OIDC with id-token: write — a malicious fork could consume Depot build minutes on this project, but cannot exfiltrate credentials.

If consuming Depot minutes from fork PRs is unacceptable, an alternative is to skip the depot job entirely on fork PRs (if: github.event.pull_request.head.repo.full_name == github.repository) instead of switching to pull_request_target.

Test plan

  • CI on this PR (test-2, in-repo branch) still passes with DEPOT_PROJECT_ID populated.
  • After merge, open a fork PR and confirm Validate Depot project id passes and the Depot build runs.
  • Confirm PUSH_IMAGES evaluates to false on fork PRs (no GHCR login attempt).
  • Confirm push-to-main still pushes images as before.

Signed-off-by: Kevin Su <pingsutw@apache.org>
Copilot AI review requested due to automatic review settings April 30, 2026 19:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modifies the shared Go Makefile’s help target phony declaration in go.Makefile.

Changes:

  • Updates the .PHONY declaration for the help target (currently to a mismatched name).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go.Makefile Outdated
##@ General

.PHONY: help
.PHONY: helppp
Signed-off-by: Kevin Su <pingsutw@apache.org>
…s.DEPOT_PROJECT_ID

Forks don't receive repo vars on pull_request events; pull_request_target runs in the base-repo context where vars are available. Explicitly checks out the PR head SHA to actually build PR code, and forces PUSH_IMAGES=false for fork PRs so secrets like FLYTE_BOT_PAT remain unreachable.

Signed-off-by: Kevin Su <pingsutw@apache.org>
Copilot AI review requested due to automatic review settings April 30, 2026 19:39
@pingsutw pingsutw changed the title test ci(flyte-binary-v2): use pull_request_target so fork PRs can access DEPOT_PROJECT_ID Apr 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates build automation by modifying the Go makefile’s help target declaration and changing the Flyte binary CI workflow to run in pull_request_target context (with PR-head checkout) while restricting image pushing to base-repo branches/PRs.

Changes:

  • Changed .PHONY declaration in go.Makefile (help target).
  • Switched CI trigger from pull_request to pull_request_target and added PR-head SHA checkout.
  • Updated PUSH_IMAGES logic to prevent image pushes from fork PRs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
go.Makefile Adjusts .PHONY declaration for the help target.
.github/workflows/flyte-binary-v2.yml Changes PR trigger to pull_request_target, checks out PR head SHA, and tightens PUSH_IMAGES for forks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go.Makefile Outdated
##@ General

.PHONY: help
.PHONY: helppp
Comment thread .github/workflows/flyte-binary-v2.yml Outdated
Comment on lines +11 to +17
# SECURITY: pull_request_target runs in the BASE repo context so repo
# variables (vars.*) are available for fork PRs. The tradeoff is that this
# job checks out and builds the PR's head ref — i.e. fork-controlled code —
# while having access to those vars. We do NOT expose repo secrets here:
# PUSH_IMAGES is forced false for fork PRs below, so FLYTE_BOT_PAT login and
# any image push only run for branches in the base repo.
pull_request_target:
Comment thread .github/workflows/flyte-binary-v2.yml
Comment on lines 22 to +26
env:
DEPOT_PROJECT_ID: ${{ vars.DEPOT_PROJECT_ID }}
# Push images on push to main, manual dispatch, OR on a PR labeled
# `test-push-image` (apply the label to a PR to push test images).
PUSH_IMAGES: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'test-push-image')) }}
# `test-push-image` from a branch in the base repo (never from forks).
PUSH_IMAGES: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name == github.repository && contains(github.event.pull_request.labels.*.name, 'test-push-image')) }}
pingsutw and others added 2 commits April 30, 2026 12:49
Signed-off-by: Kevin Su <pingsutw@apache.org>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Kevin Su <pingsutw@gmail.com>
Copilot AI review requested due to automatic review settings April 30, 2026 19:51
The metadata-action 'enable' expression checked github.event_name == 'pull_request', which (a) never matches pull_request_target runs and (b) was already dead even pre-switch since github.ref is never refs/heads/master on pull_request events. Update to push-to-main to match the other image's nightly rule (push to v2 -> nightly for devbox-bundled).

Signed-off-by: Kevin Su <pingsutw@apache.org>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Flyte single-binary v2 image build workflow so fork-based PRs can run Depot builds by switching from pull_request to pull_request_target, while gating any image-push behavior to base-repo PRs only.

Changes:

  • Switch workflow trigger from pull_request to pull_request_target to allow access to vars.DEPOT_PROJECT_ID for fork PRs.
  • Ensure PR code is built by checking out github.event.pull_request.head.sha (fallback github.sha) in all jobs.
  • Tighten image-push gating logic (PUSH_IMAGES) and add minimal job permissions for test-bootstrap.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 9 to 13
branches:
- main
pull_request:
pull_request_target:
branches:
- main
Comment on lines 18 to +20
# Push images on push to main, manual dispatch, OR on a PR labeled
# `test-push-image` (apply the label to a PR to push test images).
PUSH_IMAGES: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'test-push-image')) }}
# `test-push-image` from a branch in the base repo (never from forks).
PUSH_IMAGES: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name == github.repository && contains(github.event.pull_request.labels.*.name, 'test-push-image')) }}
Comment thread .github/workflows/flyte-binary-v2.yml
Comment thread .github/workflows/flyte-binary-v2.yml
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Kevin Su <pingsutw@gmail.com>
Copilot AI review requested due to automatic review settings April 30, 2026 20:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Kevin Su <pingsutw@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Flyte single-binary v2 build workflow so that fork-based PRs can access vars.DEPOT_PROJECT_ID and run Depot-backed build verification, while preventing fork PRs from pushing images.

Changes:

  • Switched the workflow trigger from pull_request to pull_request_target to allow fork PRs to read repo variables.
  • Updated actions/checkout@v4 steps to check out the PR head SHA (instead of the base ref) under pull_request_target.
  • Tightened PUSH_IMAGES gating logic and adjusted the nightly tagging enablement condition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 7 to 13
on:
push:
branches:
- main
pull_request:
pull_request_target:
branches:
- main
Comment on lines 156 to +159
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
Comment on lines 28 to +31
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
persist-credentials: false
@pingsutw pingsutw added this pull request to the merge queue Apr 30, 2026
@pingsutw pingsutw merged commit 8ba65d9 into main Apr 30, 2026
18 checks passed
@pingsutw pingsutw deleted the test-2 branch April 30, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants