@coffre/conformance 0.1.6 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/conformance",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
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,7 +31,8 @@
31
31
  "dependencies": {
32
32
  "jose": "6.2.3",
33
33
  "pg": "8.16.3",
34
- "@coffre/db": "0.1.6"
34
+ "@coffre/cli": "0.1.7",
35
+ "@coffre/db": "0.1.7"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/node": "26.1.1",
@@ -39,7 +40,7 @@
39
40
  "oauth4webapi": "3.8.8",
40
41
  "tsdown": "0.23.0",
41
42
  "typescript": "5.9.3",
42
- "@coffre/client": "0.1.6"
43
+ "@coffre/client": "0.1.7"
43
44
  },
44
45
  "scripts": {
45
46
  "build": "tsdown",
@@ -6,7 +6,7 @@ import { existsSync, readFileSync } from 'node:fs';
6
6
  import { using } from '../database.ts';
7
7
  import type { Deployment } from '../harness.ts';
8
8
  import { expect } from '../report.ts';
9
- import { getCalls, getUrls } from '../routes.ts';
9
+ import { getCalls, getUrls } from '@coffre/client/routes';
10
10
  import { scanTables, tables } from './storage.ts';
11
11
  import { canary, BULK, DEV, PROD, PROJECT, SERVICE, type Canaries, type People } from './people.ts';
12
12
 
@@ -0,0 +1,241 @@
1
+ // `coffre verify`, as an operator runs it against this deployment: the
2
+ // CLI's own entry, as @coffre/cli ships it, in a child process with a home
3
+ // of its own and none of this process's COFFRE_ variables. `verify
4
+ // instance` with a token from CI; signed in with `coffre login`, as a user,
5
+ // who is turned away, and as the admin, twice, then interrupted, its
6
+ // session left signed in each time; and `verify keys` with this
7
+ // deployment's keys, a wrong one and a malformed one.
8
+ import { spawn } from 'node:child_process';
9
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
10
+ import { createRequire } from 'node:module';
11
+ import { tmpdir } from 'node:os';
12
+ import { dirname, join } from 'node:path';
13
+ import { setTimeout as sleep } from 'node:timers/promises';
14
+
15
+ import { CoffreError, type CoffreClient } from '@coffre/client';
16
+
17
+ import { bearer } from '../browser.ts';
18
+ import { KEYS } from '../fixtures.ts';
19
+ import { expect, Failure } from '../report.ts';
20
+ import type { Person } from './people.ts';
21
+
22
+ /** What `coffre verify instance` makes and finds on an instance, as an owner: its own place, service and key. */
23
+ export const PROBE = { project: 'conformance', environment: 'live', service: 'token:conformance-probe', key: 'SIGN_IN_CANARY' } as const;
24
+
25
+ /** A canary the token reads, as `--canary` names it. */
26
+ export type Canary = { project: string; environment: string; key: string; value: string };
27
+
28
+ /** What a credential coffre issues, or a canary, looks like in a run's output. */
29
+ const SHOWN = /coffre_(svc|cli|web)_[A-Za-z0-9_-]{8,}|coffre-canary-[0-9a-f]{8,}/;
30
+
31
+ /** The CLI's entry, as its package ships it: built, as a deployment installs it. */
32
+ function entry(): string {
33
+ const main = join(dirname(createRequire(import.meta.url).resolve('@coffre/cli/package.json')), 'dist', 'main.js');
34
+ if (!existsSync(main)) throw new Failure('@coffre/cli is not built: run `pnpm build` at the root of the coffre repository');
35
+ return main;
36
+ }
37
+
38
+ type Run = { code: number | null; output: string };
39
+
40
+ /** A running command: what it has printed so far, stdout and stderr as one, and its exit. */
41
+ type Running = { output: () => string; exited: Promise<number | null>; kill: (signal: NodeJS.Signals) => void; waitFor: (pattern: RegExp, what: string) => Promise<RegExpExecArray> };
42
+
43
+ /** The CLI with a home of its own, where `coffre login` keeps its session: one person's terminal. */
44
+ export class Cli {
45
+ readonly origin: string;
46
+ readonly home: string;
47
+
48
+ constructor(origin: string) {
49
+ this.origin = origin;
50
+ this.home = mkdtempSync(join(tmpdir(), 'coffre-conformance-cli-'));
51
+ }
52
+
53
+ start(args: string[], env: Record<string, string> = {}, input?: string): Running {
54
+ const inherited = Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith('COFFRE_') && name !== 'NODE_OPTIONS'));
55
+ const child = spawn(process.execPath, [entry(), ...args], {
56
+ env: { ...inherited, HOME: this.home, NO_COLOR: '1', ...env },
57
+ stdio: ['pipe', 'pipe', 'pipe'],
58
+ });
59
+ let output = '';
60
+ child.stdout.setEncoding('utf8').on('data', (chunk: string) => (output += chunk));
61
+ child.stderr.setEncoding('utf8').on('data', (chunk: string) => (output += chunk));
62
+ child.stdin.end(input ?? '');
63
+ const exited = new Promise<number | null>((resolve) => child.on('exit', (code) => resolve(code)));
64
+ return {
65
+ output: () => output,
66
+ exited,
67
+ kill: (signal) => child.kill(signal),
68
+ waitFor: async (pattern, what) => {
69
+ for (let tries = 0; !pattern.test(output); tries += 1) {
70
+ if (tries >= 1200 || child.exitCode !== null) {
71
+ child.kill('SIGKILL');
72
+ throw new Failure(`coffre never got to ${what}`, output);
73
+ }
74
+ await sleep(50);
75
+ }
76
+ return pattern.exec(output)!;
77
+ },
78
+ };
79
+ }
80
+
81
+ async run(args: string[], env: Record<string, string> = {}, input?: string): Promise<Run> {
82
+ const running = this.start(args, env, input);
83
+ const code = await running.exited;
84
+ return { code, output: running.output() };
85
+ }
86
+
87
+ /** The session `coffre login` keeps here, for this run to check it is still signed in. */
88
+ session(): string {
89
+ const store = JSON.parse(readFileSync(join(this.home, '.coffre', 'credentials.json'), 'utf8')) as { instances: Record<string, { token?: string }> };
90
+ const token = store.instances[this.origin]?.token;
91
+ expect(token !== undefined, `no session for ${this.origin} in the CLI's credentials`, Object.keys(store.instances));
92
+ return token;
93
+ }
94
+
95
+ remove(): void {
96
+ rmSync(this.home, { recursive: true, force: true });
97
+ }
98
+ }
99
+
100
+ /** `coffre login`, approved by `person` in their browser, as they would: the CLI's own session. */
101
+ export async function cliLogin(cli: Cli, person: Person): Promise<{ detail: string; value: Cli }> {
102
+ const login = cli.start(['login', cli.origin, '--no-browser']);
103
+ const [, code] = await login.waitFor(/shows the code\s+(\S+)/, 'its device login');
104
+ await person.api.deviceLogins.decide(code!, true);
105
+ const status = await login.exited;
106
+ expect(status === 0, `coffre login exited ${status}`, login.output());
107
+ await bearer(cli.origin, cli.session()).me();
108
+ return { detail: `${person.email}, through \`coffre login\` approved in the browser`, value: cli };
109
+ }
110
+
111
+ /** The marks a run printed, by check: `✓`, `✗` or `–`. */
112
+ function marks(output: string): Record<string, string> {
113
+ const lines = [...output.matchAll(/^ {2}([✓✗–]) (\S.{18}) /gm)];
114
+ return Object.fromEntries(lines.map(([, mark, name]) => [name!.trim(), mark!]));
115
+ }
116
+
117
+ /** The token's run, from CI: as no one, then as the token, which is no owner and skips verification. */
118
+ export async function verifyWithToken(cli: Cli, live: { token: string; canary: Canary }): Promise<string> {
119
+ const { canary } = live;
120
+ const run = await cli.run(['verify', 'instance', cli.origin, '--canary', `${canary.project}/${canary.environment}/${canary.key}`], {
121
+ COFFRE_TOKEN: live.token,
122
+ COFFRE_CONFORMANCE_CANARY: canary.value,
123
+ });
124
+ const seen = marks(run.output);
125
+ expect(run.code === 0, `coffre verify instance with a token exited ${run.code}`, run.output);
126
+ expect(seen['token verification'] === '–', 'a token that is no owner did not skip verification', run.output);
127
+ expect(!run.output.includes(live.token) && !run.output.includes(canary.value), 'the run printed its token or its canary', run.output);
128
+ const ok = Object.values(seen).filter((mark) => mark === '✓').length;
129
+ return `${ok} checks ok as no one and as the token, its verification skipped; neither the token nor the canary shown`;
130
+ }
131
+
132
+ /** What a run as an owner must leave as it was: every member and their grants, but its service; every project and environment. */
133
+ async function everythingElse(api: CoffreClient): Promise<string> {
134
+ const { members } = await api.members.list();
135
+ const { projects } = await api.projects.list();
136
+ return JSON.stringify({
137
+ members: members.filter(({ member }) => member !== PROBE.service),
138
+ projects: projects.map(({ slug, archivedAt, environments }) => ({ slug, archivedAt, environments: environments.map(({ slug: env }) => env) })),
139
+ });
140
+ }
141
+
142
+ /** Signed in as a user, the run says so, and makes nothing; their session stays. Returns what it must leave as it was. */
143
+ export async function verifyAsUser(cli: Cli, user: Person, admin: Person): Promise<{ detail: string; value: string }> {
144
+ const before = await everythingElse(admin.api);
145
+ const run = await cli.run(['verify', 'instance']);
146
+ expect(run.code === 1, `coffre verify instance as a user exited ${run.code}, not 1`, run.output);
147
+ expect(marks(run.output).owner === '✗', 'the run went on past a user', run.output);
148
+ expect(/is neither an owner nor a root admin of \S+: nothing was made/.test(run.output), 'the run did not say plainly why it stopped', run.output);
149
+ const service = await admin.api.members.get(PROBE.service).then(
150
+ () => 'there',
151
+ (error: unknown) => (error instanceof CoffreError && error.status === 404 ? 'absent' : Promise.reject(error)),
152
+ );
153
+ expect(service === 'absent', `${PROBE.service} was made for a user`);
154
+ await bearer(cli.origin, cli.session()).me();
155
+ expect((await everythingElse(admin.api)) === before, 'the run changed a member, a grant, a project or an environment for a user');
156
+ return { detail: `${user.email}, a user, is told plainly; nothing made, the session still signed in`, value: before };
157
+ }
158
+
159
+ /** One run as the admin, with their `coffre login` session: every check passes, none skipped, and the session stays. Returns its setup's line. */
160
+ export async function verifyAsOwner(cli: Cli): Promise<{ detail: string; value: string }> {
161
+ const session = cli.session();
162
+ const run = await cli.run(['verify', 'instance']);
163
+ const seen = marks(run.output);
164
+ expect(run.code === 0, `coffre verify instance as the admin exited ${run.code}`, run.output);
165
+ // Signed in, nothing is out of reach: a check skipped, such as the token's verification, would only be noise.
166
+ const skipped = Object.entries(seen).filter(([, mark]) => mark !== '✓').map(([name]) => name);
167
+ expect(skipped.length === 0, `the run skipped ${skipped.join(', ')}`, run.output);
168
+ expect(!SHOWN.test(run.output) && !run.output.includes(session), 'the run printed a credential, the session or its canary', SHOWN.exec(run.output)?.[0]);
169
+ expect(/your session stays/.test(run.output), 'the run did not say the session stays', run.output);
170
+ await bearer(cli.origin, session).me();
171
+ const setup = /^ {2}✓ setup +(.*)$/m.exec(run.output)?.[1] ?? '';
172
+ return { detail: `${Object.keys(seen).length} checks ok, the session still signed in; ${setup.split(';')[0]}`, value: setup };
173
+ }
174
+
175
+ /**
176
+ * `coffre verify instance` interrupted mid-run by a Ctrl-C: it exits 130
177
+ * with its credential revoked, the session still signed in, and nothing it
178
+ * printed shows either, or its canary.
179
+ */
180
+ export async function verifyInterrupted(cli: Cli, admin: Person): Promise<string> {
181
+ const session = cli.session();
182
+ const running = cli.start(['verify', 'instance']);
183
+ try {
184
+ await running.waitFor(/✓ token reveal/, 'its token checks');
185
+ running.kill('SIGINT');
186
+ const status = await running.exited;
187
+ expect(status === 130, `the interrupted run exited ${status}, not 130`, running.output());
188
+ } finally {
189
+ running.kill('SIGKILL');
190
+ }
191
+ const { tokens } = await admin.api.tokens.list(PROBE.service);
192
+ expect(tokens.length === 0, `the interrupted run left ${PROBE.service} ${tokens.length} credential(s)`, tokens);
193
+ await bearer(cli.origin, session).me();
194
+ expect(!SHOWN.test(running.output()), 'the run printed a credential or a canary', SHOWN.exec(running.output())?.[0]);
195
+ return 'Ctrl-C mid-run: exit 130, its credential revoked, the session still signed in; nothing it printed shows either, or its canary';
196
+ }
197
+
198
+ /**
199
+ * After the runs: the second found everything the first made; the service
200
+ * holds no credential; the session is the one `coffre login` made, still
201
+ * signed in; the canary an operator keeps beside is as it was; nothing
202
+ * else changed; the runs' reads are in the audit log.
203
+ */
204
+ export async function verifyLeftovers(cli: Cli, admin: Person, setups: string[], before: string, kept: Canary): Promise<string> {
205
+ expect(setups[0]!.includes(`the service ${PROBE.service}`), 'the first run did not make its service', setups[0]);
206
+ expect(setups.slice(1).every((line) => line.startsWith('all found')), 'a later run made something again', setups);
207
+ const { tokens } = await admin.api.tokens.list(PROBE.service);
208
+ expect(tokens.length === 0, `${PROBE.service} still holds ${tokens.length} credential(s)`, tokens);
209
+ const { sessions } = await bearer(cli.origin, cli.session()).sessions.list();
210
+ const current = sessions.filter(({ current }) => current);
211
+ expect(current.length === 1 && current[0]!.kind === 'cli', "the CLI's session is not the one it was", sessions);
212
+ const place = `${kept.project}/${kept.environment}`;
213
+ const { values } = await admin.api.secrets.reveal(`${place}/${kept.key}`);
214
+ expect(values[kept.key] === kept.value, `${place}/${kept.key}, kept beside the run's own, was changed`);
215
+ expect((await everythingElse(admin.api)) === before, 'the runs changed a member, a grant, a project or an environment besides their own');
216
+ const { entries } = await admin.api.audit.list({ actor: PROBE.service, limit: 50 });
217
+ expect(entries.length > 0, `the audit log holds no entry by ${PROBE.service}`);
218
+ 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`;
219
+ }
220
+
221
+ /**
222
+ * `coffre verify keys`, with the admin's session: this deployment's keys
223
+ * pass, from the environment; a wrong vault key fails and the right app key
224
+ * passes, from stdin; a malformed app key fails. No key is ever printed.
225
+ */
226
+ export async function verifyKeys(cli: Cli): Promise<string> {
227
+ const wrong = Buffer.alloc(32, 7).toString('base64');
228
+ const runs: { env?: Record<string, string>; input?: string; code: number; vault: string; app: string; said?: RegExp }[] = [
229
+ { env: { COFFRE_VAULT_KEY: KEYS.VAULT_KEY, COFFRE_APP_KEY: KEYS.APP_KEY, COFFRE_VAULT_KEY_ID: KEYS.VAULT_KEY_ID }, code: 0, vault: '✓', app: '✓' },
230
+ { input: `${wrong}\n${KEYS.APP_KEY}\n`, code: 1, vault: '✗', app: '✓', said: /✗ vault key +not this instance's vault key/ },
231
+ { env: { COFFRE_VAULT_KEY: KEYS.VAULT_KEY, COFFRE_APP_KEY: 'not-a-key' }, code: 1, vault: '✓', app: '✗', said: /✗ app key +not an app key/ },
232
+ ];
233
+ for (const { env, input, code, vault, app, said } of runs) {
234
+ const run = await cli.run(['verify', 'keys'], env, input);
235
+ const seen = marks(run.output);
236
+ expect(run.code === code && seen['vault key'] === vault && seen['app key'] === app, `coffre verify keys exited ${run.code}`, run.output);
237
+ if (said !== undefined) expect(said.test(run.output), 'it did not say which key is not right', run.output);
238
+ for (const key of [KEYS.VAULT_KEY, KEYS.APP_KEY, wrong, 'not-a-key']) expect(!run.output.includes(key), 'a key was printed', run.output);
239
+ }
240
+ 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
+ }
@@ -1,6 +1,6 @@
1
- // What anyone on the network sees: health, and the headers that keep a
2
- // page from being framed, sniffed or made to run someone else's script.
3
- // These need no sign-in, so `probe` runs them against any instance.
1
+ // Health: up, and ready only once the scheduled job has beaten and the
2
+ // vault has checkpointed it. What else anyone on the network sees, its
3
+ // headers among it, `coffre verify instance` checks, here as anywhere.
4
4
  import type { Deployment } from '../harness.ts';
5
5
  import { expect, until } from '../report.ts';
6
6
 
@@ -20,55 +20,3 @@ export async function health(deployment: Deployment): Promise<string> {
20
20
  expect(ready.checkpointed === true, '/readyz passed without a checkpoint covering the heartbeat', ready);
21
21
  return deployment.beforeFirstBeat ? '/livez, and /readyz only once the heartbeat ran and was checkpointed' : '/livez and /readyz';
22
22
  }
23
-
24
- /** An instance someone else runs: up, and its scheduled job beating. */
25
- export async function reachable(origin: string): Promise<string> {
26
- const live = await fetch(`${origin}/livez`);
27
- expect(live.ok, `/livez answered ${live.status}`);
28
- const ready = await fetch(`${origin}/readyz`);
29
- expect(ready.ok, `/readyz answered ${ready.status}: is the scheduled job running?`, await ready.text());
30
- return '/livez and /readyz';
31
- }
32
-
33
- export async function headers(origin: string): Promise<string> {
34
- const anonymous = await fetch(`${origin}/api/me`);
35
- expect(anonymous.status === 401, `/api/me answered ${anonymous.status} to no one`);
36
- securityHeaders(anonymous, 'a refusal');
37
-
38
- const login = await fetch(`${origin}/login`);
39
- expect(login.status === 200, `/login answered ${login.status}`);
40
- const csp = securityHeaders(login, '/login');
41
- const html = await login.text();
42
- const nonce = /'nonce-([^']+)'/.exec(csp)![1];
43
- expect(html.includes(`nonce="${nonce}"`), "/login's scripts do not carry the policy's nonce");
44
- const again = securityHeaders(await fetch(`${origin}/login`), '/login');
45
- expect(!again.includes(`'nonce-${nonce}'`), 'two pages were served with the same nonce');
46
- const asset = /\/_coffre\/assets\/[\w.-]+\.js/.exec(html)?.[0];
47
- expect(asset !== undefined, '/login loads no script from /_coffre/assets/', html.slice(0, 2000));
48
- const script = await fetch(`${origin}${asset}`);
49
- expect(
50
- script.ok && /javascript/.test(script.headers.get('content-type') ?? ''),
51
- `${asset} answered ${script.status} ${script.headers.get('content-type')}`,
52
- );
53
-
54
- // No other site's page may read an answer: no CORS for anyone.
55
- const foreign = await fetch(`${origin}/api/me`, { headers: { origin: 'https://attacker.example' } });
56
- const allowed = foreign.headers.get('access-control-allow-origin');
57
- expect(allowed === null, `the API allows another origin to read it: ${allowed}`);
58
- return `a fresh CSP nonce per page, frames refused, nosniff; no CORS; ${asset} served`;
59
- }
60
-
61
- function securityHeaders(response: Response, what: string): string {
62
- const csp = response.headers.get('content-security-policy') ?? '';
63
- expect(/script-src 'self' 'nonce-[^']+'/.test(csp), `${what}: no nonce-based script-src`, csp);
64
- expect(csp.includes("frame-ancestors 'none'"), `${what}: frames not refused`, csp);
65
- expect(response.headers.get('x-content-type-options') === 'nosniff', `${what}: no nosniff`);
66
- expect(response.headers.get('x-frame-options') === 'DENY', `${what}: no x-frame-options DENY`);
67
- expect(response.headers.get('cross-origin-resource-policy') === 'same-origin', `${what}: other sites may embed it`);
68
- expect(/no-store/.test(response.headers.get('cache-control') ?? ''), `${what}: may be cached`);
69
- if (response.url.startsWith('https:')) {
70
- const hsts = response.headers.get('strict-transport-security') ?? '';
71
- expect(/max-age=\d{7,}/.test(hsts), `${what}: no strict-transport-security for months or more`, hsts);
72
- }
73
- return csp;
74
- }
package/src/main.ts CHANGED
@@ -5,18 +5,14 @@
5
5
  import { resolve } from 'node:path';
6
6
  import { parseArgs } from 'node:util';
7
7
 
8
- import { parseCanary, type Canary } from './checks/live.ts';
9
- import { openBrowser, PROBE } from './checks/probe.ts';
10
8
  import { boot, type Kind } from './harness.ts';
11
9
  import { Failure } from './report.ts';
12
- import { conform, probe } from './suite.ts';
10
+ import { conform } from './suite.ts';
13
11
 
14
12
  const USAGE = `usage:
15
13
  coffre-conformance workers [<dir>] --postgres <owner URL> --runtime <coffre_runtime URL>
16
14
  --vault-runtime <coffre_vault_runtime URL> [options]
17
15
  coffre-conformance node [<dir>] [options]
18
- coffre-conformance probe <url> [--token <service token> --canary <project>/<env>/<KEY>[=<value>]]
19
- coffre-conformance probe <url> --sign-in
20
16
 
21
17
  <dir> the deployment, as \`coffre init\` wrote it (default: here)
22
18
  --port <n> coffre's port; the IdP gets the next, wrangler's inspector the one after (3082)
@@ -26,27 +22,8 @@ const USAGE = `usage:
26
22
  --vault-runtime <url>
27
23
  workers: the same server as coffre_vault_runtime, the login the vault runs as
28
24
 
29
- probe checks a running instance from outside:
30
- as no one health, headers, every route refusing no one, changes from
31
- another site refused, /api/auth, nothing like a value shown
32
- with --token a service token that reads the canary's environment and
33
- holds auditor on its project: its value nowhere but its
34
- reveal, the reveal audited, nothing else in reach
35
- --token or COFFRE_TOKEN
36
- --canary the value after =, or in COFFRE_CONFORMANCE_CANARY, or on
37
- stdin, so it stays out of the shell's history
38
- with --sign-in an owner approves a device login in the browser, as for
39
- \`coffre login\`; the probe finds or makes conformance/live
40
- and token:conformance-probe, issues it a credential, writes
41
- a fresh canary, runs the token's checks, then verifies the
42
- whole audit log as the owner. The credential is revoked and
43
- the session ended however the run ends; neither it nor the
44
- canary is ever shown
45
-
46
- Each run with a token adds a few entries to the instance's audit log, which
47
- is append-only, so they stay: the canary's read, and the reads it was refused.
48
- It changes nothing else. A run with --sign-in leaves its project, environment
49
- and service for the next, and writes its canary and its grants.`;
25
+ To check an instance that is running already, from outside, use the CLI:
26
+ \`coffre verify instance\`.`;
50
27
 
51
28
  const { values, positionals } = parseArgs({
52
29
  allowPositionals: true,
@@ -56,57 +33,13 @@ const { values, positionals } = parseArgs({
56
33
  postgres: { type: 'string' },
57
34
  runtime: { type: 'string' },
58
35
  'vault-runtime': { type: 'string' },
59
- token: { type: 'string' },
60
- canary: { type: 'string' },
61
- 'sign-in': { type: 'boolean', default: false },
62
36
  help: { type: 'boolean', short: 'h' },
63
37
  },
64
38
  });
65
39
  const [command, target] = positionals;
66
40
  if (values.help || command === undefined) exit(values.help ? 0 : 2, USAGE);
67
41
 
68
- if (command === 'probe') {
69
- if (target === undefined) exit(2, USAGE);
70
- const origin = new URL(target).origin;
71
- if (values['sign-in']) {
72
- if (values.token !== undefined || values.canary !== undefined) exit(2, '--sign-in sets up its own token and canary: no --token or --canary with it');
73
- console.log(`coffre-conformance: probing ${origin}, as no one and signed in`);
74
- console.log(` (it keeps ${PROBE.project}/${PROBE.environment} and ${PROBE.service} for the next run, and its reads stay in the audit log, for good)`);
75
- const failed = await probe(origin, {
76
- signIn: ({ url, code }) => {
77
- console.log(`\n Approve the probe's sign-in, as an owner, at\n\n ${url}\n\n and check that it shows the code ${code}. Waiting for you…\n`);
78
- // On a terminal, as `coffre login`: from a script or CI, the printed address serves.
79
- if (process.stdout.isTTY) openBrowser(url);
80
- },
81
- });
82
- exit(failed.length === 0 ? 0 : 1, summary(failed));
83
- }
84
- const token = values.token ?? process.env.COFFRE_TOKEN;
85
- let canary: Canary | undefined;
86
- if (token !== undefined) {
87
- if (values.canary === undefined) exit(2, 'with a token, name its canary: --canary <project>/<environment>/<KEY>[=<value>]');
88
- try {
89
- canary = parseCanary(values.canary, values.canary.includes('=') ? undefined : await canaryValue());
90
- } catch (error) {
91
- exit(2, error instanceof Error ? error.message : String(error));
92
- }
93
- }
94
- console.log(`coffre-conformance: probing ${origin}${token === undefined ? ', as no one' : ', as no one and with a token'}`);
95
- if (token !== undefined) console.log(" (the token's reads add a few entries to the instance's audit log, for good)");
96
- const failed = await probe(origin, { token, canary });
97
- exit(failed.length === 0 ? 0 : 1, summary(failed));
98
- }
99
-
100
- /** The canary's value from the environment, or the first line of stdin when it is piped. */
101
- async function canaryValue(): Promise<string | undefined> {
102
- const given = process.env.COFFRE_CONFORMANCE_CANARY;
103
- if (given !== undefined && given !== '') return given;
104
- if (process.stdin.isTTY) return undefined;
105
- let text = '';
106
- for await (const chunk of process.stdin) text += String(chunk);
107
- return text.split(/\r?\n/)[0];
108
- }
109
-
42
+ if (command === 'probe') exit(2, 'coffre-conformance probe is now `coffre verify instance`, in the coffre CLI: npx @coffre/cli verify instance');
110
43
  if (command !== 'workers' && command !== 'node') exit(2, USAGE);
111
44
  const kind: Kind = command;
112
45
  const dir = resolve(target ?? '.');
package/src/report.ts CHANGED
@@ -49,25 +49,17 @@ export async function until(what: string, probe: () => Promise<boolean>, seconds
49
49
  type Passed<T> = string | { detail: string; value: T };
50
50
 
51
51
  export class Report {
52
- readonly #results: { name: string; status: 'ok' | 'FAIL' | 'skip'; line: string }[] = [];
52
+ readonly #results: { name: string; status: 'ok' | 'FAIL' | 'skip' }[] = [];
53
53
  readonly #width: number;
54
- readonly #quiet: boolean;
55
54
 
56
- /** `quiet`: keep the lines rather than print them, for a check made of checks to sum up. */
57
- constructor(width = 19, quiet = false) {
55
+ constructor(width = 19) {
58
56
  this.#width = width;
59
- this.#quiet = quiet;
60
57
  }
61
58
 
62
59
  get failed(): string[] {
63
60
  return this.#results.filter((result) => result.status === 'FAIL').map((result) => result.name);
64
61
  }
65
62
 
66
- /** Each check's name, what came of it, and its line. */
67
- get results(): readonly { name: string; status: 'ok' | 'FAIL' | 'skip'; line: string }[] {
68
- return this.#results;
69
- }
70
-
71
63
  /**
72
64
  * Run one check, and print what came of it. `needs` holds what earlier
73
65
  * checks produced: if any is missing, this one is skipped rather than run
@@ -99,8 +91,7 @@ export class Report {
99
91
  }
100
92
 
101
93
  #print(name: string, status: 'ok' | 'FAIL' | 'skip', line: string, detail?: unknown): void {
102
- this.#results.push({ name, status, line });
103
- if (this.#quiet) return;
94
+ this.#results.push({ name, status });
104
95
  const text = ` ${status.padEnd(5)} ${name.padEnd(this.#width)} ${line}`;
105
96
  if (status !== 'FAIL') {
106
97
  console.log(text);
package/src/suite.ts CHANGED
@@ -11,8 +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 { anonymousChecks, tokenChecks, type Canary } from './checks/live.ts';
15
- import { type Approve, probeAsUser, probeInterrupted, probeLeftovers, probeRun, signedInChecks } from './checks/probe.ts';
14
+ import { Cli, cliLogin, verifyAsOwner, verifyAsUser, verifyInterrupted, verifyKeys, verifyLeftovers, verifyWithToken } from './checks/cli.ts';
16
15
  import { pageLoad, personas, setUp, setUpLive, signInAdmin } from './checks/people.ts';
17
16
  import { health } from './checks/surface.ts';
18
17
 
@@ -20,10 +19,6 @@ import { health } from './checks/surface.ts';
20
19
  export async function conform(deployment: Deployment, options: { bulkLimit: number }): Promise<string[]> {
21
20
  const report = new Report();
22
21
  await report.check('health', {}, () => health(deployment));
23
- // What `probe` checks of a running instance, from outside: as no one, and
24
- // with a token reading one canary. The rest needs this run's own keys,
25
- // database and processes.
26
- await anonymousChecks(report, deployment.origin, { health: false });
27
22
  const admin = await report.check('sign-in', {}, () => signInAdmin(deployment));
28
23
  await report.check('page load', { admin }, ({ admin }) => pageLoad(admin));
29
24
  const canaries = await report.check('setup', { admin }, ({ admin }) => setUp(admin));
@@ -36,16 +31,25 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
36
31
  await report.check('runs audited', all, ({ people, canaries }) => revealAudited(deployment, people, canaries, 'run'));
37
32
  await report.check('cross-site', all, ({ people, canaries }) => crossSite(people, canaries));
38
33
  const live = await report.check('live setup', { admin, canaries }, ({ admin, canaries }) => setUpLive(admin, canaries));
39
- await tokenChecks(report, deployment.origin, live ?? {});
40
- // `probe --sign-in`, as an owner runs it against an instance: a user is turned away, two runs, and what stays.
41
- const origin = deployment.origin;
42
- const before = await report.check('probe as a user', { admin, people }, ({ admin, people }) => probeAsUser(origin, people.reader, admin));
43
- const first = await report.check('probe --sign-in', { admin, before }, ({ admin }) => probeRun(origin, admin));
44
- const second = await report.check('probe again', { admin, first }, ({ admin }) => probeRun(origin, admin));
45
- await report.check('probe interrupted', { admin, second }, ({ admin }) => probeInterrupted(origin, admin));
46
- await report.check('probe leftovers', { admin, before, first, second, live }, ({ admin, before, first, second, live }) =>
47
- probeLeftovers(origin, admin, [first, second], before, live.canary),
48
- );
34
+ // `coffre verify`, as an operator runs it against an instance: with a
35
+ // token from CI; then signed in with `coffre login`, a user turned away,
36
+ // the admin twice, interrupted, and what stays; and the keys.
37
+ const clis = [new Cli(deployment.origin), new Cli(deployment.origin), new Cli(deployment.origin)] as const;
38
+ try {
39
+ await report.check('verify with a token', { live }, ({ live }) => verifyWithToken(clis[0], live));
40
+ const user = await report.check('login as a user', { people }, ({ people }) => cliLogin(clis[1], people.reader));
41
+ const before = await report.check('verify as a user', { admin, people, user }, ({ admin, people, user }) => verifyAsUser(user, people.reader, admin));
42
+ const owner = await report.check('login as the admin', { admin, before }, ({ admin }) => cliLogin(clis[2], admin));
43
+ const first = await report.check('verify as the admin', { owner }, ({ owner }) => verifyAsOwner(owner));
44
+ const second = await report.check('verify again', { owner, first }, ({ owner }) => verifyAsOwner(owner));
45
+ await report.check('verify interrupted', { admin, owner, second }, ({ admin, owner }) => verifyInterrupted(owner, admin));
46
+ await report.check('verify leftovers', { admin, owner, before, first, second, live }, ({ admin, owner, before, first, second, live }) =>
47
+ verifyLeftovers(owner, admin, [first, second], before, live.canary),
48
+ );
49
+ await report.check('verify keys', { owner }, ({ owner }) => verifyKeys(owner));
50
+ } finally {
51
+ for (const cli of clis) cli.remove();
52
+ }
49
53
  await report.check('offboarding', all, ({ people, canaries }) => offboarding(deployment, people, canaries));
50
54
  await report.check('bulk limit', { people }, ({ people }) => bulkLimit(people, options.bulkLimit));
51
55
 
@@ -81,17 +85,3 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
81
85
  await report.check('tail deleted', { people }, ({ people }) => deletedTail(deployment, people));
82
86
  return report.failed;
83
87
  }
84
-
85
- /**
86
- * What can be checked of an instance someone else runs: as no one, and with
87
- * a token that reads a canary when given one, or, with `signIn`, as an owner
88
- * who signs the probe in and lets it set up its own token. With a token,
89
- * nothing is written but the audit log's entries for the token's reads.
90
- */
91
- export async function probe(origin: string, live: { token?: string; canary?: Canary; signIn?: Approve }): Promise<string[]> {
92
- const report = new Report();
93
- await anonymousChecks(report, origin, { health: true });
94
- if (live.signIn !== undefined) await signedInChecks(report, origin, live.signIn);
95
- else if (live.token !== undefined) await tokenChecks(report, origin, live);
96
- return report.failed;
97
- }