mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-11-29 15:51:52 +00:00
App grants: one secret sealed to an external app (key hub phase 1) (#286)
Some checks failed
CI / build (push) Has been cancelled
Deploy to dev2 / deploy (push) Has been cancelled
test / test (push) Has been cancelled
Some checks failed
CI / build (push) Has been cancelled
Deploy to dev2 / deploy (push) Has been cancelled
test / test (push) Has been cancelled
* App grants: hand one secret to an external app, sealed to its per-user inbox Phase 1 of the CoinPay <-> logicsrc key hub (spec: claude.ai/artifact/LAZgAiqWqeLQ14uJ5JpdKb). - /grant consent page: logicsrc fetches the request manifest from the app's own origin over TLS (/.well-known/logicsrc-grant/<nonce>), public hosts only, so the page shows a verified origin, not a claimed name - The browser decrypts with the identity key (as the vault page does) and seals with @profullstack/sealed-secrets to the app's inbox; the server stores ciphertext + metadata only (app_grant_requests, app_grants) - Signed Standard Webhooks to the app: grant.delivered / updated / revoked - Signing keys (wallet, seed, SSH) are refused for apps - rotate-keys re-seals the new value to every app grant on the old fingerprint (resealAppGrants); /apps lists and revokes grants Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * App grants: re-check the webhook host is public on every delivery Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
64eb42e2c1
commit
bbf640abeb
13 changed files with 974 additions and 4 deletions
|
|
@ -35,6 +35,7 @@
|
|||
"@logicsrc/validators": "file:../validators",
|
||||
"@profullstack/hqtui": "^0.11.1",
|
||||
"@profullstack/logicsrc-mcp": "file:../logicsrc-mcp",
|
||||
"@profullstack/sealed-secrets": "0.1.1",
|
||||
"commander": "^15.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
44
packages/cli/src/rotate-app-grants.test.ts
Normal file
44
packages/cli/src/rotate-app-grants.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// A rotation re-seals the new value to every app that holds the old one
|
||||
// through a logicsrc app grant, reading each grant's own vault and name.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createSealer } from "@profullstack/sealed-secrets";
|
||||
import { encryptValue, fingerprintValue, generateVaultKey } from "@logicsrc/plugin-credential-sharing";
|
||||
import { resealAppGrants } from "./rotate-keys.js";
|
||||
|
||||
describe("resealAppGrants", () => {
|
||||
it("seals the new value to the app's inbox and delivers it with the new fingerprint", async () => {
|
||||
const appSealer = createSealer({ app: "meshhook", scope: "workflow_secrets" });
|
||||
const inbox = await appSealer.createSeal("correct horse battery staple", "mh-user-1");
|
||||
const dek = await generateVaultKey();
|
||||
const fresh = "cp_live_rotated_fixture";
|
||||
const delivered: Array<{ id: string; sealed: string; fingerprint: string }> = [];
|
||||
const client = {
|
||||
listAppGrants: async (fp: string) => ({
|
||||
grants: fp === "fp-old"
|
||||
? [{ id: "g1", app_name: "MeshHook", origin: "https://meshhook.com", key_name: "COINPAY_API_KEY", vault_id: "v1", source_name: "COINPAY_API_KEY", fingerprint: "fp-old", status: "active",
|
||||
recipient: { format: "sealed-secrets/inbox-v2", app: "meshhook", scope: "workflow_secrets", user_id: "mh-user-1", inbox_public_key: inbox.seal.inbox_public_key } },
|
||||
{ id: "g2", app_name: "Other", origin: "https://other.example", key_name: "K", vault_id: "v-locked", source_name: "K", fingerprint: "fp-old", status: "active",
|
||||
recipient: { format: "sealed-secrets/inbox-v2", app: "x", scope: "y", user_id: "u", inbox_public_key: inbox.seal.inbox_public_key } }]
|
||||
: []
|
||||
}),
|
||||
listSecrets: async () => ({ secrets: [{ name: "COINPAY_API_KEY", ...(await encryptValue(fresh, dek)), fingerprint: fingerprintValue(fresh) }] }),
|
||||
deliverAppGrant: async (id: string, sealed: string, fingerprint: string) => {
|
||||
delivered.push({ id, sealed, fingerprint });
|
||||
return { ok: true, delivered: true };
|
||||
}
|
||||
};
|
||||
const team = { client: client as never, vaults: [{ id: "v1", name: "meshhook--prod", project: "meshhook", env: "prod", secrets: [] }], dek: async () => dek };
|
||||
|
||||
const report = await resealAppGrants(team, "fp-old");
|
||||
expect(report).toEqual(["meshhook.com:COINPAY_API_KEY updated", "other.example:K not updated (no access to its vault)"]);
|
||||
expect(delivered).toHaveLength(1);
|
||||
expect(delivered[0]!.fingerprint).toBe(fingerprintValue(fresh));
|
||||
const entry = JSON.parse(delivered[0]!.sealed.slice("sealed:v2:".length));
|
||||
const { patch } = await appSealer.openInbox(inbox.dek, inbox.seal, [entry], "mh-user-1");
|
||||
expect(patch).toEqual({ COINPAY_API_KEY: fresh });
|
||||
});
|
||||
|
||||
it("does nothing for a client without app grants (older servers, test fakes)", async () => {
|
||||
expect(await resealAppGrants({ client: {} as never, vaults: [], dek: async () => "" }, "fp")).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
@ -13,6 +13,7 @@ import {
|
|||
type RemoteSecret,
|
||||
type TeamClient
|
||||
} from "@logicsrc/plugin-credential-sharing";
|
||||
import { createSealer } from "@profullstack/sealed-secrets";
|
||||
import { print, printColumns, type OutputFormat } from "./format.js";
|
||||
import { authedClient, splitVaultName, vaultName } from "./teams.js";
|
||||
import {
|
||||
|
|
@ -339,6 +340,47 @@ export interface RotationResult {
|
|||
disruptive?: string;
|
||||
note?: string;
|
||||
error?: string;
|
||||
/** Apps that hold this value through a logicsrc app grant, and whether each got the new one. */
|
||||
apps?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* After a rotation, every app holding the OLD value through an app grant gets
|
||||
* the new one, sealed here to that app's inbox key (the server sees ciphertext).
|
||||
* Each grant reads the value from its own vault and name, so a per-vault
|
||||
* rewrite (URLs) reaches the right app. Never throws: a failure is reported.
|
||||
*/
|
||||
export async function resealAppGrants(team: Pick<Loaded, "client" | "vaults" | "dek">, oldFingerprint: string): Promise<string[]> {
|
||||
const client = team.client as TeamClient & { listAppGrants?: TeamClient["listAppGrants"] };
|
||||
if (typeof client.listAppGrants !== "function") return [];
|
||||
let grants;
|
||||
try {
|
||||
({ grants } = await client.listAppGrants(oldFingerprint));
|
||||
} catch (err) {
|
||||
return [`app grants not checked: ${(err as Error).message}`];
|
||||
}
|
||||
const out: string[] = [];
|
||||
for (const g of grants) {
|
||||
const label = `${new URL(g.origin).host}:${g.key_name}`;
|
||||
try {
|
||||
const vault = team.vaults.find((v) => v.id === g.vault_id);
|
||||
if (!vault) {
|
||||
out.push(`${label} not updated (no access to its vault)`);
|
||||
continue;
|
||||
}
|
||||
const { secrets } = await client.listSecrets(vault.id);
|
||||
const s = secrets.find((x) => x.name === g.source_name);
|
||||
if (!s || s.fingerprint === oldFingerprint) continue;
|
||||
const value = await decryptValue({ nonce: s.nonce, ciphertext: s.ciphertext }, await team.dek(vault));
|
||||
const sealer = createSealer({ app: g.recipient.app, scope: g.recipient.scope });
|
||||
const entry = await sealer.sealToInbox(g.recipient.inbox_public_key, { [g.key_name]: value }, g.recipient.user_id);
|
||||
const r = await client.deliverAppGrant(g.id, `sealed:v2:${JSON.stringify(entry)}`, s.fingerprint);
|
||||
out.push(r.delivered ? `${label} updated` : `${label} sealed, app offline (${r.error ?? "no answer"})`);
|
||||
} catch (err) {
|
||||
out.push(`${label} failed: ${(err as Error).message}`);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
async function readStdin(): Promise<string> {
|
||||
|
|
@ -664,6 +706,7 @@ export async function teamsRotateKeysAction(slug: string, filter: RotationFilter
|
|||
if (stdinValue === undefined && (spec?.method === "random" || spec?.method === "provider" || spec?.method === "desktop")) {
|
||||
const r = 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);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -702,7 +745,7 @@ export async function teamsRotateKeysAction(slug: string, filter: RotationFilter
|
|||
const { applied } = await team.client.putSecrets(vault.id, upserts, []);
|
||||
for (const name of applied) written.push(`${vault.name}:${name}`);
|
||||
}
|
||||
results.push({ ...base, status: "rotated", written, publicKey: replacement.publicKey });
|
||||
results.push({ ...base, status: "rotated", written, publicKey: replacement.publicKey, apps: await resealAppGrants(team, p.fingerprint) });
|
||||
} catch (err) {
|
||||
// A login wall or a person at the desk is not a failure: that key waits, the others go on.
|
||||
const status = err instanceof DesktopError && (err.code === "needs-login" || err.code === "busy") ? err.code : "failed";
|
||||
|
|
@ -725,7 +768,8 @@ export async function teamsRotateKeysAction(slug: string, filter: RotationFilter
|
|||
next: r.status === "todo" ? (r.error ?? r.url ?? "see --format json") : r.error ?? r.note ?? ""
|
||||
}))
|
||||
);
|
||||
for (const r of results.filter((x) => x.publicKey)) console.error(`\n${r.key} new public key (install it, remove the old one):\n${r.publicKey}`);
|
||||
for (const r of results.filter((x) => x.apps?.length)) console.error(`${r.key} apps: ${r.apps!.join("; ")}`);
|
||||
for (const r of results.filter((x) => x.publicKey)) console.error(`\n${r.key} new public key (install it, remove the old one):\n${r.publicKey}`);
|
||||
const todo = results.filter((r) => r.status === "todo").length;
|
||||
const waiting = results.filter((r) => r.status === "needs-login" || r.status === "busy");
|
||||
if (waiting.length) console.error(`\n${waiting.length} desktop key(s) waiting: ${waiting.map((r) => `${r.key} (${r.status})`).join(", ")}. Sign in in the desktop's agent browser / wait until the desk is free, then run again.`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue