@coffre/conformance 0.0.0 → 0.1.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/LICENSE +21 -0
- package/README.md +21 -3
- package/bin/coffre-conformance.js +13 -0
- package/dist/idp-DJlqS-JW.js +1122 -0
- package/dist/idp.d.ts +146 -0
- package/dist/idp.js +2 -0
- package/dist/main.js +2652 -0
- package/package.json +45 -5
- package/src/browser.ts +67 -0
- package/src/checks/access.ts +141 -0
- package/src/checks/audit.ts +267 -0
- package/src/checks/canaries.ts +121 -0
- package/src/checks/checkpoints.ts +64 -0
- package/src/checks/live.ts +321 -0
- package/src/checks/logins.ts +107 -0
- package/src/checks/members.ts +167 -0
- package/src/checks/people.ts +186 -0
- package/src/checks/readiness.ts +93 -0
- package/src/checks/signin.ts +130 -0
- package/src/checks/storage.ts +142 -0
- package/src/checks/surface.ts +74 -0
- package/src/database.ts +47 -0
- package/src/fixtures.ts +7 -0
- package/src/harness.ts +275 -0
- package/src/idp/authorize.ts +325 -0
- package/src/idp/github.ts +207 -0
- package/src/idp/http.ts +97 -0
- package/src/idp/idp.ts +331 -0
- package/src/idp/index.ts +5 -0
- package/src/idp/oidc.ts +209 -0
- package/src/idp/pages.ts +107 -0
- package/src/idp/people.ts +105 -0
- package/src/main.ts +123 -0
- package/src/report.ts +106 -0
- package/src/routes.ts +112 -0
- package/src/suite.ts +84 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export interface Persona {
|
|
4
|
+
email: string;
|
|
5
|
+
name: string;
|
|
6
|
+
/** What the seed grants them, shown on the sign-in page. */
|
|
7
|
+
note: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The people the sign-in pages offer. Mirrors the users in
|
|
12
|
+
* `dev/seed-config.mjs` (a test keeps the two in step), so each button
|
|
13
|
+
* lands on a seeded account.
|
|
14
|
+
*/
|
|
15
|
+
export const PERSONAS: readonly Persona[] = Object.freeze([
|
|
16
|
+
{ email: 'admin@acme.example', name: 'Ada Admin', note: 'root admin' },
|
|
17
|
+
{ email: 'lead@acme.example', name: 'Lea Lead', note: 'owner' },
|
|
18
|
+
{ email: 'dev@acme.example', name: 'Devon Dev', note: 'developer on dev' },
|
|
19
|
+
{ email: 'auditor@acme.example', name: 'Audrey Auditor', note: 'auditor' },
|
|
20
|
+
{ email: 'accessmgr@acme.example', name: 'Max Access', note: 'access manager' },
|
|
21
|
+
{ email: 'outsider@acme.example', name: 'Otto Outsider', note: 'registered, no grants' },
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export function normalizeEmail(email: string): string {
|
|
25
|
+
return email.trim().toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isEmail(value: string): boolean {
|
|
29
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function sha256Hex(value: string): string {
|
|
33
|
+
return createHash('sha256').update(value).digest('hex');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Stable for an email but deliberately not the email, the way real providers
|
|
38
|
+
* key accounts: a client that binds to `sub` survives an address changing
|
|
39
|
+
* hands, one that binds to `email` does not.
|
|
40
|
+
*/
|
|
41
|
+
export function defaultSubject(email: string): string {
|
|
42
|
+
return `dev-${sha256Hex(email).slice(0, 24)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function displayName(email: string): string {
|
|
46
|
+
const persona = PERSONAS.find((p) => p.email === email);
|
|
47
|
+
if (persona) return persona.name;
|
|
48
|
+
const local = email.split('@')[0]!;
|
|
49
|
+
return local.charAt(0).toUpperCase() + local.slice(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface GitHubEmail {
|
|
53
|
+
email: string;
|
|
54
|
+
primary: boolean;
|
|
55
|
+
verified: boolean;
|
|
56
|
+
visibility: 'public' | 'private' | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface GitHubAccount {
|
|
60
|
+
id: number;
|
|
61
|
+
login: string;
|
|
62
|
+
name: string;
|
|
63
|
+
emails: GitHubEmail[];
|
|
64
|
+
/** Organizations the account is an active member of. */
|
|
65
|
+
orgs: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface GitHubAccountPatch {
|
|
69
|
+
id?: number;
|
|
70
|
+
login?: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
/** Replaces the list. The first is primary unless one says so; all verified unless they say not. */
|
|
73
|
+
emails?: ReadonlyArray<{ email: string } & Partial<Omit<GitHubEmail, 'email'>>>;
|
|
74
|
+
orgs?: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Outsider's GitHub account also lists lead's address, unverified: a client
|
|
79
|
+
* that trusts unverified emails signs Otto in as Lea.
|
|
80
|
+
*/
|
|
81
|
+
const UNVERIFIED_GITHUB_EMAILS: Readonly<Record<string, readonly string[]>> = {
|
|
82
|
+
'outsider@acme.example': ['lead@acme.example'],
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export function gitHubEmails(list: NonNullable<GitHubAccountPatch['emails']>): GitHubEmail[] {
|
|
86
|
+
const primary = Math.max(0, list.findIndex((e) => e.primary));
|
|
87
|
+
return list.map((e, i) => ({
|
|
88
|
+
email: normalizeEmail(e.email),
|
|
89
|
+
primary: i === primary,
|
|
90
|
+
verified: e.verified ?? true,
|
|
91
|
+
visibility: e.visibility !== undefined ? e.visibility : i === primary ? 'public' : null,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Stable per email, so a persona keeps its numeric id across runs. */
|
|
96
|
+
export function defaultGitHubAccount(email: string): GitHubAccount {
|
|
97
|
+
const unverified = UNVERIFIED_GITHUB_EMAILS[email] ?? [];
|
|
98
|
+
return {
|
|
99
|
+
id: 1_000_000 + Number.parseInt(sha256Hex(`github:${email}`).slice(0, 7), 16),
|
|
100
|
+
login: email.split('@')[0]!.replace(/[^A-Za-z0-9-]/g, '-'),
|
|
101
|
+
name: displayName(email),
|
|
102
|
+
emails: gitHubEmails([{ email }, ...unverified.map((e) => ({ email: e, verified: false }))]),
|
|
103
|
+
orgs: ['acme'],
|
|
104
|
+
};
|
|
105
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// coffre-conformance: check a coffre deployment from outside, for what it
|
|
2
|
+
// must never do whatever code it runs. It boots the deployment itself, as
|
|
3
|
+
// `coffre init` made it or however it was changed since, signs people in
|
|
4
|
+
// through a stand-in GitHub, and takes them through the checks.
|
|
5
|
+
import { resolve } from 'node:path';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
|
|
8
|
+
import { parseCanary, type Canary } from './checks/live.ts';
|
|
9
|
+
import { boot, type Kind } from './harness.ts';
|
|
10
|
+
import { Failure } from './report.ts';
|
|
11
|
+
import { conform, probe } from './suite.ts';
|
|
12
|
+
|
|
13
|
+
const USAGE = `usage:
|
|
14
|
+
coffre-conformance workers [<dir>] --postgres <owner URL> --runtime <coffre_runtime URL>
|
|
15
|
+
--vault-runtime <coffre_vault_runtime URL> [options]
|
|
16
|
+
coffre-conformance node [<dir>] [options]
|
|
17
|
+
coffre-conformance probe <url> [--token <service token> --canary <project>/<env>/<KEY>[=<value>]]
|
|
18
|
+
|
|
19
|
+
<dir> the deployment, as \`coffre init\` wrote it (default: here)
|
|
20
|
+
--port <n> coffre's port; the IdP gets the next, wrangler's inspector the one after (3082)
|
|
21
|
+
--bulk-limit <n> the vault's bulkLimit count, when not the default (1000)
|
|
22
|
+
--postgres <url> workers: a Postgres login that may create databases; one is made for the run
|
|
23
|
+
--runtime <url> workers: the same server as coffre_runtime, the login the app runs as
|
|
24
|
+
--vault-runtime <url>
|
|
25
|
+
workers: the same server as coffre_vault_runtime, the login the vault runs as
|
|
26
|
+
|
|
27
|
+
probe checks a running instance from outside, and writes nothing to it:
|
|
28
|
+
as no one health, headers, every route refusing no one, changes from
|
|
29
|
+
another site refused, /api/auth, nothing like a value shown
|
|
30
|
+
with --token a service token that reads the canary's environment and
|
|
31
|
+
holds auditor on its project: its value nowhere but its
|
|
32
|
+
reveal, the reveal audited, nothing else in reach
|
|
33
|
+
--token or COFFRE_TOKEN
|
|
34
|
+
--canary the value after =, or in COFFRE_CONFORMANCE_CANARY, or on
|
|
35
|
+
stdin, so it stays out of the shell's history
|
|
36
|
+
|
|
37
|
+
Each run with a token adds a few entries to the instance's audit log, which
|
|
38
|
+
is append-only, so they stay: the canary's read, and the reads it was refused.
|
|
39
|
+
It changes nothing else.`;
|
|
40
|
+
|
|
41
|
+
const { values, positionals } = parseArgs({
|
|
42
|
+
allowPositionals: true,
|
|
43
|
+
options: {
|
|
44
|
+
port: { type: 'string', default: '3082' },
|
|
45
|
+
'bulk-limit': { type: 'string', default: '1000' },
|
|
46
|
+
postgres: { type: 'string' },
|
|
47
|
+
runtime: { type: 'string' },
|
|
48
|
+
'vault-runtime': { type: 'string' },
|
|
49
|
+
token: { type: 'string' },
|
|
50
|
+
canary: { type: 'string' },
|
|
51
|
+
help: { type: 'boolean', short: 'h' },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const [command, target] = positionals;
|
|
55
|
+
if (values.help || command === undefined) exit(values.help ? 0 : 2, USAGE);
|
|
56
|
+
|
|
57
|
+
if (command === 'probe') {
|
|
58
|
+
if (target === undefined) exit(2, USAGE);
|
|
59
|
+
const origin = new URL(target).origin;
|
|
60
|
+
const token = values.token ?? process.env.COFFRE_TOKEN;
|
|
61
|
+
let canary: Canary | undefined;
|
|
62
|
+
if (token !== undefined) {
|
|
63
|
+
if (values.canary === undefined) exit(2, 'with a token, name its canary: --canary <project>/<environment>/<KEY>[=<value>]');
|
|
64
|
+
try {
|
|
65
|
+
canary = parseCanary(values.canary, values.canary.includes('=') ? undefined : await canaryValue());
|
|
66
|
+
} catch (error) {
|
|
67
|
+
exit(2, error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
console.log(`coffre-conformance: probing ${origin}${token === undefined ? ', as no one' : ', as no one and with a token'}`);
|
|
71
|
+
if (token !== undefined) console.log(" (the token's reads add a few entries to the instance's audit log, for good)");
|
|
72
|
+
const failed = await probe(origin, { token, canary });
|
|
73
|
+
exit(failed.length === 0 ? 0 : 1, summary(failed));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The canary's value from the environment, or the first line of stdin when it is piped. */
|
|
77
|
+
async function canaryValue(): Promise<string | undefined> {
|
|
78
|
+
const given = process.env.COFFRE_CONFORMANCE_CANARY;
|
|
79
|
+
if (given !== undefined && given !== '') return given;
|
|
80
|
+
if (process.stdin.isTTY) return undefined;
|
|
81
|
+
let text = '';
|
|
82
|
+
for await (const chunk of process.stdin) text += String(chunk);
|
|
83
|
+
return text.split(/\r?\n/)[0];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (command !== 'workers' && command !== 'node') exit(2, USAGE);
|
|
87
|
+
const kind: Kind = command;
|
|
88
|
+
const dir = resolve(target ?? '.');
|
|
89
|
+
const port = Number(values.port);
|
|
90
|
+
const bulkLimit = Number(values['bulk-limit']);
|
|
91
|
+
if (!Number.isInteger(port) || !Number.isInteger(bulkLimit) || bulkLimit < 1) exit(2, USAGE);
|
|
92
|
+
|
|
93
|
+
console.log(`coffre-conformance: ${kind} from ${dir}`);
|
|
94
|
+
let deployment;
|
|
95
|
+
try {
|
|
96
|
+
deployment = await boot(kind, dir, {
|
|
97
|
+
port,
|
|
98
|
+
postgres: values.postgres,
|
|
99
|
+
runtime: values.runtime,
|
|
100
|
+
vaultRuntime: values['vault-runtime'],
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const detail = error instanceof Failure && error.detail !== undefined ? `\n${String(error.detail)}` : '';
|
|
104
|
+
exit(1, `the deployment did not start: ${error instanceof Error ? error.message : String(error)}${detail}`);
|
|
105
|
+
}
|
|
106
|
+
console.log(` up on ${deployment.origin}`);
|
|
107
|
+
let failed: string[];
|
|
108
|
+
try {
|
|
109
|
+
failed = await conform(deployment, { bulkLimit });
|
|
110
|
+
if (failed.length > 0) console.error(`\nThe processes' output, last lines:\n${deployment.output(4000)}`);
|
|
111
|
+
} finally {
|
|
112
|
+
await deployment.stop();
|
|
113
|
+
}
|
|
114
|
+
exit(failed.length === 0 ? 0 : 1, summary(failed));
|
|
115
|
+
|
|
116
|
+
function summary(failed: string[]): string {
|
|
117
|
+
return failed.length === 0 ? 'conformant' : `NOT conformant: ${failed.join(', ')}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function exit(code: number, message: string): never {
|
|
121
|
+
(code === 0 ? console.log : console.error)(message);
|
|
122
|
+
process.exit(code);
|
|
123
|
+
}
|
package/src/report.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Checks, and what became of each: one line apiece, and the run goes on
|
|
2
|
+
// past a failure, so one report shows everything that is wrong.
|
|
3
|
+
import { inspect } from 'node:util';
|
|
4
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
5
|
+
|
|
6
|
+
import { CoffreError } from '@coffre/client';
|
|
7
|
+
|
|
8
|
+
/** A check that failed: what went wrong, and what was seen instead. */
|
|
9
|
+
export class Failure extends Error {
|
|
10
|
+
readonly detail: unknown;
|
|
11
|
+
|
|
12
|
+
constructor(message: string, detail?: unknown) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.detail = detail;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A check that cannot run against this deployment, and why. */
|
|
19
|
+
export class Skip extends Error {}
|
|
20
|
+
|
|
21
|
+
export function expect(condition: unknown, message: string, detail?: unknown): asserts condition {
|
|
22
|
+
if (!condition) throw new Failure(message, detail);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The status coffre turned a call away with. A call that went through
|
|
27
|
+
* fails the check: `what` says what it should not have done.
|
|
28
|
+
*/
|
|
29
|
+
export async function refused(what: string, call: Promise<unknown>): Promise<CoffreError> {
|
|
30
|
+
const outcome = await call.then(
|
|
31
|
+
(value) => ({ value }),
|
|
32
|
+
(error: unknown) => ({ error }),
|
|
33
|
+
);
|
|
34
|
+
if ('value' in outcome) throw new Failure(`${what}, and was let`, outcome.value);
|
|
35
|
+
if (!(outcome.error instanceof CoffreError)) throw outcome.error;
|
|
36
|
+
expect(outcome.error.status >= 400 && outcome.error.status < 500, `${what}, and failed with ${outcome.error.status}`, outcome.error.message);
|
|
37
|
+
return outcome.error;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function until(what: string, probe: () => Promise<boolean>, seconds: number, alive = () => true): Promise<void> {
|
|
41
|
+
for (let i = 0; i < seconds * 10; i++) {
|
|
42
|
+
if (!alive()) throw new Failure(`a process exited while waiting for ${what}`);
|
|
43
|
+
if (await probe().catch(() => false)) return;
|
|
44
|
+
await sleep(100);
|
|
45
|
+
}
|
|
46
|
+
throw new Failure(`timed out waiting for ${what}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type Passed<T> = string | { detail: string; value: T };
|
|
50
|
+
|
|
51
|
+
export class Report {
|
|
52
|
+
readonly #results: { name: string; status: 'ok' | 'FAIL' | 'skip' }[] = [];
|
|
53
|
+
readonly #width: number;
|
|
54
|
+
|
|
55
|
+
constructor(width = 19) {
|
|
56
|
+
this.#width = width;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get failed(): string[] {
|
|
60
|
+
return this.#results.filter((result) => result.status === 'FAIL').map((result) => result.name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Run one check, and print what came of it. `needs` holds what earlier
|
|
65
|
+
* checks produced: if any is missing, this one is skipped rather than run
|
|
66
|
+
* against a deployment that is not in the state it expects.
|
|
67
|
+
*/
|
|
68
|
+
async check<N extends Record<string, unknown>, T = undefined>(
|
|
69
|
+
name: string,
|
|
70
|
+
needs: N,
|
|
71
|
+
run: (have: { [K in keyof N]: NonNullable<N[K]> }) => Promise<Passed<T>>,
|
|
72
|
+
): Promise<T | undefined> {
|
|
73
|
+
const missing = Object.keys(needs).filter((key) => needs[key] === undefined || needs[key] === null);
|
|
74
|
+
if (missing.length > 0) {
|
|
75
|
+
this.#print(name, 'skip', `no ${missing.join(' or ')}: an earlier check failed`);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const passed = await run(needs as { [K in keyof N]: NonNullable<N[K]> });
|
|
80
|
+
this.#print(name, 'ok', typeof passed === 'string' ? passed : passed.detail);
|
|
81
|
+
return typeof passed === 'string' ? undefined : passed.value;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error instanceof Skip) {
|
|
84
|
+
this.#print(name, 'skip', error.message);
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
const detail = error instanceof Failure ? error.detail : error instanceof Error ? error.stack : error;
|
|
88
|
+
this.#print(name, 'FAIL', error instanceof Error ? error.message : String(error), detail);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#print(name: string, status: 'ok' | 'FAIL' | 'skip', line: string, detail?: unknown): void {
|
|
94
|
+
this.#results.push({ name, status });
|
|
95
|
+
const text = ` ${status.padEnd(5)} ${name.padEnd(this.#width)} ${line}`;
|
|
96
|
+
if (status !== 'FAIL') {
|
|
97
|
+
console.log(text);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
console.error(text);
|
|
101
|
+
if (detail !== undefined) {
|
|
102
|
+
const shown = typeof detail === 'string' ? detail : inspect(detail, { depth: 6, breakLength: 100 });
|
|
103
|
+
console.error(shown.replace(/^/gm, ' '.repeat(this.#width + 9)));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/routes.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// The API's routes, as the checks call them. Both tables are typed over the
|
|
2
|
+
// client's route map, so a route added to the server fails the typecheck
|
|
3
|
+
// here until it is listed, and from then on every check that walks a table
|
|
4
|
+
// covers it: the anonymous refusal, the canary scans, the cross-site one.
|
|
5
|
+
import type { Params, RouteInput, RouteKey } from '@coffre/client';
|
|
6
|
+
|
|
7
|
+
export type GetKey = Extract<RouteKey, `GET ${string}`>;
|
|
8
|
+
|
|
9
|
+
/** Each GET route, with what to ask it. */
|
|
10
|
+
export type GetCalls = { [K in GetKey]: { params: Params<K>; input?: RouteInput<K> }[] };
|
|
11
|
+
|
|
12
|
+
/** What the GET routes are asked about: places, secrets and members to name. */
|
|
13
|
+
export type Subjects = {
|
|
14
|
+
places: { project: string; environment: string }[];
|
|
15
|
+
/** Secrets whose history to ask for. */
|
|
16
|
+
secrets: { project: string; environment: string; key: string }[];
|
|
17
|
+
/** `user:…` and `token:…`. */
|
|
18
|
+
members: string[];
|
|
19
|
+
/** Tokens whose credentials to list. */
|
|
20
|
+
services: string[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function getCalls({ places, secrets, members, services }: Subjects): GetCalls {
|
|
24
|
+
const first = places[0];
|
|
25
|
+
return {
|
|
26
|
+
'GET /me': [{ params: {} }],
|
|
27
|
+
'GET /projects': [{ params: {} }],
|
|
28
|
+
'GET /secrets/:project/:environment': places.map((params) => ({ params })),
|
|
29
|
+
'GET /secrets/:project/:environment/:key/versions': secrets.map((params) => ({ params })),
|
|
30
|
+
'GET /members': [
|
|
31
|
+
{ params: {} },
|
|
32
|
+
...(first === undefined ? [] : [{ params: {}, input: { path: `${first.project}/${first.environment}` } }]),
|
|
33
|
+
],
|
|
34
|
+
'GET /members/:member': members.map((member) => ({ params: { member } })),
|
|
35
|
+
'GET /members/:member/tokens': services.map((member) => ({ params: { member } })),
|
|
36
|
+
'GET /sessions': [{ params: {} }],
|
|
37
|
+
'GET /identities': [{ params: {} }],
|
|
38
|
+
'GET /device-logins/:code': [{ params: { code: 'BCDF-GHJK' } }],
|
|
39
|
+
'GET /syncs/providers': [{ params: {} }],
|
|
40
|
+
'GET /syncs/:project/:environment': places.map((params) => ({ params })),
|
|
41
|
+
'GET /audit': [{ params: {}, input: { limit: 500 } }, { params: {}, input: { limit: 500, detail: '1' } }],
|
|
42
|
+
'GET /audit/verification': [{ params: {} }],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Each GET call as a URL, with its parameters and query filled in. */
|
|
47
|
+
export function getUrls(origin: string, calls: GetCalls): { key: GetKey; url: string }[] {
|
|
48
|
+
const urls: { key: GetKey; url: string }[] = [];
|
|
49
|
+
for (const [key, asks] of Object.entries(calls) as [GetKey, { params: Record<string, string>; input?: object }[]][]) {
|
|
50
|
+
for (const { params, input } of asks) urls.push({ key, url: address(origin, key, params, input) });
|
|
51
|
+
}
|
|
52
|
+
return urls;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Every route, whatever its method. */
|
|
56
|
+
const EVERY_ROUTE: { [K in RouteKey]: true } = {
|
|
57
|
+
'GET /me': true,
|
|
58
|
+
'GET /projects': true,
|
|
59
|
+
'PUT /projects/:project': true,
|
|
60
|
+
'PATCH /projects/:project': true,
|
|
61
|
+
'PUT /projects/:project/:environment': true,
|
|
62
|
+
'PATCH /projects/:project/:environment': true,
|
|
63
|
+
'GET /secrets/:project/:environment': true,
|
|
64
|
+
'PATCH /secrets/:project/:environment': true,
|
|
65
|
+
'PATCH /secrets/:project/:environment/:key': true,
|
|
66
|
+
'GET /secrets/:project/:environment/:key/versions': true,
|
|
67
|
+
'POST /secrets/:project/:environment/:key/restore': true,
|
|
68
|
+
'POST /reveals': true,
|
|
69
|
+
'GET /members': true,
|
|
70
|
+
'GET /members/:member': true,
|
|
71
|
+
'PUT /members/:member': true,
|
|
72
|
+
'DELETE /members/:member': true,
|
|
73
|
+
'GET /members/:member/tokens': true,
|
|
74
|
+
'POST /members/:member/tokens': true,
|
|
75
|
+
'DELETE /members/:member/tokens/:id': true,
|
|
76
|
+
'PATCH /access/:member': true,
|
|
77
|
+
'GET /sessions': true,
|
|
78
|
+
'DELETE /sessions/:id': true,
|
|
79
|
+
'GET /identities': true,
|
|
80
|
+
'DELETE /identities/:id': true,
|
|
81
|
+
'GET /device-logins/:code': true,
|
|
82
|
+
'POST /device-logins/:code': true,
|
|
83
|
+
'GET /syncs/providers': true,
|
|
84
|
+
'GET /syncs/:project/:environment': true,
|
|
85
|
+
'POST /syncs/:project/:environment': true,
|
|
86
|
+
'PATCH /syncs/by-id/:id': true,
|
|
87
|
+
'DELETE /syncs/by-id/:id': true,
|
|
88
|
+
'POST /syncs/by-id/:id/runs': true,
|
|
89
|
+
'GET /audit': true,
|
|
90
|
+
'GET /audit/verification': true,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Every route as a method and a URL, each parameter a made-up value: what
|
|
95
|
+
* a caller with no right to any of them would send.
|
|
96
|
+
*/
|
|
97
|
+
export function everyRoute(origin: string): { key: RouteKey; method: string; url: string }[] {
|
|
98
|
+
return (Object.keys(EVERY_ROUTE) as RouteKey[]).map((key) => {
|
|
99
|
+
const [method, pattern] = key.split(' ') as [string, string];
|
|
100
|
+
const path = pattern.replace(/:(\w+)/g, (_, name: string) =>
|
|
101
|
+
encodeURIComponent(name === 'member' ? 'token:conformance-nobody' : 'conformance-nobody'),
|
|
102
|
+
);
|
|
103
|
+
return { key, method, url: `${origin}/api${path}` };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function address(origin: string, key: GetKey, params: Record<string, string>, input: object | undefined): string {
|
|
108
|
+
const path = key.slice('GET '.length).replace(/:(\w+)/g, (_, name: string) => encodeURIComponent(params[name]!));
|
|
109
|
+
const url = new URL(`${origin}/api${path}`);
|
|
110
|
+
for (const [name, value] of Object.entries(input ?? {})) url.searchParams.set(name, String(value));
|
|
111
|
+
return url.href;
|
|
112
|
+
}
|
package/src/suite.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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.
|
|
4
|
+
import type { Deployment } from './harness.ts';
|
|
5
|
+
import { Report } from './report.ts';
|
|
6
|
+
import { bulkLimit, crossSite, grantScoping, membersOnly, offboarding } from './checks/access.ts';
|
|
7
|
+
import { checkpoints, deletedTail, forgedVaultEntry, missingEntry, noAuditNoValue, revealAudited, rewrittenEntry, verification, writesAgree } from './checks/audit.ts';
|
|
8
|
+
import { earlierCheckpoint } from './checks/checkpoints.ts';
|
|
9
|
+
import { appLogin, vaultLogin } from './checks/logins.ts';
|
|
10
|
+
import { accessAuthorship, memberTampering, noAuditNoAccess, sealingRace } from './checks/members.ts';
|
|
11
|
+
import { refusedCheckpoint, missingCheckpoint, middleCut } from './checks/readiness.ts';
|
|
12
|
+
import { editedGeneration, forgedCredential, forgedIdentity, forgedApproval } from './checks/signin.ts';
|
|
13
|
+
import { canaryScan } from './checks/canaries.ts';
|
|
14
|
+
import { anonymousChecks, tokenChecks, type Canary } from './checks/live.ts';
|
|
15
|
+
import { personas, setUp, setUpLive, signInAdmin } from './checks/people.ts';
|
|
16
|
+
import { health } from './checks/surface.ts';
|
|
17
|
+
|
|
18
|
+
/** The names of the checks that failed. */
|
|
19
|
+
export async function conform(deployment: Deployment, options: { bulkLimit: number }): Promise<string[]> {
|
|
20
|
+
const report = new Report();
|
|
21
|
+
await report.check('health', {}, () => health(deployment));
|
|
22
|
+
// What `probe` checks of a running instance, from outside: as no one, and
|
|
23
|
+
// with a token reading one canary. The rest needs this run's own keys,
|
|
24
|
+
// database and processes.
|
|
25
|
+
await anonymousChecks(report, deployment.origin, { health: false });
|
|
26
|
+
const admin = await report.check('sign-in', {}, () => signInAdmin(deployment));
|
|
27
|
+
const canaries = await report.check('setup', { admin }, ({ admin }) => setUp(admin));
|
|
28
|
+
const people = await report.check('personas', { admin, canaries }, ({ admin }) => personas(deployment, admin));
|
|
29
|
+
const all = { people, canaries };
|
|
30
|
+
|
|
31
|
+
await report.check('members only', { people }, ({ people }) => membersOnly(deployment, people));
|
|
32
|
+
await report.check('grant scoping', all, ({ people, canaries }) => grantScoping(people, canaries));
|
|
33
|
+
await report.check('reveals audited', all, ({ people, canaries }) => revealAudited(deployment, people, canaries, 'reveal'));
|
|
34
|
+
await report.check('runs audited', all, ({ people, canaries }) => revealAudited(deployment, people, canaries, 'run'));
|
|
35
|
+
await report.check('cross-site', all, ({ people, canaries }) => crossSite(people, canaries));
|
|
36
|
+
const live = await report.check('live setup', { admin, canaries }, ({ admin, canaries }) => setUpLive(admin, canaries));
|
|
37
|
+
await tokenChecks(report, deployment.origin, live ?? {});
|
|
38
|
+
await report.check('offboarding', all, ({ people, canaries }) => offboarding(deployment, people, canaries));
|
|
39
|
+
await report.check('bulk limit', { people }, ({ people }) => bulkLimit(people, options.bulkLimit));
|
|
40
|
+
|
|
41
|
+
await report.check('checkpoints', { people }, ({ people }) => checkpoints(deployment, people));
|
|
42
|
+
await report.check('keys behind writes', { people }, ({ people }) => writesAgree(deployment));
|
|
43
|
+
await report.check('no audit, no value', all, ({ people, canaries }) => noAuditNoValue(deployment, people, canaries));
|
|
44
|
+
|
|
45
|
+
await report.check('access authorship', { people }, ({ people }) => accessAuthorship(deployment, people));
|
|
46
|
+
await report.check('no audit, no access', { people }, ({ people }) => noAuditNoAccess(deployment, people));
|
|
47
|
+
await report.check('full verification', { people }, ({ people }) => verification(deployment, people));
|
|
48
|
+
await report.check('checkpoint refused', {}, () => refusedCheckpoint(deployment));
|
|
49
|
+
await report.check('checkpoint missing', {}, () => missingCheckpoint(deployment));
|
|
50
|
+
await report.check('app login', {}, () => appLogin(deployment));
|
|
51
|
+
await report.check('vault login', {}, () => vaultLogin(deployment));
|
|
52
|
+
await report.check('forged grant', { people }, ({ people }) => memberTampering(deployment, people, 'grant'));
|
|
53
|
+
await report.check('forged member', { people }, ({ people }) => memberTampering(deployment, people, 'member'));
|
|
54
|
+
await report.check('stale member', { people }, ({ people }) => memberTampering(deployment, people, 'stale'));
|
|
55
|
+
await report.check('sealing race', { people }, ({ people }) => sealingRace(deployment, people));
|
|
56
|
+
await report.check('forged credential', { people }, ({ people }) => forgedCredential(deployment, people));
|
|
57
|
+
await report.check('forged identity', { people }, ({ people }) => forgedIdentity(deployment, people));
|
|
58
|
+
await report.check('forged approval', { people }, ({ people }) => forgedApproval(deployment, people));
|
|
59
|
+
await report.check('edited generation', { people }, ({ people }) => editedGeneration(deployment, people));
|
|
60
|
+
await report.check('canary scan', all, ({ people, canaries }) => canaryScan(deployment, people, canaries));
|
|
61
|
+
for (const author of ['app', 'vault'] as const) {
|
|
62
|
+
await report.check(`${author} rewritten`, { people }, ({ people }) => rewrittenEntry(deployment, people, author));
|
|
63
|
+
}
|
|
64
|
+
await report.check('vault forged', { people }, ({ people }) => forgedVaultEntry(deployment, people));
|
|
65
|
+
await report.check('middle gap', { people }, ({ people }) => missingEntry(deployment, people, 'middle'));
|
|
66
|
+
await report.check('middle cut', { people }, ({ people }) => middleCut(deployment, people));
|
|
67
|
+
await report.check('first gap', { people }, ({ people }) => missingEntry(deployment, people, 'first'));
|
|
68
|
+
await report.check('batch gap', { people }, ({ people }) => missingEntry(deployment, people, 'batch'));
|
|
69
|
+
await report.check('earlier checkpoint', { people }, ({ people }) => earlierCheckpoint(deployment, people));
|
|
70
|
+
await report.check('tail deleted', { people }, ({ people }) => deletedTail(deployment, people));
|
|
71
|
+
return report.failed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* What can be checked of an instance someone else runs: as no one, and with
|
|
76
|
+
* a token that reads a canary when given one. Nothing is written but the
|
|
77
|
+
* audit log's entries for the token's reads.
|
|
78
|
+
*/
|
|
79
|
+
export async function probe(origin: string, live: { token?: string; canary?: Canary }): Promise<string[]> {
|
|
80
|
+
const report = new Report();
|
|
81
|
+
await anonymousChecks(report, origin, { health: true });
|
|
82
|
+
if (live.token !== undefined) await tokenChecks(report, origin, live);
|
|
83
|
+
return report.failed;
|
|
84
|
+
}
|