Skip to content

fix(templates): build Next.js outside the deploy job that can mint a deploy token - #151

Open
dawsontoth wants to merge 3 commits into
mainfrom
fix/nextjs-deploy-build-job
Open

dawsontoth wants to merge 3 commits into
mainfrom
fix/nextjs-deploy-build-job

Conversation

@dawsontoth

@dawsontoth dawsontoth commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

A beaver shows friends raccoons building a toy and a basket carrying it to the owl with the key

⊙ Problem

The Next.js templates' deploy job installed dependencies and ran next build while holding id-token: write. Any dependency's install or build script could ask GitHub for the job's identity token and trade it for the deploy user's Harper token, which can deploy any app on the cluster.

🤔 Is building in CI still right for Next.js?

Yes, for now: building on the cluster fails (HarperFast/nextjs#57, HarperFast/nextjs#58). Once those land, these templates can join the shared workflow and drop the artifact.

💡 Solution

⚖️ Alternatives

  • A separate build job — a second dependency install, and no isolation the test job doesn't already have.
  • Uploading .next/cache too — 20 of the 26 MB in a fresh scaffold, and the app serves without it.

🤔 Should the build see production-environment variables?

It no longer can: next build runs outside environment: production, so variables scoped to that environment don't reach it. The template uses none; a project that needs NEXT_PUBLIC_* values at build time can pass repository variables to the Build step with env:.

🔧 Changes

✅ Verification

  • npm test: 384 pass; lint:check and format:check clean. In template.tests/deployWorkflow.test.js, a new test checks that no template's deploy job installs dependencies or builds, and new Next.js tests check the upload, the download's order and that the deploy job matches the shared one apart from the download. The scaffolded pnpm workflow keeps pnpm out of the deploy job, and the helpers moved to module scope for these. 8 of them fail on main.
  • Live smoke: scaffolded nextjs, ran npm run build, copied the project without node_modules and .next, added .next without cache/, and ran harper deploy project=nextsmoke restart=true against a throwaway Harper 5.3.2. It deployed, and GET / returned 200 with the Harper-backed counter.
  • Not run: the upload and download on a real Actions runner.

Related: HarperFast/documentation#731 (the same fix in the CI guide's Path B), HarperFast/skills#119 (the skill rule that quotes the guide).

🤖 Generated by Claude Code (Claude Opus 5.5); posted via @dawsontoth.

Related PRs: #147 overlaps (merged; this hardens its Next.js deploy job)
Complexity: medium

Review-Coverage: authored=claude; ran=gemini,codex; adjudicated=domain; declined=cursor-grok,cursor-composer,cursor-kimi,cursor-muse,muse; rounds=1; full=1 @ 98f4fdc

Review-Attention: read ~3m (decisions: build-env-scope, duplicated-deploy-gate, pr-builds) @ 98f4fdc

dawsontoth and others added 2 commits October 14, 2026 13:59
…int a deploy token

The Next.js deploy job installed dependencies and ran next build with
id-token: write, so a compromised dependency's script could request the
job's identity token and trade it for the deploy user's Harper token.
The test job now builds and uploads .next (without .next/cache) as an
artifact on main, and the deploy job downloads it after checkout and
otherwise matches the shared deploy job: it installs only the Harper CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

…e a Windows checkout has CRLF

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants