@coffre/conformance 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{idp-BeOsuZ3p.js → idp-Dyaj6k5N.js} +2 -2
- package/dist/idp.d.ts +2 -2
- package/dist/idp.js +1 -1
- package/dist/main.js +207 -50
- package/package.json +4 -4
- package/src/checks/cli.ts +83 -15
- package/src/checks/workloads.ts +17 -15
- package/src/harness.ts +10 -6
- package/src/idp/workloads.ts +2 -2
- package/src/suite.ts +2 -1
|
@@ -907,8 +907,8 @@ var OidcProvider = class {
|
|
|
907
907
|
* `permissions: id-token: write`, to the bearer of `requestToken`. Locally,
|
|
908
908
|
* `POST /workloads/token` mints one, for trying the CLI by hand:
|
|
909
909
|
*
|
|
910
|
-
*
|
|
911
|
-
*
|
|
910
|
+
* curl -s -X POST http://127.0.0.1:8081/workloads/token -d aud=http://127.0.0.1:3000 | jq -r .token |
|
|
911
|
+
* coffre login http://127.0.0.1:3000 --service <name> --id-token
|
|
912
912
|
*/
|
|
913
913
|
var WorkloadIssuer = class {
|
|
914
914
|
#origin;
|
package/dist/idp.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ interface Route {
|
|
|
21
21
|
* `permissions: id-token: write`, to the bearer of `requestToken`. Locally,
|
|
22
22
|
* `POST /workloads/token` mints one, for trying the CLI by hand:
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* curl -s -X POST http://127.0.0.1:8081/workloads/token -d aud=http://127.0.0.1:3000 | jq -r .token |
|
|
25
|
+
* coffre login http://127.0.0.1:3000 --service <name> --id-token
|
|
26
26
|
*/
|
|
27
27
|
export declare class WorkloadIssuer {
|
|
28
28
|
#private;
|
package/dist/idp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PERSONAS, i as WorkloadIssuer, n as DevIdp, r as GITHUB_RUN, t as DEFAULT_CLIENT } from "./idp-
|
|
1
|
+
import { a as PERSONAS, i as WorkloadIssuer, n as DevIdp, r as GITHUB_RUN, t as DEFAULT_CLIENT } from "./idp-Dyaj6k5N.js";
|
|
2
2
|
export { DEFAULT_CLIENT, DevIdp, GITHUB_RUN, PERSONAS, WorkloadIssuer };
|
package/dist/main.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { n as DevIdp, o as defaultGitHubAccount, r as GITHUB_RUN } from "./idp-
|
|
1
|
+
import { n as DevIdp, o as defaultGitHubAccount, r as GITHUB_RUN } from "./idp-Dyaj6k5N.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { delimiter, dirname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { inspect, parseArgs } from "node:util";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import { createHash, createHmac, createPrivateKey, hkdfSync, randomBytes, randomUUID, sign } from "node:crypto";
|
|
7
|
-
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { homedir, tmpdir } from "node:os";
|
|
9
9
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
10
10
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -364,7 +364,7 @@ async function boot(kind, at, options) {
|
|
|
364
364
|
const output = (tail = Infinity) => children.map((entry) => `--- ${entry.name}\n${Buffer.concat(entry.output).toString("utf8").slice(-tail)}`).join("\n");
|
|
365
365
|
const logs = () => output(4e3);
|
|
366
366
|
const alive = () => !children.some((entry) => entry.daemon && entry.exited);
|
|
367
|
-
function start(name, command, args, env, daemon = true) {
|
|
367
|
+
function start(name, command, args, env, daemon = true, input) {
|
|
368
368
|
const child = spawn(command, args, {
|
|
369
369
|
cwd: dir,
|
|
370
370
|
env: {
|
|
@@ -373,11 +373,15 @@ async function boot(kind, at, options) {
|
|
|
373
373
|
},
|
|
374
374
|
detached: true,
|
|
375
375
|
stdio: [
|
|
376
|
-
"ignore",
|
|
376
|
+
input === void 0 ? "ignore" : "pipe",
|
|
377
377
|
"pipe",
|
|
378
378
|
"pipe"
|
|
379
379
|
]
|
|
380
380
|
});
|
|
381
|
+
if (input !== void 0) {
|
|
382
|
+
child.stdin.on("error", () => {});
|
|
383
|
+
child.stdin.end(input);
|
|
384
|
+
}
|
|
381
385
|
const entry = {
|
|
382
386
|
name,
|
|
383
387
|
child,
|
|
@@ -395,8 +399,8 @@ async function boot(kind, at, options) {
|
|
|
395
399
|
children.push(entry);
|
|
396
400
|
return entry;
|
|
397
401
|
}
|
|
398
|
-
async function run(command, args, env = {}) {
|
|
399
|
-
const entry = start(args[0] ?? command, command, args, env, false);
|
|
402
|
+
async function run(command, args, env = {}, input) {
|
|
403
|
+
const entry = start(args[0] ?? command, command, args, env, false, input);
|
|
400
404
|
if (await new Promise((done) => {
|
|
401
405
|
entry.child.once("exit", done);
|
|
402
406
|
entry.child.once("error", done);
|
|
@@ -452,7 +456,7 @@ async function boot(kind, at, options) {
|
|
|
452
456
|
deploymentCli(dir),
|
|
453
457
|
"migrate",
|
|
454
458
|
"--yes"
|
|
455
|
-
], {
|
|
459
|
+
], {}, `${owner}\n`);
|
|
456
460
|
await run(bin("vite"), ["build", "app"]);
|
|
457
461
|
const state = join(scratch, "state");
|
|
458
462
|
start("wrangler", bin("wrangler"), [
|
|
@@ -2242,16 +2246,19 @@ function marks(output) {
|
|
|
2242
2246
|
/** The token's run, from CI: as no one, then as the token, which is no owner and skips verification. */
|
|
2243
2247
|
async function verifyWithToken(cli, live) {
|
|
2244
2248
|
const { canary } = live;
|
|
2249
|
+
const login = await cli.run([
|
|
2250
|
+
"login",
|
|
2251
|
+
cli.origin,
|
|
2252
|
+
"--token"
|
|
2253
|
+
], {}, `${live.token}\n`);
|
|
2254
|
+
expect(login.code === 0, `coffre login --token exited ${login.code}`, login.output);
|
|
2245
2255
|
const run = await cli.run([
|
|
2246
2256
|
"verify",
|
|
2247
2257
|
"instance",
|
|
2248
2258
|
cli.origin,
|
|
2249
2259
|
"--canary",
|
|
2250
2260
|
`${canary.project}/${canary.environment}/${canary.key}`
|
|
2251
|
-
], {
|
|
2252
|
-
COFFRE_TOKEN: live.token,
|
|
2253
|
-
COFFRE_CONFORMANCE_CANARY: canary.value
|
|
2254
|
-
});
|
|
2261
|
+
], {}, `${canary.value}\n`);
|
|
2255
2262
|
const seen = marks(run.output);
|
|
2256
2263
|
expect(run.code === 0, `coffre verify instance with a token exited ${run.code}`, run.output);
|
|
2257
2264
|
expect(seen["token verification"] === "–", "a token that is no owner did not skip verification", run.output);
|
|
@@ -2351,24 +2358,22 @@ async function verifyLeftovers(cli, admin, setups, before, kept) {
|
|
|
2351
2358
|
return `the second run found all; ${PROBE.service} holds no credential; the CLI's session signed in; ${place}/${kept.key} untouched; nothing else changed; ${entries.length} entries by ${PROBE.service} stay`;
|
|
2352
2359
|
}
|
|
2353
2360
|
/**
|
|
2354
|
-
* `coffre verify keys`, with the admin's session: this
|
|
2355
|
-
* pass
|
|
2356
|
-
*
|
|
2361
|
+
* `coffre verify keys`, with the admin's session, the keys piped in: this
|
|
2362
|
+
* deployment's pass; a wrong vault key fails and the right app key passes;
|
|
2363
|
+
* a malformed app key fails. No key is ever printed.
|
|
2357
2364
|
*/
|
|
2358
2365
|
async function verifyKeys(cli) {
|
|
2359
2366
|
const wrong = Buffer.alloc(32, 7).toString("base64");
|
|
2360
2367
|
const runs = [
|
|
2361
2368
|
{
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
COFFRE_APP_KEY: KEYS.APP_KEY,
|
|
2365
|
-
COFFRE_VAULT_KEY_ID: KEYS.VAULT_KEY_ID
|
|
2366
|
-
},
|
|
2369
|
+
args: ["--vault-id", KEYS.VAULT_KEY_ID],
|
|
2370
|
+
input: `${KEYS.VAULT_KEY}\n${KEYS.APP_KEY}\n`,
|
|
2367
2371
|
code: 0,
|
|
2368
2372
|
vault: "✓",
|
|
2369
2373
|
app: "✓"
|
|
2370
2374
|
},
|
|
2371
2375
|
{
|
|
2376
|
+
args: [],
|
|
2372
2377
|
input: `${wrong}\n${KEYS.APP_KEY}\n`,
|
|
2373
2378
|
code: 1,
|
|
2374
2379
|
vault: "✗",
|
|
@@ -2376,18 +2381,20 @@ async function verifyKeys(cli) {
|
|
|
2376
2381
|
said: /✗ vault key +not this instance's vault key/
|
|
2377
2382
|
},
|
|
2378
2383
|
{
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
COFFRE_APP_KEY: "not-a-key"
|
|
2382
|
-
},
|
|
2384
|
+
args: [],
|
|
2385
|
+
input: `${KEYS.VAULT_KEY}\nnot-a-key\n`,
|
|
2383
2386
|
code: 1,
|
|
2384
2387
|
vault: "✓",
|
|
2385
2388
|
app: "✗",
|
|
2386
2389
|
said: /✗ app key +not an app key/
|
|
2387
2390
|
}
|
|
2388
2391
|
];
|
|
2389
|
-
for (const {
|
|
2390
|
-
const run = await cli.run([
|
|
2392
|
+
for (const { args, input, code, vault, app, said } of runs) {
|
|
2393
|
+
const run = await cli.run([
|
|
2394
|
+
"verify",
|
|
2395
|
+
"keys",
|
|
2396
|
+
...args
|
|
2397
|
+
], {}, input);
|
|
2391
2398
|
const seen = marks(run.output);
|
|
2392
2399
|
expect(run.code === code && seen["vault key"] === vault && seen["app key"] === app, `coffre verify keys exited ${run.code}`, run.output);
|
|
2393
2400
|
if (said !== void 0) expect(said.test(run.output), "it did not say which key is not right", run.output);
|
|
@@ -2400,6 +2407,146 @@ async function verifyKeys(cli) {
|
|
|
2400
2407
|
}
|
|
2401
2408
|
return "this deployment's keys pass, vault ID included; a wrong vault key and a malformed app key are each named; no key shown";
|
|
2402
2409
|
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Everything the API does, the CLI does: with the admin's `coffre login`
|
|
2412
|
+
* session, a project and its environment, a secret set and renamed, a
|
|
2413
|
+
* service admitted and granted, a token issued into a 0600 file, then
|
|
2414
|
+
* piped to `coffre login --token` in a CLI of the service's own, read
|
|
2415
|
+
* with, revoked after its preview, and refused from then on; the grant
|
|
2416
|
+
* revoked, the secret and the project archived. No token shows in what
|
|
2417
|
+
* either prints.
|
|
2418
|
+
*/
|
|
2419
|
+
async function manageByCli(cli) {
|
|
2420
|
+
const steps = [];
|
|
2421
|
+
const ci = new Cli(cli.origin);
|
|
2422
|
+
const as = (who, label) => async (args, input, code = 0) => {
|
|
2423
|
+
const run = await who.run(args, {}, input);
|
|
2424
|
+
expect(run.code === code, `coffre ${args.join(" ")}${label} exited ${run.code}, not ${code}`, run.output);
|
|
2425
|
+
steps.push(`${args.slice(0, 2).join(" ")}${label}`);
|
|
2426
|
+
return run.output;
|
|
2427
|
+
};
|
|
2428
|
+
const [coffre, service] = [as(cli, ""), as(ci, ", as the service")];
|
|
2429
|
+
try {
|
|
2430
|
+
const value = `cli-value-${randomBytes(8).toString("hex")}`;
|
|
2431
|
+
await coffre([
|
|
2432
|
+
"projects",
|
|
2433
|
+
"create",
|
|
2434
|
+
"conformance-cli",
|
|
2435
|
+
"--name",
|
|
2436
|
+
"CLI"
|
|
2437
|
+
]);
|
|
2438
|
+
await coffre([
|
|
2439
|
+
"environments",
|
|
2440
|
+
"create",
|
|
2441
|
+
"conformance-cli/ci"
|
|
2442
|
+
]);
|
|
2443
|
+
await coffre(["set", "conformance-cli/ci/API_KEY"], value);
|
|
2444
|
+
await coffre([
|
|
2445
|
+
"rename",
|
|
2446
|
+
"conformance-cli/ci/API_KEY",
|
|
2447
|
+
"API_TOKEN"
|
|
2448
|
+
]);
|
|
2449
|
+
const refused = await coffre([
|
|
2450
|
+
"grant",
|
|
2451
|
+
"conformance-cli",
|
|
2452
|
+
"conformance-deploy",
|
|
2453
|
+
"--role",
|
|
2454
|
+
"viewer",
|
|
2455
|
+
"--env",
|
|
2456
|
+
"ci",
|
|
2457
|
+
"--service"
|
|
2458
|
+
], void 0, 1);
|
|
2459
|
+
expect(refused.includes("admit them first, `coffre admit conformance-deploy --service`"), "grant to a service not yet admitted did not say to admit it", refused);
|
|
2460
|
+
const admitted = await coffre([
|
|
2461
|
+
"admit",
|
|
2462
|
+
"conformance-deploy",
|
|
2463
|
+
"--service"
|
|
2464
|
+
]);
|
|
2465
|
+
expect(admitted.includes("next: coffre grant <project> conformance-deploy"), "admit --service did not say what comes next", admitted);
|
|
2466
|
+
await coffre([
|
|
2467
|
+
"grant",
|
|
2468
|
+
"conformance-cli",
|
|
2469
|
+
"conformance-deploy",
|
|
2470
|
+
"--role",
|
|
2471
|
+
"viewer",
|
|
2472
|
+
"--env",
|
|
2473
|
+
"ci",
|
|
2474
|
+
"--service"
|
|
2475
|
+
]);
|
|
2476
|
+
const file = join(cli.home, "ci-token");
|
|
2477
|
+
const wrote = await coffre([
|
|
2478
|
+
"tokens",
|
|
2479
|
+
"issue",
|
|
2480
|
+
"conformance-deploy",
|
|
2481
|
+
"--label",
|
|
2482
|
+
"conformance",
|
|
2483
|
+
"--expires-in",
|
|
2484
|
+
"1",
|
|
2485
|
+
"--output-file",
|
|
2486
|
+
file
|
|
2487
|
+
]);
|
|
2488
|
+
const token = readFileSync(file, "utf8").trim();
|
|
2489
|
+
expect(/^coffre_svc_/.test(token) && (statSync(file).mode & 511) === 384, "the token file is not a 0600 file holding a service token", statSync(file).mode);
|
|
2490
|
+
expect(!wrote.includes(token), "tokens issue --output-file printed the token");
|
|
2491
|
+
expect(!(await service([
|
|
2492
|
+
"login",
|
|
2493
|
+
cli.origin,
|
|
2494
|
+
"--token"
|
|
2495
|
+
], `${token}\n`)).includes(token), "coffre login --token printed the token");
|
|
2496
|
+
const read = await service(["get", "conformance-cli/ci/API_TOKEN"]);
|
|
2497
|
+
expect(read.trim() === value, "the issued token did not read the renamed secret", read);
|
|
2498
|
+
const [listed] = JSON.parse(await coffre([
|
|
2499
|
+
"tokens",
|
|
2500
|
+
"conformance-deploy",
|
|
2501
|
+
"--json"
|
|
2502
|
+
]));
|
|
2503
|
+
expect(listed?.label === "conformance", "tokens --json does not list the issued token", listed);
|
|
2504
|
+
const preview = await coffre([
|
|
2505
|
+
"tokens",
|
|
2506
|
+
"revoke",
|
|
2507
|
+
"conformance-deploy",
|
|
2508
|
+
listed.id
|
|
2509
|
+
]);
|
|
2510
|
+
expect(/Nothing changed\. Re-run with --apply/.test(preview), "tokens revoke without --apply did not preview", preview);
|
|
2511
|
+
await service(["get", "conformance-cli/ci/API_TOKEN"]);
|
|
2512
|
+
await coffre([
|
|
2513
|
+
"tokens",
|
|
2514
|
+
"revoke",
|
|
2515
|
+
"conformance-deploy",
|
|
2516
|
+
listed.id,
|
|
2517
|
+
"--apply"
|
|
2518
|
+
]);
|
|
2519
|
+
const gone = await service(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
|
|
2520
|
+
expect(/does not know this service token/.test(gone), "a revoked token was not refused plainly", gone);
|
|
2521
|
+
await coffre([
|
|
2522
|
+
"revoke",
|
|
2523
|
+
"conformance-cli",
|
|
2524
|
+
"conformance-deploy",
|
|
2525
|
+
"--env",
|
|
2526
|
+
"ci",
|
|
2527
|
+
"--service"
|
|
2528
|
+
]);
|
|
2529
|
+
await coffre(["archive", "conformance-cli/ci/API_TOKEN"]);
|
|
2530
|
+
const keys = JSON.parse(await coffre([
|
|
2531
|
+
"list",
|
|
2532
|
+
"conformance-cli/ci",
|
|
2533
|
+
"--json"
|
|
2534
|
+
]));
|
|
2535
|
+
expect(keys.length === 1 && keys[0].key === "API_TOKEN" && keys[0].archived, "the renamed secret is not listed, archived", keys);
|
|
2536
|
+
await coffre([
|
|
2537
|
+
"projects",
|
|
2538
|
+
"archive",
|
|
2539
|
+
"conformance-cli"
|
|
2540
|
+
]);
|
|
2541
|
+
const projects = JSON.parse(await coffre(["projects", "--json"]));
|
|
2542
|
+
expect(projects.find(({ slug }) => slug === "conformance-cli")?.archivedAt !== null, "the project is not archived", projects);
|
|
2543
|
+
const sessions = JSON.parse(await coffre(["sessions", "--json"]));
|
|
2544
|
+
expect(sessions.some(({ kind, current }) => kind === "cli" && current), "sessions --json does not mark this CLI's session", sessions);
|
|
2545
|
+
return `${steps.length} commands: ${[...new Set(steps)].join(", ")}; the token only in its 0600 file and piped to login, refused once revoked`;
|
|
2546
|
+
} finally {
|
|
2547
|
+
ci.remove();
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2403
2550
|
//#endregion
|
|
2404
2551
|
//#region src/chrome.ts
|
|
2405
2552
|
const NAMES = [
|
|
@@ -2912,38 +3059,47 @@ async function runsRefused(deployment, admin) {
|
|
|
2912
3059
|
return `${cases.length + 1} refused, each for its reason, none saying what the binding expects, none logged: ${cases.map(([what]) => what).join(", ")}, for another service`;
|
|
2913
3060
|
}
|
|
2914
3061
|
/**
|
|
2915
|
-
* The CLI, as a CI job runs it
|
|
2916
|
-
*
|
|
2917
|
-
*
|
|
3062
|
+
* The CLI, as a CI job runs it, as a service by its ID token: on GitHub
|
|
3063
|
+
* Actions, `--service` and the runner's token endpoint, nothing else and
|
|
3064
|
+
* nothing kept; elsewhere, the token piped to `coffre login --service
|
|
3065
|
+
* --id-token`, whose credential the next command uses. No token printed.
|
|
2918
3066
|
*/
|
|
2919
3067
|
async function cliSignsIn(deployment, canaries) {
|
|
2920
3068
|
const issuer = deployment.idp.workloads;
|
|
2921
3069
|
const cli = new Cli(deployment.origin);
|
|
2922
3070
|
try {
|
|
2923
|
-
const
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
"on GitHub Actions": {
|
|
2930
|
-
...base,
|
|
2931
|
-
ACTIONS_ID_TOKEN_REQUEST_URL: issuer.requestUrl,
|
|
2932
|
-
ACTIONS_ID_TOKEN_REQUEST_TOKEN: issuer.requestToken
|
|
2933
|
-
},
|
|
2934
|
-
"with COFFRE_ID_TOKEN": {
|
|
2935
|
-
...base,
|
|
2936
|
-
COFFRE_ID_TOKEN: given
|
|
2937
|
-
}
|
|
2938
|
-
};
|
|
2939
|
-
for (const [where, env] of Object.entries(runs)) {
|
|
2940
|
-
const run = await cli.run(["get", `${DEV}/API_KEY`], env);
|
|
3071
|
+
const read = async (where, args, env, secrets) => {
|
|
3072
|
+
const run = await cli.run([
|
|
3073
|
+
...args,
|
|
3074
|
+
"get",
|
|
3075
|
+
`${DEV}/API_KEY`
|
|
3076
|
+
], env);
|
|
2941
3077
|
expect(run.code === 0, `coffre get ${where} exited ${run.code}`, run.output);
|
|
2942
3078
|
expect(run.output.trim() === canaries[`${DEV}/API_KEY`], `coffre get ${where} did not print the value`);
|
|
2943
|
-
expect(!
|
|
2944
|
-
}
|
|
2945
|
-
|
|
2946
|
-
|
|
3079
|
+
expect(!secrets.some((secret) => run.output.includes(secret)) && !/coffre_svc_/.test(run.output), `coffre get ${where} printed a token`);
|
|
3080
|
+
};
|
|
3081
|
+
await read("on GitHub Actions", [
|
|
3082
|
+
"--url",
|
|
3083
|
+
deployment.origin,
|
|
3084
|
+
"--service",
|
|
3085
|
+
RUNNER
|
|
3086
|
+
], {
|
|
3087
|
+
ACTIONS_ID_TOKEN_REQUEST_URL: issuer.requestUrl,
|
|
3088
|
+
ACTIONS_ID_TOKEN_REQUEST_TOKEN: issuer.requestToken
|
|
3089
|
+
}, [issuer.requestToken]);
|
|
3090
|
+
expect(!existsSync(join(cli.home, ".coffre", "credentials.json")), "the CLI kept a credential on disk, for one command");
|
|
3091
|
+
const given = await mint(deployment);
|
|
3092
|
+
const login = await cli.run([
|
|
3093
|
+
"login",
|
|
3094
|
+
deployment.origin,
|
|
3095
|
+
"--service",
|
|
3096
|
+
RUNNER,
|
|
3097
|
+
"--id-token"
|
|
3098
|
+
], {}, `${given}\n`);
|
|
3099
|
+
expect(login.code === 0, `coffre login --service --id-token exited ${login.code}`, login.output);
|
|
3100
|
+
expect(!login.output.includes(given) && !/coffre_svc_/.test(login.output), "coffre login --service printed a token");
|
|
3101
|
+
await read("after coffre login --service --id-token", [], {}, [given]);
|
|
3102
|
+
return `\`coffre --service ${RUNNER} get\` on GitHub Actions, nothing kept; \`coffre login --service --id-token\` with the token piped in, then \`coffre get\`; no token printed`;
|
|
2947
3103
|
} finally {
|
|
2948
3104
|
cli.remove();
|
|
2949
3105
|
}
|
|
@@ -3053,6 +3209,7 @@ async function conform(deployment, options) {
|
|
|
3053
3209
|
live
|
|
3054
3210
|
}, ({ admin, owner, before, first, second, live }) => verifyLeftovers(owner, admin, [first, second], before, live.canary));
|
|
3055
3211
|
await report.check("verify keys", { owner }, ({ owner }) => verifyKeys(owner));
|
|
3212
|
+
await report.check("manage by CLI", { owner }, ({ owner }) => manageByCli(owner));
|
|
3056
3213
|
} finally {
|
|
3057
3214
|
for (const cli of clis) cli.remove();
|
|
3058
3215
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffre/conformance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Checks a coffre deployment from outside: what it must never do, whatever code it runs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jose": "6.2.3",
|
|
33
33
|
"pg": "8.16.3",
|
|
34
|
-
"@coffre/cli": "0.
|
|
35
|
-
"@coffre/db": "0.
|
|
34
|
+
"@coffre/cli": "0.3.0",
|
|
35
|
+
"@coffre/db": "0.3.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "26.1.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tsdown": "0.23.0",
|
|
42
42
|
"typescript": "5.9.3",
|
|
43
43
|
"vite": "8.1.5",
|
|
44
|
-
"@coffre/client": "0.
|
|
44
|
+
"@coffre/client": "0.3.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsdown",
|
package/src/checks/cli.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// `coffre verify`, as an operator runs it against this deployment: the
|
|
2
2
|
// CLI's own entry, as @coffre/cli ships it, in a child process with a home
|
|
3
3
|
// of its own and none of this process's COFFRE_ variables. `verify
|
|
4
|
-
// instance` with a token from CI
|
|
4
|
+
// instance` with a token from CI, signed in with `coffre login --token`; with `coffre login`, as a user,
|
|
5
5
|
// who is turned away, and as the admin, twice, then interrupted, its
|
|
6
6
|
// session left signed in each time; and `verify keys` with this
|
|
7
7
|
// deployment's keys, a wrong one and a malformed one.
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
|
-
import {
|
|
9
|
+
import { randomBytes } from 'node:crypto';
|
|
10
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
10
11
|
import { createRequire } from 'node:module';
|
|
11
12
|
import { tmpdir } from 'node:os';
|
|
12
13
|
import { dirname, join } from 'node:path';
|
|
@@ -117,10 +118,10 @@ function marks(output: string): Record<string, string> {
|
|
|
117
118
|
/** The token's run, from CI: as no one, then as the token, which is no owner and skips verification. */
|
|
118
119
|
export async function verifyWithToken(cli: Cli, live: { token: string; canary: Canary }): Promise<string> {
|
|
119
120
|
const { canary } = live;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
121
|
+
// As a CI step does: the token piped to `coffre login --token`, then the canary's value to the check.
|
|
122
|
+
const login = await cli.run(['login', cli.origin, '--token'], {}, `${live.token}\n`);
|
|
123
|
+
expect(login.code === 0, `coffre login --token exited ${login.code}`, login.output);
|
|
124
|
+
const run = await cli.run(['verify', 'instance', cli.origin, '--canary', `${canary.project}/${canary.environment}/${canary.key}`], {}, `${canary.value}\n`);
|
|
124
125
|
const seen = marks(run.output);
|
|
125
126
|
expect(run.code === 0, `coffre verify instance with a token exited ${run.code}`, run.output);
|
|
126
127
|
expect(seen['token verification'] === '–', 'a token that is no owner did not skip verification', run.output);
|
|
@@ -219,19 +220,20 @@ export async function verifyLeftovers(cli: Cli, admin: Person, setups: string[],
|
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
/**
|
|
222
|
-
* `coffre verify keys`, with the admin's session: this
|
|
223
|
-
* pass
|
|
224
|
-
*
|
|
223
|
+
* `coffre verify keys`, with the admin's session, the keys piped in: this
|
|
224
|
+
* deployment's pass; a wrong vault key fails and the right app key passes;
|
|
225
|
+
* a malformed app key fails. No key is ever printed.
|
|
225
226
|
*/
|
|
226
227
|
export async function verifyKeys(cli: Cli): Promise<string> {
|
|
227
228
|
const wrong = Buffer.alloc(32, 7).toString('base64');
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
{ input: `${
|
|
231
|
-
{
|
|
229
|
+
// Piped in, as a script does: the vault key's line, then the app key's.
|
|
230
|
+
const runs: { args: string[]; input: string; code: number; vault: string; app: string; said?: RegExp }[] = [
|
|
231
|
+
{ args: ['--vault-id', KEYS.VAULT_KEY_ID], input: `${KEYS.VAULT_KEY}\n${KEYS.APP_KEY}\n`, code: 0, vault: '✓', app: '✓' },
|
|
232
|
+
{ args: [], input: `${wrong}\n${KEYS.APP_KEY}\n`, code: 1, vault: '✗', app: '✓', said: /✗ vault key +not this instance's vault key/ },
|
|
233
|
+
{ args: [], input: `${KEYS.VAULT_KEY}\nnot-a-key\n`, code: 1, vault: '✓', app: '✗', said: /✗ app key +not an app key/ },
|
|
232
234
|
];
|
|
233
|
-
for (const {
|
|
234
|
-
const run = await cli.run(['verify', 'keys'],
|
|
235
|
+
for (const { args, input, code, vault, app, said } of runs) {
|
|
236
|
+
const run = await cli.run(['verify', 'keys', ...args], {}, input);
|
|
235
237
|
const seen = marks(run.output);
|
|
236
238
|
expect(run.code === code && seen['vault key'] === vault && seen['app key'] === app, `coffre verify keys exited ${run.code}`, run.output);
|
|
237
239
|
if (said !== undefined) expect(said.test(run.output), 'it did not say which key is not right', run.output);
|
|
@@ -239,3 +241,69 @@ export async function verifyKeys(cli: Cli): Promise<string> {
|
|
|
239
241
|
}
|
|
240
242
|
return "this deployment's keys pass, vault ID included; a wrong vault key and a malformed app key are each named; no key shown";
|
|
241
243
|
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Everything the API does, the CLI does: with the admin's `coffre login`
|
|
247
|
+
* session, a project and its environment, a secret set and renamed, a
|
|
248
|
+
* service admitted and granted, a token issued into a 0600 file, then
|
|
249
|
+
* piped to `coffre login --token` in a CLI of the service's own, read
|
|
250
|
+
* with, revoked after its preview, and refused from then on; the grant
|
|
251
|
+
* revoked, the secret and the project archived. No token shows in what
|
|
252
|
+
* either prints.
|
|
253
|
+
*/
|
|
254
|
+
export async function manageByCli(cli: Cli): Promise<string> {
|
|
255
|
+
const steps: string[] = [];
|
|
256
|
+
const ci = new Cli(cli.origin);
|
|
257
|
+
const as = (who: Cli, label: string) => async (args: string[], input?: string, code = 0): Promise<string> => {
|
|
258
|
+
const run = await who.run(args, {}, input);
|
|
259
|
+
expect(run.code === code, `coffre ${args.join(' ')}${label} exited ${run.code}, not ${code}`, run.output);
|
|
260
|
+
steps.push(`${args.slice(0, 2).join(' ')}${label}`);
|
|
261
|
+
return run.output;
|
|
262
|
+
};
|
|
263
|
+
const [coffre, service] = [as(cli, ''), as(ci, ', as the service')];
|
|
264
|
+
try {
|
|
265
|
+
const value = `cli-value-${randomBytes(8).toString('hex')}`;
|
|
266
|
+
await coffre(['projects', 'create', 'conformance-cli', '--name', 'CLI']);
|
|
267
|
+
await coffre(['environments', 'create', 'conformance-cli/ci']);
|
|
268
|
+
await coffre(['set', 'conformance-cli/ci/API_KEY'], value);
|
|
269
|
+
await coffre(['rename', 'conformance-cli/ci/API_KEY', 'API_TOKEN']);
|
|
270
|
+
const refused = await coffre(['grant', 'conformance-cli', 'conformance-deploy', '--role', 'viewer', '--env', 'ci', '--service'], undefined, 1);
|
|
271
|
+
expect(refused.includes('admit them first, `coffre admit conformance-deploy --service`'), 'grant to a service not yet admitted did not say to admit it', refused);
|
|
272
|
+
const admitted = await coffre(['admit', 'conformance-deploy', '--service']);
|
|
273
|
+
expect(admitted.includes('next: coffre grant <project> conformance-deploy'), 'admit --service did not say what comes next', admitted);
|
|
274
|
+
await coffre(['grant', 'conformance-cli', 'conformance-deploy', '--role', 'viewer', '--env', 'ci', '--service']);
|
|
275
|
+
|
|
276
|
+
const file = join(cli.home, 'ci-token');
|
|
277
|
+
const wrote = await coffre(['tokens', 'issue', 'conformance-deploy', '--label', 'conformance', '--expires-in', '1', '--output-file', file]);
|
|
278
|
+
const token = readFileSync(file, 'utf8').trim();
|
|
279
|
+
expect(/^coffre_svc_/.test(token) && (statSync(file).mode & 0o777) === 0o600, 'the token file is not a 0600 file holding a service token', statSync(file).mode);
|
|
280
|
+
expect(!wrote.includes(token), 'tokens issue --output-file printed the token');
|
|
281
|
+
// The token as CI uses it: piped to `coffre login --token`.
|
|
282
|
+
const signedIn = await service(['login', cli.origin, '--token'], `${token}\n`);
|
|
283
|
+
expect(!signedIn.includes(token), 'coffre login --token printed the token');
|
|
284
|
+
const read = await service(['get', 'conformance-cli/ci/API_TOKEN']);
|
|
285
|
+
expect(read.trim() === value, 'the issued token did not read the renamed secret', read);
|
|
286
|
+
|
|
287
|
+
const [listed] = JSON.parse(await coffre(['tokens', 'conformance-deploy', '--json'])) as { id: string; label: string }[];
|
|
288
|
+
expect(listed?.label === 'conformance', 'tokens --json does not list the issued token', listed);
|
|
289
|
+
const preview = await coffre(['tokens', 'revoke', 'conformance-deploy', listed!.id]);
|
|
290
|
+
expect(/Nothing changed\. Re-run with --apply/.test(preview), 'tokens revoke without --apply did not preview', preview);
|
|
291
|
+
await service(['get', 'conformance-cli/ci/API_TOKEN']);
|
|
292
|
+
await coffre(['tokens', 'revoke', 'conformance-deploy', listed!.id, '--apply']);
|
|
293
|
+
const gone = await service(['get', 'conformance-cli/ci/API_TOKEN'], undefined, 1);
|
|
294
|
+
expect(/does not know this service token/.test(gone), 'a revoked token was not refused plainly', gone);
|
|
295
|
+
|
|
296
|
+
await coffre(['revoke', 'conformance-cli', 'conformance-deploy', '--env', 'ci', '--service']);
|
|
297
|
+
await coffre(['archive', 'conformance-cli/ci/API_TOKEN']);
|
|
298
|
+
const keys = JSON.parse(await coffre(['list', 'conformance-cli/ci', '--json'])) as { key: string; archived: boolean }[];
|
|
299
|
+
expect(keys.length === 1 && keys[0]!.key === 'API_TOKEN' && keys[0]!.archived, 'the renamed secret is not listed, archived', keys);
|
|
300
|
+
await coffre(['projects', 'archive', 'conformance-cli']);
|
|
301
|
+
const projects = JSON.parse(await coffre(['projects', '--json'])) as { slug: string; archivedAt: string | null }[];
|
|
302
|
+
expect(projects.find(({ slug }) => slug === 'conformance-cli')?.archivedAt !== null, 'the project is not archived', projects);
|
|
303
|
+
const sessions = JSON.parse(await coffre(['sessions', '--json'])) as { kind: string; current: boolean }[];
|
|
304
|
+
expect(sessions.some(({ kind, current }) => kind === 'cli' && current), "sessions --json does not mark this CLI's session", sessions);
|
|
305
|
+
return `${steps.length} commands: ${[...new Set(steps)].join(', ')}; the token only in its 0600 file and piped to login, refused once revoked`;
|
|
306
|
+
} finally {
|
|
307
|
+
ci.remove();
|
|
308
|
+
}
|
|
309
|
+
}
|
package/src/checks/workloads.ts
CHANGED
|
@@ -149,28 +149,30 @@ export async function runsRefused(deployment: Deployment, admin: Person): Promis
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
|
-
* The CLI, as a CI job runs it
|
|
153
|
-
*
|
|
154
|
-
*
|
|
152
|
+
* The CLI, as a CI job runs it, as a service by its ID token: on GitHub
|
|
153
|
+
* Actions, `--service` and the runner's token endpoint, nothing else and
|
|
154
|
+
* nothing kept; elsewhere, the token piped to `coffre login --service
|
|
155
|
+
* --id-token`, whose credential the next command uses. No token printed.
|
|
155
156
|
*/
|
|
156
157
|
export async function cliSignsIn(deployment: Deployment, canaries: Canaries): Promise<string> {
|
|
157
158
|
const issuer = deployment.idp.workloads;
|
|
158
159
|
const cli = new Cli(deployment.origin);
|
|
159
160
|
try {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
const runs = {
|
|
163
|
-
'on GitHub Actions': { ...base, ACTIONS_ID_TOKEN_REQUEST_URL: issuer.requestUrl, ACTIONS_ID_TOKEN_REQUEST_TOKEN: issuer.requestToken },
|
|
164
|
-
'with COFFRE_ID_TOKEN': { ...base, COFFRE_ID_TOKEN: given },
|
|
165
|
-
};
|
|
166
|
-
for (const [where, env] of Object.entries(runs)) {
|
|
167
|
-
const run = await cli.run(['get', `${DEV}/API_KEY`], env);
|
|
161
|
+
const read = async (where: string, args: string[], env: Record<string, string>, secrets: string[]) => {
|
|
162
|
+
const run = await cli.run([...args, 'get', `${DEV}/API_KEY`], env);
|
|
168
163
|
expect(run.code === 0, `coffre get ${where} exited ${run.code}`, run.output);
|
|
169
164
|
expect(run.output.trim() === canaries[`${DEV}/API_KEY`], `coffre get ${where} did not print the value`);
|
|
170
|
-
expect(!
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
165
|
+
expect(!secrets.some((secret) => run.output.includes(secret)) && !/coffre_svc_/.test(run.output), `coffre get ${where} printed a token`);
|
|
166
|
+
};
|
|
167
|
+
await read('on GitHub Actions', ['--url', deployment.origin, '--service', RUNNER], { ACTIONS_ID_TOKEN_REQUEST_URL: issuer.requestUrl, ACTIONS_ID_TOKEN_REQUEST_TOKEN: issuer.requestToken }, [issuer.requestToken]);
|
|
168
|
+
expect(!existsSync(join(cli.home, '.coffre', 'credentials.json')), 'the CLI kept a credential on disk, for one command');
|
|
169
|
+
|
|
170
|
+
const given = await mint(deployment);
|
|
171
|
+
const login = await cli.run(['login', deployment.origin, '--service', RUNNER, '--id-token'], {}, `${given}\n`);
|
|
172
|
+
expect(login.code === 0, `coffre login --service --id-token exited ${login.code}`, login.output);
|
|
173
|
+
expect(!login.output.includes(given) && !/coffre_svc_/.test(login.output), 'coffre login --service printed a token');
|
|
174
|
+
await read('after coffre login --service --id-token', [], {}, [given]);
|
|
175
|
+
return `\`coffre --service ${RUNNER} get\` on GitHub Actions, nothing kept; \`coffre login --service --id-token\` with the token piped in, then \`coffre get\`; no token printed`;
|
|
174
176
|
} finally {
|
|
175
177
|
cli.remove();
|
|
176
178
|
}
|
package/src/harness.ts
CHANGED
|
@@ -110,14 +110,18 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
110
110
|
const logs = () => output(4000);
|
|
111
111
|
const alive = () => !children.some((entry) => entry.daemon && entry.exited);
|
|
112
112
|
|
|
113
|
-
function start(name: string, command: string, args: string[], env: Record<string, string>, daemon = true): Child {
|
|
113
|
+
function start(name: string, command: string, args: string[], env: Record<string, string>, daemon = true, input?: string): Child {
|
|
114
114
|
const child = spawn(command, args, {
|
|
115
115
|
cwd: dir,
|
|
116
116
|
env: { ...shell, ...env },
|
|
117
117
|
// Its own process group, so stopping it stops what it started (workerd).
|
|
118
118
|
detached: true,
|
|
119
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
119
|
+
stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],
|
|
120
120
|
});
|
|
121
|
+
if (input !== undefined) {
|
|
122
|
+
child.stdin!.on('error', () => {});
|
|
123
|
+
child.stdin!.end(input);
|
|
124
|
+
}
|
|
121
125
|
const entry: Child = { name, child, daemon, exited: false, output: [] };
|
|
122
126
|
child.stdout!.on('data', (chunk: Buffer) => entry.output.push(chunk));
|
|
123
127
|
child.stderr!.on('data', (chunk: Buffer) => entry.output.push(chunk));
|
|
@@ -131,8 +135,8 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
131
135
|
return entry;
|
|
132
136
|
}
|
|
133
137
|
|
|
134
|
-
async function run(command: string, args: string[], env: Record<string, string> = {}): Promise<void> {
|
|
135
|
-
const entry = start(args[0] ?? command, command, args, env, false);
|
|
138
|
+
async function run(command: string, args: string[], env: Record<string, string> = {}, input?: string): Promise<void> {
|
|
139
|
+
const entry = start(args[0] ?? command, command, args, env, false, input);
|
|
136
140
|
const code = await new Promise((done) => {
|
|
137
141
|
entry.child.once('exit', done);
|
|
138
142
|
entry.child.once('error', done);
|
|
@@ -198,9 +202,9 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
198
202
|
sql.exec(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`),
|
|
199
203
|
);
|
|
200
204
|
// As the deployment's pipeline does before it deploys: its own CLI's
|
|
201
|
-
// `coffre migrate`, in its folder, the owner's URL in
|
|
205
|
+
// `coffre migrate`, in its folder, the owner's URL piped in.
|
|
202
206
|
// A fresh log has no heartbeat: only the scheduled job can make /readyz pass.
|
|
203
|
-
await run(process.execPath, [deploymentCli(dir), 'migrate', '--yes'], {
|
|
207
|
+
await run(process.execPath, [deploymentCli(dir), 'migrate', '--yes'], {}, `${owner}\n`);
|
|
204
208
|
// The app as it deploys: its Start app, built by its own Vite, which wrangler runs unbundled.
|
|
205
209
|
await run(bin('vite'), ['build', 'app']);
|
|
206
210
|
const state = join(scratch, 'state');
|
package/src/idp/workloads.ts
CHANGED
|
@@ -16,8 +16,8 @@ import { readParams, sendJson, type Route } from './http.ts';
|
|
|
16
16
|
* `permissions: id-token: write`, to the bearer of `requestToken`. Locally,
|
|
17
17
|
* `POST /workloads/token` mints one, for trying the CLI by hand:
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* curl -s -X POST http://127.0.0.1:8081/workloads/token -d aud=http://127.0.0.1:3000 | jq -r .token |
|
|
20
|
+
* coffre login http://127.0.0.1:3000 --service <name> --id-token
|
|
21
21
|
*/
|
|
22
22
|
export class WorkloadIssuer {
|
|
23
23
|
readonly #origin: () => string;
|
package/src/suite.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { accessAuthorship, memberTampering, noAuditNoAccess, sealingRace } from
|
|
|
11
11
|
import { refusedCheckpoint, missingCheckpoint, middleCut } from './checks/readiness.ts';
|
|
12
12
|
import { editedGeneration, forgedCredential, forgedIdentity, forgedApproval } from './checks/signin.ts';
|
|
13
13
|
import { canaryScan } from './checks/canaries.ts';
|
|
14
|
-
import { Cli, cliLogin, verifyAsOwner, verifyAsUser, verifyInterrupted, verifyKeys, verifyLeftovers, verifyWithToken } from './checks/cli.ts';
|
|
14
|
+
import { Cli, cliLogin, manageByCli, verifyAsOwner, verifyAsUser, verifyInterrupted, verifyKeys, verifyLeftovers, verifyWithToken } from './checks/cli.ts';
|
|
15
15
|
import { pageLoad, personas, setUp, setUpLive, signInAdmin } from './checks/people.ts';
|
|
16
16
|
import { pagesInBrowser } from './checks/pages.ts';
|
|
17
17
|
import { browserBundle, headers, health } from './checks/surface.ts';
|
|
@@ -52,6 +52,7 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
|
|
|
52
52
|
verifyLeftovers(owner, admin, [first, second], before, live.canary),
|
|
53
53
|
);
|
|
54
54
|
await report.check('verify keys', { owner }, ({ owner }) => verifyKeys(owner));
|
|
55
|
+
await report.check('manage by CLI', { owner }, ({ owner }) => manageByCli(owner));
|
|
55
56
|
} finally {
|
|
56
57
|
for (const cli of clis) cli.remove();
|
|
57
58
|
}
|