Skip to content

Commit a8d185b

Browse files
ralyodioclaude
andauthored
feat(teams): rotate secret values, with per-entry rotation instructions (CLI 0.9.0) (#260)
`credentials rotate` only re-keys a vault: values stay the same, so it does nothing after a value leaks. This adds value rotation that agents can run. - `teams rotation <team> [project] [env]`: per value, the method (random, ssh-keygen, command, manual), where the instructions come from, how many vaults hold it, and since when. --format json carries the steps for agents. - `teams rotation-set <team> <project> <env> <KEY>`: store instructions as an encrypted `__ROTATE__<KEY>` entry. The team provider hides that prefix from sync, so it never lands in a .env and a push never deletes it. - `teams rotate-keys <team> [project] [env] [--key] [--approve]`: dry run by default. random/ssh-keygen/command values are minted and written to EVERY vault holding the same value (by fingerprint); manual ones come back as steps. `--set-from-stdin` stores a hand-rotated value everywhere the old one lives. Values never print. - Built-in catalog by key name: wallet keys and data-encryption keys are never automatic; provider keys point at the provider's dashboard; only secrets we mint ourselves are random (META_APP_SECRET etc. are not). - Empty values (one shared fingerprint) are never planned or overwritten. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ced6c5a commit a8d185b

9 files changed

Lines changed: 923 additions & 2 deletions

File tree

‎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.

‎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.8.0",
3+
"version": "0.9.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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
import { registerKeysCommands } from "./keys.js";
3737
import { sshAgentAction, sshListAction, sshPullAction, sshPushAction } from "./ssh.js";
3838
import { credentialsRotateAction } from "./rotate.js";
39+
import { teamsRotateKeysAction, teamsRotationAction, teamsRotationSetAction } from "./rotate-keys.js";
3940
import { boards, tasks } from "./fixtures.js";
4041
import { print, type OutputFormat } from "./format.js";
4142
import { parsePositiveInteger } from "./numeric-options.js";
@@ -741,6 +742,8 @@ Quick start (<team> is e.g. profullstack; see yours with "logicsrc teams list"):
741742
logicsrc teams push <team> <project> <env> ./.env -> vault
742743
logicsrc teams grant <team> <project> <env> dev@example.com
743744
logicsrc teams key your key, to read values in the web app
745+
logicsrc teams rotation <team> how each secret is rotated (agents: --format json)
746+
logicsrc teams rotate-keys <team> [project] [env] rotate values (dry run; --approve to write)
744747
745748
Deploy boxes and CI (a machine API key: one team, scoped vaults, read-only, its own identity):
746749
logicsrc keys create <name> --team <team> --vault <project>--<env> --out deploy.key
@@ -873,6 +876,95 @@ Vaults you have no access to are skipped and listed at the end.
873876
teamsExportAction(slug, { project, env, category: options.category, search: options.search }, { out: options.out, yes: options.yes })
874877
);
875878

