Skip to content

Commit 3254b27

Browse files
sh1pt-actions-fleet[bot]ralyodioclaude
authored
feat(rotation): provider rotators, consumer propagation, weekly job, runbook (CLI 0.14.0) (#265)
- Catalog covers every key in the team plan (unknown 275 -> 0): new methods `provider` and `not-secret`, plus family/owner/never/disruptive on every spec. Wallets, treasury, Lightning, exchanges, Stripe, npm, GitHub App keys, signing identities and the personal vault are `never` and owner-only; an __ROTATE__ entry cannot make them automatic. - Two-phase provider rotators (rotators.ts): resend, cloudflare-token, coinpay-api-key, coinpay-webhook-secret, vapid, postgres-role (SCRAM verifier over stdin, refuses self-hosted Supabase). - rotate-keys --propagate [root]: finds consumer env files by value, backs up (.bak-rotate-<date>, 600), rewrites, restarts with the site's deploy.env through deploy-gate 3 at a time, health-checks local + public URL, revokes the old credential only after; any failure restores vaults, files and the provider. --scheduled, --max, --max-sites, --exclude-site, --report. - scripts/logicsrc-rotate: weekly job, dry run unless LOGICSRC_ROTATE_LIVE=1, mails rotated / skipped / manual-by-owner report (never values). - docs/rotation.md (logicsrc.com/docs/rotation) + docs/ROTATION.md pointer, including the wallets and signing keys section. Co-authored-by: Anthony Ettinger <anthony@profullstack.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b5f8758 commit 3254b27

17 files changed

Lines changed: 2605 additions & 87 deletions

‎apps/logicsrc-web/src/lib/docs.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const GUIDE_SUBTITLES: Record<string, string> = {
4242
config: "Where config lives, and what each key does",
4343
permissions: "Explicit, scoped, auditable permission grants",
4444
keyring: "SSH keys and key pairs, end-to-end encrypted, with optional cloud sync",
45+
rotation: "Rotate every key, password and token in your vaults: plan, rotate, redeploy, verify, revoke",
4546
plugins: "The plugin system, and the plugins that ship with it",
4647
"openontology-governance": "An agent proposes, a human applies",
4748
"openontology-interoperability": "Mapping to RDF, SHACL and PROV-O, and where it stops",

‎apps/logicsrc-web/src/lib/specs.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export const GUIDES: Array<{ slug: string; name: string }> = [
149149
{ slug: "config", name: "Config" },
150150
{ slug: "permissions", name: "Permissions" },
151151
{ slug: "keyring", name: "Keyring" },
152+
{ slug: "rotation", name: "Rotating secrets" },
152153
{ slug: "plugins", name: "Plugins" },
153154
{ slug: "openontology-governance", name: "OpenOntology governance" },
154155
{ slug: "openontology-interoperability", name: "OpenOntology interoperability" }

‎bun.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/ROTATION.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Rotation runbook
2+
3+
The runbook for rotating every key, password and token in LogicSRC team vaults
4+
is [rotation.md](rotation.md), published at https://logicsrc.com/docs/rotation.
5+
It lives under that lowercase name because the site serves `docs/<slug>.md`.

‎docs/rotation.md‎

Lines changed: 335 additions & 0 deletions
Large diffs are not rendered by default.

‎packages/cli/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@logicsrc/cli",
3-
"version": "0.13.0",
3+
"version": "0.14.0",
44
"description": "LogicSRC CLI: every LogicSRC standard and tool as one command.",
55
"type": "module",
66
"main": "./dist/index.js",

‎packages/cli/src/index.ts‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22
import { spawnSync } from "node:child_process";
33
import { readFileSync } from "node:fs";
4+
import { homedir } from "node:os";
5+
import { join } from "node:path";
46
import { evaluateAccountPolicy, scoreAccountActionRisk } from "@logicsrc/account-core";
57
import { Command } from "commander";
68
import { createCredentialEngine, listCredentialProviders, logicsrcHome, type CredentialEndpoint } from "@logicsrc/plugin-credential-sharing";
@@ -949,6 +951,12 @@ teams
949951
.option("-k, --key <names>", "only these keys (comma-separated or repeated)", collectList)
950952
.option("--approve", "write the new values (dry run by default)")
951953
.option("--set-from-stdin", "store a value you rotated by hand (exactly one --key), everywhere the old value lives")
954+
.option("--propagate [root]", "also rewrite, restart and health-check the sites holding the old value (default root ~/www); rolls back on failure")
955+
.option("--scheduled", "unattended mode: only non-disruptive random secrets and two-phase provider rotators with known consumers")
956+
.option("--max <n>", "stop after n live rotations")
957+
.option("--exclude-site <sites>", "never rewrite or restart these sites; a value they hold is skipped (comma-separated or repeated)", collectList)
958+
.option("--max-sites <n>", "with --scheduled: skip values read by more than n sites (default 5)")
959+
.option("--report <file>", "also write the JSON results (never values) to this file, mode 600")
952960
.option("--format <format>", "table, json, or markdown", "table")
953961
.description("Rotate secret values: automatic ones are minted and written to every vault holding the old value; manual ones come back as steps.")
954962
.addHelpText(
@@ -959,19 +967,33 @@ Dry run first, then apply:
959967
logicsrc teams rotate-keys profullstack b1dz prod --approve rotate one vault's automatic keys
960968
logicsrc teams rotate-keys profullstack --key SSH_ID_ED25519 --approve
961969
new-key | logicsrc teams rotate-keys profullstack b1dz prod --key RESEND_API_KEY --set-from-stdin --approve
970+
logicsrc teams rotate-keys profullstack wx93 prod --key CRON_SECRET --propagate --approve
971+
logicsrc teams rotate-keys profullstack --scheduled --propagate --approve --report r.json (the weekly job)
972+
973+
Provider rotators (method provider): resend, cloudflare-token, coinpay-api-key,
974+
coinpay-webhook-secret, vapid, postgres-role. Each mints the new credential,
975+
writes the vaults, redeploys consumers, health-checks them, and only then
976+
revokes the old one; any failure restores the old value everywhere.
977+
Runbook: https://logicsrc.com/docs/rotation
962978
963979
Values never print. The same value stored in other vaults (same fingerprint) is
964980
rotated there too. Vaults you cannot decrypt are named and keep the OLD value.
965981
After rotating: redeploy the consumers, install new SSH public keys, revoke the old values.
966982
`
967983
)
968-
.action((slug, project, env, options) =>
969-
teamsRotateKeysAction(slug, { project, env, keys: options.key }, {
984+
.action(async (slug, project, env, options) => {
985+
await teamsRotateKeysAction(slug, { project, env, keys: options.key }, {
970986
approve: Boolean(options.approve),
971987
setFromStdin: Boolean(options.setFromStdin),
972-
format: options.format as OutputFormat
973-
})
974-
);
988+
format: options.format as OutputFormat,
989+
propagate: options.propagate === undefined ? undefined : options.propagate === true ? join(homedir(), "www") : String(options.propagate),
990+
scheduled: Boolean(options.scheduled),
991+
max: options.max === undefined ? undefined : Number(options.max),
992+
report: options.report,
993+
excludeSites: options.excludeSite,
994+
maxSites: options.maxSites === undefined ? undefined : Number(options.maxSites)
995+
});
996+
});
975997

976998
teams
977999
.command("clean")

‎packages/cli/src/propagate.test.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { mkdtempSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync, readdirSync } from "node:fs";
2+
import { tmpdir } from "node:os";
3+
import { join } from "node:path";
4+
import { afterEach, describe, expect, it } from "vitest";
5+
import { envFilesIn, findConsumers, inBatches, replaceInValue, restoreBackup, rewriteEnvFile, strayCopies } from "./propagate.js";
6+
7+
const dirs: string[] = [];
8+
function www(): string {
9+
const d = mkdtempSync(join(tmpdir(), "logicsrc-propagate-"));
10+
dirs.push(d);
11+
return d;
12+
}
13+
afterEach(() => {
14+
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
15+
});
16+
17+
const OLD = "old-secret-0123456789";
18+
const NEW = "new-secret-abcdefghij";
19+
20+
describe("propagate", () => {
21+
it("finds consumers by value, skipping backups, and flags build-time keys", () => {
22+
const root = www();
23+
mkdirSync(join(root, "a.com"));
24+
mkdirSync(join(root, "b.com"));
25+
writeFileSync(join(root, "a.com", "app.env"), `X=1\nCRON_SECRET=${OLD}\nRENAMED="${OLD}"\n`);
26+
writeFileSync(join(root, "a.com", "app.env.bak-001"), `CRON_SECRET=${OLD}\n`);
27+
writeFileSync(join(root, "a.com", "app.bak-002.env"), `CRON_SECRET=${OLD}\n`);
28+
writeFileSync(join(root, "b.com", "deploy.env"), `NEXT_PUBLIC_THING=${OLD}\n`);
29+
expect(envFilesIn(join(root, "a.com")).map((f) => f.split("/").pop())).toEqual(["app.env"]);
30+
const hits = findConsumers(root, [{ oldValue: OLD, newValue: NEW }]);
31+
expect(hits.map((h) => [h.site, h.keys, h.needsBuild])).toEqual([
32+
["a.com", ["CRON_SECRET", "RENAMED"], false],
33+
["b.com", ["NEXT_PUBLIC_THING"], true]
34+
]);
35+
});
36+
37+
it("rewrites in place with a 600 backup, keeps mode and quotes, and restores", () => {
38+
const root = www();
39+
const f = join(root, "app.env");
40+
writeFileSync(f, `A=${OLD}\nB='${OLD}'\nDATABASE_URL=postgres://u:${OLD}@h:5432/d\nC=keep\n`, { mode: 0o600 });
41+
const { backup, keys } = rewriteEnvFile(f, [{ oldValue: OLD, newValue: NEW }], "20261029");
42+
expect(keys).toEqual(["A", "B", "DATABASE_URL"]);
43+
expect(readFileSync(f, "utf8")).toBe(`A=${NEW}\nB='${NEW}'\nDATABASE_URL=postgres://u:${NEW}@h:5432/d\nC=keep\n`);
44+
expect(statSync(f).mode & 0o777).toBe(0o600);
45+
expect(statSync(backup).mode & 0o777).toBe(0o600);
46+
expect(backup).toMatch(/app\.env\.bak-rotate-20261029$/);
47+
restoreBackup(f, backup);
48+
expect(readFileSync(f, "utf8")).toContain(`A=${OLD}`);
49+
const second = rewriteEnvFile(f, [{ oldValue: OLD, newValue: NEW }], "20261029");
50+
expect(second.backup).toMatch(/-2$/);
51+
expect(readdirSync(root).filter((n) => n.includes("rotate-tmp"))).toEqual([]);
52+
});
53+
54+
it("ignores short values that could collide with unrelated text", () => {
55+
expect(replaceInValue("abc", [{ oldValue: "abc", newValue: "x" }])).toBeNull();
56+
});
57+
58+
it("finds stray copies (crontab, scripts)", () => {
59+
const root = www();
60+
writeFileSync(join(root, "s"), `curl -H "x: ${OLD}"`);
61+
expect(strayCopies([join(root, "s"), join(root, "missing")], [{ oldValue: OLD, newValue: NEW }])).toEqual([join(root, "s")]);
62+
});
63+
64+
it("runs at most 3 at a time", async () => {
65+
let running = 0;
66+
let peak = 0;
67+
await inBatches([1, 2, 3, 4, 5, 6, 7], 3, async () => {
68+
peak = Math.max(peak, ++running);
69+
await new Promise((r) => setTimeout(r, 5));
70+
running--;
71+
});
72+
expect(peak).toBe(3);
73+
});
74+
});

0 commit comments

Comments
 (0)