security: keep signing keys out of deployable team vaults (CLI 0.13.0) (#264)
Some checks are pending
CI / build (push) Waiting to run
Deploy to dev2 / deploy (push) Waiting to run
test / test (push) Waiting to run

* security: keep signing keys out of deployable team vaults (CLI 0.13.0)

After the 2026-10-27 dev2 incident, root on the box drained every wallet
whose key sat in an app.env, and deploys write app.env from team vaults.
Wallet keys, seed phrases, hsm secrets and SSH/deploy keys now stay out of
that path:

- server: a machine (deploy) key never receives a signing key from
  GET /vaults/:id/secrets (listed as `withheld`, audited as
  secrets:withheld:signing) and cannot write or delete one (403
  signing_key_machine_write). People still see them, so they can move them.
- CLI `teams push` refuses a .env holding signing keys, by name or by value
  shape (PEM private key, 0x-hex, Solana base58/byte array, mnemonic), unless
  --allow-signing-keys.
- CLI `teams pull` withholds signing keys by default; --include-signing-keys
  needs a person at a terminal, so deploy-app.sh's fallback to the logged-in
  account withholds them too.
- One name rule in packages/opencreds/src/signing-keys.ts, mirrored in
  apps/pwa/src/lib/signing-keys.mjs, both held to one fixture file.

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

* fix: bound the wallet-name regex, build PEM fixtures at runtime

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

---------

Co-authored-by: Anthony Ettinger <anthony@profullstack.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sh1pt-actions-fleet[bot] 2026-10-28 19:31:28 +00:00 • committed by GitHub
parent 1bff3e975c
commit b5f875837a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 297 additions and 12 deletions

View file

@ -0,0 +1,24 @@
// Copy of the NAME rule in packages/opencreds/src/signing-keys.ts (read the
// reasoning there). The server only sees secret names, so this is what it
// enforces: a machine key never receives or writes a signing key. Both copies
// are held to packages/opencreds/src/signing-keys.fixtures.json.
const norm = (name) => `_${name.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_`;
/** Seed phrases and raw key material, whatever service they belong to. */
const ALWAYS = /_(MNEMONIC|SEED_PHRASE|SEEDPHRASE|SEED_WORDS|RECOVERY_PHRASE|XPRV|XPRIV|HSM_SECRET|KEYPAIR|KEY_PAIR)_/;
/** "Private key" in any spelling, and SSH / deploy keys that open a box. */
const PRIVATE = /_(PRIVATE_KEY|PRIV_KEY|PRIVKEY|PRIVATEKEY|SIGNING_KEY|SIGNER_KEY|SSH_KEY|DEPLOY_KEY)(_|$)/;
/** App keys that sign tokens or pushes, not funds; needed by a running service. */
const SERVICE = /_(VAPID|GITHUB_APP|GH_APP|JWT|JWK|DKIM|APNS|APPLE|FIREBASE|GOOGLE|GCP|SERVICE_ACCOUNT|SAML|OIDC|WEBHOOK|TLS|SSL|CERT|CLERK|SUPABASE)_/;
/** A wallet word next to KEY / SECRET / SEED: SOLANA_SECRET_KEY, RELAYER_KEY, WALLET_SEED. */
const WALLET = /_(SOLANA|SOL|EVM|ETH|ETHEREUM|BTC|BITCOIN|WALLET|HOT_WALLET|RELAYER|TREASURY|SIGNER|OPERATOR|DEPLOYER|PAYER|FEE_PAYER)_(?:[A-Z0-9]{1,24}_){0,4}(KEY|SECRET|SEED)_/;
/** ...unless it is plainly an address, an RPC or an API credential. */
const NOT_A_KEY = /_(RPC|API|URL|ADDRESS|ADDR|PUBLIC|PUBKEY|PUB|ID|NAME)_/;
export function isSigningKeyName(name) {
const n = norm(name);
if (ALWAYS.test(n)) return true;
if (PRIVATE.test(n)) return !SERVICE.test(n);
return WALLET.test(n) && !NOT_A_KEY.test(n);
}

View file

@ -18,6 +18,7 @@ import { id, sha256, token } from "../lib/crypto.mjs";
import { keyFingerprint, requestOriginInfo } from "../lib/keyfp.mjs";
import sodium from "libsodium-wrappers";
import { bearer, keyForBearer, keyCoversVault, normalizeKey } from "../lib/apikey.mjs";
import { isSigningKeyName } from "../lib/signing-keys.mjs";
import {
TeamMemberError,
normEmail,
@ -709,9 +710,14 @@ credshareRouter.delete("/api/credshare/vaults/:id/key-grants/:keyId", api(async
credshareRouter.get("/api/credshare/vaults/:id/secrets", api(async (req, res, user, key) => {
const vault = await vaultCtx(res, req.params.id, user.id, key); if (!vault) return;
const rows = await all(`SELECT * FROM credshare_secrets WHERE vault_id = ? ORDER BY name`, [vault.id]);
const all_ = await all(`SELECT * FROM credshare_secrets WHERE vault_id = ? ORDER BY name`, [vault.id]);
// A deploy box never receives a signing key (wallet key, seed, SSH key): root
// on a box running 24/7 must not mean the keys that move money.
const withheld = isMachine(key) ? all_.filter((s) => isSigningKeyName(s.name)).map((s) => s.name) : [];
const rows = withheld.length ? all_.filter((s) => !withheld.includes(s.name)) : all_;
await audit({ req, teamId: vault.team_id, vaultId: vault.id, actorUserId: user.id, action: "secrets:fetch", keyName: key?.name ?? (req.user ? "browser session" : null) });
res.json({ vaultId: vault.id, keyVersion: Number(vault.key_version ?? 1), secrets: rows.map((s) => ({ name: s.name, nonce: s.nonce, ciphertext: s.ciphertext, fingerprint: s.fingerprint, version: s.version, updatedAt: s.updated_at })) });
if (withheld.length) await audit({ req, teamId: vault.team_id, vaultId: vault.id, actorUserId: user.id, actorKeyId: key.id, action: "secrets:withheld:signing", keyName: withheld.join(",") });
res.json({ vaultId: vault.id, keyVersion: Number(vault.key_version ?? 1), withheld, secrets: rows.map((s) => ({ name: s.name, nonce: s.nonce, ciphertext: s.ciphertext, fingerprint: s.fingerprint, version: s.version, updatedAt: s.updated_at })) });
}, { machine: "read" }));
credshareRouter.put("/api/credshare/vaults/:id/secrets", api(async (req, res, user, key) => {
@ -728,6 +734,10 @@ credshareRouter.put("/api/credshare/vaults/:id/secrets", api(async (req, res, us
}
const upserts = Array.isArray(req.body?.upserts) ? req.body.upserts : [];
const deletes = Array.isArray(req.body?.deletes) ? req.body.deletes : [];
if (isMachine(key)) {
const signing = [...upserts.map((u) => u?.name), ...deletes].filter((n) => typeof n === "string" && isSigningKeyName(n));
if (signing.length) return res.status(403).json({ error: `A machine key cannot write signing keys (${signing.join(", ")}). Keep them in \`logicsrc keyring\` and unlock them where they are used.`, code: "signing_key_machine_write" });
}
const applied = [];
for (const u of upserts) {
if (!u || typeof u.name !== "string" || typeof u.nonce !== "string" || typeof u.ciphertext !== "string" || typeof u.fingerprint !== "string") {