Skip to content

kernel deploy bakes the private record key (kernel audit S2.1) - #52

Open
phasenull wants to merge 2 commits into
mainfrom
feat/private-record-key
Open

phasenull wants to merge 2 commits into
mainfrom
feat/private-record-key

Conversation

@phasenull

@phasenull phasenull commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

The CLI half of kernel audit item S2.1, proposal (a), which the owner approved ("Needs your call" item 1 in typetorch/kernel#19). The kernel half is typetorch/kernel#22, stacked on kernel #19.

What

typetorch kernel deploy bakes a random private record key into the place. The kernel MACs every private/<id> record it writes with this key. A reserved server follows a stored non-default branch or pin only when the record's mac verifies. So a leaked DataStore key can no longer send reserved match servers to a branch the attacker controls.

  • Where the key goes: ServerStorage.TypeTorchKernelSecrets, attribute PrivateRecordKey (64 lowercase hex = 32 random bytes).
    • It is a kernel slot (a TypeTorch* child of a service in the stamped project), so every engine replaces it on every kernel deploy: luau, splice/lune with --place-file, and --replace-place.
    • It is never replicated and never in a DataStore. The kernel reads it at boot into a script local and removes the folder before game code runs.
  • Generated once, kept stable: ~/.config/typetorch/keys/<universeId>.private-record.key, beside the signing keys.
    • JSON { v: 1, kind: "typetorch-private-record-key", universeId, key, createdAt }.
    • Mode 0600 in a 0700 folder, written as a temp file and renamed into place.
    • Refused inside the project or any git work tree (assertOutsideRepos). Loose permissions get a chmod 600 warning.
    • Every later deploy reuses it, so records stay valid across kernel deploys.
  • Flags:
    • --private-record-key-file <path>
    • --rotate-private-key: a new key. The old file is kept as <file>.old-<time> and never deleted.
    • A dry run never writes the file: it uses a throwaway key and says so.
  • Never shown: only the fingerprint (first 8 hex of its SHA-256) is printed and logged (privateRecordKey: { fingerprint, state, path, createdAt } in kernel-deploys.jsonl and the patch records). The key is registered for redaction (registerSecret).
  • Baked only for a kernel that reads it (its Kernel.server.luau names TypeTorchKernelSecrets, i.e. kernel 0.5.10+). An older kernel would leave the folder where game code can read it. For an older kernel the deploy warns "not baked", and --rotate-private-key is refused.

Rollout: release together with the kernel PR; the order doesn't matter

  • New CLI, old kernel: nothing is baked (warned). No change.
  • New kernel, old CLI: the kernel finds no key and keeps today's trust, with one warning per server. A kernel-only update can't break live reserved servers.
  • Both:
    • The first kernel deploy makes the key. Copy ~/.config/typetorch/keys/<universeId>.private-record.key to every other machine that runs kernel deploy.
    • A second machine without the file makes a NEW key, and only warns ("a NEW private record key was made ... copy that machine's file here instead"). With a new key, reserved servers on other branches made before that deploy boot the default branch once.
    • Reserved dev-branch servers made before the first keyed deploy also boot the default branch once (proposal (a)'s known cost).

Judgment calls

  • No environment variable for the path (only the flag). This keeps env.ts (touched by Security fixes from the 2026-12-05 audit #48 and apikeys with groups, groups and members commands, TYPETORCH_FLEET_KEY alias (backend plans/38) #51) out of this PR.
  • The build outputs in .typetorch/ hold the key: out/place.rbxl, out/kernel-slots.rbxm, place-patches/*.rbxl and place-backups/*.rbxl, like the rest of the place. They are local and gitignored (.typetorch/), and that is accepted. The temporary gen project JSON holds it until the Rojo build finishes.
  • The key goes to Roblox only: as the luau engine's binary slots input, and into the place.
  • The kernel-support check is a source scan (kernelReadsPrivateKey), not a package.json field. That works for checkouts and packaged kernels (both ship src/).

Expected conflicts with open PRs

Tests

  • bun test: 921 pass, 2 skip, 1 fail. The one failure is the pre-existing backend bless test, which also fails on origin/main.
  • tsc --noEmit: clean.
  • test/privatekey.test.ts (12 tests):
    • Key file: made once (0600 / 0700, 64 hex), reused unchanged. Rotation keeps the old file. A dry run writes nothing. Another universe's file, a broken file (the error never holds the key) and a path inside the repo are refused. A loose-mode warning.
    • preparePrivateKey: not baked for an old kernel, and --rotate-private-key refused there. Made, then reused. Output shows the fingerprint, never the key. A dry-run rotation keeps the file.
    • The slot in the stamped project: next to the backup, picked up by kernelLayout and slotsProject.
    • The luau engine end to end (fake Open Cloud, tasks in Lune): the saved place holds the key. No task script, task result, record, report or JSON output contains it.
    • The splice and lune engines on a real Rojo build: the patched place holds exactly one copy, also after a second deploy. The patch report, the binary verifier, the Lune verifier (and verify.json), the summary and the place summary never contain the key.
    • A name-drift check against the kernel checkout: FindFirstChild("TypeTorchKernelSecrets") and GetAttribute("PrivateRecordKey"). It runs when ../kernel, or TYPETORCH_KERNEL_DIR, has the support.
  • Environment notes:
    • backend bless > sends the public keys ... fails in the full run on this machine and also fails on origin/main (passes alone): a pre-existing order-dependent test, not from this change.
    • The Rojo tests ran with TYPETORCH_ROJO = rokit's rojo 7.7.0-rc.1 (7.6.1 isn't installed here).
  • CHANGELOG.md is gitignored and lives only in the main checkout, which this worktree-only change doesn't touch: please add the entry on merge.

🤖 Generated with Claude Code

phasenull and others added 2 commits December 5, 2026 22:28
A random 32-byte key per universe, made once in ~/.config/typetorch/keys/<universeId>.private-record.key (0600,
outside every repo; --private-record-key-file) and reused by every kernel deploy; --rotate-private-key makes a new
one and keeps the old file. Baked as ServerStorage.TypeTorchKernelSecrets.PrivateRecordKey, a kernel slot every
engine replaces, only for a kernel that reads it (0.5.10+). Only its fingerprint is printed or logged
(kernel-deploys.jsonl privateRecordKey); dry runs never write the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nel name drift check

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.

1 participant