fix(rotation): OAuth client ids are identifiers, never rotated (CLI 0.16.2) (#299)

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:
Anthony Ettinger 2026-11-30 12:12:50 -08:00 • committed by GitHub
parent 41ad9f0987
commit 267973f439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 215 additions and 19 deletions

View file

@ -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"]);
});
});