@coffre/conformance 0.3.0 → 0.4.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/dist/main.js +1343 -79
- package/package.json +4 -4
- package/src/bundle.ts +5 -0
- package/src/checks/access.ts +53 -1
- package/src/checks/canaries.ts +5 -4
- package/src/checks/cli.ts +5 -3
- package/src/checks/deletion.ts +98 -0
- package/src/checks/environments.ts +193 -0
- package/src/checks/mcp.ts +475 -0
- package/src/checks/pages.ts +172 -11
- package/src/checks/people.ts +17 -13
- package/src/checks/workloads.ts +2 -6
- package/src/chrome.ts +48 -10
- package/src/draining.ts +4 -3
- package/src/suite.ts +17 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffre/conformance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jose": "6.2.3",
|
|
33
33
|
"pg": "8.16.3",
|
|
34
|
-
"@coffre/cli": "0.
|
|
35
|
-
"@coffre/db": "0.
|
|
34
|
+
"@coffre/cli": "0.4.0",
|
|
35
|
+
"@coffre/db": "0.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "26.1.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tsdown": "0.23.0",
|
|
42
42
|
"typescript": "5.9.3",
|
|
43
43
|
"vite": "8.1.5",
|
|
44
|
-
"@coffre/client": "0.
|
|
44
|
+
"@coffre/client": "0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsdown",
|
package/src/bundle.ts
CHANGED
|
@@ -17,6 +17,11 @@ export const SERVER_TABLES = [
|
|
|
17
17
|
'audit_log',
|
|
18
18
|
'consumed_tokens',
|
|
19
19
|
'device_authorizations',
|
|
20
|
+
'dismissed_keys',
|
|
21
|
+
'mcp_approvals',
|
|
22
|
+
'mcp_connections',
|
|
23
|
+
'oauth_clients',
|
|
24
|
+
'secret_references',
|
|
20
25
|
'secret_versions',
|
|
21
26
|
'service_bindings',
|
|
22
27
|
'vault_grants',
|
package/src/checks/access.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { bearer } from '../browser.ts';
|
|
4
4
|
import type { Deployment } from '../harness.ts';
|
|
5
5
|
import { expect, refused } from '../report.ts';
|
|
6
|
-
import { BULK, DEV, PROD, signIn, valuesIn, type Canaries, type People } from './people.ts';
|
|
6
|
+
import { BULK, canary, DEV, PROD, PROJECT, signIn, valuesIn, type Canaries, type People } from './people.ts';
|
|
7
7
|
import { pollDevice, startDevice } from './signin.ts';
|
|
8
8
|
|
|
9
9
|
export async function membersOnly(deployment: Deployment, { stranger }: People): Promise<string> {
|
|
@@ -117,6 +117,58 @@ export async function offboarding(deployment: Deployment, { admin, leaver, servi
|
|
|
117
117
|
return `the report names ${exposed.length} values; re-admission revives no old session, token or approval; a fresh provider callback works`;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Grants on every project: one on `*` reaches a project made after it; one
|
|
122
|
+
* on `*` and a slug reaches that environment in every project and never
|
|
123
|
+
* another; nobody but an owner gives one; and removing a member takes
|
|
124
|
+
* them. Its services are removed, and its project archived, as it ends.
|
|
125
|
+
*/
|
|
126
|
+
export async function everyProject(deployment: Deployment, { admin, reader }: People, canaries: Canaries): Promise<string> {
|
|
127
|
+
const services = { everything: 'token:conformance-everywhere', dev: 'token:conformance-every-dev', manager: 'token:conformance-manager' };
|
|
128
|
+
const client = async (member: string) => bearer(deployment.origin, (await admin.api.tokens.issue(member, { expiresInDays: 1 })).token);
|
|
129
|
+
for (const member of Object.values(services)) await admin.api.members.add(member);
|
|
130
|
+
|
|
131
|
+
// A project's access manager, and a viewer, are not owners.
|
|
132
|
+
await admin.api.access.set(services.manager, { [PROJECT]: 'access-manager' });
|
|
133
|
+
const manager = await client(services.manager);
|
|
134
|
+
await refused("a project's access manager granted on every project", manager.access.set(services.everything, { '*': 'viewer' }));
|
|
135
|
+
await refused('a viewer granted themselves every project', reader.api.access.set(reader.member, { '*/prod': 'viewer' }));
|
|
136
|
+
await admin.api.access.set(services.everything, { '*': 'viewer' });
|
|
137
|
+
await admin.api.access.set(services.dev, { '*/dev': 'viewer' });
|
|
138
|
+
const [everything, dev] = [await client(services.everything), await client(services.dev)];
|
|
139
|
+
|
|
140
|
+
// Made after the grants: a project with a dev and a prod.
|
|
141
|
+
const later = `${PROJECT}-later`;
|
|
142
|
+
const made = await admin.api.projects.create(later, { name: 'Made later' });
|
|
143
|
+
expect(made.inherited.some((grant) => grant.member === services.everything && grant.place === '*'), 'making a project did not say who reaches it', made.inherited);
|
|
144
|
+
for (const environment of ['dev', 'prod']) {
|
|
145
|
+
const path = `${later}/${environment}`;
|
|
146
|
+
const { inherited } = await admin.api.environments.create(path, { name: environment });
|
|
147
|
+
const reaches = inherited.filter((grant) => grant.member === services.dev).length;
|
|
148
|
+
expect(reaches === (environment === 'dev' ? 1 : 0), `making ${path} misnamed who reaches it through dev in every project`, inherited);
|
|
149
|
+
canaries[`${path}/API_KEY`] = canary();
|
|
150
|
+
await admin.api.secrets.set(path, valuesIn(canaries, path));
|
|
151
|
+
}
|
|
152
|
+
for (const path of [`${later}/prod`, `${later}/dev`, PROD]) {
|
|
153
|
+
const read = await everything.secrets.reveal(path);
|
|
154
|
+
expect(read.values.API_KEY === canaries[`${path}/API_KEY`], `viewer on every project could not read ${path}`, read.values);
|
|
155
|
+
}
|
|
156
|
+
await refused('viewer on every project wrote a value', everything.secrets.set(`${later}/prod`, { API_KEY: 'from everywhere' }));
|
|
157
|
+
const devRead = await dev.secrets.reveal(`${later}/dev`);
|
|
158
|
+
expect(devRead.values.API_KEY === canaries[`${later}/dev/API_KEY`], 'viewer on dev in every project could not read a dev made later', devRead.values);
|
|
159
|
+
await refused('viewer on dev in every project read a prod made later', dev.secrets.reveal(`${later}/prod`));
|
|
160
|
+
await refused('viewer on dev in every project read prod', dev.secrets.reveal(PROD));
|
|
161
|
+
|
|
162
|
+
// Removed, they hold nothing, and the list of grants on every project is as it was.
|
|
163
|
+
for (const member of Object.values(services)) await admin.api.members.remove(member);
|
|
164
|
+
await refused('a removed member read through a grant on every project', everything.secrets.reveal(`${later}/prod`));
|
|
165
|
+
await refused('a removed member read through a grant on dev in every project', dev.secrets.reveal(`${later}/dev`));
|
|
166
|
+
const left = (await admin.api.members.list('*')).members.filter((member) => Object.values(services).includes(member.member));
|
|
167
|
+
expect(left.length === 0, 'grants on every project outlived their members', left);
|
|
168
|
+
await admin.api.projects.update(later, { archived: true });
|
|
169
|
+
return 'a grant on every project reaches a project made after it; one on dev, every dev and nothing else; refused to non-owners; gone with its member';
|
|
170
|
+
}
|
|
171
|
+
|
|
120
172
|
/** Reading more values at once than the vault allows in its window is refused. */
|
|
121
173
|
export async function bulkLimit({ admin, bulk }: People, limit: number): Promise<string> {
|
|
122
174
|
const values: Record<string, string> = {};
|
package/src/checks/canaries.ts
CHANGED
|
@@ -34,13 +34,14 @@ function pages(people: People): string[] {
|
|
|
34
34
|
'/audit',
|
|
35
35
|
'/settings',
|
|
36
36
|
'/auth/device',
|
|
37
|
+
'/oauth/authorize',
|
|
37
38
|
'/projects',
|
|
38
|
-
`/projects/${PROJECT}
|
|
39
|
+
...['', '/users', '/service-accounts', '/settings'].map((tab) => `/projects/${PROJECT}${tab}`),
|
|
39
40
|
...[DEV, PROD, BULK].map((path) => `/projects/${path}`),
|
|
40
41
|
'/users',
|
|
41
|
-
...users.
|
|
42
|
-
'/
|
|
43
|
-
`/
|
|
42
|
+
...users.flatMap((person) => ['', '/activity'].map((tab) => `/users/${encodeURIComponent(person.email)}${tab}`)),
|
|
43
|
+
'/service-accounts',
|
|
44
|
+
...['', '/access', '/activity'].map((tab) => `/service-accounts/${SERVICE.slice('token:'.length)}${tab}`),
|
|
44
45
|
];
|
|
45
46
|
}
|
|
46
47
|
|
package/src/checks/cli.ts
CHANGED
|
@@ -203,7 +203,8 @@ export async function verifyInterrupted(cli: Cli, admin: Person): Promise<string
|
|
|
203
203
|
* else changed; the runs' reads are in the audit log.
|
|
204
204
|
*/
|
|
205
205
|
export async function verifyLeftovers(cli: Cli, admin: Person, setups: string[], before: string, kept: Canary): Promise<string> {
|
|
206
|
-
|
|
206
|
+
// Shown as people read it, service:<name>, though the API keeps token:<name>.
|
|
207
|
+
expect(setups[0]!.includes(`the service account ${PROBE.service.replace(/^token:/, 'service:')}`), 'the first run did not make its service account', setups[0]);
|
|
207
208
|
expect(setups.slice(1).every((line) => line.startsWith('all found')), 'a later run made something again', setups);
|
|
208
209
|
const { tokens } = await admin.api.tokens.list(PROBE.service);
|
|
209
210
|
expect(tokens.length === 0, `${PROBE.service} still holds ${tokens.length} credential(s)`, tokens);
|
|
@@ -268,8 +269,9 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
268
269
|
await coffre(['set', 'conformance-cli/ci/API_KEY'], value);
|
|
269
270
|
await coffre(['rename', 'conformance-cli/ci/API_KEY', 'API_TOKEN']);
|
|
270
271
|
const refused = await coffre(['grant', 'conformance-cli', 'conformance-deploy', '--role', 'viewer', '--env', 'ci', '--service'], undefined, 1);
|
|
271
|
-
expect(refused.includes('admit them first, `coffre admit conformance-deploy
|
|
272
|
+
expect(refused.includes('admit them first, `coffre admit service:conformance-deploy`'), 'grant to a service not yet admitted did not say to admit it', refused);
|
|
272
273
|
const admitted = await coffre(['admit', 'conformance-deploy', '--service']);
|
|
274
|
+
expect(admitted.includes('admitted service:conformance-deploy') && !admitted.includes('token:'), 'admit --service did not name the service account as service:<name>', admitted);
|
|
273
275
|
expect(admitted.includes('next: coffre grant <project> conformance-deploy'), 'admit --service did not say what comes next', admitted);
|
|
274
276
|
await coffre(['grant', 'conformance-cli', 'conformance-deploy', '--role', 'viewer', '--env', 'ci', '--service']);
|
|
275
277
|
|
|
@@ -291,7 +293,7 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
291
293
|
await service(['get', 'conformance-cli/ci/API_TOKEN']);
|
|
292
294
|
await coffre(['tokens', 'revoke', 'conformance-deploy', listed!.id, '--apply']);
|
|
293
295
|
const gone = await service(['get', 'conformance-cli/ci/API_TOKEN'], undefined, 1);
|
|
294
|
-
expect(/does not know this
|
|
296
|
+
expect(/does not know this bearer token/.test(gone), 'a revoked token was not refused plainly', gone);
|
|
295
297
|
|
|
296
298
|
await coffre(['revoke', 'conformance-cli', 'conformance-deploy', '--env', 'ci', '--service']);
|
|
297
299
|
await coffre(['archive', 'conformance-cli/ci/API_TOKEN']);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Deleting an archived project, and an archived environment, for good, as an
|
|
2
|
+
// owner does it with the CLI: shown first, then done with --apply. Its values
|
|
3
|
+
// are erased in the database, it leaves every list, its slug is free for
|
|
4
|
+
// another, and the log, which still names it by its tombstone, verifies.
|
|
5
|
+
import { randomBytes } from 'node:crypto';
|
|
6
|
+
|
|
7
|
+
import { CoffreError } from '@coffre/client';
|
|
8
|
+
|
|
9
|
+
import { using } from '../database.ts';
|
|
10
|
+
import type { Deployment } from '../harness.ts';
|
|
11
|
+
import { expect } from '../report.ts';
|
|
12
|
+
import type { Cli } from './cli.ts';
|
|
13
|
+
import type { Person } from './people.ts';
|
|
14
|
+
import { query } from './storage.ts';
|
|
15
|
+
|
|
16
|
+
const PROJECT = 'conformance-gone';
|
|
17
|
+
const SERVICE = 'token:conformance-gone-ci';
|
|
18
|
+
|
|
19
|
+
/** Each version under a project, by whether it still holds a ciphertext or a wrapped key. */
|
|
20
|
+
async function sealed(deployment: Deployment, projectId: string): Promise<{ versions: number; sealed: number }> {
|
|
21
|
+
const rows = await using(deployment.database(), (sql) =>
|
|
22
|
+
query<{ ciphertext: number | string; wrapped: number | string }>(
|
|
23
|
+
sql,
|
|
24
|
+
`SELECT length(v.ciphertext) AS ciphertext, length(v.wrapped_dek) AS wrapped
|
|
25
|
+
FROM secret_versions v JOIN secrets s ON s.id = v.secret_id WHERE s.project_id = $1`,
|
|
26
|
+
[projectId],
|
|
27
|
+
));
|
|
28
|
+
return { versions: rows.length, sealed: rows.filter((row) => Number(row.ciphertext) > 0 || Number(row.wrapped) > 0).length };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function projectId(deployment: Deployment, slug: string): Promise<string | undefined> {
|
|
32
|
+
const [row] = await using(deployment.database(), (sql) => query<{ id: string }>(sql, 'SELECT id FROM projects WHERE slug = $1', [slug]));
|
|
33
|
+
return row?.id;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function deletion(deployment: Deployment, cli: Cli, admin: Person): Promise<string> {
|
|
37
|
+
const run = async (args: string[], code = 0): Promise<string> => {
|
|
38
|
+
const result = await cli.run(args);
|
|
39
|
+
expect(result.code === code, `coffre ${args.join(' ')} exited ${result.code}, not ${code}`, result.output);
|
|
40
|
+
return result.output;
|
|
41
|
+
};
|
|
42
|
+
const value = () => `deleted-value-${randomBytes(8).toString('hex')}`;
|
|
43
|
+
await admin.api.projects.create(PROJECT, { name: 'Gone' });
|
|
44
|
+
for (const environment of ['prod', 'dev']) {
|
|
45
|
+
await admin.api.environments.create(`${PROJECT}/${environment}`, { name: environment });
|
|
46
|
+
await admin.api.secrets.set(`${PROJECT}/${environment}`, { API_KEY: value(), DATABASE_URL: value() });
|
|
47
|
+
}
|
|
48
|
+
await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: value() });
|
|
49
|
+
await admin.api.members.add(SERVICE);
|
|
50
|
+
await admin.api.access.set(SERVICE, { [`${PROJECT}/prod`]: 'viewer' });
|
|
51
|
+
const id = (await projectId(deployment, PROJECT))!;
|
|
52
|
+
|
|
53
|
+
// Live, it is refused; archived, it is shown first and nothing changes.
|
|
54
|
+
const live = await run(['projects', 'delete', PROJECT, '--apply'], 1);
|
|
55
|
+
expect(/not archived/.test(live), 'deleting a live project was not refused as not archived', live);
|
|
56
|
+
await run(['projects', 'archive', PROJECT]);
|
|
57
|
+
const preview = await run(['projects', 'delete', PROJECT]);
|
|
58
|
+
expect(/erased: 5 versions/.test(preview) && /revoked: 1 grant/.test(preview) && preview.includes('service:conformance-gone-ci would hold nothing anywhere'),
|
|
59
|
+
'the preview does not say what the deletion takes', preview);
|
|
60
|
+
expect(/Backups taken before the deletion still hold the encrypted values/.test(preview) && /Nothing changed/.test(preview),
|
|
61
|
+
'the preview does not warn of backups, or changed something', preview);
|
|
62
|
+
expect((await sealed(deployment, id)).sealed === 5, 'the preview erased something');
|
|
63
|
+
|
|
64
|
+
const done = await run(['projects', 'delete', PROJECT, '--apply']);
|
|
65
|
+
expect(/^deleted conformance-gone, for good/.test(done), 'the deletion did not say it was done', done);
|
|
66
|
+
|
|
67
|
+
// The values are erased; the names stay, under the tombstone's slug.
|
|
68
|
+
const after = await sealed(deployment, id);
|
|
69
|
+
expect(after.versions === 5 && after.sealed === 0, 'a deleted project still holds a ciphertext or a wrapped key', after);
|
|
70
|
+
const [tombstone] = await using(deployment.database(), (sql) => query<{ slug: string }>(sql, 'SELECT slug FROM projects WHERE id = $1', [id]));
|
|
71
|
+
expect(/^conformance-gone~deleted-\d{4}-\d{2}-\d{2}$/.test(tombstone?.slug ?? ''), 'the tombstone is not named for the day', tombstone);
|
|
72
|
+
expect((await admin.api.projects.list()).projects.every((project) => !project.slug.startsWith(PROJECT)), 'a deleted project is still listed');
|
|
73
|
+
expect((await admin.api.members.get(SERVICE)).live.grants === 0, 'a grant on the deleted project is still live');
|
|
74
|
+
const revealed = await admin.api.secrets.reveal(`${tombstone!.slug}/prod`).then(() => null, (error: unknown) => error);
|
|
75
|
+
expect(revealed instanceof CoffreError && revealed.status === 404, 'a deleted project is still revealed by its tombstone', revealed);
|
|
76
|
+
|
|
77
|
+
// Its slug is another project's now; the log tells the two apart.
|
|
78
|
+
const fresh = value();
|
|
79
|
+
await admin.api.projects.create(PROJECT, { name: 'Gone, again' });
|
|
80
|
+
await admin.api.environments.create(`${PROJECT}/prod`, { name: 'prod' });
|
|
81
|
+
await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: fresh });
|
|
82
|
+
expect((await projectId(deployment, PROJECT)) !== id, 'the new project took the deleted one\'s row');
|
|
83
|
+
expect((await admin.api.secrets.reveal(`${PROJECT}/prod/API_KEY`)).values.API_KEY === fresh, 'the new project does not read its own value');
|
|
84
|
+
const { entries } = await admin.api.audit.list({ path: tombstone!.slug, limit: 500 });
|
|
85
|
+
expect(entries.some((entry) => entry.action === 'project.delete' && entry.decision === 'allow'), 'the deletion is not in the log under its tombstone', entries.slice(0, 5));
|
|
86
|
+
|
|
87
|
+
// An environment alone, the same way.
|
|
88
|
+
await admin.api.environments.update(`${PROJECT}/prod`, { archived: true });
|
|
89
|
+
await run(['environments', 'delete', `${PROJECT}/prod`, '--apply']);
|
|
90
|
+
await admin.api.environments.create(`${PROJECT}/prod`, { name: 'prod, again' });
|
|
91
|
+
const environments = (await admin.api.projects.list()).projects.find((project) => project.slug === PROJECT)?.environments ?? [];
|
|
92
|
+
expect(environments.length === 1 && environments[0]!.name === 'prod, again', 'a deleted environment is still listed, or its slug is not free', environments);
|
|
93
|
+
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`;
|
|
98
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// What arranges and fills environments: folders, which change nothing but
|
|
2
|
+
// how lists read, forks, and references, which the vault seals
|
|
3
|
+
// (docs/design/environments.md).
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
import { CoffreError } from '@coffre/client';
|
|
7
|
+
|
|
8
|
+
import { using } from '../database.ts';
|
|
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';
|
|
12
|
+
import { query } from './storage.ts';
|
|
13
|
+
|
|
14
|
+
/** Where the fork check copies dev to; archived once checked. */
|
|
15
|
+
const FORKED = `${PROJECT}/forked`;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A folder grants, hides and renames nothing: a secret filed in one is
|
|
19
|
+
* still read, run and exported by its own name, by the same people, and
|
|
20
|
+
* only those who may write may file it.
|
|
21
|
+
*/
|
|
22
|
+
export async function folders({ admin, reader }: People, canaries: Canaries): Promise<string> {
|
|
23
|
+
const keys = Object.keys(valuesIn(canaries, DEV));
|
|
24
|
+
const key = keys[0];
|
|
25
|
+
expect(key !== undefined, 'dev holds no secret to file');
|
|
26
|
+
await admin.api.projects.update(PROJECT, { folder: 'Conformance' });
|
|
27
|
+
await admin.api.secrets.update(`${DEV}/${key}`, { folder: 'filed' });
|
|
28
|
+
try {
|
|
29
|
+
const project = (await reader.api.projects.list()).projects.find((each) => each.slug === PROJECT);
|
|
30
|
+
expect(project?.folder === 'Conformance', 'a project filed in a folder is not listed in it', project);
|
|
31
|
+
const listed = (await reader.api.secrets.list(DEV)).keys.find((each) => each.key === key);
|
|
32
|
+
expect(listed?.folder === 'filed', 'a secret filed in a folder is not listed in it', listed);
|
|
33
|
+
const read = await reader.api.secrets.reveal(DEV);
|
|
34
|
+
expect(JSON.stringify(Object.keys(read.values).sort()) === JSON.stringify([...keys].sort()), 'filing a secret changed the names a run injects', Object.keys(read.values));
|
|
35
|
+
expect(read.values[key] === canaries[`${DEV}/${key}`], 'filing a secret changed its value');
|
|
36
|
+
await refused('a viewer filed a secret', reader.api.secrets.update(`${DEV}/${key}`, { folder: 'elsewhere' }));
|
|
37
|
+
await refused('a viewer filed a project', reader.api.projects.update(PROJECT, { folder: 'Elsewhere' }));
|
|
38
|
+
await refused('a folder name with a slash was taken', admin.api.secrets.update(`${DEV}/${key}`, { folder: 'a/b' }));
|
|
39
|
+
} finally {
|
|
40
|
+
await admin.api.secrets.update(`${DEV}/${key}`, { folder: null });
|
|
41
|
+
await admin.api.projects.update(PROJECT, { folder: null });
|
|
42
|
+
}
|
|
43
|
+
return 'a filed secret is read and run by its own name, by the same people; only writers file it';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A fork copies dev's values into a new environment, and nothing of who
|
|
48
|
+
* may read dev: a viewer on dev reads neither the fork nor makes one.
|
|
49
|
+
*/
|
|
50
|
+
export async function forks({ admin, reader }: People, canaries: Canaries): Promise<string> {
|
|
51
|
+
const dev = valuesIn(canaries, DEV);
|
|
52
|
+
await refused('a viewer forked an environment', reader.api.environments.create(FORKED, { name: 'Forked', from: DEV.split('/')[1]! }));
|
|
53
|
+
const made = await admin.api.environments.create(FORKED, { name: 'Forked', from: DEV.split('/')[1]! });
|
|
54
|
+
try {
|
|
55
|
+
expect(made.forked?.keys === Object.keys(dev).length, "the fork did not copy each of dev's keys", made);
|
|
56
|
+
const read = await admin.api.secrets.reveal(FORKED);
|
|
57
|
+
expect(JSON.stringify(Object.entries(read.values).sort()) === JSON.stringify(Object.entries(dev).sort()), "the fork's values are not dev's");
|
|
58
|
+
const history = await admin.api.secrets.history(`${FORKED}/${Object.keys(dev)[0]}`);
|
|
59
|
+
expect(history.versions.length === 1, 'the fork carried history', history.versions);
|
|
60
|
+
await refused("a viewer on dev read dev's fork", reader.api.secrets.reveal(FORKED));
|
|
61
|
+
} finally {
|
|
62
|
+
await admin.api.environments.update(FORKED, { archived: true });
|
|
63
|
+
}
|
|
64
|
+
return "a fork holds dev's values and no history, and a viewer on dev neither makes one nor reads it";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The key in dev the reference check makes, archived once checked. */
|
|
68
|
+
const HELD = 'CONFORMANCE_REFERENCE';
|
|
69
|
+
const FORGED = 'CONFORMANCE_FORGED';
|
|
70
|
+
|
|
71
|
+
/** The status a call failed with and its reason, the vault's or the app's, or that it went through. */
|
|
72
|
+
async function outcome(call: Promise<unknown>): Promise<string> {
|
|
73
|
+
try {
|
|
74
|
+
await call;
|
|
75
|
+
return 'let through';
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (!(error instanceof CoffreError)) throw error;
|
|
78
|
+
return `${error.status} ${error.reason ?? error.code}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A reference lets whoever reads its holder read its source, so only the
|
|
84
|
+
* vault makes one, and a read through one is checked against the vault's
|
|
85
|
+
* own entry: the reader, a viewer on dev with no grant on prod, reads
|
|
86
|
+
* prod's value through dev's reference, and the read is in prod's log and
|
|
87
|
+
* dev's; a reference row the vault never made, written straight into the
|
|
88
|
+
* database, reads nothing; a developer on dev who cannot read prod makes
|
|
89
|
+
* none; and once broken, it reads no more.
|
|
90
|
+
*/
|
|
91
|
+
export async function references(deployment: Deployment, { admin, reader, leaver }: People, canaries: Canaries): Promise<string> {
|
|
92
|
+
const [sourceKey] = Object.keys(valuesIn(canaries, PROD));
|
|
93
|
+
expect(sourceKey !== undefined, 'prod holds no secret to refer to');
|
|
94
|
+
const source = `${PROD}/${sourceKey}`;
|
|
95
|
+
await refused('a viewer on dev read prod directly', reader.api.secrets.reveal(source));
|
|
96
|
+
expect(await outcome(leaver.api.secrets.set(DEV, { [HELD]: { ref: source } })) === '403 missing_secret_read',
|
|
97
|
+
"a developer on dev who cannot read prod made a reference to prod's secret");
|
|
98
|
+
|
|
99
|
+
await admin.api.secrets.set(DEV, { [HELD]: { ref: source } });
|
|
100
|
+
try {
|
|
101
|
+
const read = await reader.api.secrets.reveal(`${DEV}/${HELD}`);
|
|
102
|
+
expect(read.values[HELD] === canaries[source], "a viewer on dev did not read prod's value through dev's reference");
|
|
103
|
+
const logged = async (path: string) => (await admin.api.audit.list({ path, limit: 200 })).entries
|
|
104
|
+
.filter((entry) => entry.action === 'secret.read' && entry.actorId === reader.email && entry.metadata.via !== undefined).length;
|
|
105
|
+
expect(await logged(PROD) >= 1 && await logged(DEV) >= 1, "the read through the reference is not in both the source's log and the holder's");
|
|
106
|
+
|
|
107
|
+
// What it reads cannot be archived while it reads it (D41): not the key, nor its environment. Its
|
|
108
|
+
// project could be, since the reference is held there too, and archiving it stops no one else's read.
|
|
109
|
+
const archives: [string, (archived: boolean) => Promise<unknown>][] = [
|
|
110
|
+
[source, (archived) => admin.api.secrets.update(source, { archived })],
|
|
111
|
+
[PROD, (archived) => admin.api.environments.update(PROD, { archived })],
|
|
112
|
+
];
|
|
113
|
+
for (const [what, archive] of archives) {
|
|
114
|
+
const refusal = await archive(true).then(() => null, (error: unknown) => error);
|
|
115
|
+
if (refusal === null) await archive(false);
|
|
116
|
+
expect(refusal instanceof CoffreError && refusal.status === 409 && refusal.message.includes(`${DEV}/${HELD} reads ${source}`),
|
|
117
|
+
`${what} was archived, or refused without naming the reference, while a reference read it`, refusal instanceof Error ? refusal.message : refusal);
|
|
118
|
+
}
|
|
119
|
+
// Unless what holds it is archived (D58): nobody reads through it then, so its source archives. Restored,
|
|
120
|
+
// the holder reads nothing through it until its source is back, and says so.
|
|
121
|
+
await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
|
|
122
|
+
const underArchived = await outcome(admin.api.secrets.update(source, { archived: true })).finally(() => admin.api.secrets.update(`${DEV}/${HELD}`, { archived: false }));
|
|
123
|
+
try {
|
|
124
|
+
expect(underArchived === 'let through', `${source} could not be archived while only an archived key referred to it: ${underArchived}`);
|
|
125
|
+
const restored = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
|
|
126
|
+
expect(restored.startsWith('409 '), `a reference read a source archived while its holder was: ${restored}`);
|
|
127
|
+
} finally {
|
|
128
|
+
if (underArchived === 'let through') await admin.api.secrets.update(source, { archived: false });
|
|
129
|
+
}
|
|
130
|
+
const back = await reader.api.secrets.reveal(`${DEV}/${HELD}`);
|
|
131
|
+
expect(back.values[HELD] === canaries[source], 'a reference did not read its source again once both were restored');
|
|
132
|
+
|
|
133
|
+
// A row the vault never sealed: a reference to prod, held in dev, pointing at a vault entry about something else.
|
|
134
|
+
const forged = await using(deployment.database(), async (sql) => {
|
|
135
|
+
const [holder] = await query<{ id: string; project_id: string; environment_id: string }>(sql,
|
|
136
|
+
'SELECT id, project_id, environment_id FROM secrets WHERE key = $1', [HELD]);
|
|
137
|
+
const [target] = await query<{ id: string; project_id: string; environment_id: string }>(sql,
|
|
138
|
+
'SELECT s.id, s.project_id, s.environment_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]]);
|
|
139
|
+
const [entry] = await query<{ seq: number | string | bigint }>(sql,
|
|
140
|
+
"SELECT seq FROM audit_log WHERE author = 'vault' AND action = 'access.grant' AND decision = 'allow' ORDER BY seq DESC LIMIT 1");
|
|
141
|
+
const id = randomUUID();
|
|
142
|
+
await query(sql, 'INSERT INTO secrets (id, project_id, environment_id, key, current_version) VALUES ($1, $2, $3, $4, 0)', [id, holder!.project_id, holder!.environment_id, FORGED]);
|
|
143
|
+
await query(sql, `INSERT INTO secret_references (id, project_id, environment_id, secret_id, source_project_id, source_environment_id, source_secret_id, created_seq, created_by)
|
|
144
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [randomUUID(), holder!.project_id, holder!.environment_id, id, target!.project_id, target!.environment_id, target!.id, String(entry!.seq), admin.member]);
|
|
145
|
+
return id;
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
const forgedRead = await outcome(reader.api.secrets.reveal(`${DEV}/${FORGED}`));
|
|
149
|
+
// Read from its seal, the row is no reference at all, and its key holds no value; the vault would refuse it anyway.
|
|
150
|
+
expect(['404 no_value', '404 not_found', '403 bad_claim'].includes(forgedRead), `a reference row the vault never made was read: ${forgedRead}`);
|
|
151
|
+
} finally {
|
|
152
|
+
await using(deployment.database(), async (sql) => {
|
|
153
|
+
await query(sql, 'DELETE FROM secret_references WHERE secret_id = $1', [forged]);
|
|
154
|
+
await query(sql, 'DELETE FROM secrets WHERE id = $1', [forged]);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await admin.api.references.break(`${DEV}/${HELD}`);
|
|
159
|
+
const after = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
|
|
160
|
+
expect(after.startsWith('409 '), `a broken reference still read: ${after}`);
|
|
161
|
+
} finally {
|
|
162
|
+
await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
|
|
163
|
+
}
|
|
164
|
+
return "a viewer on dev reads prod's value through a reference, logged in both; prod and its key cannot be archived while it reads them, but can once its holder is archived, which then reads nothing until they are back; a forged row is refused, a broken one reads no more, and none is made without read on the source";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A key prod has and dev does not, for the missing-keys check; archived once checked. */
|
|
168
|
+
const PROD_ONLY = 'CONFORMANCE_PROD_ONLY';
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Key names are metadata: what dev is missing is compared only with the
|
|
172
|
+
* environments the viewer reads. The admin sees prod's key missing from dev;
|
|
173
|
+
* the reader, a viewer on dev alone, sees nothing of prod, and dismisses
|
|
174
|
+
* nothing. A dismissal is the team's, and restoring undoes it.
|
|
175
|
+
*/
|
|
176
|
+
export async function missingKeys({ admin, reader }: People): Promise<string> {
|
|
177
|
+
await admin.api.secrets.set(PROD, { [PROD_ONLY]: canary() });
|
|
178
|
+
try {
|
|
179
|
+
const seen = await admin.api.environments.missing(DEV);
|
|
180
|
+
expect(seen.missing.some((key) => key.key === PROD_ONLY), "the admin was not told dev lacks prod's key", seen);
|
|
181
|
+
const hidden = await reader.api.environments.missing(DEV);
|
|
182
|
+
expect(![...hidden.missing, ...hidden.dismissed].some((key) => key.key === PROD_ONLY), "a viewer on dev learned a key name from prod, which they cannot read", hidden);
|
|
183
|
+
await refused('a viewer dismissed a missing key', reader.api.environments.dismiss(DEV, { [PROD_ONLY]: true }));
|
|
184
|
+
await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: true });
|
|
185
|
+
const dismissed = await admin.api.environments.missing(DEV);
|
|
186
|
+
expect(dismissed.dismissed.some((key) => key.key === PROD_ONLY) && !dismissed.missing.some((key) => key.key === PROD_ONLY), 'a dismissed key was still listed as missing', dismissed);
|
|
187
|
+
await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: null });
|
|
188
|
+
expect((await admin.api.environments.missing(DEV)).missing.some((key) => key.key === PROD_ONLY), 'a restored key was not missing again');
|
|
189
|
+
} finally {
|
|
190
|
+
await admin.api.secrets.update(`${PROD}/${PROD_ONLY}`, { archived: true });
|
|
191
|
+
}
|
|
192
|
+
return "only who reads prod learns what dev lacks of it; a viewer dismisses nothing; a dismissal is listed, and restored";
|
|
193
|
+
}
|