879+
const collectList = (value: string, previous: string[] = []): string[] => [...previous, ...value.split(",").map((v) => v.trim()).filter(Boolean)];
880+
const collectRepeat = (value: string, previous: string[] = []): string[] => [...previous, value];
881+
882+
teams
883+
.command("rotation")
884+
.argument("<slug>", "Team slug")
885+
.argument("[project]", "Only this project")
886+
.argument("[env]", "Only this environment")
887+
.option("-k, --key <names>", "only these keys (comma-separated or repeated)", collectList)
888+
.option("--format <format>", "table, json, or markdown", "table")
889+
.description("Show how each secret value is rotated: method, instructions, which vaults share it. Never shows values.")
890+
.addHelpText(
891+
"after",
892+
`
893+
Methods: random (we mint it), ssh-keygen (new ed25519 keypair), command (a CLI prints
894+
the new value), manual (steps + url for a person or agent). Instructions come from the
895+
key's own __ROTATE__<KEY> entry, else a built-in catalog by key name.
896+
897+
logicsrc teams rotation profullstack every value in the team
898+
logicsrc teams rotation profullstack b1dz prod --format json steps per key, for agents
899+
`
900+
)
901+
.action((slug, project, env, options) =>
902+
teamsRotationAction(slug, { project, env, keys: options.key }, { format: options.format as OutputFormat })
903+
);
904+
905+
teams
906+
.command("rotation-set")
907+
.argument("<slug>", "Team slug")
908+
.argument("<project>", "Project name")
909+
.argument("<env>", "Environment name")
910+
.argument("<key>", "Secret name the instructions are for")
911+
.option("--method <method>", "random, ssh-keygen, command, or manual")
912+
.option("--json <spec>", "the whole spec as JSON instead of flags")
913+
.option("--format <alphabet>", "random: hex, base64, base64url, alnum (default: like the old value)")
914+
.option("--length <n>", "random: length in characters (default: like the old value, min 32)")
915+
.option("--command <cmd>", "command: shell command that prints the new value on stdout")
916+
.option("--url <url>", "where to rotate it (provider dashboard)")
917+
.option("--step <text>", "one step; repeat for several", collectRepeat)
918+
.option("--consumer <name>", "what reads this value and must be redeployed; repeat", collectRepeat)
919+
.option("--note <text>", "why, shown in the plan")
920+
.option("--output <format>", "table, json, or markdown", "table")
921+
.description("Store rotation instructions with a secret (as __ROTATE__<KEY>, encrypted, never pulled into .env).")
922+
.addHelpText(
923+
"after",
924+
`
925+
Examples:
926+
logicsrc teams rotation-set profullstack infernet prod CRON_SECRET --method random --consumer "dev2 crontab"
927+
logicsrc teams rotation-set profullstack b1dz prod RESEND_API_KEY --method manual \
928+
--url https://resend.com/api-keys --step "Create a key named b1dz-prod" --step "Revoke the old key"
929+
logicsrc teams rotation-set profullstack app prod CF_TOKEN --method command --command "my-cf-mint-token"
930+
`
931+
)
932+
.action((slug, project, env, key, options) =>
933+
teamsRotationSetAction(slug, project, env, key, { ...options, outputFormat: options.output as OutputFormat })
934+
);
935+
936+
teams
937+
.command("rotate-keys")
938+
.argument("<slug>", "Team slug")
939+
.argument("[project]", "Only this project")
940+
.argument("[env]", "Only this environment")
941+
.option("-k, --key <names>", "only these keys (comma-separated or repeated)", collectList)
942+
.option("--approve", "write the new values (dry run by default)")
943+
.option("--set-from-stdin", "store a value you rotated by hand (exactly one --key), everywhere the old value lives")
944+
.option("--format <format>", "table, json, or markdown", "table")
945+
.description("Rotate secret values: automatic ones are minted and written to every vault holding the old value; manual ones come back as steps.")
946+
.addHelpText(
947+
"after",
948+
`
949+
Dry run first, then apply:
950+
logicsrc teams rotate-keys profullstack plan for the whole team
951+
logicsrc teams rotate-keys profullstack b1dz prod --approve rotate one vault's automatic keys
952+
logicsrc teams rotate-keys profullstack --key SSH_ID_ED25519 --approve
953+
new-key | logicsrc teams rotate-keys profullstack b1dz prod --key RESEND_API_KEY --set-from-stdin --approve
954+
955+
Values never print. The same value stored in other vaults (same fingerprint) is
956+
rotated there too. Vaults you cannot decrypt are named and keep the OLD value.
957+
After rotating: redeploy the consumers, install new SSH public keys, revoke the old values.
958+
`
959+
)
960+
.action((slug, project, env, options) =>
961+
teamsRotateKeysAction(slug, { project, env, keys: options.key }, {
962+
approve: Boolean(options.approve),
963+
setFromStdin: Boolean(options.setFromStdin),
964+
format: options.format as OutputFormat
965+
})
966+
);
967+
876968
teams
877969
.command("key")
878970
.description("Print this machine's identity secret key, to read vault values in the web app.")
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
catalogSpec,
4+
detectFormat,
5+
generateRandomSecret,
6+
isNotSecret,
7+
parseRotationSpec,
8+
planRotations,
9+
rotationEntryName,
10+
ROTATE_PREFIX,
11+
EMPTY_FINGERPRINT,
12+
isoTime
13+
} from "./rotation-catalog.js";
14+
import { newEd25519, specFromOptions } from "./rotate-keys.js";
15+
import { ROTATION_ENTRY_PREFIX } from "@logicsrc/plugin-credential-sharing";
16+
17+
describe("catalog", () => {
18+
it("never automates wallet keys or keys that protect stored data", () => {
19+
for (const k of ["SYSTEM_MNEMONIC_SOL", "SOLANA_PRIVATE_KEY", "EVM_PRIVATE_KEY", "X402_CRAWLER_PRIVATE_KEY", "SETTINGS_ENCRYPTION_KEY", "ENCRYPTION_KEY"]) {
20+
expect(catalogSpec(k)?.method, k).toBe("manual");
21+
}
22+
});
23+
24+
it("mints our own shared secrets automatically", () => {
25+
for (const k of ["CRON_SECRET", "INTERNAL_API_KEY", "NEXTAUTH_SECRET", "INFERNET_ADMIN_TOKEN"]) {
26+
expect(catalogSpec(k)?.method, k).toBe("random");
27+
}
28+
});
29+
30+
it("never mints random values for provider-issued secrets with our-looking names", () => {
31+
for (const k of ["META_APP_SECRET", "GOOGLE_AUTH_SECRET", "FACEBOOK_APP_SECRET"]) expect(catalogSpec(k)?.method, k).toBe("manual");
32+
expect(catalogSpec("REMINDERS_CRON_SECRET")?.method).toBe("random");
33+
expect(catalogSpec("PIT_ADMIN_TOKEN")?.method).toBe("random");
34+
expect(catalogSpec("INFERNET_CLI_SESSION_SECRET")?.method).toBe("random");
35+
});
36+
37+
it("rotates ssh private keys with ssh-keygen, never their public halves or config", () => {
38+
expect(catalogSpec("SSH_ID_ED25519")?.method).toBe("ssh-keygen");
39+
expect(catalogSpec("SSH_ID_ED25519_DEPLOY")?.method).toBe("ssh-keygen");
40+
expect(catalogSpec("DEPLOY_KEY")?.method).toBe("ssh-keygen");
41+
expect(catalogSpec("SSH_ID_ED25519_PUB")).toBeNull();
42+
expect(catalogSpec("SSH_CONFIG")).toBeNull();
43+
expect(isNotSecret("SSH_KNOWN_HOSTS")).toBe(true);
44+
});
45+
46+
it("points provider keys at the provider, with a url", () => {
47+
const stripe = catalogSpec("STRIPE_SECRET_KEY");
48+
expect(stripe?.method).toBe("manual");
49+
expect(stripe?.url).toContain("stripe.com");
50+
expect(catalogSpec("ANTHROPIC_API_KEY")?.url).toContain("anthropic.com");
51+
expect(catalogSpec("SOME_VENDOR_API_KEY")?.method).toBe("manual");
52+
});
53+
54+
it("knows nothing about plain config", () => {
55+
expect(catalogSpec("SOLANA_RPC_URL")).toBeNull();
56+
expect(catalogSpec("NODE_ENV")).toBeNull();
57+
});
58+
});
59+
60+
describe("random secrets", () => {
61+
it("keep the old value's alphabet and length, never shorter than 32", () => {
62+
const hex = "a".repeat(64);
63+
expect(detectFormat(hex)).toBe("hex");
64+
const next = generateRandomSecret({}, hex);
65+
expect(next).toMatch(/^[0-9a-f]{64}$/);
66+
expect(next).not.toBe(hex);
67+
expect(generateRandomSecret({}, "short")).toHaveLength(32);
68+
expect(generateRandomSecret({ format: "alnum", length: 40 })).toMatch(/^[A-Za-z0-9]{40}$/);
69+
expect(generateRandomSecret({ format: "base64url", length: 48 })).toMatch(/^[A-Za-z0-9_-]{48}$/);
70+
});
71+
});
72+
73+
describe("specs", () => {
74+
it("validate what agents will follow", () => {
75+
expect(parseRotationSpec('{"method":"manual","steps":["a",""," ","b"]}').steps).toEqual(["a", "b"]);
76+
expect(() => parseRotationSpec('{"method":"delete-everything"}')).toThrow(/method/);
77+
expect(() => parseRotationSpec('{"method":"command"}')).toThrow(/command/);
78+
expect(() => parseRotationSpec('{"method":"random","length":4}')).toThrow(/length/);
79+
expect(() => parseRotationSpec("not json")).toThrow(/JSON/);
80+
});
81+
82+
it("can be built from CLI flags", () => {
83+
const spec = specFromOptions({ method: "manual", url: "https://x.test", step: ["one", "two"], consumer: ["dev2"], outputFormat: "json" });
84+
expect(spec).toMatchObject({ method: "manual", url: "https://x.test", steps: ["one", "two"], consumers: ["dev2"] });
85+
});
86+
87+
it("are stored under the prefix the team provider hides from .env sync", () => {
88+
expect(ROTATE_PREFIX).toBe(ROTATION_ENTRY_PREFIX);
89+
expect(rotationEntryName("CRON_SECRET")).toBe("__ROTATE__CRON_SECRET");
90+
});
91+
});
92+
93+
describe("planRotations", () => {
94+
const row = (vault: string, key: string, fingerprint: string, updatedAt = "2026-10-01") => ({ vault, key, fingerprint, updatedAt });
95+
96+
it("rotates one value once, however many vaults hold it", () => {
97+
const plan = planRotations(
98+
[row("a--prod", "ANTHROPIC_API_KEY", "f1"), row("b--prod", "ANTHROPIC_API_KEY", "f1", "2026-09-01"), row("c--prod", "ANTHROPIC_API_KEY", "f2")],
99+
new Map()
100+
);
101+
expect(plan).toHaveLength(2);
102+
expect(plan[0]).toMatchObject({ vaults: ["a--prod", "b--prod"], oldestUpdate: "2026-09-01", source: "catalog" });
103+
});
104+
105+
it("prefers the entry's own instructions, and never plans rotation entries or public keys", () => {
106+
const plan = planRotations(
107+
[row("a--prod", "CRON_SECRET", "f1"), row("a--prod", "__ROTATE__CRON_SECRET", "f9"), row("a--prod", "SSH_ID_ED25519_PUB", "f8")],
108+
new Map([["a--prod\u0000CRON_SECRET", { method: "command" as const, command: "mint" }]])
109+
);
110+
expect(plan.map((p) => p.key)).toEqual(["CRON_SECRET"]);
111+
expect(plan[0]).toMatchObject({ method: "command", source: "entry", automatic: true });
112+
});
113+
114+
it("never plans or propagates empty values, which all share one fingerprint", () => {
115+
const plan = planRotations([row("a--prod", "SHOPIFY_ACCESS_TOKEN", EMPTY_FINGERPRINT), row("b--prod", "OPENAI_API_KEY", EMPTY_FINGERPRINT)], new Map());
116+
expect(plan).toEqual([]);
117+
});
118+
119+
it("treats trading knobs named *_SEED_* as config, not wallet seeds", () => {
120+
expect(planRotations([row("a--prod", "ARB_AUTO_SEED_MIN_USD", "f1")], new Map())).toEqual([]);
121+
expect(isoTime(1785867760)).toMatch(/^2026-/);
122+
});
123+
124+
it("flags secret-looking keys nobody wrote instructions for, and skips plain config", () => {
125+
const plan = planRotations([row("a--prod", "MYSTERY_SIGNING_THING", "f1"), row("a--prod", "SNIPE_MODE", "f2"), row("a--prod", "V2_SIZE_USD", "f3")], new Map());
126+
expect(plan.map((p) => p.key)).toEqual(["MYSTERY_SIGNING_THING"]);
127+
expect(plan[0]).toMatchObject({ method: "unknown", source: "none", automatic: false });
128+
});
129+
});
130+
131+
describe("newEd25519", () => {
132+
it("returns an OpenSSH keypair and leaves no files behind", () => {
133+
const pair = newEd25519("test");
134+
expect(pair.privateKey).toContain("BEGIN OPENSSH PRIVATE KEY");
135+
expect(pair.publicKey).toMatch(/^ssh-ed25519 \S+ test$/);
136+
});
137+
});

0 commit comments

Comments
 (0)