@coffre/conformance 0.14.7 → 0.16.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/README.md +2 -3
- package/dist/main.js +820 -944
- package/package.json +4 -6
- package/src/bundle.ts +8 -12
- package/src/checks/access.ts +9 -5
- package/src/checks/audit.ts +183 -200
- package/src/checks/canaries.ts +2 -15
- package/src/checks/cli.ts +38 -22
- package/src/checks/deletion.ts +18 -10
- package/src/checks/environments.ts +67 -33
- package/src/checks/logins.ts +30 -53
- package/src/checks/mcp.ts +83 -29
- package/src/checks/members.ts +127 -81
- package/src/checks/pages.ts +4 -4
- package/src/checks/people.ts +11 -0
- package/src/checks/signin.ts +25 -23
- package/src/checks/storage.ts +37 -67
- package/src/checks/surface.ts +22 -13
- package/src/checks/workloads.ts +36 -15
- package/src/database.ts +14 -26
- package/src/harness.ts +38 -39
- package/src/main.ts +4 -5
- package/src/report.ts +18 -1
- package/src/suite.ts +9 -21
- 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,11 +28,11 @@ 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
37
|
};
|
|
38
38
|
|
|
@@ -42,8 +42,8 @@ export type Deployment = {
|
|
|
42
42
|
idp: DevIdp;
|
|
43
43
|
/** The one bootstrap Owner the vault is told of: the first to sign in, who owns the instance. */
|
|
44
44
|
owner: string;
|
|
45
|
-
/** Whether
|
|
46
|
-
|
|
45
|
+
/** Whether it serves a database its vault has not adopted yet, so /readyz fails until it has. */
|
|
46
|
+
fresh: boolean;
|
|
47
47
|
/** What the Cron trigger does every five minutes. */
|
|
48
48
|
scheduled(options?: { allowFailure?: boolean }): Promise<void>;
|
|
49
49
|
/** Stop what serves the deployment and start it again on the same data: new isolates on Workers, new processes on Node. */
|
|
@@ -52,12 +52,10 @@ export type Deployment = {
|
|
|
52
52
|
serving(): Record<string, number>;
|
|
53
53
|
/** The app's database, as its owner. */
|
|
54
54
|
database(): Promise<Sql>;
|
|
55
|
-
/** The app's database as the login the app runs as
|
|
56
|
-
runtime: (
|
|
57
|
-
/** The database as the login the vault runs as
|
|
58
|
-
vaultRuntime: (
|
|
59
|
-
/** The file holding the database, when it is one. */
|
|
60
|
-
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>;
|
|
61
59
|
/** The browser's half of the app's build: its static files. */
|
|
62
60
|
clientDir: string;
|
|
63
61
|
/** The processes' output: all of it, or the last `tail` characters of each. */
|
|
@@ -106,9 +104,9 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
106
104
|
);
|
|
107
105
|
if (busy) throw new Failure(`port ${taken} is taken; pass --port for a free run of three`);
|
|
108
106
|
}
|
|
109
|
-
if (
|
|
107
|
+
if (options.postgres === undefined || options.runtime === undefined || options.vaultRuntime === undefined) {
|
|
110
108
|
throw new Failure(
|
|
111
|
-
'
|
|
109
|
+
'a deployment runs on Postgres: pass --postgres <owner URL>, --runtime <coffre_runtime URL> and --vault-runtime <coffre_vault_runtime URL>',
|
|
112
110
|
);
|
|
113
111
|
}
|
|
114
112
|
|
|
@@ -214,20 +212,24 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
214
212
|
throw error;
|
|
215
213
|
}
|
|
216
214
|
|
|
217
|
-
|
|
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() {
|
|
218
220
|
const name = `coffre_conformance_${randomBytes(4).toString('hex')}`;
|
|
219
221
|
const owner = withDatabase(options.postgres!, name);
|
|
220
|
-
const runtime = withDatabase(options.runtime!, name);
|
|
221
|
-
const vaultRuntime = withDatabase(options.vaultRuntime!, name);
|
|
222
222
|
await using(postgres(withDatabase(options.postgres!, 'postgres')), (sql) => sql.exec(`CREATE DATABASE ${name}`));
|
|
223
223
|
cleanup = () =>
|
|
224
224
|
using(postgres(withDatabase(options.postgres!, 'postgres')), (sql) =>
|
|
225
225
|
sql.exec(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`),
|
|
226
226
|
);
|
|
227
|
-
// As the deployment's pipeline does before it deploys: its own CLI's
|
|
228
|
-
// `coffre migrate`, in its folder, the owner's URL piped in.
|
|
229
|
-
// A fresh log has no heartbeat: only the scheduled job can make /readyz pass.
|
|
230
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();
|
|
231
233
|
// The app as it deploys: its Start app, built by its own Vite, which wrangler runs unbundled.
|
|
232
234
|
await run(bin('vite'), ['build', 'app']);
|
|
233
235
|
const state = join(scratch, 'state');
|
|
@@ -260,7 +262,7 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
260
262
|
origin,
|
|
261
263
|
idp,
|
|
262
264
|
owner: OWNER,
|
|
263
|
-
|
|
265
|
+
fresh: true,
|
|
264
266
|
async scheduled(options = {}) {
|
|
265
267
|
const response = await fetch(`${origin}/cdn-cgi/local/scheduled?cron=*/5+*+*+*+*`);
|
|
266
268
|
if (!response.ok && !options.allowFailure) throw new Failure(`the scheduled handler answered ${response.status}`, `${await response.text()}\n${logs()}`);
|
|
@@ -274,7 +276,6 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
274
276
|
database: () => postgres(owner),
|
|
275
277
|
runtime: () => postgres(runtime),
|
|
276
278
|
vaultRuntime: () => postgres(vaultRuntime),
|
|
277
|
-
databaseFile: null,
|
|
278
279
|
clientDir: join(dir, 'app/dist/client'),
|
|
279
280
|
output,
|
|
280
281
|
stop,
|
|
@@ -282,14 +283,13 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
282
283
|
}
|
|
283
284
|
|
|
284
285
|
async function startNode(): Promise<Deployment> {
|
|
285
|
-
const
|
|
286
|
+
const { owner, runtime, vaultRuntime } = await ownDatabase();
|
|
286
287
|
const socket = join(scratch, 'vault.sock');
|
|
287
|
-
await run(bin('coffre-server'), ['migrate', `file:${database}`]);
|
|
288
288
|
const startVault = async () => {
|
|
289
289
|
rmSync(socket, { force: true });
|
|
290
290
|
const started = start('vault', process.execPath, ['src/vault.ts'], {
|
|
291
291
|
VAULT_SOCKET: socket,
|
|
292
|
-
DATABASE_URL:
|
|
292
|
+
DATABASE_URL: vaultRuntime,
|
|
293
293
|
VAULT_KEY_ID: KEYS.VAULT_KEY_ID,
|
|
294
294
|
VAULT_KEY: KEYS.VAULT_KEY,
|
|
295
295
|
...OWNER_VARS,
|
|
@@ -305,9 +305,8 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
305
305
|
start('server', bin('srvx'), ['--prod', '--host=127.0.0.1', 'app/dist/server/server.js'], {
|
|
306
306
|
PORT: String(port),
|
|
307
307
|
PUBLIC_URL: origin,
|
|
308
|
-
DATABASE_URL:
|
|
308
|
+
DATABASE_URL: runtime,
|
|
309
309
|
VAULT_SOCKET: socket,
|
|
310
|
-
AUDIT_ANCHOR: join(scratch, 'anchor.json'),
|
|
311
310
|
APP_KEY: KEYS.APP_KEY,
|
|
312
311
|
ALLOW_LOOPBACK_ISSUERS_FOR_DEVELOPMENT: 'true',
|
|
313
312
|
...github,
|
|
@@ -318,9 +317,10 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
318
317
|
origin,
|
|
319
318
|
idp,
|
|
320
319
|
owner: OWNER,
|
|
321
|
-
|
|
322
|
-
// `serve` runs the job as it starts, and every five minutes after:
|
|
323
|
-
//
|
|
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.
|
|
324
324
|
async scheduled() {
|
|
325
325
|
await halt(server);
|
|
326
326
|
server = startServer();
|
|
@@ -334,10 +334,9 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
|
|
|
334
334
|
await until('the restarted server', async () => (await fetch(`${origin}/livez`)).ok, 30, alive);
|
|
335
335
|
},
|
|
336
336
|
serving: () => ({ vault: vault.child.pid!, server: server.child.pid! }),
|
|
337
|
-
database:
|
|
338
|
-
runtime:
|
|
339
|
-
vaultRuntime:
|
|
340
|
-
databaseFile: database,
|
|
337
|
+
database: () => postgres(owner),
|
|
338
|
+
runtime: () => postgres(runtime),
|
|
339
|
+
vaultRuntime: () => postgres(vaultRuntime),
|
|
341
340
|
clientDir: join(dir, 'app/dist/client'),
|
|
342
341
|
output,
|
|
343
342
|
stop,
|
package/src/main.ts
CHANGED
|
@@ -10,19 +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>
|
|
13
|
+
coffre-conformance workers|node [<dir>] --postgres <owner URL> --runtime <coffre_runtime URL>
|
|
14
14
|
--vault-runtime <coffre_vault_runtime URL> [options]
|
|
15
|
-
coffre-conformance node [<dir>] [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
|
-
|
|
24
|
+
the same server as coffre_vault_runtime, the login the vault runs as
|
|
26
25
|
|
|
27
26
|
To check an instance that is running already, from outside, use the CLI:
|
|
28
27
|
\`coffre verify instance\`.`;
|
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
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,15 +88,13 @@ 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
100
|
await report.check('forged grant', { people }, ({ people }) => memberTampering(deployment, people, 'grant'));
|
|
@@ -108,16 +105,7 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
|
|
|
108
105
|
await report.check('forged identity', { people }, ({ people }) => forgedIdentity(deployment, people));
|
|
109
106
|
await report.check('forged approval', { people }, ({ people }) => forgedApproval(deployment, people));
|
|
110
107
|
await report.check('edited generation', { people }, ({ people }) => editedGeneration(deployment, people));
|
|
108
|
+
await report.check('log cut', { people }, ({ people }) => logCut(deployment, people));
|
|
111
109
|
await report.check('canary scan', all, ({ people, canaries }) => canaryScan(deployment, people, canaries));
|
|
112
|
-
for (const author of ['app', 'vault'] as const) {
|
|
113
|
-
await report.check(`${author} rewritten`, { people }, ({ people }) => rewrittenEntry(deployment, people, author));
|
|
114
|
-
}
|
|
115
|
-
await report.check('vault forged', { people }, ({ people }) => forgedVaultEntry(deployment, people));
|
|
116
|
-
await report.check('middle gap', { people }, ({ people }) => missingEntry(deployment, people, 'middle'));
|
|
117
|
-
await report.check('middle cut', { people }, ({ people }) => middleCut(deployment, people));
|
|
118
|
-
await report.check('first gap', { people }, ({ people }) => missingEntry(deployment, people, 'first'));
|
|
119
|
-
await report.check('batch gap', { people }, ({ people }) => missingEntry(deployment, people, 'batch'));
|
|
120
|
-
await report.check('earlier checkpoint', { people }, ({ people }) => earlierCheckpoint(deployment, people));
|
|
121
|
-
await report.check('tail deleted', { people }, ({ people }) => deletedTail(deployment, people));
|
|
122
110
|
return report.failed;
|
|
123
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
|
-
}
|