Skip to content

Sign Reprint pulls with one key per machine - #6169

Merged
chubes4 merged 2 commits into
trunkfrom
chubes/reprint-machine-key
Nov 30, 2026
Merged

chubes4 merged 2 commits into
trunkfrom
chubes/reprint-machine-key

Conversation

@chubes4

@chubes4 chubes4 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude Opus 5.5 (Claude Code), running as Franklin, Chris's agent, found this while stress-testing Reprint pull on real WordPress.com sites, then wrote the fix and tests and ran the reproduction below. Chris reviews before merge.

Proposed Changes

  • Two local sites pulling the same WordPress.com site at the same time failed with AUTH_UNKNOWN_KEY (HTTP 403). Studio generated a Reprint key per local site, and Jetpack keeps one key per site (Reprint export: update Reprint to 0.11.2 and accept public-key signed requests jetpack#53537: "Installing a key replaces the previous one"). The second pull installed its key over the first one's, and the first pull's next request was refused.
  • Studio now signs every Reprint pull with one key per machine, ~/.studio/reprint-key.pem, passed to preflight, pull-files and pull-db as --private-key-path. Every local site on the machine installs the same key, so they no longer replace each other's.
  • The key is generated in Node (RSA 3072, the same as reprint keygen) on first use. It is written to a temporary file and hard-linked into place, so pulls that start at the same time end up with the same key. This also removes the pull-metadata and keygen Reprint calls from the start of each pull.
  • Keys in existing per-site state directories are no longer used. --private-key-path takes precedence over them, and the next pull installs the machine key.
  • Pulling one site from two different machines still conflicts, because Jetpack keeps one key per site. That limit was a deliberate Jetpack decision and is out of scope here.

Testing Instructions

With STUDIO_ENABLE_PULL_REPRINT=1, start two pulls of the same remote into two different local sites, about two seconds apart:

studio pull --path <site-a> --remote-site <id> --options all &
studio pull --path <site-b> --remote-site <id> --options all &
  • On trunk (macOS, a preview site): the first pull succeeds and the second fails at files-pull with AUTH_UNKNOWN_KEY.
  • With this change: both pulls succeed, in two runs out of two. The first run started with no ~/.studio/reprint-key.pem. Afterwards there is a single key file with mode 0600.

Unit tests: npx vitest run apps/cli/lib/pull apps/cli/commands/tests/pull.test.ts. The new test checks that three pulls starting together get one key, and that it signs for the public key it reports. The same key-creation code was also run on a Windows 11 VM, with the same result.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@github-actions github-actions 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.

Auto-approved: chubes4 is a trusted author.

@chubes4
chubes4 merged commit 675a86c into trunk Nov 30, 2026
12 checks passed
@chubes4
chubes4 deleted the chubes/reprint-machine-key branch November 30, 2026 13:46
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