@coffre/conformance 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/dist/main.js +968 -1336
- package/package.json +4 -4
- package/src/bundle.ts +7 -21
- package/src/checks/access.ts +14 -12
- package/src/checks/audit.ts +189 -295
- package/src/checks/canaries.ts +2 -15
- package/src/checks/cli.ts +39 -23
- package/src/checks/deletion.ts +18 -10
- package/src/checks/environments.ts +68 -49
- package/src/checks/logins.ts +32 -87
- package/src/checks/mcp.ts +83 -29
- package/src/checks/members.ts +127 -81
- package/src/checks/pages.ts +11 -17
- package/src/checks/people.ts +11 -0
- package/src/checks/signin.ts +25 -23
- package/src/checks/storage.ts +39 -78
- package/src/checks/surface.ts +22 -13
- package/src/checks/workloads.ts +32 -17
- package/src/database.ts +7 -28
- package/src/harness.ts +38 -62
- package/src/main.ts +5 -10
- package/src/report.ts +18 -1
- package/src/suite.ts +10 -23
- package/src/unserved.ts +9 -0
- package/src/checks/checkpoints.ts +0 -66
- package/src/checks/readiness.ts +0 -99
package/src/checks/canaries.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// A value leaves coffre through a reveal and nowhere else: not in any
|
|
2
2
|
// answer to a GET, whoever asks, not in a page, and not in what it stores or
|
|
3
3
|
// prints. Every value set is a random canary, so finding one is a leak.
|
|
4
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
5
4
|
|
|
6
5
|
import { using } from '../database.ts';
|
|
7
6
|
import type { Deployment } from '../harness.ts';
|
|
@@ -97,9 +96,9 @@ export async function canaryScan(deployment: Deployment, people: People, canarie
|
|
|
97
96
|
const names = await tables(sql);
|
|
98
97
|
// Prove the reader sees bytes before trusting an absence of plaintext.
|
|
99
98
|
const control = canary();
|
|
100
|
-
await sql.exec(
|
|
99
|
+
await sql.exec('CREATE TABLE conformance_canary_probe (value bytea)');
|
|
101
100
|
try {
|
|
102
|
-
await sql.query(
|
|
101
|
+
await sql.query('INSERT INTO conformance_canary_probe VALUES ($1)', [Buffer.from(control)]);
|
|
103
102
|
let found = false;
|
|
104
103
|
await scanTables(sql, ['conformance_canary_probe'], (_, bytes) => { found ||= Buffer.from(bytes).includes(control); });
|
|
105
104
|
expect(found, 'the database scanner missed its planted binary canary');
|
|
@@ -109,21 +108,9 @@ export async function canaryScan(deployment: Deployment, people: People, canarie
|
|
|
109
108
|
await scanTables(sql, names, look);
|
|
110
109
|
stored.push(`${names.length} tables, with a binary positive control`);
|
|
111
110
|
});
|
|
112
|
-
if (deployment.databaseFile !== null) {
|
|
113
|
-
look("the database's file", files(deployment.databaseFile));
|
|
114
|
-
stored.push('the database file and WAL');
|
|
115
|
-
}
|
|
116
111
|
look("the processes' output", deployment.output());
|
|
117
112
|
stored.push("the processes' output");
|
|
118
113
|
|
|
119
114
|
expect(leaks.length === 0, 'a value was found outside a reveal', leaks);
|
|
120
115
|
return `${answers} answers from ${Object.keys(routes).length} GET routes and ${paths.length} pages as ${callers.length} callers, and ${stored.join(', ')}: no value`;
|
|
121
116
|
}
|
|
122
|
-
|
|
123
|
-
/** A SQLite file and its write-ahead log, as bytes: what anyone with the disk would read. */
|
|
124
|
-
function files(path: string): Buffer {
|
|
125
|
-
expect(existsSync(path), `the store file could not be found: ${path}`);
|
|
126
|
-
return Buffer.concat([path, `${path}-wal`]
|
|
127
|
-
.filter((file) => existsSync(file))
|
|
128
|
-
.map((file) => readFileSync(file)));
|
|
129
|
-
}
|
package/src/checks/cli.ts
CHANGED
|
@@ -115,7 +115,7 @@ function marks(output: string): Record<string, string> {
|
|
|
115
115
|
return Object.fromEntries(lines.map(([, mark, name]) => [name!.trim(), mark!]));
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
/** The token's run, from CI: as no one, then as the token, which
|
|
118
|
+
/** The token's run, from CI: as no one, then as the token, which reads no audit log but its project's, so holds none to its head. */
|
|
119
119
|
export async function verifyWithToken(cli: Cli, live: { token: string; canary: Canary }): Promise<string> {
|
|
120
120
|
const { canary } = live;
|
|
121
121
|
// As a CI step does: the token piped to `coffre login --token`, then the canary's value to the check.
|
|
@@ -124,10 +124,10 @@ export async function verifyWithToken(cli: Cli, live: { token: string; canary: C
|
|
|
124
124
|
const run = await cli.run(['verify', 'instance', cli.origin, '--canary', `${canary.project}/${canary.environment}/${canary.key}`], {}, `${canary.value}\n`);
|
|
125
125
|
const seen = marks(run.output);
|
|
126
126
|
expect(run.code === 0, `coffre verify instance with a token exited ${run.code}`, run.output);
|
|
127
|
-
expect(
|
|
127
|
+
expect(!('owner log proofs' in seen), "a token's run held the log to its head, which only an owner's reads whole", run.output);
|
|
128
128
|
expect(!run.output.includes(live.token) && !run.output.includes(canary.value), 'the run printed its token or its canary', run.output);
|
|
129
129
|
const ok = Object.values(seen).filter((mark) => mark === '✓').length;
|
|
130
|
-
return `${ok} checks ok as no one and as the token
|
|
130
|
+
return `${ok} checks ok as no one and as the token; neither the token nor the canary shown`;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/** What a run as an owner must leave as it was: every member and their grants, but its service; every project and environment. */
|
|
@@ -163,7 +163,8 @@ export async function verifyAsOwner(cli: Cli): Promise<{ detail: string; value:
|
|
|
163
163
|
const run = await cli.run(['verify', 'instance']);
|
|
164
164
|
const seen = marks(run.output);
|
|
165
165
|
expect(run.code === 0, `coffre verify instance as the admin exited ${run.code}`, run.output);
|
|
166
|
-
// Signed in, nothing is out of reach: a check skipped
|
|
166
|
+
// Signed in, nothing is out of reach: a check skipped would only be noise.
|
|
167
|
+
expect(seen['owner log proofs'] === '✓', "the run did not hold the log's newest entries to the head the vault signed", run.output);
|
|
167
168
|
const skipped = Object.entries(seen).filter(([, mark]) => mark !== '✓').map(([name]) => name);
|
|
168
169
|
expect(skipped.length === 0, `the run skipped ${skipped.join(', ')}`, run.output);
|
|
169
170
|
expect(!SHOWN.test(run.output) && !run.output.includes(session), 'the run printed a credential, the session or its canary', SHOWN.exec(run.output)?.[0]);
|
|
@@ -215,37 +216,36 @@ export async function verifyLeftovers(cli: Cli, admin: Person, setups: string[],
|
|
|
215
216
|
const { values } = await admin.api.secrets.reveal(`${place}/${kept.key}`);
|
|
216
217
|
expect(values[kept.key] === kept.value, `${place}/${kept.key}, kept beside the run's own, was changed`);
|
|
217
218
|
expect((await everythingElse(admin.api)) === before, 'the runs changed a member, a grant, a project or an environment besides their own');
|
|
218
|
-
const { entries } = await admin.api.audit.list({ actor: PROBE.service, limit: 50
|
|
219
|
+
const { entries } = await admin.api.audit.list({ actor: PROBE.service, limit: 50 });
|
|
219
220
|
expect(entries.length > 0, `the audit log holds no entry by ${PROBE.service}`);
|
|
220
221
|
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`;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
/**
|
|
224
|
-
* `coffre verify keys`, with the admin's session, the
|
|
225
|
-
* deployment's
|
|
226
|
-
*
|
|
225
|
+
* `coffre verify keys`, with the admin's session, the key piped in: this
|
|
226
|
+
* deployment's vault key passes, its vault ID as given; a wrong key and a
|
|
227
|
+
* malformed one each fail, named. No key is ever printed.
|
|
227
228
|
*/
|
|
228
229
|
export async function verifyKeys(cli: Cli): Promise<string> {
|
|
229
230
|
const wrong = Buffer.alloc(32, 7).toString('base64');
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
{ args: [
|
|
233
|
-
{ args: [], input:
|
|
234
|
-
{ args: [], input: `${KEYS.VAULT_KEY}\nnot-a-key\n`, code: 1, vault: '✓', app: '✗', said: /✗ app key +not an app key/ },
|
|
231
|
+
const runs: { args: string[]; input: string; code: number; key: string; said?: RegExp }[] = [
|
|
232
|
+
{ args: ['--vault-id', KEYS.VAULT_KEY_ID], input: `${KEYS.VAULT_KEY}\n`, code: 0, key: '✓' },
|
|
233
|
+
{ args: [], input: `${wrong}\n`, code: 1, key: '✗', said: /✗ key +not this instance's/ },
|
|
234
|
+
{ args: [], input: 'not-a-key\n', code: 1, key: '✗', said: /✗ key +not a key/ },
|
|
235
235
|
];
|
|
236
|
-
for (const { args, input, code,
|
|
236
|
+
for (const { args, input, code, key, said } of runs) {
|
|
237
237
|
const run = await cli.run(['verify', 'keys', ...args], {}, input);
|
|
238
|
-
|
|
239
|
-
expect(run.
|
|
240
|
-
|
|
241
|
-
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);
|
|
238
|
+
expect(run.code === code && marks(run.output)['key'] === key, `coffre verify keys exited ${run.code}`, run.output);
|
|
239
|
+
if (said !== undefined) expect(said.test(run.output), 'it did not say the key is not right', run.output);
|
|
240
|
+
for (const shown of [KEYS.VAULT_KEY, KEYS.APP_KEY, wrong, 'not-a-key']) expect(!run.output.includes(shown), 'a key was printed', run.output);
|
|
242
241
|
}
|
|
243
|
-
return "this deployment's
|
|
242
|
+
return "this deployment's vault key passes, vault ID included; a wrong key and a malformed one are each named; no key shown";
|
|
244
243
|
}
|
|
245
244
|
|
|
246
245
|
/**
|
|
247
246
|
* Everything the API does, the CLI does: with the admin's `coffre login`
|
|
248
|
-
* session, a project and its environment,
|
|
247
|
+
* session, a project and its environment, made twice, the second time
|
|
248
|
+
* changing nothing, a secret set and renamed, a
|
|
249
249
|
* service admitted and granted, a token issued into a 0600 file, then
|
|
250
250
|
* piped to `coffre login --token` in a CLI of the service's own, read
|
|
251
251
|
* with, revoked after its preview, and refused from then on; the grant
|
|
@@ -265,10 +265,27 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
265
265
|
return run.output;
|
|
266
266
|
};
|
|
267
267
|
const [coffre, service, agent] = [as(cli, ''), as(ci, ', as the service'), as(helper, ', with a personal token')];
|
|
268
|
+
// A revocation takes up to the vault's memory, 2 seconds (D218): the token was asked about a moment ago. Asked every
|
|
269
|
+
// 250 ms until refused, for that and a second more.
|
|
270
|
+
const revoked = async (who: Cli, label: string, args: string[]): Promise<void> => {
|
|
271
|
+
for (const started = Date.now(); ; await sleep(250)) {
|
|
272
|
+
const run = await who.run(args, {});
|
|
273
|
+
const waited = Date.now() - started;
|
|
274
|
+
if (run.code === 0 && waited < 3000) continue;
|
|
275
|
+
expect(run.code === 1, `coffre ${args.join(' ')}${label} exited ${run.code} ${waited} ms after its token was revoked, not 1`, run.output);
|
|
276
|
+
expect(/does not know this bearer token/.test(run.output), `a revoked token${label} was not refused plainly`, run.output);
|
|
277
|
+
steps.push(`${args.slice(0, 2).join(' ')}${label}`);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
268
281
|
try {
|
|
269
282
|
const value = `cli-value-${randomBytes(8).toString('hex')}`;
|
|
270
283
|
await coffre(['projects', 'create', 'conformance-cli', '--name', 'CLI']);
|
|
271
284
|
await coffre(['environments', 'create', 'conformance-cli/ci']);
|
|
285
|
+
// Made again, as a script that makes what it needs does: the server refuses it, `exists`, and the CLI says nothing changed.
|
|
286
|
+
const again = (await coffre(['projects', 'create', 'conformance-cli'])) + (await coffre(['environments', 'create', 'conformance-cli/ci']));
|
|
287
|
+
expect(again.includes('conformance-cli exists already: nothing changed') && again.includes('conformance-cli/ci exists already: nothing changed'),
|
|
288
|
+
'making a project or an environment that is there already did not say nothing changed', again);
|
|
272
289
|
await coffre(['set', 'conformance-cli/ci/API_KEY'], value);
|
|
273
290
|
await coffre(['rename', 'conformance-cli/ci/API_KEY', 'API_TOKEN']);
|
|
274
291
|
const refused = await coffre(['grant', 'conformance-cli', 'conformance-deploy', '--role', 'viewer', '--env', 'ci', '--service'], undefined, 1);
|
|
@@ -295,8 +312,7 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
295
312
|
expect(/Nothing changed\. Re-run with --apply/.test(preview), 'tokens revoke without --apply did not preview', preview);
|
|
296
313
|
await service(['get', 'conformance-cli/ci/API_TOKEN']);
|
|
297
314
|
await coffre(['tokens', 'revoke', 'conformance-deploy', listed!.id, '--apply']);
|
|
298
|
-
|
|
299
|
-
expect(/does not know this bearer token/.test(gone), 'a revoked token was not refused plainly', gone);
|
|
315
|
+
await revoked(ci, ', as the service', ['get', 'conformance-cli/ci/API_TOKEN']);
|
|
300
316
|
|
|
301
317
|
// A personal token, for an agent with a CLI of its own: it reads as the admin, within its scope, and makes no token.
|
|
302
318
|
const personal = join(cli.home, 'agent-token');
|
|
@@ -314,7 +330,7 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
314
330
|
const [mine] = JSON.parse(await coffre(['tokens', '--json'])) as { id: string; label: string }[];
|
|
315
331
|
expect(mine?.label === 'conformance-agent', 'tokens --json does not list the personal token', mine);
|
|
316
332
|
await coffre(['tokens', 'revoke', mine!.id, '--apply']);
|
|
317
|
-
await
|
|
333
|
+
await revoked(helper, ', with a personal token', ['get', 'conformance-cli/ci/API_TOKEN']);
|
|
318
334
|
|
|
319
335
|
await coffre(['revoke', 'conformance-cli', 'conformance-deploy', '--env', 'ci', '--service']);
|
|
320
336
|
await coffre(['archive', 'conformance-cli/ci/API_TOKEN']);
|
package/src/checks/deletion.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { CoffreError } from '@coffre/client';
|
|
|
8
8
|
|
|
9
9
|
import { using } from '../database.ts';
|
|
10
10
|
import type { Deployment } from '../harness.ts';
|
|
11
|
-
import { expect } from '../report.ts';
|
|
11
|
+
import { expect, until, PUBLISHED_SECONDS } from '../report.ts';
|
|
12
12
|
import type { Cli } from './cli.ts';
|
|
13
13
|
import type { Person } from './people.ts';
|
|
14
14
|
import { query } from './storage.ts';
|
|
@@ -72,7 +72,8 @@ export async function deletion(deployment: Deployment, cli: Cli, admin: Person):
|
|
|
72
72
|
expect((await admin.api.projects.list()).projects.every((project) => !project.slug.startsWith(PROJECT)), 'a deleted project is still listed');
|
|
73
73
|
expect((await admin.api.members.get(SERVICE)).live.grants === 0, 'a grant on the deleted project is still live');
|
|
74
74
|
const revealed = await admin.api.secrets.reveal(`${tombstone!.slug}/prod`).then(() => null, (error: unknown) => error);
|
|
75
|
-
|
|
75
|
+
// 0.16 refuses the tombstone's slug as no path at all (400), where 0.14 found nothing there (404).
|
|
76
|
+
expect(revealed instanceof CoffreError && (revealed.status === 404 || revealed.status === 400), 'a deleted project is still revealed by its tombstone', revealed);
|
|
76
77
|
|
|
77
78
|
// Its slug is another project's now; the log tells the two apart.
|
|
78
79
|
const fresh = value();
|
|
@@ -81,18 +82,25 @@ export async function deletion(deployment: Deployment, cli: Cli, admin: Person):
|
|
|
81
82
|
await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: fresh });
|
|
82
83
|
expect((await projectId(deployment, PROJECT)) !== id, 'the new project took the deleted one\'s row');
|
|
83
84
|
expect((await admin.api.secrets.reveal(`${PROJECT}/prod/API_KEY`)).values.API_KEY === fresh, 'the new project does not read its own value');
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
// The page lists the deletion once the signer has published it, within its minute.
|
|
86
|
+
type Page = Awaited<ReturnType<typeof admin.api.audit.list>>;
|
|
87
|
+
let page: Page | Error | undefined;
|
|
88
|
+
const deleted = () => page !== undefined && !(page instanceof Error) && page.entries.some((entry) => entry.action === 'project.delete' && entry.decision === 'allow');
|
|
89
|
+
await until('the deletion on the log under its tombstone', async () => {
|
|
90
|
+
page = await admin.api.audit.list({ path: tombstone!.slug, limit: 500 }).catch((error: unknown) => error instanceof Error ? error : new Error(String(error)));
|
|
91
|
+
return page instanceof Error || deleted();
|
|
92
|
+
}, PUBLISHED_SECONDS).catch(() => undefined);
|
|
93
|
+
expect(!(page instanceof Error), 'the log cannot be read under the tombstone\'s slug', page instanceof Error ? page.message : page);
|
|
94
|
+
expect(deleted(), 'the deletion is not in the log under its tombstone', (page as Page | undefined)?.entries.slice(0, 5));
|
|
86
95
|
|
|
87
96
|
// An environment alone, the same way.
|
|
88
97
|
await admin.api.environments.update(`${PROJECT}/prod`, { archived: true });
|
|
89
98
|
await run(['environments', 'delete', `${PROJECT}/prod`, '--apply']);
|
|
90
|
-
await admin.api.environments.create(`${PROJECT}/prod`, {
|
|
99
|
+
await admin.api.environments.create(`${PROJECT}/prod`, {});
|
|
100
|
+
// 0.16 names a place by its slug alone (0.14.7 kept a display name): the new prod is told from the deleted one by holding no key.
|
|
91
101
|
const environments = (await admin.api.projects.list()).projects.find((project) => project.slug === PROJECT)?.environments ?? [];
|
|
92
|
-
expect(environments.length === 1 && environments[0]!.
|
|
102
|
+
expect(environments.length === 1 && environments[0]!.slug === 'prod' && environments[0]!.details?.secretCount === 0,
|
|
103
|
+
'a deleted environment is still listed, or its slug is not free', environments);
|
|
93
104
|
expect((await sealed(deployment, (await projectId(deployment, PROJECT))!)).sealed === 0, 'a deleted environment still holds a value');
|
|
94
|
-
|
|
95
|
-
const verified = await admin.api.audit.verify();
|
|
96
|
-
expect(verified.ok, 'the log does not verify after the deletions', verified);
|
|
97
|
-
return `${PROJECT} and ${PROJECT}/prod deleted by the CLI: 5 versions erased, a grant revoked, both unlisted and their slugs reused; ${verified.entries} entries verify`;
|
|
105
|
+
return `${PROJECT} and ${PROJECT}/prod deleted by the CLI: 5 versions erased, a grant revoked, both unlisted and their slugs reused`;
|
|
98
106
|
}
|
|
@@ -7,13 +7,9 @@ import { CoffreError, type AuditEntryView } from '@coffre/client';
|
|
|
7
7
|
|
|
8
8
|
import { using } from '../database.ts';
|
|
9
9
|
import type { Deployment } from '../harness.ts';
|
|
10
|
-
import { expect, refused } from '../report.ts';
|
|
11
|
-
import { canary, DEV, PROD, PROJECT, valuesIn, type Canaries, type People } from './people.ts';
|
|
10
|
+
import { expect, refused, until, PUBLISHED_SECONDS } from '../report.ts';
|
|
11
|
+
import { canary, DEV, PROD, PROJECT, valuesIn, type Canaries, type People, type Person } from './people.ts';
|
|
12
12
|
import { query } from './storage.ts';
|
|
13
|
-
import { listed } from './audit.ts';
|
|
14
|
-
|
|
15
|
-
/** A read of one key refused, whatever the reason (D153): `outcome`'s status and code. */
|
|
16
|
-
const NO = '404 not_available';
|
|
17
13
|
|
|
18
14
|
/** Where the fork check copies dev to; archived once checked. */
|
|
19
15
|
const FORKED = `${PROJECT}/forked`;
|
|
@@ -141,8 +137,7 @@ export async function personalConfigs(deployment: Deployment, { admin, reader }:
|
|
|
141
137
|
|
|
142
138
|
/** The key in dev the reference check makes, archived once checked. */
|
|
143
139
|
const HELD = 'CONFORMANCE_REFERENCE';
|
|
144
|
-
|
|
145
|
-
const FORGED = `CONFORMANCE_FORGED_${randomUUID().slice(0, 8).toUpperCase()}`;
|
|
140
|
+
const FORGED = 'CONFORMANCE_FORGED';
|
|
146
141
|
|
|
147
142
|
/** The status a call failed with and its reason, the vault's or the app's, or that it went through. */
|
|
148
143
|
async function outcome(call: Promise<unknown>): Promise<string> {
|
|
@@ -169,26 +164,33 @@ export async function references(deployment: Deployment, { admin, reader, leaver
|
|
|
169
164
|
expect(sourceKey !== undefined, 'prod holds no secret to refer to');
|
|
170
165
|
const source = `${PROD}/${sourceKey}`;
|
|
171
166
|
await refused('a viewer on dev read prod directly', reader.api.secrets.reveal(source));
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
// 0.14 refused it `missing_secret_read`; 0.16's vault, `no_access`, as any place the maker does not read.
|
|
168
|
+
const made = await outcome(leaver.api.secrets.set(DEV, { [HELD]: { ref: source } }));
|
|
169
|
+
expect(made === '403 no_access', "a developer on dev who cannot read prod made a reference to prod's secret", made);
|
|
174
170
|
|
|
175
171
|
await admin.api.secrets.set(DEV, { [HELD]: { ref: source } });
|
|
176
172
|
try {
|
|
177
173
|
const read = await reader.api.secrets.reveal(`${DEV}/${HELD}`);
|
|
178
174
|
expect(read.values[HELD] === canaries[source], "a viewer on dev did not read prod's value through dev's reference");
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
// 0.16's entry names the read by its reader and its request, and each key read through a reference by its holder, `through`;
|
|
176
|
+
// the page lists it once the signer has published it, within its minute. The source key's own log is looked at
|
|
177
|
+
// too, to tell a read missing from prod's log from one missing from the log altogether.
|
|
178
|
+
const through = (entry: AuditEntryView) => entry.requestId === read.operationId && entry.action === 'secret.read'
|
|
179
|
+
&& entry.actorType === 'user' && entry.actorId === reader.email
|
|
180
|
+
&& Array.isArray(entry.metadata.keys) && entry.metadata.keys.some((key: unknown) => typeof key === 'object' && key !== null && 'through' in key);
|
|
181
|
+
const seen: Record<string, boolean> = { [PROD]: false, [DEV]: false, [source]: false };
|
|
182
|
+
const shown: Record<string, AuditEntryView[]> = {};
|
|
183
|
+
await until('the read through the reference on the logs', async () => {
|
|
184
|
+
for (const path of Object.keys(seen)) seen[path] ||= (shown[path] = (await admin.api.audit.list({ path, limit: 200 })).entries).some(through);
|
|
185
|
+
return Object.values(seen).every(Boolean);
|
|
186
|
+
}, PUBLISHED_SECONDS).catch(() => undefined);
|
|
187
|
+
expect(seen[PROD] && seen[DEV], "the reader's read through the reference is not in both the source's log and the holder's",
|
|
188
|
+
{ seen, shown: Object.fromEntries(Object.entries(shown).map(([path, entries]) => [path, entries.slice(0, 5).map((entry) => `${entry.seq} ${entry.action} ${entry.actorId} ${entry.requestId}`)])) });
|
|
189
189
|
|
|
190
190
|
// What it reads cannot be archived while it reads it (D41): not the key, nor its environment. Its
|
|
191
191
|
// project could be, since the reference is held there too, and archiving it stops no one else's read.
|
|
192
|
+
// 0.16's refusal does not name the holder, as 0.14.7's did: the source's references list does, to whoever
|
|
193
|
+
// lists or manages access there, and the refusal says so.
|
|
192
194
|
const archives: [string, (archived: boolean) => Promise<unknown>][] = [
|
|
193
195
|
[source, (archived) => admin.api.secrets.update(source, { archived })],
|
|
194
196
|
[PROD, (archived) => admin.api.environments.update(PROD, { archived })],
|
|
@@ -196,8 +198,10 @@ export async function references(deployment: Deployment, { admin, reader, leaver
|
|
|
196
198
|
for (const [what, archive] of archives) {
|
|
197
199
|
const refusal = await archive(true).then(() => null, (error: unknown) => error);
|
|
198
200
|
if (refusal === null) await archive(false);
|
|
199
|
-
expect(refusal instanceof CoffreError && refusal.status === 409 && refusal.
|
|
200
|
-
`${what} was archived, or refused
|
|
201
|
+
expect(refusal instanceof CoffreError && refusal.status === 409 && refusal.reason === 'referenced',
|
|
202
|
+
`${what} was archived, or refused other than as referenced, while a reference read it`, refusal instanceof Error ? refusal.message : refusal);
|
|
203
|
+
const holders = (await admin.api.references.list(what)).references.filter((reference) => reference.source === source).map((reference) => reference.holder);
|
|
204
|
+
expect(holders.includes(`${DEV}/${HELD}`), `${what}'s references do not name ${DEV}/${HELD}, the reference that blocks its archive`, holders);
|
|
201
205
|
}
|
|
202
206
|
// Unless what holds it is archived (D58): nobody reads through it then, so its source archives. Restored,
|
|
203
207
|
// the holder reads nothing through it until its source is back, and says so.
|
|
@@ -206,44 +210,39 @@ export async function references(deployment: Deployment, { admin, reader, leaver
|
|
|
206
210
|
try {
|
|
207
211
|
expect(underArchived === 'let through', `${source} could not be archived while only an archived key referred to it: ${underArchived}`);
|
|
208
212
|
const restored = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
|
|
209
|
-
|
|
210
|
-
expect(restored === NO, `a reference read a source archived while its holder was: ${restored}`);
|
|
213
|
+
expect(restored.startsWith('409 '), `a reference read a source archived while its holder was: ${restored}`);
|
|
211
214
|
} finally {
|
|
212
215
|
if (underArchived === 'let through') await admin.api.secrets.update(source, { archived: false });
|
|
213
216
|
}
|
|
214
217
|
const back = await reader.api.secrets.reveal(`${DEV}/${HELD}`);
|
|
215
218
|
expect(back.values[HELD] === canaries[source], 'a reference did not read its source again once both were restored');
|
|
216
219
|
|
|
217
|
-
// A row the vault never sealed: a
|
|
220
|
+
// A row the vault never sealed: a key in dev whose row says it reads prod's secret, its MAC none of the vault's.
|
|
218
221
|
const forged = await using(deployment.database(), async (sql) => {
|
|
219
|
-
const [holder] = await query<{
|
|
220
|
-
'SELECT
|
|
221
|
-
const [target] = await query<{ id: string
|
|
222
|
-
'SELECT s.id
|
|
223
|
-
const [entry] = await query<{ seq: number | string | bigint }>(sql,
|
|
224
|
-
"SELECT seq FROM audit_log WHERE author = 'vault' AND action = 'access.grant' AND decision = 'allow' ORDER BY seq DESC LIMIT 1");
|
|
222
|
+
const [holder] = await query<{ project_id: string; environment_id: string }>(sql,
|
|
223
|
+
'SELECT project_id, environment_id FROM secrets WHERE key = $1', [HELD]);
|
|
224
|
+
const [target] = await query<{ id: string }>(sql,
|
|
225
|
+
'SELECT s.id FROM secrets s JOIN environments e ON e.id = s.environment_id WHERE s.key = $1 AND e.slug = $2', [sourceKey, PROD.split('/')[1]]);
|
|
225
226
|
const id = randomUUID();
|
|
226
|
-
|
|
227
|
-
await query(sql, `INSERT INTO
|
|
228
|
-
VALUES ($1, $2, $3, $4, $5, $
|
|
227
|
+
const now = new Date();
|
|
228
|
+
await query(sql, `INSERT INTO secrets (id, project_id, environment_id, key, created_at, updated_at, versions, source_id, source_set_at, source_set_by)
|
|
229
|
+
VALUES ($1, $2, $3, $4, $5, $5, 0, $6, $5, $7)`, [id, holder!.project_id, holder!.environment_id, FORGED, now, target!.id, admin.member]);
|
|
229
230
|
return id;
|
|
230
231
|
});
|
|
231
232
|
try {
|
|
232
233
|
const forgedRead = await outcome(reader.api.secrets.reveal(`${DEV}/${FORGED}`));
|
|
233
|
-
//
|
|
234
|
-
expect(
|
|
234
|
+
// A row the vault did not write is no row to it: the key is not there (0.16's `unknown_key`), and nothing is read through it.
|
|
235
|
+
expect(forgedRead === '404 unknown_key', `a reference row the vault never made was read: ${forgedRead}`);
|
|
235
236
|
} finally {
|
|
236
|
-
|
|
237
|
-
// names the key, and the log keeps every entry.
|
|
238
|
-
await using(deployment.database(), async (sql) => {
|
|
239
|
-
await query(sql, 'DELETE FROM secret_references WHERE secret_id = $1', [forged]);
|
|
240
|
-
await query(sql, sql.engine === 'postgres' ? 'UPDATE secrets SET archived_at = now() WHERE id = $1' : 'UPDATE secrets SET archived_at = CAST(unixepoch(\'subsec\') * 1000 AS INTEGER) WHERE id = $1', [forged]);
|
|
241
|
-
});
|
|
237
|
+
await using(deployment.database(), (sql) => query(sql, 'DELETE FROM secrets WHERE id = $1', [forged]));
|
|
242
238
|
}
|
|
243
239
|
|
|
244
240
|
await admin.api.references.break(`${DEV}/${HELD}`);
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
// A key whose reference ended has no value until someone writes one (0.16's `no_value`; 0.14.7 answered 409).
|
|
242
|
+
const broken = await reader.api.secrets.reveal(`${DEV}/${HELD}`).then((answer) => answer, (error: unknown) => error);
|
|
243
|
+
const said = broken instanceof CoffreError ? `${broken.status} ${broken.reason ?? broken.code}` : 'let through';
|
|
244
|
+
expect(said === '404 no_value' && !JSON.stringify(broken instanceof Error ? { ...broken, message: broken.message } : broken).includes(canaries[source]!),
|
|
245
|
+
`a broken reference still read, or was refused other than as holding no value: ${said}`, broken instanceof Error ? broken.message : broken);
|
|
247
246
|
} finally {
|
|
248
247
|
await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
|
|
249
248
|
}
|
|
@@ -270,23 +269,43 @@ export async function loosening({ admin, reader, leaver }: People): Promise<stri
|
|
|
270
269
|
try {
|
|
271
270
|
await refused('a viewer read a sensitive value', reader.api.secrets.reveal(path));
|
|
272
271
|
expect((await leaver.api.secrets.list(DEV)).loosenable === false, 'a developer on dev is told they make a sensitive value a secret in place');
|
|
273
|
-
|
|
272
|
+
const theirs = await loosen(leaver);
|
|
273
|
+
expect(theirs.status >= 400 && theirs.status < 500, `a developer on dev made a sensitive value a secret in place, answered ${theirs.status}`, await theirs.text());
|
|
274
274
|
expect((await admin.api.secrets.list(DEV)).loosenable === true, 'the admin, an Owner of the whole instance, is told they do not loosen');
|
|
275
|
-
const
|
|
276
|
-
|
|
275
|
+
const answer = await loosen(admin);
|
|
276
|
+
const text = await answer.text();
|
|
277
|
+
expect(answer.ok, `the admin's loosening answered ${answer.status}`, text);
|
|
278
|
+
expect(!text.includes(value), "the admin's loosening answered the value", text);
|
|
279
|
+
const marked = JSON.parse(text) as { keys: Record<string, unknown> };
|
|
277
280
|
expect(JSON.stringify(marked.keys[LOOSE]) === JSON.stringify({ version: 2, sensitivity: 'secret' }), 'the loosening made no new secret version', marked.keys);
|
|
278
281
|
const read = await reader.api.secrets.reveal(path);
|
|
279
282
|
expect(read.values[LOOSE] === value, "the reader did not read the loosened value as dev's secret");
|
|
280
283
|
const versions = (await admin.api.secrets.history(path)).versions.map((version) => version.sensitivity);
|
|
281
284
|
expect(versions.join() === 'secret,sensitive', 'the loosening changed the old version too, or made none', versions);
|
|
282
|
-
|
|
283
|
-
|
|
285
|
+
// The page lists what the signer has published, within its minute. The entry's line for the key says the nature it
|
|
286
|
+
// `was` and the one it is now (docs/design/0.16.md, "A change that makes any key looser is logged `secret.loosen`").
|
|
287
|
+
let logged: AuditEntryView[] = [];
|
|
288
|
+
await until('the loosening on the audit page', async () => {
|
|
289
|
+
logged = (await admin.api.audit.list({ path, limit: 50 })).entries.filter((entry) => entry.action === 'secret.loosen');
|
|
290
|
+
return logged.length > 0;
|
|
291
|
+
}, PUBLISHED_SECONDS).catch(() => undefined);
|
|
292
|
+
const lines = (logged.length === 1 ? logged[0]!.metadata.keys : undefined) as { key?: unknown; was?: unknown; nature?: unknown }[] | undefined;
|
|
293
|
+
expect(lines?.some((line) => line.key === LOOSE && line.was === 'sensitive' && line.nature === 'secret') === true, 'the loosening is not its own entry, saying both levels', logged);
|
|
284
294
|
} finally {
|
|
285
295
|
await admin.api.secrets.set(DEV, { [LOOSE]: null });
|
|
286
296
|
}
|
|
287
297
|
return 'the admin makes a sensitive value a secret in place, answered no value, as a new version, logged as secret.loosen; a developer on dev may not';
|
|
288
298
|
}
|
|
289
299
|
|
|
300
|
+
/**
|
|
301
|
+
* `{ sensitivity }` alone, a nature changed in place, as the page sends it:
|
|
302
|
+
* the client's types carry it again once 0.16 serves it (UNSERVED, in
|
|
303
|
+
* ../unserved.ts).
|
|
304
|
+
*/
|
|
305
|
+
function loosen(person: Person): Promise<Response> {
|
|
306
|
+
return person.browser.send('PATCH', `/api/secrets/${DEV}`, { [LOOSE]: { sensitivity: 'secret' } });
|
|
307
|
+
}
|
|
308
|
+
|
|
290
309
|
/**
|
|
291
310
|
* Within a project, key names are not secret; values are. What dev is
|
|
292
311
|
* missing is compared with every sibling: the reader, a viewer on dev who
|
package/src/checks/logins.ts
CHANGED
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
// Each component's database login writes
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// Each component's database login writes what it must and nothing else
|
|
2
|
+
// (docs/design/0.16.md, "Four rules"): the app's only reads; the vault's
|
|
3
|
+
// writes every row and entry, but not 0.14's archived log, and neither
|
|
4
|
+
// changes the schema or steps around its privileges. 0.14 also held the
|
|
5
|
+
// vault's login off the app's tables and both off rewriting the log; in
|
|
6
|
+
// 0.16 the vault writes every table, the log's included, and the signer
|
|
7
|
+
// holds what the log is held to.
|
|
6
8
|
import { using, type Sql } from '../database.ts';
|
|
7
9
|
import type { Deployment } from '../harness.ts';
|
|
8
|
-
import { expect
|
|
10
|
+
import { expect } from '../report.ts';
|
|
9
11
|
import { quoted, tables } from './storage.ts';
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
VALUES (9000000000, '${author}', '${author}:0', 0, 'system:conformance', 'probe', 'allow', ${ZEROS}, ${ZEROS}, ${ZEROS}, true)`;
|
|
17
|
-
const IMMUTABLE = [
|
|
18
|
-
"UPDATE audit_log SET action = 'rewritten' WHERE author = 'app'",
|
|
19
|
-
"UPDATE audit_log SET action = 'rewritten' WHERE author = 'vault'",
|
|
20
|
-
'DELETE FROM audit_log', 'TRUNCATE audit_log', 'DROP TABLE audit_log',
|
|
21
|
-
'UPDATE secret_versions SET id = id', 'DELETE FROM secret_versions',
|
|
22
|
-
'DELETE FROM vault_members', 'CREATE TABLE conformance_probe (id integer)',
|
|
23
|
-
'CREATE TEMP TABLE conformance_probe (id integer)',
|
|
24
|
-
'ALTER TABLE audit_log DISABLE TRIGGER USER', "SET session_replication_role = 'replica'",
|
|
13
|
+
/** What neither login may do: make or drop a table, empty one, or turn off the database's own checks. */
|
|
14
|
+
const BYPASSES = [
|
|
15
|
+
'CREATE TABLE conformance_probe (id integer)', 'CREATE TEMP TABLE conformance_probe (id integer)',
|
|
16
|
+
'DROP TABLE log', 'TRUNCATE log', 'TRUNCATE secret_versions',
|
|
17
|
+
'ALTER TABLE log_pending DISABLE TRIGGER USER', "SET session_replication_role = 'replica'",
|
|
25
18
|
'SET ROLE coffre_owner',
|
|
26
19
|
];
|
|
27
20
|
|
|
28
|
-
/** A column of each app table, for an update that would change nothing, if it were allowed. */
|
|
29
|
-
const APP_COLUMNS: Record<string, string> = {
|
|
30
|
-
projects: 'id', environments: 'id', secrets: 'id', secret_versions: 'id', identities: 'id',
|
|
31
|
-
credentials: 'id', device_authorizations: 'id',
|
|
32
|
-
};
|
|
33
|
-
|
|
34
21
|
async function refuses(sql: Sql, statements: string[]): Promise<number> {
|
|
35
22
|
for (const statement of statements) {
|
|
36
23
|
await sql.exec('BEGIN');
|
|
@@ -48,7 +35,7 @@ async function refuses(sql: Sql, statements: string[]): Promise<number> {
|
|
|
48
35
|
return statements.length;
|
|
49
36
|
}
|
|
50
37
|
|
|
51
|
-
/** Neither table nor column grants may let a login write
|
|
38
|
+
/** Neither table nor column grants may let a login write these tables. */
|
|
52
39
|
async function noWrites(sql: Sql, names: readonly string[]): Promise<void> {
|
|
53
40
|
const columns = await sql.query<{ table_name: string; column_name: string; insertable: boolean; updatable: boolean; deletable: boolean; truncatable: boolean }>(
|
|
54
41
|
`SELECT table_name, column_name,
|
|
@@ -68,72 +55,30 @@ async function noWrites(sql: Sql, names: readonly string[]): Promise<void> {
|
|
|
68
55
|
}
|
|
69
56
|
}
|
|
70
57
|
|
|
58
|
+
/** The app's login writes no table: every row is the vault's. */
|
|
71
59
|
export async function appLogin(deployment: Deployment): Promise<string> {
|
|
72
|
-
|
|
73
|
-
expect(deployment.runtime !== null, 'the app runtime login is missing');
|
|
74
|
-
const protectedTables = (await using(deployment.database(), tables)).filter((name) => name.startsWith('vault_'));
|
|
60
|
+
const all = await using(deployment.database(), tables);
|
|
75
61
|
return using(deployment.runtime(), async (sql) => {
|
|
76
|
-
await noWrites(sql,
|
|
77
|
-
const statements = [...
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
62
|
+
await noWrites(sql, all);
|
|
63
|
+
const statements = [...BYPASSES, 'SET ROLE coffre_vault',
|
|
64
|
+
"INSERT INTO log_pending (kept, body, mac) VALUES (true, '{}', decode(repeat('00', 36), 'hex'))",
|
|
65
|
+
'UPDATE log SET body = body', 'DELETE FROM log', 'UPDATE log_head SET size = size',
|
|
66
|
+
'UPDATE secret_versions SET id = id', 'DELETE FROM secrets', 'UPDATE principals SET role = role', 'UPDATE grants SET role = role'];
|
|
67
|
+
for (const table of all) statements.push(`DELETE FROM ${quoted(table)}`, `TRUNCATE ${quoted(table)}`);
|
|
82
68
|
const count = await refuses(sql, statements);
|
|
83
|
-
return `${count} writes and bypasses refused; no
|
|
69
|
+
return `${count} writes and bypasses refused; no write privilege on any of ${all.length} tables`;
|
|
84
70
|
});
|
|
85
71
|
}
|
|
86
72
|
|
|
73
|
+
/** The vault's login writes coffre's rows, never 0.14's archived log, and empties no table. */
|
|
87
74
|
export async function vaultLogin(deployment: Deployment): Promise<string> {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* the one the harness was given logs in, as coffre_vault_hot, with the
|
|
97
|
-
* timeouts and generic plans 0022 gives it, and holds what the vault's
|
|
98
|
-
* login holds, no more.
|
|
99
|
-
*/
|
|
100
|
-
export async function hotLogin(deployment: Deployment): Promise<string> {
|
|
101
|
-
if (deployment.kind === 'node') throw new Skip('SQLite has no database logins');
|
|
102
|
-
expect(deployment.hotRuntime !== null, 'the hot path login is missing');
|
|
103
|
-
const appTables = await vaultReadOnly(deployment);
|
|
104
|
-
return using(deployment.hotRuntime(), async (sql) => {
|
|
105
|
-
const [login] = await sql.query<{ name: string; lock: string; statement: string; plans: string; members: boolean }>(`SELECT current_user AS name,
|
|
106
|
-
current_setting('lock_timeout') AS lock, current_setting('statement_timeout') AS statement, current_setting('plan_cache_mode') AS plans,
|
|
107
|
-
has_table_privilege(current_user, 'vault_members', 'INSERT') AS members`);
|
|
108
|
-
expect(login.name === 'coffre_vault_hot', `the hot path's URL logs in as ${login.name}, not coffre_vault_hot`);
|
|
109
|
-
expect(login.lock === '1s' && login.statement === '2s' && login.plans === 'force_generic_plan', "the hot path's login lacks its timeouts or generic plans", login);
|
|
110
|
-
expect(login.members, "the hot path's login cannot write members, as the vault's can");
|
|
111
|
-
return `as coffre_vault_hot, lock 1s, statement 2s, generic plans; ${await vaultRefuses(sql, appTables)}`;
|
|
75
|
+
const all = await using(deployment.database(), tables);
|
|
76
|
+
return using(deployment.vaultRuntime(), async (sql) => {
|
|
77
|
+
await noWrites(sql, ['audit_archive']);
|
|
78
|
+
const statements = [...BYPASSES, 'SET ROLE coffre_app',
|
|
79
|
+
'UPDATE audit_archive SET action = action', 'DELETE FROM audit_archive', 'INSERT INTO audit_archive SELECT * FROM audit_archive LIMIT 1'];
|
|
80
|
+
for (const table of all) statements.push(`TRUNCATE ${quoted(table)}`);
|
|
81
|
+
const count = await refuses(sql, statements);
|
|
82
|
+
return `${count} writes and bypasses refused; 0.14's archived log not writable`;
|
|
112
83
|
});
|
|
113
84
|
}
|
|
114
|
-
|
|
115
|
-
/** The tables only the app writes: every one but the vault's and the log's. */
|
|
116
|
-
async function vaultReadOnly(deployment: Deployment): Promise<string[]> {
|
|
117
|
-
return (await using(deployment.database(), tables)).filter((name) =>
|
|
118
|
-
!['vault_members', 'vault_grants', 'audit_log', 'audit_chain_head'].includes(name));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** What a vault login may not do: write the app's tables, replace the log's head, rewrite the log or act as the app. */
|
|
122
|
-
async function vaultRefuses(sql: Sql, appTables: readonly string[]): Promise<string> {
|
|
123
|
-
await noWrites(sql, appTables);
|
|
124
|
-
const [head] = await sql.query<{ insertable: boolean; deletable: boolean; identity_updatable: boolean; truncatable: boolean }>(`SELECT
|
|
125
|
-
has_table_privilege(current_user, 'audit_chain_head', 'INSERT') AS insertable,
|
|
126
|
-
has_table_privilege(current_user, 'audit_chain_head', 'DELETE') AS deletable,
|
|
127
|
-
has_table_privilege(current_user, 'audit_chain_head', 'TRUNCATE') AS truncatable,
|
|
128
|
-
has_column_privilege(current_user, 'audit_chain_head', 'only_row', 'UPDATE') AS identity_updatable`);
|
|
129
|
-
expect(!head.insertable && !head.deletable && !head.truncatable && !head.identity_updatable, 'the vault can replace the head row', head);
|
|
130
|
-
const statements = [...IMMUTABLE, appendAs('app'), 'SET ROLE coffre_app',
|
|
131
|
-
'UPDATE audit_chain_head SET only_row = only_row', 'DELETE FROM audit_chain_head', 'TRUNCATE audit_chain_head',
|
|
132
|
-
'UPDATE vault_members SET principal = principal', 'UPDATE vault_grants SET role = role'];
|
|
133
|
-
for (const table of appTables) {
|
|
134
|
-
const column = APP_COLUMNS[table];
|
|
135
|
-
if (column !== undefined) statements.push(`UPDATE ${quoted(table)} SET ${column} = ${column}`);
|
|
136
|
-
}
|
|
137
|
-
const count = await refuses(sql, statements);
|
|
138
|
-
return `${count} writes and bypasses refused; app tables have no write privileges`;
|
|
139
|
-
}
|