@coffre/conformance 0.15.0 → 0.16.1
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/README.md +4 -6
- package/dist/main.js +968 -1336
- package/package.json +4 -4
- package/src/bundle.ts +7 -21
- package/src/checks/access.ts +14 -12
- package/src/checks/audit.ts +189 -295
- package/src/checks/canaries.ts +2 -15
- package/src/checks/cli.ts +39 -23
- package/src/checks/deletion.ts +18 -10
- package/src/checks/environments.ts +68 -49
- package/src/checks/logins.ts +32 -87
- package/src/checks/mcp.ts +83 -29
- package/src/checks/members.ts +127 -81
- package/src/checks/pages.ts +11 -17
- package/src/checks/people.ts +11 -0
- package/src/checks/signin.ts +25 -23
- package/src/checks/storage.ts +39 -78
- package/src/checks/surface.ts +22 -13
- package/src/checks/workloads.ts +32 -17
- package/src/database.ts +7 -28
- package/src/harness.ts +38 -62
- package/src/main.ts +5 -10
- package/src/report.ts +18 -1
- package/src/suite.ts +10 -23
- package/src/unserved.ts +9 -0
- package/src/checks/checkpoints.ts +0 -66
- package/src/checks/readiness.ts +0 -99
package/src/harness.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// in as the environment its wrangler.jsonc or .env would give it, with
|
|
3
3
|
// GitHub's URLs pointed at a stand-in IdP running in this process.
|
|
4
4
|
//
|
|
5
|
-
// workers two Workers under `wrangler dev
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
5
|
+
// workers two Workers under `wrangler dev`
|
|
6
|
+
// node the app's build under srvx and its vault process
|
|
7
|
+
//
|
|
8
|
+
// Either on a Postgres database of its own, created for the run and dropped
|
|
9
|
+
// after, each component through its own login.
|
|
10
10
|
//
|
|
11
11
|
// Ports: coffre on `port`, the IdP on the next, wrangler's inspector on the
|
|
12
12
|
// one after.
|
|
@@ -18,7 +18,7 @@ import { tmpdir } from 'node:os';
|
|
|
18
18
|
import { dirname, join, resolve } from 'node:path';
|
|
19
19
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
20
20
|
|
|
21
|
-
import { postgres,
|
|
21
|
+
import { postgres, using, type Sql } from './database.ts';
|
|
22
22
|
import { KEYS } from './fixtures.ts';
|
|
23
23
|
import { drainingConfig } from './draining.ts';
|
|
24
24
|
import { DevIdp } from './idp/index.ts';
|
|
@@ -28,14 +28,12 @@ export type Kind = 'workers' | 'node';
|
|
|
28
28
|
|
|
29
29
|
export type HarnessOptions = {
|
|
30
30
|
port: number;
|
|
31
|
-
/** Postgres as a login that may create databases
|
|
31
|
+
/** Postgres as a login that may create databases. */
|
|
32
32
|
postgres?: string;
|
|
33
|
-
/** The same server as coffre_runtime, the login the app runs as
|
|
33
|
+
/** The same server as coffre_runtime, the login the app runs as. */
|
|
34
34
|
runtime?: string;
|
|
35
|
-
/** The same server as coffre_vault_runtime, the login the vault runs as
|
|
35
|
+
/** The same server as coffre_vault_runtime, the login the vault runs as. */
|
|
36
36
|
vaultRuntime?: string;
|
|
37
|
-
/** The same server as coffre_vault_hot, the login 0.15's uses run as; workers only. */
|
|
38
|
-
hotRuntime?: string;
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
export type Deployment = {
|
|
@@ -44,8 +42,8 @@ export type Deployment = {
|
|
|
44
42
|
idp: DevIdp;
|
|
45
43
|
/** The one bootstrap Owner the vault is told of: the first to sign in, who owns the instance. */
|
|
46
44
|
owner: string;
|
|
47
|
-
/** Whether
|
|
48
|
-
|
|
45
|
+
/** Whether it serves a database its vault has not adopted yet, so /readyz fails until it has. */
|
|
46
|
+
fresh: boolean;
|
|
49
47
|
/** What the Cron trigger does every five minutes. */
|
|
50
48
|
scheduled(options?: { allowFailure?: boolean }): Promise<void>;
|
|
51
49
|
/** Stop what serves the deployment and start it again on the same data: new isolates on Workers, new processes on Node. */
|
|
@@ -54,14 +52,10 @@ export type Deployment = {
|
|
|
54
52
|
serving(): Record<string, number>;
|
|
55
53
|
/** The app's database, as its owner. */
|
|
56
54
|
database(): Promise<Sql>;
|
|
57
|
-
/** The app's database as the login the app runs as
|
|
58
|
-
runtime: (
|
|
59
|
-
/** The database as the login the vault runs as
|
|
60
|
-
vaultRuntime: (
|
|
61
|
-
/** The database as the login 0.15's uses run as, likewise. */
|
|
62
|
-
hotRuntime: (() => Promise<Sql>) | null;
|
|
63
|
-
/** The file holding the database, when it is one. */
|
|
64
|
-
databaseFile: string | null;
|
|
55
|
+
/** The app's database as the login the app runs as. */
|
|
56
|
+
runtime: () => Promise<Sql>;
|
|
57
|
+
/** The database as the login the vault runs as. */
|
|
58
|
+
vaultRuntime: () => Promise<Sql>;
|
|
65
59
|
/** The browser's half of the app's build: its static files. */
|
|
66
60
|
clientDir: string;
|
|
67
61
|
/** The processes' output: all of it, or the last `tail` characters of each. */
|
|
@@ -110,10 +104,9 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
110
104
|
);
|
|
111
105
|
if (busy) throw new Failure(`port ${taken} is taken; pass --port for a free run of three`);
|
|
112
106
|
}
|
|
113
|
-
if (
|
|
107
|
+
if (options.postgres === undefined || options.runtime === undefined || options.vaultRuntime === undefined) {
|
|
114
108
|
throw new Failure(
|
|
115
|
-
'
|
|
116
|
-
'and --hot-runtime <coffre_vault_hot URL>',
|
|
109
|
+
'a deployment runs on Postgres: pass --postgres <owner URL>, --runtime <coffre_runtime URL> and --vault-runtime <coffre_vault_runtime URL>',
|
|
117
110
|
);
|
|
118
111
|
}
|
|
119
112
|
|
|
@@ -205,19 +198,12 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
205
198
|
rmSync(scratch, { recursive: true, force: true });
|
|
206
199
|
}
|
|
207
200
|
|
|
208
|
-
/**
|
|
209
|
-
* The door open: requests answered, not held. The first after a start cuts 0.15's log over from 0.14, and the
|
|
210
|
-
* others answer 503 meanwhile, with Retry-After, as a deployment's clients see; a check's requests come after.
|
|
211
|
-
*/
|
|
212
|
-
const doorOpen = () => until(`${origin}/api/me answered, not held`, async () => (await fetch(`${origin}/api/me`)).status !== 503, 60, alive);
|
|
213
|
-
|
|
214
201
|
try {
|
|
215
202
|
const deployment =
|
|
216
203
|
kind === 'workers'
|
|
217
204
|
? await startWorkers()
|
|
218
205
|
: await startNode();
|
|
219
206
|
await until(`${origin}/livez`, async () => (await fetch(`${origin}/livez`)).ok, 120, alive);
|
|
220
|
-
await doorOpen();
|
|
221
207
|
return deployment;
|
|
222
208
|
} catch (error) {
|
|
223
209
|
const seen = logs();
|
|
@@ -226,21 +212,24 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
226
212
|
throw error;
|
|
227
213
|
}
|
|
228
214
|
|
|
229
|
-
|
|
215
|
+
/**
|
|
216
|
+
* The run's own database, made and migrated, as each login reaches it: migrated as the deployment's pipeline does
|
|
217
|
+
* before it deploys, by its own CLI's `coffre migrate`, in its folder, the owner's URL piped in.
|
|
218
|
+
*/
|
|
219
|
+
async function ownDatabase() {
|
|
230
220
|
const name = `coffre_conformance_${randomBytes(4).toString('hex')}`;
|
|
231
221
|
const owner = withDatabase(options.postgres!, name);
|
|
232
|
-
const runtime = withDatabase(options.runtime!, name);
|
|
233
|
-
const vaultRuntime = withDatabase(options.vaultRuntime!, name);
|
|
234
|
-
const hotRuntime = withDatabase(options.hotRuntime!, name);
|
|
235
222
|
await using(postgres(withDatabase(options.postgres!, 'postgres')), (sql) => sql.exec(`CREATE DATABASE ${name}`));
|
|
236
223
|
cleanup = () =>
|
|
237
224
|
using(postgres(withDatabase(options.postgres!, 'postgres')), (sql) =>
|
|
238
225
|
sql.exec(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`),
|
|
239
226
|
);
|
|
240
|
-
// As the deployment's pipeline does before it deploys: its own CLI's
|
|
241
|
-
// `coffre migrate`, in its folder, the owner's URL piped in.
|
|
242
|
-
// A fresh log has no heartbeat: only the scheduled job can make /readyz pass.
|
|
243
227
|
await run(process.execPath, [deploymentCli(dir), 'migrate', '--yes'], {}, `${owner}\n`);
|
|
228
|
+
return { owner, runtime: withDatabase(options.runtime!, name), vaultRuntime: withDatabase(options.vaultRuntime!, name) };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function startWorkers(): Promise<Deployment> {
|
|
232
|
+
const { owner, runtime, vaultRuntime } = await ownDatabase();
|
|
244
233
|
// The app as it deploys: its Start app, built by its own Vite, which wrangler runs unbundled.
|
|
245
234
|
await run(bin('vite'), ['build', 'app']);
|
|
246
235
|
const state = join(scratch, 'state');
|
|
@@ -265,7 +254,6 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
265
254
|
...OWNER_VARS,
|
|
266
255
|
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: runtime,
|
|
267
256
|
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_VAULT_HYPERDRIVE: vaultRuntime,
|
|
268
|
-
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HOT_HYPERDRIVE: hotRuntime,
|
|
269
257
|
WRANGLER_SEND_METRICS: 'false',
|
|
270
258
|
});
|
|
271
259
|
let wrangler = startWrangler();
|
|
@@ -274,7 +262,7 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
274
262
|
origin,
|
|
275
263
|
idp,
|
|
276
264
|
owner: OWNER,
|
|
277
|
-
|
|
265
|
+
fresh: true,
|
|
278
266
|
async scheduled(options = {}) {
|
|
279
267
|
const response = await fetch(`${origin}/cdn-cgi/local/scheduled?cron=*/5+*+*+*+*`);
|
|
280
268
|
if (!response.ok && !options.allowFailure) throw new Failure(`the scheduled handler answered ${response.status}`, `${await response.text()}\n${logs()}`);
|
|
@@ -283,14 +271,11 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
283
271
|
await halt(wrangler);
|
|
284
272
|
wrangler = startWrangler();
|
|
285
273
|
await until(`${origin}/livez`, async () => (await fetch(`${origin}/livez`)).ok, 120, alive);
|
|
286
|
-
await doorOpen();
|
|
287
274
|
},
|
|
288
275
|
serving: () => ({ wrangler: wrangler.child.pid! }),
|
|
289
276
|
database: () => postgres(owner),
|
|
290
277
|
runtime: () => postgres(runtime),
|
|
291
278
|
vaultRuntime: () => postgres(vaultRuntime),
|
|
292
|
-
hotRuntime: () => postgres(hotRuntime),
|
|
293
|
-
databaseFile: null,
|
|
294
279
|
clientDir: join(dir, 'app/dist/client'),
|
|
295
280
|
output,
|
|
296
281
|
stop,
|
|
@@ -298,18 +283,13 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
298
283
|
}
|
|
299
284
|
|
|
300
285
|
async function startNode(): Promise<Deployment> {
|
|
301
|
-
const
|
|
286
|
+
const { owner, runtime, vaultRuntime } = await ownDatabase();
|
|
302
287
|
const socket = join(scratch, 'vault.sock');
|
|
303
|
-
await run(bin('coffre-server'), ['migrate', `file:${database}`]);
|
|
304
288
|
const startVault = async () => {
|
|
305
289
|
rmSync(socket, { force: true });
|
|
306
290
|
const started = start('vault', process.execPath, ['src/vault.ts'], {
|
|
307
291
|
VAULT_SOCKET: socket,
|
|
308
|
-
DATABASE_URL:
|
|
309
|
-
// SQLite has no logins: the hot path's database is the same file.
|
|
310
|
-
HOT_DATABASE_URL: `file:${database}`,
|
|
311
|
-
// Kept across a restart, as a deployment keeps it: the checkpointer goes on from the pair it signed.
|
|
312
|
-
CHECKPOINTER_MEMORY: join(scratch, 'checkpointer-memory'),
|
|
292
|
+
DATABASE_URL: vaultRuntime,
|
|
313
293
|
VAULT_KEY_ID: KEYS.VAULT_KEY_ID,
|
|
314
294
|
VAULT_KEY: KEYS.VAULT_KEY,
|
|
315
295
|
...OWNER_VARS,
|
|
@@ -325,9 +305,8 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
325
305
|
start('server', bin('srvx'), ['--prod', '--host=127.0.0.1', 'app/dist/server/server.js'], {
|
|
326
306
|
PORT: String(port),
|
|
327
307
|
PUBLIC_URL: origin,
|
|
328
|
-
DATABASE_URL:
|
|
308
|
+
DATABASE_URL: runtime,
|
|
329
309
|
VAULT_SOCKET: socket,
|
|
330
|
-
AUDIT_ANCHOR: join(scratch, 'anchor.json'),
|
|
331
310
|
APP_KEY: KEYS.APP_KEY,
|
|
332
311
|
ALLOW_LOOPBACK_ISSUERS_FOR_DEVELOPMENT: 'true',
|
|
333
312
|
...github,
|
|
@@ -338,14 +317,14 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
338
317
|
origin,
|
|
339
318
|
idp,
|
|
340
319
|
owner: OWNER,
|
|
341
|
-
|
|
342
|
-
// `serve` runs the job as it starts, and every five minutes after:
|
|
343
|
-
//
|
|
320
|
+
fresh: false,
|
|
321
|
+
// `serve` runs the job as it starts, and every five minutes after: so restart the server, as the Cron trigger's
|
|
322
|
+
// request does on Workers. 0.14's run ended with the vault's checkpoint entry, which this waited for; 0.16's app has
|
|
323
|
+
// no job left, the signer's minute does the upkeep (docs/design/0.16.md, "The server"), so the server answering is its end.
|
|
344
324
|
async scheduled() {
|
|
345
325
|
await halt(server);
|
|
346
326
|
server = startServer();
|
|
347
327
|
await until('the restarted server', async () => (await fetch(`${origin}/livez`)).ok, 30, alive);
|
|
348
|
-
await doorOpen();
|
|
349
328
|
},
|
|
350
329
|
async restart() {
|
|
351
330
|
await halt(server);
|
|
@@ -353,14 +332,11 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
353
332
|
vault = await startVault();
|
|
354
333
|
server = startServer();
|
|
355
334
|
await until('the restarted server', async () => (await fetch(`${origin}/livez`)).ok, 30, alive);
|
|
356
|
-
await doorOpen();
|
|
357
335
|
},
|
|
358
336
|
serving: () => ({ vault: vault.child.pid!, server: server.child.pid! }),
|
|
359
|
-
database:
|
|
360
|
-
runtime:
|
|
361
|
-
vaultRuntime:
|
|
362
|
-
hotRuntime: null,
|
|
363
|
-
databaseFile: database,
|
|
337
|
+
database: () => postgres(owner),
|
|
338
|
+
runtime: () => postgres(runtime),
|
|
339
|
+
vaultRuntime: () => postgres(vaultRuntime),
|
|
364
340
|
clientDir: join(dir, 'app/dist/client'),
|
|
365
341
|
output,
|
|
366
342
|
stop,
|
package/src/main.ts
CHANGED
|
@@ -10,21 +10,18 @@ import { Failure } from './report.ts';
|
|
|
10
10
|
import { conform } from './suite.ts';
|
|
11
11
|
|
|
12
12
|
const USAGE = `usage:
|
|
13
|
-
coffre-conformance workers [<dir>] --postgres <owner URL> --runtime <coffre_runtime URL>
|
|
14
|
-
--vault-runtime <coffre_vault_runtime URL>
|
|
15
|
-
coffre-conformance node [<dir>] [options]
|
|
13
|
+
coffre-conformance workers|node [<dir>] --postgres <owner URL> --runtime <coffre_runtime URL>
|
|
14
|
+
--vault-runtime <coffre_vault_runtime URL> [options]
|
|
16
15
|
|
|
17
16
|
<dir> the deployment, as \`coffre init\` wrote it (default: here)
|
|
18
17
|
--port <n> coffre's port; the IdP gets the next, wrangler's inspector the one after (3082)
|
|
19
18
|
--bulk-limit <n> the vault's bulkLimit count, when not the default (1000)
|
|
20
19
|
--browser <path> Chrome or Chromium, to load the pages in (default: one found here;
|
|
21
20
|
without one, that check is skipped)
|
|
22
|
-
--postgres <url>
|
|
23
|
-
--runtime <url>
|
|
21
|
+
--postgres <url> a Postgres login that may create databases; one is made for the run
|
|
22
|
+
--runtime <url> the same server as coffre_runtime, the login the app runs as
|
|
24
23
|
--vault-runtime <url>
|
|
25
|
-
|
|
26
|
-
--hot-runtime <url>
|
|
27
|
-
workers: the same server as coffre_vault_hot, the login 0.15's uses run as
|
|
24
|
+
the same server as coffre_vault_runtime, the login the vault runs as
|
|
28
25
|
|
|
29
26
|
To check an instance that is running already, from outside, use the CLI:
|
|
30
27
|
\`coffre verify instance\`.`;
|
|
@@ -38,7 +35,6 @@ const { values, positionals } = parseArgs({
|
|
|
38
35
|
postgres: { type: 'string' },
|
|
39
36
|
runtime: { type: 'string' },
|
|
40
37
|
'vault-runtime': { type: 'string' },
|
|
41
|
-
'hot-runtime': { type: 'string' },
|
|
42
38
|
help: { type: 'boolean', short: 'h' },
|
|
43
39
|
},
|
|
44
40
|
});
|
|
@@ -61,7 +57,6 @@ try {
|
|
|
61
57
|
postgres: values.postgres,
|
|
62
58
|
runtime: values.runtime,
|
|
63
59
|
vaultRuntime: values['vault-runtime'],
|
|
64
|
-
hotRuntime: values['hot-runtime'],
|
|
65
60
|
});
|
|
66
61
|
} catch (error) {
|
|
67
62
|
const detail = error instanceof Failure && error.detail !== undefined ? `\n${String(error.detail)}` : '';
|
package/src/report.ts
CHANGED
|
@@ -37,6 +37,16 @@ export async function refused(what: string, call: Promise<unknown>): Promise<Cof
|
|
|
37
37
|
return outcome.error;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* How long a check waits for an entry on the audit page, which lists only
|
|
42
|
+
* what the signer has published (`log`, not `log_pending`). Told of an entry,
|
|
43
|
+
* the signer signs it within a second; if that word was lost, its minute's
|
|
44
|
+
* run takes it (`TICK_MS` and `CHECK_MS` in packages/vault/src/signer-host.ts).
|
|
45
|
+
* So the minute, and half a minute more for a loaded host. An entry still
|
|
46
|
+
* absent then is a defect, not a timing.
|
|
47
|
+
*/
|
|
48
|
+
export const PUBLISHED_SECONDS = 60 + 30;
|
|
49
|
+
|
|
40
50
|
export async function until(what: string, probe: () => Promise<boolean>, seconds: number, alive = () => true): Promise<void> {
|
|
41
51
|
for (let i = 0; i < seconds * 10; i++) {
|
|
42
52
|
if (!alive()) throw new Failure(`a process exited while waiting for ${what}`);
|
|
@@ -51,9 +61,12 @@ type Passed<T> = string | { detail: string; value: T };
|
|
|
51
61
|
export class Report {
|
|
52
62
|
readonly #results: { name: string; status: 'ok' | 'FAIL' | 'skip' }[] = [];
|
|
53
63
|
readonly #width: number;
|
|
64
|
+
readonly #unserved: Readonly<Record<string, string>>;
|
|
54
65
|
|
|
55
|
-
|
|
66
|
+
/** `unserved`: checks skipped by name, each with why (../unserved.ts). */
|
|
67
|
+
constructor(width = 19, unserved: Readonly<Record<string, string>> = {}) {
|
|
56
68
|
this.#width = width;
|
|
69
|
+
this.#unserved = unserved;
|
|
57
70
|
}
|
|
58
71
|
|
|
59
72
|
get failed(): string[] {
|
|
@@ -70,6 +83,10 @@ export class Report {
|
|
|
70
83
|
needs: N,
|
|
71
84
|
run: (have: { [K in keyof N]: NonNullable<N[K]> }) => Promise<Passed<T>>,
|
|
72
85
|
): Promise<T | undefined> {
|
|
86
|
+
if (Object.hasOwn(this.#unserved, name)) {
|
|
87
|
+
this.#print(name, 'skip', `not served in 0.16 yet: ${this.#unserved[name]}`);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
73
90
|
const missing = Object.keys(needs).filter((key) => needs[key] === undefined || needs[key] === null);
|
|
74
91
|
if (missing.length > 0) {
|
|
75
92
|
this.#print(name, 'skip', `no ${missing.join(' or ')}: an earlier check failed`);
|
package/src/suite.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
// The checks, in the order they build on each other: people first, then
|
|
2
|
-
// what they may do, then what was written down, and last the tampering
|
|
3
|
-
// which leaves the audit log broken for good.
|
|
2
|
+
// what they may do, then what was written down, and last the tampering.
|
|
4
3
|
import type { Deployment } from './harness.ts';
|
|
5
4
|
import { Report } from './report.ts';
|
|
5
|
+
import { UNSERVED } from './unserved.ts';
|
|
6
6
|
import { bulkLimit, crossSite, grantScoping, instanceRoles, membersOnly, offboarding } from './checks/access.ts';
|
|
7
|
-
import {
|
|
8
|
-
import { earlierCheckpoint } from './checks/checkpoints.ts';
|
|
7
|
+
import { auditPageProofs, auditProven, logCut, noAuditNoValue, revealAudited, writesAgree } from './checks/audit.ts';
|
|
9
8
|
import { deletion } from './checks/deletion.ts';
|
|
10
9
|
import { folders, forks, inheritance, loosening, missingKeys, personalConfigs, references } from './checks/environments.ts';
|
|
11
|
-
import { appLogin,
|
|
10
|
+
import { appLogin, vaultLogin } from './checks/logins.ts';
|
|
12
11
|
import { mcpRead, mcpChanges, mcpConnect, mcpValues } from './checks/mcp.ts';
|
|
13
12
|
import { accessAuthorship, memberTampering, noAuditNoAccess, sealingRace } from './checks/members.ts';
|
|
14
|
-
import { refusedCheckpoint, missingCheckpoint, middleCut } from './checks/readiness.ts';
|
|
15
13
|
import { editedGeneration, forgedCredential, forgedIdentity, forgedApproval } from './checks/signin.ts';
|
|
16
14
|
import { canaryScan } from './checks/canaries.ts';
|
|
17
15
|
import { Cli, cliLogin, manageByCli, verifyAsOwner, verifyAsUser, verifyInterrupted, verifyKeys, verifyLeftovers, verifyWithToken } from './checks/cli.ts';
|
|
18
16
|
import { pageLoad, personas, setUp, setUpLive, signInAdmin } from './checks/people.ts';
|
|
19
17
|
import { pagesInBrowser, pastedValues, signinErrorOnce } from './checks/pages.ts';
|
|
20
|
-
import { browserBundle, headers, health } from './checks/surface.ts';
|
|
18
|
+
import { browserBundle, headers, health, readyOnceAdopted } from './checks/surface.ts';
|
|
21
19
|
import { cliSignsIn, exchangesLimited, keysUploaded, runSignsIn, runsRefused, runUnbound, spentOnce, tokensUnlogged, trustRun } from './checks/workloads.ts';
|
|
22
20
|
|
|
23
21
|
/** The names of the checks that failed. */
|
|
24
22
|
export async function conform(deployment: Deployment, options: { bulkLimit: number; browser: string | null }): Promise<string[]> {
|
|
25
|
-
const report = new Report();
|
|
23
|
+
const report = new Report(undefined, UNSERVED);
|
|
24
|
+
await report.check('ready once adopted', {}, () => readyOnceAdopted(deployment));
|
|
26
25
|
await report.check('health', {}, () => health(deployment));
|
|
27
26
|
await report.check('browser bundle', {}, () => browserBundle(deployment));
|
|
28
27
|
const admin = await report.check('sign-in', {}, () => signInAdmin(deployment));
|
|
@@ -89,18 +88,15 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
|
|
|
89
88
|
await report.check('exchanges limited', { binding }, () => exchangesLimited(deployment));
|
|
90
89
|
await report.check('tokens unlogged', { binding }, () => tokensUnlogged(deployment));
|
|
91
90
|
|
|
92
|
-
await report.check('checkpoints', { people }, ({ people }) => checkpoints(deployment, people));
|
|
93
91
|
await report.check('keys behind writes', { people }, ({ people }) => writesAgree(deployment));
|
|
94
92
|
await report.check('no audit, no value', all, ({ people, canaries }) => noAuditNoValue(deployment, people, canaries));
|
|
95
93
|
|
|
96
94
|
await report.check('access authorship', { people }, ({ people }) => accessAuthorship(deployment, people));
|
|
97
95
|
await report.check('no audit, no access', { people }, ({ people }) => noAuditNoAccess(deployment, people));
|
|
98
|
-
await report.check('
|
|
99
|
-
await report.check('
|
|
100
|
-
await report.check('checkpoint missing', {}, () => missingCheckpoint(deployment));
|
|
96
|
+
await report.check('audit proven', { people }, ({ people }) => auditProven(people));
|
|
97
|
+
await report.check('audit page proofs', { people }, ({ people }) => auditPageProofs(people));
|
|
101
98
|
await report.check('app login', {}, () => appLogin(deployment));
|
|
102
99
|
await report.check('vault login', {}, () => vaultLogin(deployment));
|
|
103
|
-
await report.check('hot login', {}, () => hotLogin(deployment));
|
|
104
100
|
await report.check('forged grant', { people }, ({ people }) => memberTampering(deployment, people, 'grant'));
|
|
105
101
|
await report.check('forged member', { people }, ({ people }) => memberTampering(deployment, people, 'member'));
|
|
106
102
|
await report.check('stale member', { people }, ({ people }) => memberTampering(deployment, people, 'stale'));
|
|
@@ -109,16 +105,7 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
|
|
|
109
105
|
await report.check('forged identity', { people }, ({ people }) => forgedIdentity(deployment, people));
|
|
110
106
|
await report.check('forged approval', { people }, ({ people }) => forgedApproval(deployment, people));
|
|
111
107
|
await report.check('edited generation', { people }, ({ people }) => editedGeneration(deployment, people));
|
|
108
|
+
await report.check('log cut', { people }, ({ people }) => logCut(deployment, people));
|
|
112
109
|
await report.check('canary scan', all, ({ people, canaries }) => canaryScan(deployment, people, canaries));
|
|
113
|
-
for (const author of ['app', 'vault'] as const) {
|
|
114
|
-
await report.check(`${author} rewritten`, { people }, ({ people }) => rewrittenEntry(deployment, people, author));
|
|
115
|
-
}
|
|
116
|
-
await report.check('vault forged', { people }, ({ people }) => forgedVaultEntry(deployment, people));
|
|
117
|
-
await report.check('middle gap', { people }, ({ people }) => missingEntry(deployment, people, 'middle'));
|
|
118
|
-
await report.check('middle cut', { people }, ({ people }) => middleCut(deployment, people));
|
|
119
|
-
await report.check('first gap', { people }, ({ people }) => missingEntry(deployment, people, 'first'));
|
|
120
|
-
await report.check('batch gap', { people }, ({ people }) => missingEntry(deployment, people, 'batch'));
|
|
121
|
-
await report.check('earlier checkpoint', { people }, ({ people }) => earlierCheckpoint(deployment, people));
|
|
122
|
-
await report.check('tail deleted', { people }, ({ people }) => deletedTail(deployment, people));
|
|
123
110
|
return report.failed;
|
|
124
111
|
}
|
package/src/unserved.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The checks of what 0.16 declares and does not serve yet, by name, each
|
|
2
|
+
// with what it needs and why it waits. The suite skips each, saying so,
|
|
3
|
+
// and runs it again once its line goes: the area that serves the route
|
|
4
|
+
// deletes the line, as it deletes the route's from the server's
|
|
5
|
+
// `api/routes/unserved.ts`. Only a route that comes back belongs here; a
|
|
6
|
+
// check of one 0.16 drops goes with the route.
|
|
7
|
+
export const UNSERVED: Readonly<Record<string, string>> = {
|
|
8
|
+
'ready once adopted': "/readyz says only that the database is migrated: whether the vault has adopted it and the signer signed is still to design: both are stored, and the vault's `about` reads nothing (docs/design/0.16.md, \"Readiness\")",
|
|
9
|
+
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// A holder of both log keys can chain again. Every checkpoint must still
|
|
2
|
-
// pin the prefix it signed, even if a later checkpoint is valid.
|
|
3
|
-
import { createHash, createHmac, createPrivateKey, hkdfSync, sign } from 'node:crypto';
|
|
4
|
-
|
|
5
|
-
import { using } from '../database.ts';
|
|
6
|
-
import { KEYS } from '../fixtures.ts';
|
|
7
|
-
import type { Deployment } from '../harness.ts';
|
|
8
|
-
import { expect } from '../report.ts';
|
|
9
|
-
import type { People } from './people.ts';
|
|
10
|
-
import { appendOnlyLifted, entryFields, restoreRow, transaction } from './storage.ts';
|
|
11
|
-
|
|
12
|
-
/** Leave one old signature invalid, reseal the chain, and make later checkpoints valid. */
|
|
13
|
-
export async function earlierCheckpoint(deployment: Deployment, { admin }: People): Promise<string> {
|
|
14
|
-
expect((await admin.api.audit.verifyWhole()).ok, 'the log does not verify before checkpoint tampering');
|
|
15
|
-
await using(deployment.database(), (sql) => appendOnlyLifted(sql, async () => {
|
|
16
|
-
const rows = await sql.query('SELECT * FROM audit_log ORDER BY seq');
|
|
17
|
-
const signed = rows.filter((row) => row.author === 'vault' && row.action === 'audit.checkpoint' && row.decision === 'allow');
|
|
18
|
-
expect(signed.length >= 2, 'two checkpoints are needed');
|
|
19
|
-
const [head] = await sql.query('SELECT * FROM audit_chain_head');
|
|
20
|
-
// The vault's signing key, which it derives from its KEK: HKDF-SHA-256 under the vault's label.
|
|
21
|
-
const seed = Buffer.from(hkdfSync('sha256', Buffer.from(KEYS.VAULT_KEY, 'base64'), Buffer.alloc(0), 'coffre.vault.signing-key.v1', 32));
|
|
22
|
-
const signingKey = createPrivateKey({ key: Buffer.concat([Buffer.from('302e020100300506032b657004220420', 'hex'), seed]), format: 'der', type: 'pkcs8' });
|
|
23
|
-
const keys = {
|
|
24
|
-
app: Buffer.from(hkdfSync('sha256', Buffer.from(KEYS.APP_KEY, 'base64'), Buffer.alloc(0), 'coffre.audit.app.v2', 32)),
|
|
25
|
-
vault: Buffer.from(hkdfSync('sha256', seed, Buffer.alloc(0), 'coffre.audit.vault.v2', 32)),
|
|
26
|
-
};
|
|
27
|
-
const hashes = new Map<bigint, string>();
|
|
28
|
-
let previous = Buffer.alloc(32);
|
|
29
|
-
try {
|
|
30
|
-
await transaction(sql, async () => {
|
|
31
|
-
for (const original of rows) {
|
|
32
|
-
const row = { ...original };
|
|
33
|
-
if (row.author === 'vault' && row.action === 'audit.checkpoint' && row.decision === 'allow') {
|
|
34
|
-
const checkpoint = JSON.parse(String(row.metadata)) as { seq: number; hash: string; signedAt: string; signature: string };
|
|
35
|
-
if (row.seq === signed[0].seq) checkpoint.signature = Buffer.alloc(64).toString('base64');
|
|
36
|
-
else {
|
|
37
|
-
checkpoint.hash = hashes.get(BigInt(checkpoint.seq))!;
|
|
38
|
-
checkpoint.signature = sign(null, Buffer.from(`coffre.checkpoint.v3|${checkpoint.seq}|${checkpoint.hash}|${checkpoint.signedAt}`), signingKey).toString('base64');
|
|
39
|
-
}
|
|
40
|
-
row.metadata = JSON.stringify(checkpoint);
|
|
41
|
-
}
|
|
42
|
-
const fields = entryFields(row);
|
|
43
|
-
row.prev_hash = previous;
|
|
44
|
-
row.mac = createHmac('sha256', keys[row.author as 'app' | 'vault']).update('coffre.audit.mac.v2').update(previous).update(fields).digest();
|
|
45
|
-
previous = createHash('sha256').update('coffre.audit.chain.v2').update(previous).update(fields).update(row.mac as Buffer).digest();
|
|
46
|
-
row.hash = previous;
|
|
47
|
-
hashes.set(BigInt(String(row.seq)), previous.toString('hex'));
|
|
48
|
-
await restoreRow(sql, 'audit_log', row, 'seq');
|
|
49
|
-
}
|
|
50
|
-
await restoreRow(sql, 'audit_chain_head', { ...head, head_hash: previous }, 'only_row');
|
|
51
|
-
});
|
|
52
|
-
// The page's check goes on from the newest checkpoint, valid: the walk from the first entry reads them all.
|
|
53
|
-
const result = await admin.api.audit.verifyWhole();
|
|
54
|
-
expect(!result.ok && result.author === 'vault' && result.failedAtSeq === Number(signed[0].seq)
|
|
55
|
-
&& result.reason === 'a checkpoint the vault did not sign', 'a valid later checkpoint hid an invalid earlier one', result);
|
|
56
|
-
} finally {
|
|
57
|
-
await transaction(sql, async () => {
|
|
58
|
-
for (const row of rows) await restoreRow(sql, 'audit_log', row, 'seq');
|
|
59
|
-
await restoreRow(sql, 'audit_chain_head', head, 'only_row');
|
|
60
|
-
});
|
|
61
|
-
keys.app.fill(0); keys.vault.fill(0); seed.fill(0);
|
|
62
|
-
}
|
|
63
|
-
}));
|
|
64
|
-
expect((await admin.api.audit.verifyWhole()).ok, 'restoring the signed prefixes did not restore verification');
|
|
65
|
-
return 'an invalid earlier checkpoint was caught despite valid MACs and a valid later checkpoint';
|
|
66
|
-
}
|
package/src/checks/readiness.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// Readiness needs both halves of the Cron's work: a recent anchor, and in it
|
|
2
|
-
// a checkpoint the vault signed over the beat, which the app verified to.
|
|
3
|
-
// Either missing turns /readyz red.
|
|
4
|
-
import { using } from '../database.ts';
|
|
5
|
-
import type { Deployment } from '../harness.ts';
|
|
6
|
-
import { expect, until } from '../report.ts';
|
|
7
|
-
import { appendOnlyLifted, insertRow, logRefuses, query, transaction } from './storage.ts';
|
|
8
|
-
import type { People } from './people.ts';
|
|
9
|
-
|
|
10
|
-
async function red(deployment: Deployment): Promise<void> {
|
|
11
|
-
await until('readiness red', async () => (await fetch(`${deployment.origin}/readyz`)).status === 503, 10);
|
|
12
|
-
const body = await (await fetch(`${deployment.origin}/readyz`)).json() as { ok: boolean; checkpointed: boolean };
|
|
13
|
-
expect(body.ok === false && body.checkpointed === false, 'readiness did not report the missing checkpoint', body);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function refusedCheckpoint(deployment: Deployment): Promise<string> {
|
|
17
|
-
expect((await fetch(`${deployment.origin}/readyz`)).ok, 'readiness is not green before the checkpoint refusal');
|
|
18
|
-
await using(deployment.database(), (sql) => logRefuses(sql, async () => {
|
|
19
|
-
const [before] = await sql.query<{ seq: number | string }>("SELECT seq FROM audit_log WHERE action = 'audit.heartbeat' ORDER BY seq DESC LIMIT 1");
|
|
20
|
-
await deployment.scheduled({ allowFailure: true });
|
|
21
|
-
await until('the new heartbeat', async () => {
|
|
22
|
-
const [after] = await sql.query<{ seq: number | string }>("SELECT seq FROM audit_log WHERE action = 'audit.heartbeat' ORDER BY seq DESC LIMIT 1");
|
|
23
|
-
return BigInt(after.seq) > BigInt(before.seq);
|
|
24
|
-
}, 10);
|
|
25
|
-
await red(deployment);
|
|
26
|
-
}, 'audit.checkpoint'));
|
|
27
|
-
await deployment.scheduled();
|
|
28
|
-
await until('readiness recovered', async () => (await fetch(`${deployment.origin}/readyz`)).ok, 20);
|
|
29
|
-
return 'a committed heartbeat with a refused checkpoint turns readiness red, then recovers';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function missingCheckpoint(deployment: Deployment): Promise<string> {
|
|
33
|
-
expect((await fetch(`${deployment.origin}/readyz`)).ok, 'readiness is not green before removing checkpoints');
|
|
34
|
-
await using(deployment.database(), (sql) => appendOnlyLifted(sql, async () => {
|
|
35
|
-
const rows = await sql.query("SELECT * FROM audit_log WHERE action = 'audit.checkpoint' ORDER BY seq");
|
|
36
|
-
expect(rows.length > 0, 'no checkpoints to remove');
|
|
37
|
-
await sql.exec("DELETE FROM audit_log WHERE action = 'audit.checkpoint'");
|
|
38
|
-
try {
|
|
39
|
-
// Readiness vouches for the prefix the anchor holds, which the deletions leave: the next beat finds them gone.
|
|
40
|
-
await deployment.scheduled({ allowFailure: true });
|
|
41
|
-
await red(deployment);
|
|
42
|
-
} finally {
|
|
43
|
-
for (const row of rows) await insertRow(sql, 'audit_log', row);
|
|
44
|
-
}
|
|
45
|
-
}));
|
|
46
|
-
await deployment.scheduled();
|
|
47
|
-
await until('readiness recovered', async () => (await fetch(`${deployment.origin}/readyz`)).ok, 20);
|
|
48
|
-
return 'checkpoints deleted: the next beat finds them gone and readiness is red; restored, the next beat recovers';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** A hole before the latest signed prefix must stop the next scheduled checkpoint. */
|
|
52
|
-
export async function middleCut(deployment: Deployment, { admin }: People): Promise<string> {
|
|
53
|
-
expect((await fetch(`${deployment.origin}/readyz`)).ok, 'readiness is not green before the middle cut');
|
|
54
|
-
let seq = 0;
|
|
55
|
-
await using(deployment.database(), async (sql) => {
|
|
56
|
-
const [head] = await sql.query<{ next_seq: string | number }>('SELECT next_seq FROM audit_chain_head');
|
|
57
|
-
const [latest] = await sql.query<{ seq: string | number; metadata: string }>(
|
|
58
|
-
"SELECT seq, metadata FROM audit_log WHERE author = 'vault' AND action = 'audit.checkpoint' AND decision = 'allow' ORDER BY seq DESC LIMIT 1",
|
|
59
|
-
);
|
|
60
|
-
expect(latest !== undefined, 'no signed prefix to cut from');
|
|
61
|
-
const signed = JSON.parse(latest.metadata) as { seq: number };
|
|
62
|
-
// An old heartbeat and its checkpoint carry no access change or linked write: nothing names them but the
|
|
63
|
-
// checkpoint, which names the heartbeat as the last entry it signs.
|
|
64
|
-
const [heartbeat] = await query<{ seq: string | number }>(sql, `SELECT h.seq FROM audit_log h JOIN audit_log c ON c.seq = h.seq + 1
|
|
65
|
-
WHERE h.action = 'audit.heartbeat' AND h.seq > 0 AND c.author = 'vault' AND c.action = 'audit.checkpoint'
|
|
66
|
-
AND c.decision = 'allow' AND c.seq < $1 AND NOT EXISTS
|
|
67
|
-
(SELECT 1 FROM audit_log linked WHERE linked.related_seq IN (h.seq, c.seq) AND linked.seq <> c.seq) ORDER BY h.seq LIMIT 1`, [signed.seq]);
|
|
68
|
-
expect(heartbeat !== undefined, 'no older heartbeat and checkpoint to cut');
|
|
69
|
-
seq = Number(heartbeat.seq);
|
|
70
|
-
const kept = await query(sql, 'SELECT * FROM audit_log WHERE seq >= $1 AND seq <= $2 ORDER BY seq', [seq, seq + 1]);
|
|
71
|
-
expect(kept.length === 2, 'the middle cut needs two adjacent entries');
|
|
72
|
-
await appendOnlyLifted(sql, async () => {
|
|
73
|
-
await query(sql, 'UPDATE audit_log SET related_seq = NULL WHERE seq = $1', [seq + 1]);
|
|
74
|
-
await query(sql, 'DELETE FROM audit_log WHERE seq >= $1 AND seq <= $2', [seq, seq + 1]);
|
|
75
|
-
try {
|
|
76
|
-
// Do not call full verification first: the scheduled job must find the hole itself.
|
|
77
|
-
await deployment.scheduled({ allowFailure: true });
|
|
78
|
-
let checkpoint: { decision: string; code: string | null; metadata: string } | undefined;
|
|
79
|
-
await until('the checkpoint after the cut', async () => {
|
|
80
|
-
[checkpoint] = await query(sql, `SELECT decision, code, metadata FROM audit_log
|
|
81
|
-
WHERE author = 'vault' AND action = 'audit.checkpoint' AND seq >= $1 ORDER BY seq LIMIT 1`, [head.next_seq]);
|
|
82
|
-
return checkpoint !== undefined;
|
|
83
|
-
}, 10);
|
|
84
|
-
expect(checkpoint?.decision === 'deny' && checkpoint.code === 'log_broken', 'the checkpoint signed over a middle cut', checkpoint);
|
|
85
|
-
const detail = JSON.parse(checkpoint.metadata) as { reason: string };
|
|
86
|
-
expect(detail.reason.includes(`sequence gap: expected seq ${seq}`), 'the checkpoint did not name the middle gap', detail);
|
|
87
|
-
await red(deployment);
|
|
88
|
-
} finally {
|
|
89
|
-
await transaction(sql, async () => {
|
|
90
|
-
for (const row of kept) await insertRow(sql, 'audit_log', row);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
await deployment.scheduled();
|
|
96
|
-
await until('readiness recovered after the middle cut', async () => (await fetch(`${deployment.origin}/readyz`)).ok, 20);
|
|
97
|
-
expect((await admin.api.audit.verify()).ok, 'the restored middle cut did not verify');
|
|
98
|
-
return `entries ${seq} and ${seq + 1}, before the latest signed prefix, cut: checkpoint log_broken, readiness red; restored and recovered`;
|
|
99
|
-
}
|