mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 01:14:47 +00:00
fix(rotation): OAuth client ids are identifiers, never rotated (CLI 0.16.2)
c0upons CoinPay sign-in broke with `invalid_client: Invalid client_id`. c0upons--prod's COINPAY_CLIENT_ID held the same value as COINPAY_API_KEY, and a rotation writes every vault:key with the value's fingerprint, whatever the key is called. The 2026-11-22 coinpay-api-key run minted a new cp_live_ key, wrote it into COINPAY_CLIENT_ID too, and saved the rotator state as __ROTATE__COINPAY_CLIENT_ID (targets[0] was the client id), so the plan showed the client id as provider/coinpay/automatic from then on. - New method `identifier`: every *_CLIENT_ID (COINPAY_CLIENT_ID, *_OAUTH_CLIENT_ID, GOOGLE_CLIENT_ID...) gets it from the catalog, never automatic, with the reason. A __ROTATE__ entry claiming otherwise is ignored and reported in the plan with the command to reset it. - rotate-keys never writes a rotated value into a client id under another name (named in the result instead), records rotator state under the plan's own key, and skips a client id outright. - coinpay-api-key and coinpay-webhook-secret refuse a client id in preflight and mint without calling CoinPay. - rotation-set refuses random/provider/command/ssh-keygen for a client id. - Tests for each; docs/rotation.md. Co-authored-by: riotcoder <riotcoder@profullstack.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
41ad9f0987
commit
465d0ae23b
11 changed files with 215 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@logicsrc/cli",
|
||||
"version": "0.16.1",
|
||||
"version": "0.16.2",
|
||||
"description": "LogicSRC CLI: every LogicSRC standard and tool as one command.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
|
|
|||
|
|
@ -918,7 +918,7 @@ teams
|
|||
.argument("<project>", "Project name")
|
||||
.argument("<env>", "Environment name")
|
||||
.argument("<key>", "Secret name the instructions are for")
|
||||
.option("--method <method>", "random, ssh-keygen, command, or manual")
|
||||
.option("--method <method>", "random, ssh-keygen, command, manual, or identifier (OAuth client ids: never rotated)")
|
||||
.option("--json <spec>", "the whole spec as JSON instead of flags")
|
||||
.option("--format <alphabet>", "random: hex, base64, base64url, alnum (default: like the old value)")
|
||||
.option("--length <n>", "random: length in characters (default: like the old value, min 32)")
|
||||
|
|
|
|||
|
|
@ -211,4 +211,34 @@ describe("rotate-keys two-phase flow", () => {
|
|||
expect(readFileSync(join(root, "a.com", "app.env"), "utf8")).toBe("RESEND_API_KEY=re_old_xxxxxxxxxxxxxxxx\n");
|
||||
process.exitCode = 0;
|
||||
});
|
||||
|
||||
it("never writes a rotated key into an OAuth client id holding the same value, nor its rotator state", async () => {
|
||||
const SAME = "re_old_xxxxxxxxxxxxxxxx";
|
||||
const team = await makeTeam({ "a--prod": { COINPAY_CLIENT_ID: SAME }, "b--prod": { RESEND_API_KEY: SAME } });
|
||||
const fetch = (async (_url: any, init: any = {}) =>
|
||||
(init.method ?? "GET") === "POST"
|
||||
? new Response(JSON.stringify({ id: "new-id", token: "re_new_yyyyyyyyyyyyyyyy" }), { status: 201 })
|
||||
: new Response(JSON.stringify({ data: [] }), { status: 200 })) as typeof globalThis.fetch;
|
||||
const [r] = await teamsRotateKeysAction("t", { keys: ["RESEND_API_KEY"] }, { ...quiet, approve: true }, { ops: ops(), fetch, strayText: () => [], env: {} });
|
||||
expect(r!.status).toBe("rotated");
|
||||
expect(r!.written).toEqual(["b--prod:RESEND_API_KEY"]);
|
||||
expect(r!.note).toMatch(/a--prod:COINPAY_CLIENT_ID/);
|
||||
expect(await team.read("b--prod", "RESEND_API_KEY")).toBe("re_new_yyyyyyyyyyyyyyyy");
|
||||
expect(await team.read("a--prod", "COINPAY_CLIENT_ID")).toBe(SAME);
|
||||
expect(await team.read("a--prod", "__ROTATE__COINPAY_CLIENT_ID")).toBeUndefined();
|
||||
expect(JSON.parse((await team.read("b--prod", "__ROTATE__RESEND_API_KEY"))!).state).toEqual({ keyId: "new-id" });
|
||||
});
|
||||
|
||||
it("a client id with a stale provider entry is skipped, never minted", async () => {
|
||||
const team = await makeTeam({
|
||||
"c--prod": { COINPAY_CLIENT_ID: "cp_live_0123456789abcdef", __ROTATE__COINPAY_CLIENT_ID: JSON.stringify({ method: "provider", provider: "coinpay-api-key" }) }
|
||||
});
|
||||
const calls: string[] = [];
|
||||
const fetch = (async (url: any) => (calls.push(String(url)), new Response("{}", { status: 200 }))) as typeof globalThis.fetch;
|
||||
const [r] = await teamsRotateKeysAction("t", { keys: ["COINPAY_CLIENT_ID"] }, { ...quiet, approve: true }, { ops: ops(), fetch, strayText: () => [], env: { COINPAY_ROTATE_TOKEN: "s" } });
|
||||
expect(r!.method).toBe("identifier");
|
||||
expect(r!.status).toBe("skipped");
|
||||
expect(calls).toEqual([]);
|
||||
expect(await team.read("c--prod", "COINPAY_CLIENT_ID")).toBe("cp_live_0123456789abcdef");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import {
|
|||
type PlannedRotation,
|
||||
type RotationSpec
|
||||
} from "./rotation-catalog.js";
|
||||
import { identifierSpec, isIdentifier } from "./rotation-catalog.js";
|
||||
import { ROTATORS, defaultRun, rewriteUrls, type Minted, type ProviderRotator, type RotatorContext } from "./rotators.js";
|
||||
import { DesktopError, desktopHost, desktopReport, desktopRotator, type DesktopExec, type DesktopSession } from "./desktop-rotator.js";
|
||||
import { DESKTOP_RECIPES } from "./desktop-recipes.js";
|
||||
|
|
@ -137,6 +138,20 @@ function siblings(team: Loaded, fingerprint: string): Array<{ vault: VaultState;
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a rotation of `key` writes: every vault:key holding the value, except
|
||||
* OAuth client ids under another name. A client id that holds a secret's value
|
||||
* is a misconfiguration; overwriting it with a freshly minted key (and then
|
||||
* recording the rotator's state under the client id's name) is how
|
||||
* COINPAY_CLIENT_ID came to be "auto-rotated" by the CoinPay API key rotator.
|
||||
* The plan's own key comes first, so rotator state lands on that key.
|
||||
*/
|
||||
export function rotationTargets<T extends { key: string }>(all: T[], key: string): { targets: T[]; skipped: T[] } {
|
||||
const skipped = all.filter((t) => t.key !== key && isIdentifier(t.key));
|
||||
const targets = all.filter((t) => !skipped.includes(t));
|
||||
return { targets: [...targets.filter((t) => t.key === key), ...targets.filter((t) => t.key !== key)], skipped };
|
||||
}
|
||||
|
||||
// ---- plan ------------------------------------------------------------------
|
||||
|
||||
export async function teamsRotationAction(slug: string, filter: RotationFilter, options: { format: OutputFormat }): Promise<void> {
|
||||
|
|
@ -203,8 +218,18 @@ export function specFromOptions(options: RotationSetOptions): RotationSpec {
|
|||
);
|
||||
}
|
||||
|
||||
/** OAuth client ids only take instructions that rotate nothing. */
|
||||
export function checkSpecForKey(key: string, spec: RotationSpec): RotationSpec {
|
||||
if (!isIdentifier(key)) return spec;
|
||||
if (spec.method === "identifier" || spec.method === "not-secret") return { ...identifierSpec(), ...spec, method: "identifier", never: true };
|
||||
if (spec.method === "manual") return { ...spec, never: true };
|
||||
throw new Error(
|
||||
`${key} is an OAuth client id: an identifier registered at the provider, not a secret. It cannot rotate by method ${spec.method} (a new value is an unregistered client). Use --method identifier, and rotate the client secret instead.`
|
||||
);
|
||||
}
|
||||
|
||||
export async function teamsRotationSetAction(slug: string, project: string, env: string, key: string, options: RotationSetOptions): Promise<void> {
|
||||
const spec = specFromOptions(options);
|
||||
const spec = checkSpecForKey(key, specFromOptions(options));
|
||||
const team = await loadTeam(slug);
|
||||
const name = vaultName(project, env);
|
||||
const v = team.vaults.find((x) => x.name === name);
|
||||
|
|
@ -491,12 +516,16 @@ async function vaultValues(team: Loaded, v: VaultState): Promise<Record<string,
|
|||
async function rotateTwoPhase(
|
||||
team: Loaded,
|
||||
p: PlannedRotation,
|
||||
targets: Array<{ vault: VaultState; key: string }>,
|
||||
targetsIn: Array<{ vault: VaultState; key: string }>,
|
||||
base: RotationResult,
|
||||
options: RotateKeysOptions,
|
||||
deps: Required<Pick<RotateDeps, "ops" | "fetch" | "now" | "env">> & { strayText: () => string[]; rotatorFor: (spec: RotationSpec) => ProviderRotator | undefined }
|
||||
): Promise<RotationResult> {
|
||||
const spec = p.spec!;
|
||||
let targets = targetsIn;
|
||||
if (isIdentifier(p.key)) return { ...base, status: "skipped", error: "an OAuth client id is an identifier, not a secret: never rotated" };
|
||||
targets = rotationTargets(targets, p.key).targets;
|
||||
if (!targets.length) return { ...base, status: "skipped", error: "nothing to write" };
|
||||
const first = targets[0]!;
|
||||
const oldValue = await readValue(team, first.vault, first.key);
|
||||
const firstValues = await vaultValues(team, first.vault);
|
||||
|
|
@ -666,8 +695,15 @@ export async function teamsRotateKeysAction(slug: string, filter: RotationFilter
|
|||
disruptive: spec?.disruptive,
|
||||
note: spec?.note
|
||||
};
|
||||
const targets = siblings(team, p.fingerprint);
|
||||
const { targets, skipped } = rotationTargets(siblings(team, p.fingerprint), p.key);
|
||||
base.vaults = targets.map((t) => `${t.vault.name}:${t.key}`);
|
||||
const skippedNote = skipped.length ? `not written (OAuth client ids holding this value; fix them by hand): ${skipped.map((t) => `${t.vault.name}:${t.key}`).join(", ")}` : "";
|
||||
const withSkipped = (r: RotationResult): RotationResult => (skippedNote && !r.note?.includes(skippedNote) ? { ...r, note: [r.note, skippedNote].filter(Boolean).join("; ") } : r);
|
||||
if (skippedNote) base.note = [base.note, skippedNote].filter(Boolean).join("; ");
|
||||
if (isIdentifier(p.key) && stdinValue === undefined) {
|
||||
results.push({ ...base, status: "skipped", error: "an OAuth client id is an identifier, not a secret: never rotated" });
|
||||
continue;
|
||||
}
|
||||
if (stdinValue === undefined && !p.automatic) {
|
||||
const todo: RotationResult = { ...base, status: "todo", steps: spec?.steps ?? ["No instructions: add some with logicsrc teams rotation-set."] };
|
||||
// Report-only desktop keys: with --approve and a desktop host, an agent looks the key up (changes nothing).
|
||||
|
|
@ -704,7 +740,7 @@ export async function teamsRotateKeysAction(slug: string, filter: RotationFilter
|
|||
}
|
||||
try {
|
||||
if (stdinValue === undefined && (spec?.method === "random" || spec?.method === "provider" || spec?.method === "desktop")) {
|
||||
const r = await rotateTwoPhase(team, p, targets, base, options, deps);
|
||||
const r = withSkipped(await rotateTwoPhase(team, p, targets, base, options, deps));
|
||||
if (r.status === "rotated" || r.status === "rolled-back") live++;
|
||||
if (r.status === "rotated") r.apps = await resealAppGrants(team, p.fingerprint);
|
||||
results.push(r);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { catalogSpec, isAutomatic, isNotSecret, planRotations, baseKeyName, EMPTY_FINGERPRINT } from "./rotation-catalog.js";
|
||||
import { scheduledBlock } from "./rotate-keys.js";
|
||||
import { catalogSpec, isAutomatic, isIdentifier, isNotSecret, parseRotationSpec, planRotations, baseKeyName, EMPTY_FINGERPRINT } from "./rotation-catalog.js";
|
||||
import { checkSpecForKey, rotationTargets, scheduledBlock } from "./rotate-keys.js";
|
||||
|
||||
const method = (k: string) => catalogSpec(k)?.method;
|
||||
|
||||
|
|
@ -134,3 +134,56 @@ describe("scheduledBlock", () => {
|
|||
expect(scheduledBlock(p(catalogSpec("SYSTEM_MNEMONIC_SOL")))).toMatch(/person|never/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("OAuth client ids are identifiers, never rotated (c0upons invalid_client, 2026-11-22)", () => {
|
||||
const row = (vault: string, key: string, fingerprint: string) => ({ vault, key, fingerprint, updatedAt: "2026-11-22T00:00:00Z" });
|
||||
|
||||
it("classifies every *_CLIENT_ID as an identifier that is never automatic", () => {
|
||||
for (const k of ["COINPAY_CLIENT_ID", "COINPAY_OAUTH_CLIENT_ID", "GOOGLE_CLIENT_ID", "GITHUB_OAUTH_CLIENT_ID", "CLIENT_ID", "COINPAY_CLIENT_ID__1"]) {
|
||||
expect(isIdentifier(k)).toBe(true);
|
||||
const spec = catalogSpec(k);
|
||||
expect(spec?.method).toBe("identifier");
|
||||
expect(spec?.never).toBe(true);
|
||||
expect(isAutomatic(spec)).toBe(false);
|
||||
expect(spec?.note).toMatch(/not a secret/);
|
||||
}
|
||||
for (const k of ["COINPAY_CLIENT_SECRET", "COINPAY_API_KEY", "CLIENT_IDS_URL"]) expect(isIdentifier(k)).toBe(false);
|
||||
expect(catalogSpec("COINPAY_API_KEY")?.provider).toBe("coinpay-api-key");
|
||||
expect(isAutomatic(catalogSpec("COINPAY_API_KEY"))).toBe(true);
|
||||
});
|
||||
|
||||
it("a __ROTATE__ entry claiming provider rotation is overridden and reported, not automatic", () => {
|
||||
const entries = new Map([["c0upons--prod\u0000COINPAY_CLIENT_ID", parseRotationSpec(JSON.stringify({ method: "provider", provider: "coinpay-api-key", family: "coinpay" }))]]);
|
||||
const plan = planRotations([row("c0upons--prod", "COINPAY_CLIENT_ID", "f1"), row("other--prod", "COINPAY_CLIENT_ID", "f2")], entries);
|
||||
expect(plan).toHaveLength(1);
|
||||
expect(plan[0]).toMatchObject({ key: "COINPAY_CLIENT_ID", method: "identifier", automatic: false, source: "entry" });
|
||||
expect(plan[0]!.spec?.note).toMatch(/is ignored/);
|
||||
expect(scheduledBlock(plan[0]!)).toBe("needs a person");
|
||||
});
|
||||
|
||||
it("an identifier entry drops the key from the plan again", () => {
|
||||
const entries = new Map([["a--prod\u0000COINPAY_CLIENT_ID", parseRotationSpec(JSON.stringify({ method: "identifier" }))]]);
|
||||
expect(planRotations([row("a--prod", "COINPAY_CLIENT_ID", "f1")], entries)).toEqual([]);
|
||||
});
|
||||
|
||||
it("rotation-set refuses an automatic method for a client id", () => {
|
||||
for (const method of ["random", "provider", "command", "ssh-keygen"]) {
|
||||
const spec = parseRotationSpec(JSON.stringify({ method, provider: "coinpay-api-key", command: "x" }));
|
||||
expect(() => checkSpecForKey("COINPAY_CLIENT_ID", spec)).toThrow(/OAuth client id/);
|
||||
}
|
||||
expect(checkSpecForKey("COINPAY_CLIENT_ID", { method: "identifier" })).toMatchObject({ method: "identifier", never: true });
|
||||
expect(checkSpecForKey("COINPAY_CLIENT_ID", { method: "manual", steps: ["x"] })).toMatchObject({ method: "manual", never: true });
|
||||
expect(checkSpecForKey("COINPAY_API_KEY", { method: "provider", provider: "coinpay-api-key" }).method).toBe("provider");
|
||||
});
|
||||
|
||||
it("a rotation never writes into a client id that shares the value, and the plan's key comes first", () => {
|
||||
const all = [
|
||||
{ vault: "a", key: "COINPAY_CLIENT_ID" },
|
||||
{ vault: "b", key: "COINPAY_API_KEY" },
|
||||
{ vault: "c", key: "CP_KEY" }
|
||||
];
|
||||
const { targets, skipped } = rotationTargets(all, "COINPAY_API_KEY");
|
||||
expect(targets.map((t) => t.key)).toEqual(["COINPAY_API_KEY", "CP_KEY"]);
|
||||
expect(skipped.map((t) => t.vault)).toEqual(["a"]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -36,9 +36,13 @@ export function isoTime(value: unknown): string {
|
|||
* provider-issued keys without a rotator, wallet seeds,
|
||||
* encryption keys that protect stored data.
|
||||
* not-secret public config that happens to look like a secret (URLs,
|
||||
* client ids, publishable keys). Dropped from the plan.
|
||||
* publishable keys). Dropped from the plan.
|
||||
* identifier an OAuth client id (COINPAY_CLIENT_ID, *_OAUTH_CLIENT_ID): a
|
||||
* name registered at the provider, not a secret. A new value is
|
||||
* not a credential, it is an unknown client (invalid_client), so
|
||||
* nothing ever rotates one, whatever its __ROTATE__ entry says.
|
||||
*/
|
||||
export type RotationMethod = "random" | "ssh-keygen" | "command" | "provider" | "desktop" | "manual" | "not-secret";
|
||||
export type RotationMethod = "random" | "ssh-keygen" | "command" | "provider" | "desktop" | "manual" | "not-secret" | "identifier";
|
||||
export type RandomFormat = "hex" | "base64" | "base64url" | "alnum";
|
||||
/** Who has to do a manual rotation: an agent with dashboard/CLI access, or Anthony (money, signing ceremonies, his logins). */
|
||||
export type RotationOwner = "agent" | "anthony";
|
||||
|
|
@ -87,7 +91,33 @@ export function rotationEntryName(key: string): string {
|
|||
return `${ROTATE_PREFIX}${key}`;
|
||||
}
|
||||
|
||||
const METHODS: readonly RotationMethod[] = ["random", "ssh-keygen", "command", "provider", "desktop", "manual", "not-secret"];
|
||||
const METHODS: readonly RotationMethod[] = ["random", "ssh-keygen", "command", "provider", "desktop", "manual", "not-secret", "identifier"];
|
||||
|
||||
/**
|
||||
* OAuth client ids: identifiers registered at the provider (CoinPay's
|
||||
* oauth_clients, Google, GitHub), sent in the clear on every authorize URL.
|
||||
* Minting a new one does not rotate anything, it breaks sign-in with
|
||||
* `invalid_client` (c0upons, 2026-11-22). Only the client SECRET rotates.
|
||||
*/
|
||||
export function isIdentifier(key: string): boolean {
|
||||
return /(^|_)CLIENT_ID$/.test(baseKeyName(key));
|
||||
}
|
||||
|
||||
/** The spec every identifier gets: never automatic, and the reason. */
|
||||
export function identifierSpec(extraNote?: string): RotationSpec {
|
||||
return {
|
||||
method: "identifier",
|
||||
never: true,
|
||||
family: "oauth-client",
|
||||
note:
|
||||
"an OAuth client id is an identifier registered at the provider, not a secret: a new value is an unregistered client (invalid_client). Rotate the client secret instead." +
|
||||
(extraNote ? ` ${extraNote}` : ""),
|
||||
steps: [
|
||||
"Nothing to rotate. If it must change, register a new OAuth client at the provider (same redirect URIs), then store its id and secret together.",
|
||||
"To fix a wrong value: copy the registered client_id (match the app's redirect URI host) into the vault and redeploy the app."
|
||||
]
|
||||
};
|
||||
}
|
||||
const FORMATS: readonly RandomFormat[] = ["hex", "base64", "base64url", "alnum"];
|
||||
|
||||
/** Parse and validate a stored spec. Throws with a message naming the problem. */
|
||||
|
|
@ -449,6 +479,7 @@ export function isNotSecret(key: string): boolean {
|
|||
|
||||
export function catalogSpec(key: string): RotationSpec | null {
|
||||
const name = baseKeyName(key);
|
||||
if (isIdentifier(name)) return identifierSpec();
|
||||
if (isNotSecret(name)) return { method: "not-secret", note: "public or plain config" };
|
||||
if (CREDENTIAL_URL.test(name)) {
|
||||
return {
|
||||
|
|
@ -469,7 +500,7 @@ export function catalogSpec(key: string): RotationSpec | null {
|
|||
|
||||
/** Automatic = we can produce the new value without a person. */
|
||||
export function isAutomatic(spec: RotationSpec | null): boolean {
|
||||
if (!spec || spec.never) return false;
|
||||
if (!spec || spec.never || spec.method === "identifier") return false;
|
||||
if (spec.method === "desktop") return Boolean(spec.recipe && DESKTOP_RECIPES[spec.recipe] && DESKTOP_RECIPES[spec.recipe]!.mode !== "report");
|
||||
return spec.method === "random" || spec.method === "ssh-keygen" || spec.method === "command" || spec.method === "provider";
|
||||
}
|
||||
|
|
@ -533,6 +564,8 @@ export function planRotations(rows: PlanInput[], entrySpecs: Map<string, Rotatio
|
|||
if (isRotationEntry(r.key) || r.key.startsWith(ARCHIVE_PREFIX) || r.fingerprint === EMPTY_FINGERPRINT) continue;
|
||||
const entry = entrySpecs.get(`${r.vault}\u0000${r.key}`);
|
||||
if (entry?.method === "not-secret") continue;
|
||||
// An identifier is planned only to show (and correct) a stale entry that claims it rotates.
|
||||
if (isIdentifier(r.key) && (!entry || entry.method === "identifier")) continue;
|
||||
if (!entry && isNotSecret(r.key)) continue;
|
||||
// Config with no instructions is not a secret to rotate; an explicit entry overrides.
|
||||
if (!entry && !looksSecret(r.key) && !catalogSpec(r.key)) continue;
|
||||
|
|
@ -545,8 +578,14 @@ export function planRotations(rows: PlanInput[], entrySpecs: Map<string, Rotatio
|
|||
// An entry spec in any vault holding this value applies to all of them.
|
||||
const fromEntry = members.map((m) => entrySpecs.get(`${m.vault}\u0000${m.key}`)).find(Boolean) ?? null;
|
||||
const fromCatalog = catalogSpec(first.key);
|
||||
// An entry can add steps, but it cannot make a never-automated key (wallet, signing, Stripe) automatic.
|
||||
const spec = fromEntry && fromCatalog?.never ? { ...fromEntry, never: true, owner: fromCatalog.owner, family: fromEntry.family ?? fromCatalog.family } : fromEntry ?? fromCatalog;
|
||||
// An entry can add steps, but it cannot make a never-automated key (wallet, signing, Stripe) automatic,
|
||||
// and an OAuth client id is never rotated at all: its entry is reported as stale.
|
||||
const spec =
|
||||
fromEntry && isIdentifier(first.key)
|
||||
? identifierSpec(`Its __ROTATE__ entry says method ${fromEntry.method}${fromEntry.provider ? ` (${fromEntry.provider})` : ""} and is ignored: reset it with logicsrc teams rotation-set <team> <project> <env> ${first.key} --method identifier.`)
|
||||
: fromEntry && fromCatalog?.never
|
||||
? { ...fromEntry, never: true, owner: fromCatalog.owner, family: fromEntry.family ?? fromCatalog.family }
|
||||
: fromEntry ?? fromCatalog;
|
||||
out.push({
|
||||
key: first.key,
|
||||
vaults: members.map((m) => m.vault).sort(),
|
||||
|
|
|
|||
|
|
@ -340,3 +340,18 @@ describe("postgres-role", () => {
|
|||
expect(rewriteUrls({ A: "postgres://u:old@h/d", B: "postgres://u:other@h/d", C: "plain" }, "old", "n w")).toEqual({ A: "postgres://u:n%20w@h/d" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("CoinPay rotators never touch OAuth client ids", () => {
|
||||
it("refuses COINPAY_CLIENT_ID in preflight and mint without calling CoinPay", async () => {
|
||||
const { fetch, calls } = fakeFetch(() => ({ status: 200, body: { businesses: [] } }));
|
||||
const env = { COINPAY_ROTATE_TOKEN: "session" };
|
||||
for (const key of ["COINPAY_CLIENT_ID", "COINPAY_OAUTH_CLIENT_ID", "C0UPONS_COINPAY_CLIENT_ID"]) {
|
||||
const c = ctx({ key, oldValue: "cp_live_0123456789abcdef", fetch, env, vaultValues: { COINPAY_API_KEY: "cp_live_x" } });
|
||||
expect(await coinpayApiKeyRotator.preflight(c)).toMatch(/OAuth client id/);
|
||||
await expect(coinpayApiKeyRotator.mint(c)).rejects.toThrow(/OAuth client id/);
|
||||
expect(await coinpayWebhookSecretRotator.preflight(c)).toMatch(/OAuth client id/);
|
||||
await expect(coinpayWebhookSecretRotator.mint(c)).rejects.toThrow(/OAuth client id/);
|
||||
}
|
||||
expect(calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { createHash, createHmac, generateKeyPairSync, pbkdf2Sync, randomBytes } from "node:crypto";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { generateRandomSecret } from "./rotation-catalog.js";
|
||||
import { generateRandomSecret, isIdentifier } from "./rotation-catalog.js";
|
||||
import { localVersion } from "./update.js";
|
||||
|
||||
/**
|
||||
|
|
@ -322,16 +322,29 @@ async function coinpayBusiness(ctx: RotatorContext, match: (b: any) => boolean):
|
|||
* DELETE for a scoped key, or regenerating the legacy slot (its new value is
|
||||
* thrown away unread) for the legacy key.
|
||||
*/
|
||||
/**
|
||||
* An OAuth client id (COINPAY_CLIENT_ID) is registered in CoinPay's
|
||||
* oauth_clients; it is not an API key. "Rotating" it with a freshly minted
|
||||
* cp_live_ key leaves the app sending an unknown client_id (invalid_client).
|
||||
*/
|
||||
const IDENTIFIER_REFUSAL = "an OAuth client id is an identifier registered at CoinPay, not a secret: the CoinPay rotators never rotate it";
|
||||
|
||||
function refuseIdentifier(ctx: Pick<RotatorContext, "key">): void {
|
||||
if (isIdentifier(ctx.key)) throw new RotatorError(IDENTIFIER_REFUSAL);
|
||||
}
|
||||
|
||||
export const coinpayApiKeyRotator: ProviderRotator = {
|
||||
id: "coinpay-api-key",
|
||||
title: "CoinPay business API key",
|
||||
overlap: true,
|
||||
async preflight(ctx) {
|
||||
if (isIdentifier(ctx.key)) return IDENTIFIER_REFUSAL;
|
||||
const s = await coinpaySession(ctx);
|
||||
if ("error" in s) return s.error === NO_SESSION ? `${NO_SESSION} (owner of the business)` : s.error;
|
||||
return null;
|
||||
},
|
||||
async mint(ctx) {
|
||||
refuseIdentifier(ctx);
|
||||
await requireSession(ctx);
|
||||
const base = coinpayBase(ctx);
|
||||
const r = await call(ctx, `${base}/api/businesses`, { method: "GET", token: ctx.oldValue });
|
||||
|
|
@ -389,12 +402,14 @@ export const coinpayWebhookSecretRotator: ProviderRotator = {
|
|||
title: "CoinPay webhook secret",
|
||||
overlap: false,
|
||||
async preflight(ctx) {
|
||||
if (isIdentifier(ctx.key)) return IDENTIFIER_REFUSAL;
|
||||
const s = await coinpaySession(ctx);
|
||||
if ("error" in s) return s.error;
|
||||
if (!findApiKey(ctx)) return "no CoinPay API key in the same vault to find the business with";
|
||||
return null;
|
||||
},
|
||||
async mint(ctx) {
|
||||
refuseIdentifier(ctx);
|
||||
const apiKey = findApiKey(ctx);
|
||||
if (!apiKey) throw new RotatorError("needs the vault's CoinPay API key to find the business with");
|
||||
await requireSession(ctx);
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ export function registerRotation(server: McpServer, options: RotationToolsOption
|
|||
{
|
||||
title: "Set Key Rotation Instructions",
|
||||
description:
|
||||
"Store rotation instructions for one key as its encrypted __ROTATE__<KEY> entry (logicsrc teams rotation-set). spec is the JSON spec: {method, url?, steps?, consumers?, note?, provider?, recipe?, format?, length?, command?}. A wallet, signing or banned-provider key can never be made automatic.",
|
||||
"Store rotation instructions for one key as its encrypted __ROTATE__<KEY> entry (logicsrc teams rotation-set). spec is the JSON spec: {method, url?, steps?, consumers?, note?, provider?, recipe?, format?, length?, command?}. A wallet, signing or banned-provider key can never be made automatic, and an OAuth client id (*_CLIENT_ID) only takes method identifier or manual: it is an identifier, never rotated.",
|
||||
inputSchema: {
|
||||
team: z.string(),
|
||||
project: z.string(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue