feat(sdk): allow new signing key (#2088)

This commit is contained in:
jubnl
2026-08-28 00:56:44 +02:00
committed by GitHub
parent 922f37ab52
commit d8fd2deb12
22 changed files with 915 additions and 71 deletions
+18 -4
View File
@@ -1375,7 +1375,8 @@ whatever else it needs. Pass a command explicitly to skip the menu (and for scri
CI). `trek-plugin help <command>` — or `trek-plugin <command> --help` — prints a full
page for any command.
**The path is four commands**, and the other ten are steps one of them already does:
**The path is four commands**, and the others are steps one of them already does
(with two exceptions that undo or repair: `unrelease` and `rotate-key`):
```bash
trek-plugin create [name] [--type integration|page|widget|trip-page]
@@ -1412,6 +1413,15 @@ trek-plugin shot [dir] [--port 4317] [--out docs/screenshot.png] [--dark] [--no-
trek-plugin keygen [--key file]
trek-plugin sign [zip] [--key file]
# Move a published plugin to a NEW signing key WITHOUT shipping a version (lost or
# compromised key, planned rotation): fetches your published entry, re-signs every
# pinned version's artifact with the new key (each verified against its sha256 first,
# all-or-nothing), swaps authorPublicKey, and opens a registry PR flagged as a
# rotation. The PR needs a maintainer's `allow-key-change` label, and every admin who
# has the plugin must re-trust the new key. To rotate WHILE shipping a version, use
# `publish --sign --allow-key-change` instead.
trek-plugin rotate-key [dir] [--id plugin-id] [--key file] [--out entry.json] [--draft]
# Emit the ready-to-PR registry entry: commitSha (resolved from the git tag),
# downloadUrl, sha256, size, and the manifest's `trek` range verbatim — plus
# requiredAddons and pluginDependencies, which the registry parity-checks against the
@@ -1422,8 +1432,9 @@ trek-plugin entry --repo owner/name --tag vX.Y.Z [--zip plugin.zip] [--merge ent
# The registry checks that genuinely need the network: the tag resolves to the commit
# the entry pins, the released artifact downloads and hashes to the pinned sha256, the
# id is not bound to another GitHub owner, and an update does not drop or rotate a
# signing key you already published under. `publish` runs this for you.
trek-plugin preflight [dir] --repo owner/name --tag vX.Y.Z [--entry file.json] [--all]
# signing key you already published under (`--allow-key-change` declares a deliberate
# rotation, turning that refusal into a pass). `publish` runs this for you.
trek-plugin preflight [dir] --repo owner/name --tag vX.Y.Z [--entry file.json] [--all] [--allow-key-change]
# Pack -> cut the GitHub release -> print the entry, without opening the registry PR.
trek-plugin release [dir] --repo owner/name --tag vX.Y.Z [--sign] [--merge entry.json]
@@ -1454,7 +1465,10 @@ opts out). See [[Publishing a Plugin|Plugin-Publishing]].
- **Optional author signing:** an entry may carry `authorPublicKey` (stable,
TOFU-pinned on first install) and each version a `signature` over the artifact
bytes. Unsigned plugins install on sha256 alone; a plugin that was signed can't
later go unsigned or swap its key without an explicit admin re-trust.
later go unsigned, and a key *rotation* is a deliberate act the SDK drives —
`trek-plugin rotate-key`, or `publish --sign --allow-key-change` — that still
needs a registry maintainer's `allow-key-change` label plus an explicit admin
re-trust on every instance.
Full walkthrough: [[Publishing a Plugin|Plugin-Publishing]]. Overview:
[[Plugins|Plugins]].
+5 -3
View File
@@ -163,9 +163,9 @@ flow is in [[Publishing a Plugin|Plugin-Publishing]].
| `trek-plugin validate [dir]` | Manifest + layout checks, and the gate for publishing: parses the manifest with the same rules as install, then runs every registry gate that can be answered from the working tree — exiting non-zero on any of them. It **fails** if `README.md` is missing, is missing one of the four required sections, has too little prose, still holds template placeholders, does not explain every permission the manifest declares, or has no usable screenshot (no image at all, or every local image path is missing on disk — a remote `https://` image passes here and is verified later by `preflight`); it also fails if `server/index.js` was never built. Failures that only the registry cares about do **not** block `trek-plugin pack`, so the dev loop keeps working while the docs are still a stub — but they do stop `publish`, which runs these same checks first and refuses before anything is packed, tagged or released. A handful of checks are *warnings* that never fail the command: directory name ≠ plugin id, an unbounded `trek` range, an unknown required addon, emoji in manifest text, an undeclared egress host, and a page/widget not using the design kit. This is a **subset** of registry CI — CI additionally verifies the release tag/commit, the artifact's sha256, and the README over the network. A local pass predicts a CI pass. |
| `trek-plugin preflight --repo <o/n> --tag <vX>` | Runs the **full** registry CI checks locally over the network (tag→commit, manifest parity, artifact sha256/size, native scan, README quality gate) against your pushed release — so you catch a CI failure before opening the PR. |
| `trek-plugin submit --repo <o/n> --tag <vX>` | Opens the registry PR for you: forks TREK-Plugins, fast-forwards the fork, branches off the registry's current main, writes/merges `registry/plugins/<id>.json`, pushes, and creates the PR. Requires `gh`. |
| `trek-plugin publish --repo <o/n> --tag <vX>` | **The one-command release**: local gates → pack → tag + GitHub release → preflight → open the registry PR. Nothing is packed, tagged or released until the local gates pass (`--no-checks` skips them). A failure after the release is cut rolls back the tag and release that run created, so the same tag can be re-used (`--keep-release` opts out). Add `--sign` to sign it. Requires `git` + `gh`. |
| `trek-plugin publish --repo <o/n> --tag <vX>` | **The one-command release**: local gates → pack → tag + GitHub release → preflight → open the registry PR. Nothing is packed, tagged or released until the local gates pass (`--no-checks` skips them). A failure after the release is cut rolls back the tag and release that run created, so the same tag can be re-used (`--keep-release` opts out). Add `--sign` to sign it; `--sign --allow-key-change` rotates your signing key as part of the release. Requires `git` + `gh`. |
| `trek-plugin unrelease <vX> --repo <o/n>` | Deletes a stranded GitHub release + remote tag + local tag. Refuses a version that is published in the registry (its artifact is immutable); `--yes` consents when the registry index can't be checked. |
| `trek-plugin keygen` / `sign` | `keygen` creates an Ed25519 signing key; `sign` (or `--sign` on `entry`/`release`/`submit`) signs the artifact and fills `authorPublicKey` + `signature` so TREK pins your identity (TOFU). |
| `trek-plugin keygen` / `sign` / `rotate-key` | `keygen` creates an Ed25519 signing key; `sign` (or `--sign` on `entry`/`release`/`submit`) signs the artifact and fills `authorPublicKey` + `signature` so TREK pins your identity (TOFU). `rotate-key` moves a published plugin to a **new** key without shipping a version: it re-signs every pinned artifact with the new key and opens a rotation PR (a maintainer must label it `allow-key-change`; every admin must re-trust). `publish --sign --allow-key-change` rotates as part of a release. |
| `trek-plugin pack [dir] [--out plugin.zip] [--json]` | Validates, then builds `plugin.zip` in the installer's exact layout (`trek-plugin.json`, `README.md`, `LICENSE`, `package.json` at the root; `server/` and `client/` recursed) and prints its **sha256 + byte size**. Skips `node_modules`, `.git`, `.ts` and `.map` files, and **refuses native binaries** (`.node`, `binding.gyp`, `prebuilds/`) and over-size archives, same as the installer. **`docs/` is intentionally NOT shipped** — the store fetches your screenshot from `docs/screenshot.png` in the repo. |
| `trek-plugin entry --repo <owner/name> --tag <vX.Y.Z> [--zip plugin.zip] [--merge entry.json] [--out file]` | Emits the ready-to-PR registry entry: `commitSha` (resolved from the tag), `downloadUrl`, `sha256` + `size` (from the packed zip), and the manifest's **`trek` range verbatim** — the entry's only compatibility field. `--merge` prepends this version onto an existing `registry/plugins/<id>.json` for an update, keeping versions newest-first (registry CI enforces that ordering). |
| `trek-plugin release [dir] --repo <owner/name> --tag <vX.Y.Z>` | The one-shot: `pack` → `gh release create` (uploads the zip) → print the registry `entry`. Requires the `gh` CLI authenticated. |
@@ -181,7 +181,9 @@ flow is in [[Publishing a Plugin|Plugin-Publishing]].
(stable across versions) and a per-version `signature`. TREK verifies it offline
and pins the key trust-on-first-use. Signing is opt-in — an unsigned entry
installs on `sha256` alone — but once a plugin has shipped signed, an unsigned
update for it is refused. See [[Publishing a Plugin|Plugin-Publishing]].
update for it is refused, and a key change is only accepted as a deliberate,
maintainer-approved rotation (`rotate-key` / `--allow-key-change`) that each
admin must re-trust. See [[Publishing a Plugin|Plugin-Publishing]].
## Not a permission — settings-page actions
+59 -6
View File
@@ -218,7 +218,8 @@ the network: the tag resolves to the pinned `commitSha`; the **manifest** at tha
matches the entry; the **README** at that commit passes the quality gate; the released
artifact downloads, hashes to the pinned **sha256**, carries **no native binaries** and
verifies against your key; your plugin id is not bound to a different GitHub owner; and
an update does not drop or rotate a signing key you already published under.
an update does not drop or rotate a signing key you already published under
(`--allow-key-change` declares a deliberate rotation — see "Rotating your signing key").
Re-grading the manifest and the README *at the commit* is not redundant with the local
pass: an author who writes the README and forgets to commit it has a green tree and a
@@ -316,10 +317,12 @@ npx trek-plugin-sdk publish --repo you/repo --tag v1.2.0 --sign
`--sign` signs the exact artifact bytes and fills both `authorPublicKey` (entry)
and `signature` (version) for you. If the plugin was already published signed,
`publish` **refuses an unsigned release at step 1** — before anything is packed,
tagged or released — because a GitHub release is immutable and learning this at
step 4 would have burned the tag. **Back up `~/.trek-plugin/signing.key`** —
losing it means you can't ship signed updates.
`publish` **refuses an unsigned release at step 1** — and, since SDK 1.7.0, one
whose signing key's *identity* differs from the published `authorPublicKey` —
before anything is packed, tagged or released, because a GitHub release is
immutable and learning this at step 4 would have burned the tag. **Back up
`~/.trek-plugin/signing.key`** — losing it means a full key rotation (see below),
which strands every install until its admin re-trusts you.
**By hand with minisign**, if you prefer:
@@ -361,7 +364,57 @@ matches its pin). What
you can never do is go back: once a plugin has shipped signed, an *unsigned* update
is refused (`SIGNATURE_MISSING`) on every instance that already has it, and a key
*rotation* needs a registry maintainer override (`allow-key-change`) plus an admin
re-trust on each instance. So sign whenever you like — but back the key up.
re-trust on each instance — see the next section. So sign whenever you like — but
back the key up.
### Rotating your signing key
A rotation — lost key, compromised machine, planned hygiene — is the one signing
change with a sanctioned path, and since SDK 1.7.0 the SDK drives its whole
artifact half. Two flows, one rule: a rotated entry must have **every** version
re-signed with the new key, because TREK verifies whichever version it installs
against the entry's single `authorPublicKey`.
**Without shipping a version:**
```bash
npx trek-plugin-sdk rotate-key # from the plugin dir; --id <plugin-id> from elsewhere
# --key <file> for a key not at ~/.trek-plugin/signing.key
# --out entry.json writes the rotated entry for a hand-made PR instead of opening one
```
It fetches your published registry entry, downloads every pinned artifact,
verifies each against its pinned `sha256`, re-signs all of them with the new key
(all-or-nothing — one unfetchable or tampered artifact aborts the whole rotation),
swaps `authorPublicKey`, and opens a registry PR titled as a rotation. (If the key
was merely *lost*, `keygen` first — the default path is free again. A
*compromised* key still on disk needs `--key` for the new one; `keygen` refuses to
overwrite.)
**As part of a release:**
```bash
npx trek-plugin-sdk publish --repo you/repo --tag v1.3.0 --sign --allow-key-change
```
Step 1 accepts the new key, the update merges onto your existing entry with the
older versions re-signed under the new key, and the PR title carries
"(key rotation)". The same `--allow-key-change` flag exists on
`entry`/`preflight`/`submit`/`release` for hand-assembled flows.
Either way, the SDK can only do the artifact half. The PR body says the rest out
loud, and neither step is a formality:
1. a **registry maintainer** must apply the `allow-key-change` label — CI refuses
a changed `authorPublicKey` without it, and authors can't self-serve the label;
2. **every admin** who already installed the plugin sees `SIGNATURE_KEY_CHANGED`
(with both key fingerprints, to verify the new one with you out of band) and
must re-trust the new key before their instance receives another update.
Without `--allow-key-change`, a differing key is still refused everywhere —
deliberately, because the *accidental* version of this (publishing from a second
machine whose freshly-generated key isn't the one you published under) wants the
original key restored, not a rotation.
## Updating
+5 -1
View File
@@ -306,4 +306,8 @@ are refused (they'd collide with admin API routes) — and an `id` stays bound t
the GitHub owner who first registered it, so
nobody can repoint an existing plugin. Entries may optionally carry an author
signing key (`authorPublicKey` + a per-version `signature`) for offline signature
verification on top of the SHA-256 pin.
verification on top of the SHA-256 pin. A signed plugin's key changes only through
a maintainer-approved rotation; an instance that already has the plugin then shows
`SIGNATURE_KEY_CHANGED` — with both key fingerprints, so you can check the new one
with the author out of band — and pauses that plugin's updates until you re-trust
the new key.