Skip to content

fix(ci): vet the adhoc build ref before running it with release secrets - #12161

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/adhoc-build-ref-vetting
Aug 4, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/adhoc-build-ref-vetting

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens the adhoc macOS build workflow (added in #12051) against the P1 flagged by the v1.4.165-rc.0 prod release scan: the workflow checked out any requested ref and ran that ref's scripts (verify-macos-release-env.mjs, ensure-native-runtime.mjs, electron-builder.config.cjs) with MAC_CERTS, the notary app-specific password, and the adhoc publisher token in reach. Dispatching a fork PR ref ("just build that community PR") would hand fork code the release signing identity.

Changes, all in .github/workflows/adhoc-mac-build.yml:

  • New "Vet the requested ref" step before checkout:
    • refs/pull/* / pull/* refs are refused outright.
    • Branches/tags resolve in a bare tree:0 scratch fetch of the repo's heads and tags (annotated tags peel to their commit).
    • Raw SHAs must be reachable from a repo branch or tag. This check is load-bearing, not belt-and-braces: a partial clone lazily fetches PR-only commits by SHA on demand, so "the object resolves" is not a trust test (verified live — see Testing).
    • Checkout now pins the vetted SHA, so a push to the branch between vetting and checkout cannot swap the commit.
  • The job now references an adhoc-mac-build environment. This is a no-op until repo settings give it teeth; the intended follow-up (admin-only) is to move the 7 signing/notary/App secrets into it and pin its deployment branch policy to main, which fences stale copies of this workflow on old branches away from the secrets entirely.

Trust model note: a vetted branch always belongs to someone with write access — the same trust the dispatch button already requires. This PR removes the escalation from "can dispatch a build" to "can run unreviewed fork code with signing credentials".

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

The four package commands don't exercise workflow YAML; instead the vetting script was extracted from the YAML (parse-validated) and run locally against the real stablyai/orca remote across 9 cases:

input result
main vetted → 8c5371ebad (current main head)
refs/heads/main vetted → same SHA
v1.4.164 (annotated tag) vetted → 9cea094620 (peeled commit, not the tag object)
8c5371ebad (short SHA on main) vetted → full SHA
pull/12137/head refused (PR ref)
refs/pull/12137/merge refused (PR ref)
totally-made-up-branch-xyz refused (does not resolve)
deadbeef… (alien SHA) refused (does not resolve)
real fork-PR head SHA (94d88dbc60e1…, exists only behind refs/pull/*) refused by the reachability check — the partial clone did lazily resolve the object, confirming name resolution alone would have been bypassable

AI Review Report

Reviewed as part of the v1.4.164..v1.4.165-rc.0 prod release scan (7 orchestrated reviewers; the security and release/package workers independently converged on this finding). Risks checked for this fix: ref-name ambiguity (branch vs tag tie-break kept branch-first to match actions/checkout behavior; exact-name resolution avoids ls-remote tail-glob mismatches), TOCTOU between vet and checkout (closed by pinning the SHA), shell injection (untrusted values enter only via env:, per the file's existing zizmor conventions), and lazy promisor fetch resurrecting the fork-SHA hole (closed by the reachability check). Cross-platform: CI-only change, runs on the macOS runner's bash + git ≥2.20 (--filter=tree:0, for-each-ref --contains need 2.20/2.7); no app code, shortcuts, paths, or Electron surface touched.

Security Audit

This PR is itself the security fix for the release-scan P1. Input handling: inputs.ref and inputs.label reach shell only through env: vars in quoted expansions (unchanged pattern). Command execution: the new step runs only git with argv arrays against https://github.com/${{ github.repository }}. Secrets: no new secret exposure; the step runs before any secret-bearing step. Residual risk, explicitly out of scope here and needing repo admin: (1) create/protect the adhoc-mac-build environment, move MAC_CERTS, MAC_CERTS_PASSWORD, APPLE_ID, APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID, HOURLY_RELEASE_APP_ID, HOURLY_RELEASE_APP_PRIVATE_KEY into it, delete the repo-level copies, and set its deployment branch policy to main; until then a stale workflow copy on an old branch can still read repo-level secrets. (2) A vetted repo branch still runs its own lockfile/postinstall and electron-builder config with signing env — inherent to "sign someone's branch"; the environment policy plus write-access trust is the accepted boundary. (3) Repo-wide SHA-pinning of third-party actions (nick-fields/retry, pnpm/action-setup) is a separate consistent follow-up; this file matches house tag-pin style for now.

Notes

  • macOS-only CI workflow; no app runtime, packaging output, or updater behavior changes. The v1.4.165-rc.0 release does not need to wait on this — the workflow is not part of the shipped build.
  • After merge, dispatches should keep using "Use workflow from: main"; once the environment branch policy lands, that becomes enforced rather than advisory.

Post-Merge Action Items (repo admin — this PR alone does not finish the fix)

  • Configure the adhoc-mac-build environment (auto-created on first dispatch, or create it under Settings → Environments): set deployment branch policy to main only. This is what actually fences stale copies of this workflow on old branches; until then the environment: line is advisory.
  • (Optional) Add required reviewers to the environment if per-dispatch approval friction is wanted.
  • Move the 7 secrets into the environment, then delete the repo-level copies: MAC_CERTS, MAC_CERTS_PASSWORD, APPLE_ID, APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID, HOURLY_RELEASE_APP_ID, HOURLY_RELEASE_APP_PRIVATE_KEY. Requires the secret values, so admin-only.
  • ⚠️ Before deleting the repo-level secrets: hourly-mac-build.yml reads the same repo-level secrets and will break the moment they're deleted. Either give the hourly workflow its own environment first (separate PR, ask if wanted) and copy the secrets into both, or skip the deletion and keep only the branch-policy/reviewer gate — accepting that stale workflow copies can still read repo-level secrets.
  • (Only if warranted) Rotate the Apple cert/notary credentials — needed only if an untrusted ref may already have been built. The workflow is new in the v1.4.165 cycle, so this is likely unnecessary.
  • (Follow-up, separate PR) Repo-wide SHA-pinning of third-party actions (nick-fields/retry, pnpm/action-setup) across all workflows; house style is currently tag pins everywhere, so it should be done consistently rather than just here.

The adhoc workflow checked out any requested ref and ran its scripts and
electron-builder config with MAC_CERTS, the notary password, and the adhoc
publisher token in reach — including refs/pull/* fork code a maintainer
could dispatch in one innocuous-looking click.

Vet the ref before checkout: PR refs are refused, branches/tags resolve in
a bare tree:0 scratch fetch, raw SHAs must be reachable from a repo branch
or tag (a partial clone lazily serves PR-only commits by SHA, so name
resolution alone is not a trust test), and checkout pins the vetted SHA so
a race push cannot swap the commit. Also reference an adhoc-mac-build
environment so the secrets can later be fenced off from stale workflow
copies via repo settings.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The workflow documents repository ref restrictions and rejects pull-request refs. It assigns the build job to the adhoc-mac-build environment. A pre-checkout step fetches branches and tags into a bare scratch repository, resolves the requested ref, verifies commit reachability, and outputs a pinned SHA. The checkout step uses that SHA.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes vetting the adhoc build ref before using release secrets.
Description check ✅ Passed The description includes all required sections and provides clear security, testing, AI review, platform, and follow-up details.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e3c70036-ca02-4715-b14f-e8349f521baf

📥 Commits

Reviewing files that changed from the base of the PR and between 8c5371e and d26a700.

📒 Files selected for processing (1)
  • .github/workflows/adhoc-mac-build.yml

Comment on lines +87 to +94
# Why an environment: it gives the signing/notary/App secrets somewhere to
# live that a stale copy of this workflow on an old branch cannot reach.
# Referencing it is a no-op until repo settings give it teeth; the intended
# follow-up is to move MAC_CERTS, MAC_CERTS_PASSWORD, APPLE_ID,
# APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID, HOURLY_RELEASE_APP_ID, and
# HOURLY_RELEASE_APP_PRIVATE_KEY into it, then pin its deployment branch
# policy to main so only main's copy of this file can read them.
environment: adhoc-mac-build

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="stablyai/orca"
environment="adhoc-mac-build"

echo "Environment configuration:"
gh api "repos/$repo/environments/$environment"

echo "Environment deployment branch policies:"
gh api "repos/$repo/environments/$environment/deployment-branch-policies" || true

echo "Repository secret names:"
gh secret list --repo "$repo"

echo "Environment secret names:"
gh secret list --repo "$repo" --env "$environment"

Repository: stablyai/orca

Length of output: 336


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Workflow references:"
rg -n "adhoc-mac-build|MAC_CERTS|MAC_CERTS_PASSWORD|APPLE_ID|APPLE_APP_SPECIFIC_PASSWORD|APPLE_TEAM_ID|HOURLY_RELEASE_APP_ID|HOURLY_RELEASE_APP_PRIVATE_KEY|environment:" .github/workflows/adhoc-mac-build.yml .github/workflows || true

echo
echo "Repository secret names:"
gh secret list --repo "stablyai/orca" || true

echo
echo "Files mentioning environment references:"
rg -n "environment:\\s*adhoc-mac-build|secrets:\\s*\\n?\\s*[A-Z0-9_.]+" .github/workflows || true

echo
echo "Workflow status/stat excerpt if available:"
git ls-files .github/workflows/adhoc-mac-build.yml
wc -l .github/workflows/adhoc-mac-build.yml
sed -n '70,105p' .github/workflows/adhoc-mac-build.yml

Repository: stablyai/orca

Length of output: 9578


Complete the environment secret migration before relying on this control.

The adhoc-mac-build environment does not restrict secrets.* usage, and the workflow still reads signing/App/release keys from repository-level secrets. Move those secrets into adhoc-mac-build, remove the repository-level copies, and pin the environment deployment policy to main before treating this workflow as protected.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens the ad-hoc macOS build workflow by introducing a ref-vetting step that runs before checkout and before any signing secrets are in scope. The fix directly addresses a previously identified issue where dispatching a fork PR ref could run unreviewed code against MAC_CERTS, the notary app-specific password, and the App token.

  • Ref vetting logic: PR refs (refs/pull/* / pull/*) are refused outright with a clear error. Other inputs are resolved against a bare scratch clone fetching only the commit graph (--filter=tree:0) of the repo's heads and tags; raw SHAs must additionally pass a for-each-ref --contains reachability check, which correctly rejects fork/PR-only commits that a partial clone could otherwise lazily fetch by SHA.
  • TOCTOU closure: the checkout step now pins steps.vetted.outputs.sha instead of the original branch name, so a push to the branch between vetting and checkout cannot swap the commit that runs with secrets.
  • Environment stub: environment: adhoc-mac-build is added as a no-op placeholder; the inline comment documents that the intended follow-up is to migrate the seven signing/notary/App secrets into this environment and pin its deployment branch policy to main.

Confidence Score: 4/5

Safe to merge; the core vetting logic is correct and closes the fork-code-with-signing-credentials path, but the environment declaration is a no-op until an admin migrates secrets and sets branch policies

The ref vetting, reachability check, and SHA pinning are all implemented correctly and the test matrix in the PR description covers the key bypass attempts including the partial-clone/lazy-fetch edge case. The minor gap is the third rev-parse candidate lacking a -- separator (produces a confusing error, not a bypass) and the environment: adhoc-mac-build declaration providing no actual isolation today — the signing secrets remain at repo scope until an admin completes the follow-up steps.

Files Needing Attention: .github/workflows/adhoc-mac-build.yml — specifically the vet step loop and the environment declaration

Important Files Changed

Filename Overview
.github/workflows/adhoc-mac-build.yml Adds a ref-vetting step before checkout that blocks PR refs outright and verifies branch/tag reachability for raw SHAs; pins the vetted SHA at checkout to close the TOCTOU window; adds an environment reference as a no-op placeholder for future secret isolation

Sequence Diagram

sequenceDiagram
    participant Operator
    participant GHA as GitHub Actions
    participant VetStep as Vet the requested ref
    participant GitHub as github.com/stablyai/orca
    participant Checkout as actions/checkout

    Operator->>GHA: workflow_dispatch(ref, label)
    GHA->>VetStep: "REQUESTED_REF = inputs.ref || github.ref_name"
    VetStep->>VetStep: "case match refs/pull/* or pull/*?"
    alt PR ref detected
        VetStep-->>GHA: exit 1 (refused)
    else non-PR ref
        VetStep->>GitHub: "git init bare + fetch --filter=tree:0 refs/heads/* refs/tags/*"
        GitHub-->>VetStep: commit graph (no trees/blobs)
        VetStep->>VetStep: rev-parse: try refs/heads/REF then refs/tags/REF then REF
        alt resolves to a SHA
            VetStep->>VetStep: for-each-ref --contains SHA refs/heads refs/tags
            alt SHA reachable from branch or tag
                VetStep-->>GHA: "output sha=pinned SHA"
                GHA->>Checkout: "ref = steps.vetted.outputs.sha"
                Checkout->>GitHub: clone at pinned SHA
                GitHub-->>Checkout: source tree
                Checkout-->>GHA: workspace ready
                GHA->>GHA: run build with MAC_CERTS + notary secrets
            else SHA not reachable (fork/PR-only commit)
                VetStep-->>GHA: exit 1 (not reachable from any branch or tag)
            end
        else does not resolve
            VetStep-->>GHA: exit 1 (does not resolve)
        end
    end
Loading

Reviews (1): Last reviewed commit: "fix(ci): vet the adhoc build ref before ..." | Re-trigger Greptile

Comment on lines +133 to +138
for cand in "refs/heads/$REQUESTED_REF" "refs/tags/$REQUESTED_REF" "$REQUESTED_REF"; do
if sha="$(git -C "$scratch" rev-parse --verify --quiet "$cand^{commit}")"; then
break
fi
sha=""
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Third rev-parse candidate lacks -- separator

The third loop candidate passes $REQUESTED_REF directly to git rev-parse without a -- end-of-options separator. If an operator types a value like -foo or --help in the dispatch UI, git receives rev-parse --verify --quiet --help^{commit}, treating it as an unknown option instead of a refspec. In practice this still results in a failed resolution and a rejected ref — so there is no security bypass — but the error message from git will be cryptic ("unknown option") rather than the clearer workflow-level message. The first two candidates are safe because the refs/heads/ and refs/tags/ prefixes prevent any --leading value from being parsed as a flag.

Replacing the bare candidate with -- "$REQUESTED_REF^{commit}" (after inserting -- before the argument in the rev-parse call for all three candidates) would both eliminate the confusion and signal the intent that the argument is always a refspec, never an option.

# APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID, HOURLY_RELEASE_APP_ID, and
# HOURLY_RELEASE_APP_PRIVATE_KEY into it, then pin its deployment branch
# policy to main so only main's copy of this file can read them.
environment: adhoc-mac-build

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 environment: adhoc-mac-build is a no-op until the environment is created and secrets migrated

Referencing a GitHub environment that has not yet been created with protection rules provides no isolation today. If the environment does not exist in repo settings, GitHub will resolve it implicitly with no branch policy and no secret scope restriction, meaning the seven signing/notary/App secrets remain readable by any workflow run — including stale copies of this file on old branches — just as before. The inline comment documents this correctly, but the gap is worth calling out explicitly: the protection this declaration is intended to enforce becomes active only after an admin creates the adhoc-mac-build environment, moves the secrets into it, and sets its deployment branch policy to main. Until then, the environment: line is advisory documentation rather than a control.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@brennanb2025
brennanb2025 merged commit c4ae923 into main Aug 4, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ts (stablyai#12161)

The adhoc workflow checked out any requested ref and ran its scripts and
electron-builder config with MAC_CERTS, the notary password, and the adhoc
publisher token in reach — including refs/pull/* fork code a maintainer
could dispatch in one innocuous-looking click.

Vet the ref before checkout: PR refs are refused, branches/tags resolve in
a bare tree:0 scratch fetch, raw SHAs must be reachable from a repo branch
or tag (a partial clone lazily serves PR-only commits by SHA, so name
resolution alone is not a trust test), and checkout pins the vetted SHA so
a race push cannot swap the commit. Also reference an adhoc-mac-build
environment so the secrets can later be fenced off from stale workflow
copies via repo settings.
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.

1 participant