@coffre/conformance 0.6.1 → 0.7.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 +267 -30
- package/package.json +4 -4
- package/src/checks/audit.ts +30 -21
- package/src/checks/cli.ts +26 -4
- package/src/checks/environments.ts +71 -0
- package/src/checks/pages.ts +7 -7
- package/src/checks/workloads.ts +40 -0
- package/src/suite.ts +5 -2
package/dist/main.js
CHANGED
|
@@ -204,7 +204,8 @@ function createClient(options) {
|
|
|
204
204
|
projects: {
|
|
205
205
|
/** With their environments. */
|
|
206
206
|
list: () => call("GET /projects", {}),
|
|
207
|
-
|
|
207
|
+
/** Its `name`, which releases before 0.6.2 show, defaults to the slug. */
|
|
208
|
+
create: (project, input = {}) => call("PUT /projects/:project", { project }, input),
|
|
208
209
|
update: (project, patch) => call("PATCH /projects/:project", { project }, patch),
|
|
209
210
|
/** What deleting an archived project would erase and revoke; changes nothing. */
|
|
210
211
|
previewDelete: (project) => {
|
|
@@ -215,7 +216,8 @@ function createClient(options) {
|
|
|
215
216
|
delete: (project) => call("DELETE /projects/:project", { project })
|
|
216
217
|
},
|
|
217
218
|
environments: {
|
|
218
|
-
|
|
219
|
+
/** As a project's: its `name` defaults to the slug. `from` forks a sibling. */
|
|
220
|
+
create: (path, input = {}) => call("PUT /projects/:project/:environment", place(path), input),
|
|
219
221
|
update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch),
|
|
220
222
|
/** What deleting an archived environment would erase and revoke; changes nothing. */
|
|
221
223
|
previewDelete: (path) => {
|
|
@@ -226,6 +228,14 @@ function createClient(options) {
|
|
|
226
228
|
delete: (path) => call("DELETE /projects/:project/:environment", place(path)),
|
|
227
229
|
/** The keys its sibling environments have and it lacks, read or not, and those its team dismissed. */
|
|
228
230
|
missing: (path) => call("GET /projects/:project/:environment/missing", place(path)),
|
|
231
|
+
/** A project's personal configs, for whoever manages its environments: whose, of what, and their key names. */
|
|
232
|
+
personal: (project) => call("GET /personal/:project", place(project)),
|
|
233
|
+
/**
|
|
234
|
+
* A version of what reading it would open: it changes whenever a read
|
|
235
|
+
* would, and reads no value, so it is not logged. Poll it, and read
|
|
236
|
+
* only when it changed.
|
|
237
|
+
*/
|
|
238
|
+
version: (path) => call("GET /projects/:project/:environment/version", place(path)),
|
|
229
239
|
/** Dismiss missing keys (`true`) or restore them (`null`). */
|
|
230
240
|
dismiss: (path, patch) => call("PATCH /projects/:project/:environment/dismissals", place(path), patch)
|
|
231
241
|
},
|
|
@@ -249,7 +259,12 @@ function createClient(options) {
|
|
|
249
259
|
/** A new version holding the old one's value. */
|
|
250
260
|
restore: (path, version) => call("POST /secrets/:project/:environment/:key/restore", place(path), { version }),
|
|
251
261
|
rename: (path, key) => call("PATCH /secrets/:project/:environment/:key", place(path), { key }),
|
|
252
|
-
update: (path, patch) => call("PATCH /secrets/:project/:environment/:key", place(path), patch)
|
|
262
|
+
update: (path, patch) => call("PATCH /secrets/:project/:environment/:key", place(path), patch),
|
|
263
|
+
/**
|
|
264
|
+
* In a fork, a key back to its parent's value (`true`), its own kept,
|
|
265
|
+
* or its own served again (`false`); `from` holds the parent's.
|
|
266
|
+
*/
|
|
267
|
+
inherit: (path, inherit) => call("PATCH /secrets/:project/:environment/:key", place(path), { inherit })
|
|
253
268
|
},
|
|
254
269
|
/**
|
|
255
270
|
* References: secrets read through others (docs/design/environments.md).
|
|
@@ -272,6 +287,10 @@ function createClient(options) {
|
|
|
272
287
|
/** Offboards; returns what to rotate. */
|
|
273
288
|
remove: (member) => call("DELETE /members/:member", { member })
|
|
274
289
|
},
|
|
290
|
+
/**
|
|
291
|
+
* A member's tokens: a service account's bearer tokens, or a person's
|
|
292
|
+
* personal tokens (`user:<email>`), which act as them within their scope.
|
|
293
|
+
*/
|
|
275
294
|
tokens: {
|
|
276
295
|
list: (member) => call("GET /members/:member/tokens", { member }),
|
|
277
296
|
/** What the token would reach, as the server would issue it now; issues nothing. */
|
|
@@ -295,6 +314,13 @@ function createClient(options) {
|
|
|
295
314
|
return send(method, `${route}?dryRun=1`, input);
|
|
296
315
|
},
|
|
297
316
|
create: (member, input) => call("POST /members/:member/bindings", { member }, input),
|
|
317
|
+
/** The service's bindings on an issuer that new keys would replace, and the keys as checked; writes nothing. */
|
|
318
|
+
previewKeys: (member, input) => {
|
|
319
|
+
const [method, route] = address("POST /members/:member/bindings/keys", { member });
|
|
320
|
+
return send(method, `${route}?dryRun=1`, input);
|
|
321
|
+
},
|
|
322
|
+
/** New keys, uploaded, for every binding of the service on the issuer: each replaced by one the same but for them. */
|
|
323
|
+
replaceKeys: (member, input) => call("POST /members/:member/bindings/keys", { member }, input),
|
|
298
324
|
remove: (member, id) => call("DELETE /members/:member/bindings/:id", {
|
|
299
325
|
member,
|
|
300
326
|
id
|
|
@@ -2263,7 +2289,11 @@ function sorted(value) {
|
|
|
2263
2289
|
}
|
|
2264
2290
|
//#endregion
|
|
2265
2291
|
//#region src/checks/audit.ts
|
|
2266
|
-
/**
|
|
2292
|
+
/**
|
|
2293
|
+
* Every returned value read, committed by the vault under the response's
|
|
2294
|
+
* operation: one entry for the place, which lists each secret of a read of
|
|
2295
|
+
* several, and which a look for any one of them finds.
|
|
2296
|
+
*/
|
|
2267
2297
|
async function revealAudited(deployment, { admin, reader }, canaries, purpose) {
|
|
2268
2298
|
const path = purpose === "reveal" ? `${DEV}/API_KEY` : DEV;
|
|
2269
2299
|
const { operationId, values } = await reader.api.secrets.reveal(path);
|
|
@@ -2271,24 +2301,41 @@ async function revealAudited(deployment, { admin, reader }, canaries, purpose) {
|
|
|
2271
2301
|
const expected = purpose === "reveal" ? { API_KEY: canaries[`${DEV}/API_KEY`] } : valuesIn(canaries, DEV);
|
|
2272
2302
|
expect(JSON.stringify(Object.entries(values).sort()) === JSON.stringify(Object.entries(expected).sort()), "the read returned different values", values);
|
|
2273
2303
|
const bundle = (await everyAuditEntry(admin.api)).filter((entry) => entry.operationId === operationId);
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2304
|
+
expect(bundle.length === 1, "the read of one place is not logged as one entry", bundle);
|
|
2305
|
+
const [entry] = bundle;
|
|
2306
|
+
const read = entry.secrets ?? [{
|
|
2307
|
+
key: entry.key,
|
|
2308
|
+
version: entry.version
|
|
2309
|
+
}];
|
|
2310
|
+
expect(JSON.stringify(read.map((secret) => secret.key).sort()) === JSON.stringify(Object.keys(expected).sort()), "the read does not list each value once", entry);
|
|
2311
|
+
expect(entry.author === "vault" && entry.action === "secret.read" && entry.decision === "allow", "the read's entry is not the vault's allowed read", entry);
|
|
2312
|
+
expect(entry.metadata.purpose === purpose && entry.requestId !== null, "the read does not name its request and its purpose", entry);
|
|
2278
2313
|
const { keys: listed } = await admin.api.secrets.list(DEV);
|
|
2279
|
-
for (const
|
|
2314
|
+
for (const secret of read) {
|
|
2315
|
+
expect(secret.version === listed.find((key) => key.key === secret.key)?.version, `the entry for ${String(secret.key)} names another version`, entry);
|
|
2316
|
+
const own = await admin.api.audit.list({
|
|
2317
|
+
path: `${DEV}/${String(secret.key)}`,
|
|
2318
|
+
limit: 200
|
|
2319
|
+
});
|
|
2320
|
+
expect(own.entries.some((found) => found.seq === entry.seq), `the read is not in ${String(secret.key)}'s log`, own.entries.slice(0, 5));
|
|
2321
|
+
}
|
|
2280
2322
|
await using(deployment.database(), async (sql) => {
|
|
2281
|
-
const rows = await query(sql,
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2323
|
+
const rows = await query(sql, "SELECT author, action, decision, request_id, secret_id, metadata FROM audit_log WHERE operation_id = $1", [operationId]);
|
|
2324
|
+
expect(rows.length === 1, "the committed read is not one entry", rows);
|
|
2325
|
+
const [row] = rows;
|
|
2326
|
+
expect(row.author === "vault" && row.action === "secret.read" && row.decision === "allow" && row.request_id !== null, "the committed read is not the vault release", row);
|
|
2327
|
+
const metadata = JSON.parse(row.metadata);
|
|
2328
|
+
const committed = metadata.secrets ?? [{
|
|
2329
|
+
secretId: row.secret_id,
|
|
2330
|
+
version: metadata.version
|
|
2331
|
+
}];
|
|
2332
|
+
expect(metadata.purpose === purpose && committed.length === Object.keys(expected).length, "the committed read does not name its purpose and each secret", row);
|
|
2333
|
+
for (const secret of committed) {
|
|
2334
|
+
const [current] = await query(sql, "SELECT current_version FROM secrets WHERE id = $1", [secret.secretId]);
|
|
2335
|
+
expect(current?.current_version === secret.version, "the committed read names another version", row);
|
|
2289
2336
|
}
|
|
2290
2337
|
});
|
|
2291
|
-
return `${
|
|
2338
|
+
return `${read.length} values read by the vault for ${purpose}, in one entry under ${operationId}`;
|
|
2292
2339
|
}
|
|
2293
2340
|
/** Full verification must reach the stored head, not just some intact prefix. */
|
|
2294
2341
|
async function verification(deployment, { admin }) {
|
|
@@ -2519,13 +2566,13 @@ async function deletedTail(deployment, { admin }) {
|
|
|
2519
2566
|
async function everyAuditEntry(api) {
|
|
2520
2567
|
const all = [];
|
|
2521
2568
|
for (let before;;) {
|
|
2522
|
-
const { entries } = await api.audit.list({
|
|
2569
|
+
const { entries, more } = await api.audit.list({
|
|
2523
2570
|
before,
|
|
2524
2571
|
limit: 500,
|
|
2525
2572
|
detail: "1"
|
|
2526
2573
|
});
|
|
2527
2574
|
all.push(...entries);
|
|
2528
|
-
if (entries.length
|
|
2575
|
+
if (!more || entries.length === 0) return all;
|
|
2529
2576
|
before = entries.at(-1).seq;
|
|
2530
2577
|
}
|
|
2531
2578
|
}
|
|
@@ -2747,6 +2794,72 @@ async function forks({ admin, reader }, canaries) {
|
|
|
2747
2794
|
}
|
|
2748
2795
|
return "a fork holds dev's values and no history, and a viewer on dev neither makes one nor reads it";
|
|
2749
2796
|
}
|
|
2797
|
+
/** Where the inheritance check forks prod; archived once checked. */
|
|
2798
|
+
const INHERITS = `${PROJECT$1}/prod-inherits`;
|
|
2799
|
+
/**
|
|
2800
|
+
* A fork that inherits reads its parent's values live and copies none, and
|
|
2801
|
+
* lends nothing (docs/design/forking.md): the reader, a viewer on dev given
|
|
2802
|
+
* the fork alone, reads none of what it inherits from prod.
|
|
2803
|
+
*/
|
|
2804
|
+
async function inheritance({ admin, reader }, canaries) {
|
|
2805
|
+
const prod = valuesIn(canaries, PROD);
|
|
2806
|
+
const [key] = Object.keys(prod);
|
|
2807
|
+
expect(key !== void 0, "prod holds no secret to inherit");
|
|
2808
|
+
const made = await admin.api.environments.create(INHERITS, {
|
|
2809
|
+
from: PROD.split("/")[1],
|
|
2810
|
+
inherit: true
|
|
2811
|
+
});
|
|
2812
|
+
try {
|
|
2813
|
+
expect(made.forked?.inherits === true && made.forked.keys === 0, "a fork that inherits copied something", made);
|
|
2814
|
+
const read = await admin.api.secrets.reveal(INHERITS);
|
|
2815
|
+
expect(JSON.stringify(Object.entries(read.values).sort()) === JSON.stringify(Object.entries(prod).sort()), "the fork does not read prod's values");
|
|
2816
|
+
const listed = await admin.api.secrets.list(INHERITS);
|
|
2817
|
+
expect(listed.keys.every((each) => each.parent?.state === "inherited"), "a key the fork inherits is not listed as inherited", listed.keys);
|
|
2818
|
+
await admin.api.access.set(reader.member, { [INHERITS]: "viewer" });
|
|
2819
|
+
try {
|
|
2820
|
+
await refused$1("a reader of the fork alone read what it inherits from prod", reader.api.secrets.reveal(INHERITS));
|
|
2821
|
+
await refused$1("a reader of the fork alone read one key it inherits from prod", reader.api.secrets.reveal(`${INHERITS}/${key}`));
|
|
2822
|
+
} finally {
|
|
2823
|
+
await admin.api.access.set(reader.member, { [INHERITS]: null });
|
|
2824
|
+
}
|
|
2825
|
+
} finally {
|
|
2826
|
+
await admin.api.environments.update(INHERITS, { archived: true });
|
|
2827
|
+
}
|
|
2828
|
+
return "a fork that inherits prod reads prod's values, copies none, and lends none to a reader of the fork alone";
|
|
2829
|
+
}
|
|
2830
|
+
/** The key the reader keeps in their personal dev, which goes with it once checked. */
|
|
2831
|
+
const PERSONAL = "CONFORMANCE_PERSONAL";
|
|
2832
|
+
/**
|
|
2833
|
+
* A personal config's values are its owner's alone (docs/design/forking.md,
|
|
2834
|
+
* R8): the reader, a viewer on dev, keeps a value in `dev@me` and reads it;
|
|
2835
|
+
* the admin, an Owner of the whole instance, sees that it exists and its
|
|
2836
|
+
* key's name, and reads none of it, and their own `dev@me` is dev; and a
|
|
2837
|
+
* row made the admin's around coffre, in the database, opens nothing,
|
|
2838
|
+
* since the vault bound the value to its owner.
|
|
2839
|
+
*/
|
|
2840
|
+
async function personalConfigs(deployment, { admin, reader }) {
|
|
2841
|
+
const mine = `${DEV}@me`;
|
|
2842
|
+
const value = canary();
|
|
2843
|
+
await reader.api.secrets.set(mine, { [PERSONAL]: value });
|
|
2844
|
+
try {
|
|
2845
|
+
expect((await reader.api.secrets.reveal(`${mine}/${PERSONAL}`)).values[PERSONAL] === value, "the reader did not read their own personal value");
|
|
2846
|
+
const config = (await admin.api.environments.personal(PROJECT$1)).configs.find((each) => each.owner === reader.member);
|
|
2847
|
+
expect(config?.keys.includes(PERSONAL) === true, "the reader's personal config, or its key's name, is not listed to the admin", config);
|
|
2848
|
+
expect((await outcome(admin.api.secrets.reveal(`${PROJECT$1}/${config.slug}`))).startsWith("403 "), "an Owner of the instance read a member's personal config");
|
|
2849
|
+
const theirs = await admin.api.secrets.reveal(mine);
|
|
2850
|
+
expect(!(PERSONAL in theirs.values), "the admin's dev@me read the reader's personal value");
|
|
2851
|
+
const owner = async (member) => using(deployment.database(), (sql) => query(sql, "UPDATE environments SET owner = $1 WHERE slug = $2", [member, config.slug]));
|
|
2852
|
+
await owner(admin.member);
|
|
2853
|
+
try {
|
|
2854
|
+
expect(await outcome(admin.api.secrets.reveal(`${mine}/${PERSONAL}`)) !== "let through", "a personal config made the admin's in the database opened for them");
|
|
2855
|
+
} finally {
|
|
2856
|
+
await owner(reader.member);
|
|
2857
|
+
}
|
|
2858
|
+
} finally {
|
|
2859
|
+
await reader.api.environments.delete(mine);
|
|
2860
|
+
}
|
|
2861
|
+
return "a personal value is read by its owner alone: an Owner sees its key's name, reads none of it, and a forged owner opens nothing";
|
|
2862
|
+
}
|
|
2750
2863
|
/** The key in dev the reference check makes, archived once checked. */
|
|
2751
2864
|
const HELD = "CONFORMANCE_REFERENCE";
|
|
2752
2865
|
const FORGED = "CONFORMANCE_FORGED";
|
|
@@ -3075,6 +3188,8 @@ function getCalls({ places, secrets, members, services }) {
|
|
|
3075
3188
|
"GET /projects": [{ params: {} }],
|
|
3076
3189
|
"GET /secrets/:project/:environment": places.map((params) => ({ params })),
|
|
3077
3190
|
"GET /projects/:project/:environment/missing": places.map((params) => ({ params })),
|
|
3191
|
+
"GET /personal/:project": [...new Set(places.map((params) => params.project))].map((project) => ({ params: { project } })),
|
|
3192
|
+
"GET /projects/:project/:environment/version": places.map((params) => ({ params })),
|
|
3078
3193
|
"GET /secrets/:project/:environment/:key/versions": secrets.map((params) => ({ params })),
|
|
3079
3194
|
"GET /members": [{ params: {} }, ...first === void 0 ? [] : [{
|
|
3080
3195
|
params: {},
|
|
@@ -3563,19 +3678,26 @@ async function verifyKeys(cli) {
|
|
|
3563
3678
|
* service admitted and granted, a token issued into a 0600 file, then
|
|
3564
3679
|
* piped to `coffre login --token` in a CLI of the service's own, read
|
|
3565
3680
|
* with, revoked after its preview, and refused from then on; the grant
|
|
3566
|
-
* revoked, the secret and the project archived.
|
|
3567
|
-
*
|
|
3681
|
+
* revoked, the secret and the project archived. A personal token too, for
|
|
3682
|
+
* an agent's CLI of its own: it reads within its scope, writes nothing
|
|
3683
|
+
* past it, makes no token, and is refused once revoked. No token shows in
|
|
3684
|
+
* what any prints.
|
|
3568
3685
|
*/
|
|
3569
3686
|
async function manageByCli(cli) {
|
|
3570
3687
|
const steps = [];
|
|
3571
3688
|
const ci = new Cli(cli.origin);
|
|
3689
|
+
const helper = new Cli(cli.origin);
|
|
3572
3690
|
const as = (who, label) => async (args, input, code = 0) => {
|
|
3573
3691
|
const run = await who.run(args, {}, input);
|
|
3574
3692
|
expect(run.code === code, `coffre ${args.join(" ")}${label} exited ${run.code}, not ${code}`, run.output);
|
|
3575
3693
|
steps.push(`${args.slice(0, 2).join(" ")}${label}`);
|
|
3576
3694
|
return run.output;
|
|
3577
3695
|
};
|
|
3578
|
-
const [coffre, service] = [
|
|
3696
|
+
const [coffre, service, agent] = [
|
|
3697
|
+
as(cli, ""),
|
|
3698
|
+
as(ci, ", as the service"),
|
|
3699
|
+
as(helper, ", with a personal token")
|
|
3700
|
+
];
|
|
3579
3701
|
try {
|
|
3580
3702
|
const value = `cli-value-${randomBytes(8).toString("hex")}`;
|
|
3581
3703
|
await coffre([
|
|
@@ -3669,6 +3791,48 @@ async function manageByCli(cli) {
|
|
|
3669
3791
|
]);
|
|
3670
3792
|
const gone = await service(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
|
|
3671
3793
|
expect(/does not know this bearer token/.test(gone), "a revoked token was not refused plainly", gone);
|
|
3794
|
+
const personal = join(cli.home, "agent-token");
|
|
3795
|
+
await coffre([
|
|
3796
|
+
"tokens",
|
|
3797
|
+
"issue",
|
|
3798
|
+
"--label",
|
|
3799
|
+
"conformance-agent",
|
|
3800
|
+
"--scope",
|
|
3801
|
+
"conformance-cli/ci=viewer",
|
|
3802
|
+
"--expires-in",
|
|
3803
|
+
"30m",
|
|
3804
|
+
"--output-file",
|
|
3805
|
+
personal
|
|
3806
|
+
]);
|
|
3807
|
+
const pat = readFileSync(personal, "utf8").trim();
|
|
3808
|
+
expect(/^coffre_pat_/.test(pat) && (statSync(personal).mode & 511) === 384, "the personal token file is not a 0600 file holding a personal token", statSync(personal).mode);
|
|
3809
|
+
expect(!(await agent([
|
|
3810
|
+
"login",
|
|
3811
|
+
cli.origin,
|
|
3812
|
+
"--token"
|
|
3813
|
+
], `${pat}\n`)).includes(pat), "coffre login --token printed a personal token");
|
|
3814
|
+
const whoami = await agent(["whoami"]);
|
|
3815
|
+
expect(whoami.includes("personal token \"conformance-agent\""), "whoami does not name the personal token it signed in with", whoami);
|
|
3816
|
+
expect((await agent(["get", "conformance-cli/ci/API_TOKEN"])).trim() === value, "the personal token did not read within its scope");
|
|
3817
|
+
await agent(["set", "conformance-cli/ci/OTHER"], "x\n", 1);
|
|
3818
|
+
const minted = await agent([
|
|
3819
|
+
"tokens",
|
|
3820
|
+
"issue",
|
|
3821
|
+
"--label",
|
|
3822
|
+
"again",
|
|
3823
|
+
"--scope",
|
|
3824
|
+
"conformance-cli/ci=viewer"
|
|
3825
|
+
], void 0, 1);
|
|
3826
|
+
expect(/a personal token cannot do this/.test(minted), "a personal token made another, or was not refused plainly", minted);
|
|
3827
|
+
const [mine] = JSON.parse(await coffre(["tokens", "--json"]));
|
|
3828
|
+
expect(mine?.label === "conformance-agent", "tokens --json does not list the personal token", mine);
|
|
3829
|
+
await coffre([
|
|
3830
|
+
"tokens",
|
|
3831
|
+
"revoke",
|
|
3832
|
+
mine.id,
|
|
3833
|
+
"--apply"
|
|
3834
|
+
]);
|
|
3835
|
+
await agent(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
|
|
3672
3836
|
await coffre([
|
|
3673
3837
|
"revoke",
|
|
3674
3838
|
"conformance-cli",
|
|
@@ -3693,9 +3857,10 @@ async function manageByCli(cli) {
|
|
|
3693
3857
|
expect(projects.find(({ slug }) => slug === "conformance-cli")?.archivedAt !== null, "the project is not archived", projects);
|
|
3694
3858
|
const sessions = JSON.parse(await coffre(["sessions", "--json"]));
|
|
3695
3859
|
expect(sessions.some(({ kind, current }) => kind === "cli" && current), "sessions --json does not mark this CLI's session", sessions);
|
|
3696
|
-
return `${steps.length} commands: ${[...new Set(steps)].join(", ")};
|
|
3860
|
+
return `${steps.length} commands: ${[...new Set(steps)].join(", ")}; each token only in its 0600 file and piped to login, refused once revoked; a personal token reads within its scope and makes no token`;
|
|
3697
3861
|
} finally {
|
|
3698
3862
|
ci.remove();
|
|
3863
|
+
helper.remove();
|
|
3699
3864
|
}
|
|
3700
3865
|
}
|
|
3701
3866
|
//#endregion
|
|
@@ -3910,22 +4075,22 @@ const PAGES = [
|
|
|
3910
4075
|
],
|
|
3911
4076
|
[
|
|
3912
4077
|
`/projects/${PROJECT$1}`,
|
|
3913
|
-
|
|
4078
|
+
PROJECT$1,
|
|
3914
4079
|
"Environments"
|
|
3915
4080
|
],
|
|
3916
4081
|
[
|
|
3917
4082
|
`/projects/${PROJECT$1}/users`,
|
|
3918
|
-
|
|
4083
|
+
PROJECT$1,
|
|
3919
4084
|
"Users"
|
|
3920
4085
|
],
|
|
3921
4086
|
[
|
|
3922
4087
|
`/projects/${PROJECT$1}/service-accounts`,
|
|
3923
|
-
|
|
4088
|
+
PROJECT$1,
|
|
3924
4089
|
"Service accounts"
|
|
3925
4090
|
],
|
|
3926
4091
|
[
|
|
3927
4092
|
`/projects/${PROJECT$1}/settings`,
|
|
3928
|
-
|
|
4093
|
+
PROJECT$1,
|
|
3929
4094
|
"Settings"
|
|
3930
4095
|
],
|
|
3931
4096
|
[
|
|
@@ -4186,7 +4351,7 @@ const typeLines = (steps) => `(async () => {
|
|
|
4186
4351
|
node.dispatchEvent(new Event('input', { bubbles: true }));
|
|
4187
4352
|
node.setSelectionRange(text.length, text.length);
|
|
4188
4353
|
};
|
|
4189
|
-
button('
|
|
4354
|
+
button('Add secret')?.click();
|
|
4190
4355
|
const named = await shown('Name of the new secret');
|
|
4191
4356
|
if (named === null) return { field: null };
|
|
4192
4357
|
typed(named, name);
|
|
@@ -4228,7 +4393,7 @@ async function pastedValues(deployment, admin, browser) {
|
|
|
4228
4393
|
try {
|
|
4229
4394
|
const caret = added.length;
|
|
4230
4395
|
const adding = await chrome.load(page, admin.browser.cookies(), void 0, pasteInto({
|
|
4231
|
-
open: "
|
|
4396
|
+
open: "Add secret",
|
|
4232
4397
|
name: "PASTED_KEY",
|
|
4233
4398
|
field: "Value for PASTED_KEY",
|
|
4234
4399
|
text: added,
|
|
@@ -4694,6 +4859,71 @@ async function cliSignsIn(deployment, canaries) {
|
|
|
4694
4859
|
cli.remove();
|
|
4695
4860
|
}
|
|
4696
4861
|
}
|
|
4862
|
+
/** A pod of a private cluster, whose issuer coffre cannot reach: a viewer on dev. */
|
|
4863
|
+
const POD = "token:conformance-pod";
|
|
4864
|
+
const CLUSTER = "https://kubernetes.default.svc.cluster.local";
|
|
4865
|
+
const POD_ACCOUNT = {
|
|
4866
|
+
sub: "system:serviceaccount:ci:deploy",
|
|
4867
|
+
uid: "4f1c8d2a-7b3e-4c1d-9a2f-0e6b5c4d3a21"
|
|
4868
|
+
};
|
|
4869
|
+
/**
|
|
4870
|
+
* A binding that carries its issuer's keys: the dev IdP's, uploaded under an
|
|
4871
|
+
* issuer at a `.local` host, which no binding could fetch from. A pod's
|
|
4872
|
+
* token buys a credential by its service account's UID, a nested claim; one
|
|
4873
|
+
* of another UID, or that lives past the hour, does not. Its keys replaced
|
|
4874
|
+
* by the ES256 key alone, an RS256 token is refused and an ES256 one taken.
|
|
4875
|
+
*/
|
|
4876
|
+
async function keysUploaded(deployment, admin, canaries) {
|
|
4877
|
+
await admin.api.members.add(POD);
|
|
4878
|
+
await admin.api.access.set(POD, { [DEV]: "viewer" });
|
|
4879
|
+
const { keys } = await (await fetch(deployment.idp.workloads.jwksUrl)).json();
|
|
4880
|
+
const claims = {
|
|
4881
|
+
sub: POD_ACCOUNT.sub,
|
|
4882
|
+
"kubernetes.io.serviceaccount.uid": POD_ACCOUNT.uid
|
|
4883
|
+
};
|
|
4884
|
+
const made = await admin.api.bindings.create(POD, {
|
|
4885
|
+
profile: "custom",
|
|
4886
|
+
issuer: CLUSTER,
|
|
4887
|
+
claims,
|
|
4888
|
+
jwks: { keys },
|
|
4889
|
+
label: "conformance pod"
|
|
4890
|
+
});
|
|
4891
|
+
expect(made.binding.keys?.length === 2 && /^sha256:/.test(made.binding.jwksUri), "the binding does not show the keys uploaded with it", made.binding);
|
|
4892
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
4893
|
+
const pod = (alg, uid = POD_ACCOUNT.uid, times = {}) => mint(deployment, {
|
|
4894
|
+
iss: CLUSTER,
|
|
4895
|
+
sub: POD_ACCOUNT.sub,
|
|
4896
|
+
"kubernetes.io": {
|
|
4897
|
+
namespace: "ci",
|
|
4898
|
+
serviceaccount: {
|
|
4899
|
+
name: "deploy",
|
|
4900
|
+
uid
|
|
4901
|
+
}
|
|
4902
|
+
},
|
|
4903
|
+
...times
|
|
4904
|
+
}, { alg });
|
|
4905
|
+
const issued = await exchange(deployment, await pod("RS256"), POD);
|
|
4906
|
+
expect(issued.status === 200 && typeof issued.token === "string", "the pod's token bought no credential", shown(issued));
|
|
4907
|
+
const { values } = await bearer(deployment.origin, issued.token).secrets.reveal(`${DEV}/API_KEY`);
|
|
4908
|
+
expect(values.API_KEY === canaries[`${DEV}/API_KEY`], "the credential did not read the value as the service");
|
|
4909
|
+
const other = await exchange(deployment, await pod("RS256", "another-uid"), POD);
|
|
4910
|
+
expect(other.status === 401 && other.reason === "no_match", "a token of another service account under the same name was taken", shown(other));
|
|
4911
|
+
const long = await exchange(deployment, await pod("RS256", POD_ACCOUNT.uid, {
|
|
4912
|
+
iat: now,
|
|
4913
|
+
nbf: now,
|
|
4914
|
+
exp: now + 3601
|
|
4915
|
+
}), POD);
|
|
4916
|
+
expect(long.status === 401 && long.reason === "too_long", "a token that lives past the hour was taken", shown(long));
|
|
4917
|
+
await admin.api.bindings.replaceKeys(POD, {
|
|
4918
|
+
issuer: CLUSTER,
|
|
4919
|
+
jwks: { keys: keys.filter((key) => key.alg === "ES256") }
|
|
4920
|
+
});
|
|
4921
|
+
const dropped = await exchange(deployment, await pod("RS256"), POD);
|
|
4922
|
+
expect(dropped.status === 401 && dropped.reason === "unknown_key", "a token signed by a key no longer uploaded was taken", shown(dropped));
|
|
4923
|
+
const kept = await exchange(deployment, await pod("ES256"), POD);
|
|
4924
|
+
expect(kept.status === 200, "a token signed by the key kept was refused", shown(kept));
|
|
4925
|
+
return `${POD} trusts ${CLUSTER} by its uploaded keys: a pod's token taken by its account's UID; another UID, and a token living past the hour, refused; the RS256 key replaced away, its tokens refused and ES256's taken`;
|
|
4926
|
+
}
|
|
4697
4927
|
/** Removing the binding ends the credentials it issued at once, and the next run gets none. */
|
|
4698
4928
|
async function runUnbound(deployment, admin, bindingId, credential) {
|
|
4699
4929
|
const me = (token) => fetch(`${deployment.origin}/api/me`, { headers: { authorization: `Bearer ${token}` } }).then((response) => response.status);
|
|
@@ -4760,6 +4990,8 @@ async function conform(deployment, options) {
|
|
|
4760
4990
|
await report.check("grant scoping", all, ({ people, canaries }) => grantScoping(people, canaries));
|
|
4761
4991
|
await report.check("folders", all, ({ people, canaries }) => folders(people, canaries));
|
|
4762
4992
|
await report.check("forks", all, ({ people, canaries }) => forks(people, canaries));
|
|
4993
|
+
await report.check("inheritance", all, ({ people, canaries }) => inheritance(people, canaries));
|
|
4994
|
+
await report.check("personal configs", { people }, ({ people }) => personalConfigs(deployment, people));
|
|
4763
4995
|
await report.check("references", all, ({ people, canaries }) => references(deployment, people, canaries));
|
|
4764
4996
|
await report.check("missing keys", { people }, ({ people }) => missingKeys(people));
|
|
4765
4997
|
await report.check("MCP connect", { people }, ({ people }) => mcpConnect(deployment, people));
|
|
@@ -4835,6 +5067,11 @@ async function conform(deployment, options) {
|
|
|
4835
5067
|
canaries,
|
|
4836
5068
|
binding
|
|
4837
5069
|
}, ({ canaries }) => cliSignsIn(deployment, canaries));
|
|
5070
|
+
await report.check("keys uploaded", {
|
|
5071
|
+
admin,
|
|
5072
|
+
canaries,
|
|
5073
|
+
binding
|
|
5074
|
+
}, ({ admin, canaries }) => keysUploaded(deployment, admin, canaries));
|
|
4838
5075
|
await report.check("run unbound", {
|
|
4839
5076
|
admin,
|
|
4840
5077
|
binding,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffre/conformance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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/
|
|
35
|
-
"@coffre/
|
|
34
|
+
"@coffre/cli": "0.7.0",
|
|
35
|
+
"@coffre/db": "0.7.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.7.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsdown",
|
package/src/checks/audit.ts
CHANGED
|
@@ -11,7 +11,11 @@ import { expect, until } from '../report.ts';
|
|
|
11
11
|
import { appendOnlyLifted, entryFields, insertRow, LOG_REFUSAL, logRefuses, query } from './storage.ts';
|
|
12
12
|
import { DEV, PROJECT, valuesIn, type Canaries, type People } from './people.ts';
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Every returned value read, committed by the vault under the response's
|
|
16
|
+
* operation: one entry for the place, which lists each secret of a read of
|
|
17
|
+
* several, and which a look for any one of them finds.
|
|
18
|
+
*/
|
|
15
19
|
export async function revealAudited(deployment: Deployment, { admin, reader }: People, canaries: Canaries, purpose: 'reveal' | 'run'): Promise<string> {
|
|
16
20
|
const path = purpose === 'reveal' ? `${DEV}/API_KEY` : DEV;
|
|
17
21
|
const { operationId, values } = await reader.api.secrets.reveal(path);
|
|
@@ -20,29 +24,34 @@ export async function revealAudited(deployment: Deployment, { admin, reader }: P
|
|
|
20
24
|
expect(JSON.stringify(Object.entries(values).sort()) === JSON.stringify(Object.entries(expected).sort()), 'the read returned different values', values);
|
|
21
25
|
const entries = await everyAuditEntry(admin.api);
|
|
22
26
|
const bundle = entries.filter((entry) => entry.operationId === operationId);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(
|
|
28
|
-
|
|
27
|
+
expect(bundle.length === 1, 'the read of one place is not logged as one entry', bundle);
|
|
28
|
+
const [entry] = bundle as [AuditEntryView];
|
|
29
|
+
const read = entry.secrets ?? [{ key: entry.key, version: entry.version }];
|
|
30
|
+
expect(JSON.stringify(read.map((secret) => secret.key).sort()) === JSON.stringify(Object.keys(expected).sort()), 'the read does not list each value once', entry);
|
|
31
|
+
expect(entry.author === 'vault' && entry.action === 'secret.read' && entry.decision === 'allow', "the read's entry is not the vault's allowed read", entry);
|
|
32
|
+
expect(entry.metadata.purpose === purpose && entry.requestId !== null, 'the read does not name its request and its purpose', entry);
|
|
29
33
|
const { keys: listed } = await admin.api.secrets.list(DEV);
|
|
30
|
-
for (const
|
|
31
|
-
expect(
|
|
34
|
+
for (const secret of read) {
|
|
35
|
+
expect(secret.version === listed.find((key) => key.key === secret.key)?.version, `the entry for ${String(secret.key)} names another version`, entry);
|
|
36
|
+
// Who read this key: the entry of the place's read is among the key's own.
|
|
37
|
+
const own = await admin.api.audit.list({ path: `${DEV}/${String(secret.key)}`, limit: 200 });
|
|
38
|
+
expect(own.entries.some((found) => found.seq === entry.seq), `the read is not in ${String(secret.key)}'s log`, own.entries.slice(0, 5));
|
|
32
39
|
}
|
|
33
40
|
await using(deployment.database(), async (sql) => {
|
|
34
|
-
const rows = await query<{ author: string; action: string; decision: string; request_id: string | null;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const rows = await query<{ author: string; action: string; decision: string; request_id: string | null; secret_id: string | null; metadata: string }>(sql,
|
|
42
|
+
'SELECT author, action, decision, request_id, secret_id, metadata FROM audit_log WHERE operation_id = $1', [operationId]);
|
|
43
|
+
expect(rows.length === 1, 'the committed read is not one entry', rows);
|
|
44
|
+
const [row] = rows as [(typeof rows)[number]];
|
|
45
|
+
expect(row.author === 'vault' && row.action === 'secret.read' && row.decision === 'allow' && row.request_id !== null, 'the committed read is not the vault release', row);
|
|
46
|
+
const metadata = JSON.parse(row.metadata) as { purpose: string; version?: number; secrets?: { secretId: string; version: number }[] };
|
|
47
|
+
const committed = metadata.secrets ?? [{ secretId: row.secret_id!, version: metadata.version! }];
|
|
48
|
+
expect(metadata.purpose === purpose && committed.length === Object.keys(expected).length, 'the committed read does not name its purpose and each secret', row);
|
|
49
|
+
for (const secret of committed) {
|
|
50
|
+
const [current] = await query<{ current_version: number }>(sql, 'SELECT current_version FROM secrets WHERE id = $1', [secret.secretId]);
|
|
51
|
+
expect(current?.current_version === secret.version, 'the committed read names another version', row);
|
|
43
52
|
}
|
|
44
53
|
});
|
|
45
|
-
return `${
|
|
54
|
+
return `${read.length} values read by the vault for ${purpose}, in one entry under ${operationId}`;
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
/** Full verification must reach the stored head, not just some intact prefix. */
|
|
@@ -259,9 +268,9 @@ export async function deletedTail(deployment: Deployment, { admin }: People): Pr
|
|
|
259
268
|
export async function everyAuditEntry(api: CoffreClient): Promise<AuditEntryView[]> {
|
|
260
269
|
const all: AuditEntryView[] = [];
|
|
261
270
|
for (let before: number | undefined; ; ) {
|
|
262
|
-
const { entries } = await api.audit.list({ before, limit: 500, detail: '1' });
|
|
271
|
+
const { entries, more } = await api.audit.list({ before, limit: 500, detail: '1' });
|
|
263
272
|
all.push(...entries);
|
|
264
|
-
if (entries.length
|
|
273
|
+
if (!more || entries.length === 0) return all;
|
|
265
274
|
before = entries.at(-1)!.seq;
|
|
266
275
|
}
|
|
267
276
|
}
|
package/src/checks/cli.ts
CHANGED
|
@@ -249,19 +249,22 @@ export async function verifyKeys(cli: Cli): Promise<string> {
|
|
|
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
|
|
252
|
-
* revoked, the secret and the project archived.
|
|
253
|
-
*
|
|
252
|
+
* revoked, the secret and the project archived. A personal token too, for
|
|
253
|
+
* an agent's CLI of its own: it reads within its scope, writes nothing
|
|
254
|
+
* past it, makes no token, and is refused once revoked. No token shows in
|
|
255
|
+
* what any prints.
|
|
254
256
|
*/
|
|
255
257
|
export async function manageByCli(cli: Cli): Promise<string> {
|
|
256
258
|
const steps: string[] = [];
|
|
257
259
|
const ci = new Cli(cli.origin);
|
|
260
|
+
const helper = new Cli(cli.origin);
|
|
258
261
|
const as = (who: Cli, label: string) => async (args: string[], input?: string, code = 0): Promise<string> => {
|
|
259
262
|
const run = await who.run(args, {}, input);
|
|
260
263
|
expect(run.code === code, `coffre ${args.join(' ')}${label} exited ${run.code}, not ${code}`, run.output);
|
|
261
264
|
steps.push(`${args.slice(0, 2).join(' ')}${label}`);
|
|
262
265
|
return run.output;
|
|
263
266
|
};
|
|
264
|
-
const [coffre, service] = [as(cli, ''), as(ci, ', as the service')];
|
|
267
|
+
const [coffre, service, agent] = [as(cli, ''), as(ci, ', as the service'), as(helper, ', with a personal token')];
|
|
265
268
|
try {
|
|
266
269
|
const value = `cli-value-${randomBytes(8).toString('hex')}`;
|
|
267
270
|
await coffre(['projects', 'create', 'conformance-cli', '--name', 'CLI']);
|
|
@@ -295,6 +298,24 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
295
298
|
const gone = await service(['get', 'conformance-cli/ci/API_TOKEN'], undefined, 1);
|
|
296
299
|
expect(/does not know this bearer token/.test(gone), 'a revoked token was not refused plainly', gone);
|
|
297
300
|
|
|
301
|
+
// 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
|
+
const personal = join(cli.home, 'agent-token');
|
|
303
|
+
await coffre(['tokens', 'issue', '--label', 'conformance-agent', '--scope', 'conformance-cli/ci=viewer', '--expires-in', '30m', '--output-file', personal]);
|
|
304
|
+
const pat = readFileSync(personal, 'utf8').trim();
|
|
305
|
+
expect(/^coffre_pat_/.test(pat) && (statSync(personal).mode & 0o777) === 0o600, 'the personal token file is not a 0600 file holding a personal token', statSync(personal).mode);
|
|
306
|
+
const loggedIn = await agent(['login', cli.origin, '--token'], `${pat}\n`);
|
|
307
|
+
expect(!loggedIn.includes(pat), 'coffre login --token printed a personal token');
|
|
308
|
+
const whoami = await agent(['whoami']);
|
|
309
|
+
expect(whoami.includes('personal token "conformance-agent"'), 'whoami does not name the personal token it signed in with', whoami);
|
|
310
|
+
expect((await agent(['get', 'conformance-cli/ci/API_TOKEN'])).trim() === value, 'the personal token did not read within its scope');
|
|
311
|
+
await agent(['set', 'conformance-cli/ci/OTHER'], 'x\n', 1);
|
|
312
|
+
const minted = await agent(['tokens', 'issue', '--label', 'again', '--scope', 'conformance-cli/ci=viewer'], undefined, 1);
|
|
313
|
+
expect(/a personal token cannot do this/.test(minted), 'a personal token made another, or was not refused plainly', minted);
|
|
314
|
+
const [mine] = JSON.parse(await coffre(['tokens', '--json'])) as { id: string; label: string }[];
|
|
315
|
+
expect(mine?.label === 'conformance-agent', 'tokens --json does not list the personal token', mine);
|
|
316
|
+
await coffre(['tokens', 'revoke', mine!.id, '--apply']);
|
|
317
|
+
await agent(['get', 'conformance-cli/ci/API_TOKEN'], undefined, 1);
|
|
318
|
+
|
|
298
319
|
await coffre(['revoke', 'conformance-cli', 'conformance-deploy', '--env', 'ci', '--service']);
|
|
299
320
|
await coffre(['archive', 'conformance-cli/ci/API_TOKEN']);
|
|
300
321
|
const keys = JSON.parse(await coffre(['list', 'conformance-cli/ci', '--json'])) as { key: string; archived: boolean }[];
|
|
@@ -304,8 +325,9 @@ export async function manageByCli(cli: Cli): Promise<string> {
|
|
|
304
325
|
expect(projects.find(({ slug }) => slug === 'conformance-cli')?.archivedAt !== null, 'the project is not archived', projects);
|
|
305
326
|
const sessions = JSON.parse(await coffre(['sessions', '--json'])) as { kind: string; current: boolean }[];
|
|
306
327
|
expect(sessions.some(({ kind, current }) => kind === 'cli' && current), "sessions --json does not mark this CLI's session", sessions);
|
|
307
|
-
return `${steps.length} commands: ${[...new Set(steps)].join(', ')};
|
|
328
|
+
return `${steps.length} commands: ${[...new Set(steps)].join(', ')}; each token only in its 0600 file and piped to login, refused once revoked; a personal token reads within its scope and makes no token`;
|
|
308
329
|
} finally {
|
|
309
330
|
ci.remove();
|
|
331
|
+
helper.remove();
|
|
310
332
|
}
|
|
311
333
|
}
|
|
@@ -64,6 +64,77 @@ export async function forks({ admin, reader }: People, canaries: Canaries): Prom
|
|
|
64
64
|
return "a fork holds dev's values and no history, and a viewer on dev neither makes one nor reads it";
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** Where the inheritance check forks prod; archived once checked. */
|
|
68
|
+
const INHERITS = `${PROJECT}/prod-inherits`;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A fork that inherits reads its parent's values live and copies none, and
|
|
72
|
+
* lends nothing (docs/design/forking.md): the reader, a viewer on dev given
|
|
73
|
+
* the fork alone, reads none of what it inherits from prod.
|
|
74
|
+
*/
|
|
75
|
+
export async function inheritance({ admin, reader }: People, canaries: Canaries): Promise<string> {
|
|
76
|
+
const prod = valuesIn(canaries, PROD);
|
|
77
|
+
const [key] = Object.keys(prod);
|
|
78
|
+
expect(key !== undefined, 'prod holds no secret to inherit');
|
|
79
|
+
const made = await admin.api.environments.create(INHERITS, { from: PROD.split('/')[1]!, inherit: true });
|
|
80
|
+
try {
|
|
81
|
+
expect(made.forked?.inherits === true && made.forked.keys === 0, 'a fork that inherits copied something', made);
|
|
82
|
+
const read = await admin.api.secrets.reveal(INHERITS);
|
|
83
|
+
expect(JSON.stringify(Object.entries(read.values).sort()) === JSON.stringify(Object.entries(prod).sort()), "the fork does not read prod's values");
|
|
84
|
+
const listed = await admin.api.secrets.list(INHERITS);
|
|
85
|
+
expect(listed.keys.every((each) => each.parent?.state === 'inherited'), 'a key the fork inherits is not listed as inherited', listed.keys);
|
|
86
|
+
|
|
87
|
+
await admin.api.access.set(reader.member, { [INHERITS]: 'viewer' });
|
|
88
|
+
try {
|
|
89
|
+
await refused("a reader of the fork alone read what it inherits from prod", reader.api.secrets.reveal(INHERITS));
|
|
90
|
+
await refused("a reader of the fork alone read one key it inherits from prod", reader.api.secrets.reveal(`${INHERITS}/${key}`));
|
|
91
|
+
} finally {
|
|
92
|
+
await admin.api.access.set(reader.member, { [INHERITS]: null });
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
await admin.api.environments.update(INHERITS, { archived: true });
|
|
96
|
+
}
|
|
97
|
+
return "a fork that inherits prod reads prod's values, copies none, and lends none to a reader of the fork alone";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The key the reader keeps in their personal dev, which goes with it once checked. */
|
|
101
|
+
const PERSONAL = 'CONFORMANCE_PERSONAL';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A personal config's values are its owner's alone (docs/design/forking.md,
|
|
105
|
+
* R8): the reader, a viewer on dev, keeps a value in `dev@me` and reads it;
|
|
106
|
+
* the admin, an Owner of the whole instance, sees that it exists and its
|
|
107
|
+
* key's name, and reads none of it, and their own `dev@me` is dev; and a
|
|
108
|
+
* row made the admin's around coffre, in the database, opens nothing,
|
|
109
|
+
* since the vault bound the value to its owner.
|
|
110
|
+
*/
|
|
111
|
+
export async function personalConfigs(deployment: Deployment, { admin, reader }: People): Promise<string> {
|
|
112
|
+
const mine = `${DEV}@me`;
|
|
113
|
+
const value = canary();
|
|
114
|
+
await reader.api.secrets.set(mine, { [PERSONAL]: value });
|
|
115
|
+
try {
|
|
116
|
+
expect((await reader.api.secrets.reveal(`${mine}/${PERSONAL}`)).values[PERSONAL] === value, 'the reader did not read their own personal value');
|
|
117
|
+
const config = (await admin.api.environments.personal(PROJECT)).configs.find((each) => each.owner === reader.member);
|
|
118
|
+
expect(config?.keys.includes(PERSONAL) === true, "the reader's personal config, or its key's name, is not listed to the admin", config);
|
|
119
|
+
expect((await outcome(admin.api.secrets.reveal(`${PROJECT}/${config!.slug}`))).startsWith('403 '), "an Owner of the instance read a member's personal config");
|
|
120
|
+
const theirs = await admin.api.secrets.reveal(mine);
|
|
121
|
+
expect(!(PERSONAL in theirs.values), "the admin's dev@me read the reader's personal value");
|
|
122
|
+
|
|
123
|
+
const owner = async (member: string) => using(deployment.database(), (sql) =>
|
|
124
|
+
query(sql, 'UPDATE environments SET owner = $1 WHERE slug = $2', [member, config!.slug]));
|
|
125
|
+
await owner(admin.member);
|
|
126
|
+
try {
|
|
127
|
+
const forged = await outcome(admin.api.secrets.reveal(`${mine}/${PERSONAL}`));
|
|
128
|
+
expect(forged !== 'let through', 'a personal config made the admin\'s in the database opened for them');
|
|
129
|
+
} finally {
|
|
130
|
+
await owner(reader.member);
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
await reader.api.environments.delete(mine);
|
|
134
|
+
}
|
|
135
|
+
return "a personal value is read by its owner alone: an Owner sees its key's name, reads none of it, and a forged owner opens nothing";
|
|
136
|
+
}
|
|
137
|
+
|
|
67
138
|
/** The key in dev the reference check makes, archived once checked. */
|
|
68
139
|
const HELD = 'CONFORMANCE_REFERENCE';
|
|
69
140
|
const FORGED = 'CONFORMANCE_FORGED';
|
package/src/checks/pages.ts
CHANGED
|
@@ -14,10 +14,10 @@ import { DEV, type Person, PROJECT, signIn } from './people.ts';
|
|
|
14
14
|
/** Each page, the heading it shows, and the tab it is, for a page with tabs. */
|
|
15
15
|
const PAGES: [path: string, heading: string, tab: string | null][] = [
|
|
16
16
|
['/projects', 'Projects', null],
|
|
17
|
-
[`/projects/${PROJECT}`,
|
|
18
|
-
[`/projects/${PROJECT}/users`,
|
|
19
|
-
[`/projects/${PROJECT}/service-accounts`,
|
|
20
|
-
[`/projects/${PROJECT}/settings`,
|
|
17
|
+
[`/projects/${PROJECT}`, PROJECT, 'Environments'],
|
|
18
|
+
[`/projects/${PROJECT}/users`, PROJECT, 'Users'],
|
|
19
|
+
[`/projects/${PROJECT}/service-accounts`, PROJECT, 'Service accounts'],
|
|
20
|
+
[`/projects/${PROJECT}/settings`, PROJECT, 'Settings'],
|
|
21
21
|
['/audit', 'Audit', null],
|
|
22
22
|
];
|
|
23
23
|
|
|
@@ -117,7 +117,7 @@ export async function pagesInBrowser(deployment: Deployment, admin: Person, brow
|
|
|
117
117
|
const then = path === account ? openFromMenu('button[aria-label^="Actions for"]', 'Remove') : undefined;
|
|
118
118
|
const loaded = await chrome.load(new URL(path, deployment.origin).href, admin.browser.cookies(), undefined, then);
|
|
119
119
|
expect(loaded.errors.length === 0, `${path}, signed in, reported errors in the browser`, loaded.errors.join('\n'));
|
|
120
|
-
// The heading, then what may follow it in the h1
|
|
120
|
+
// The heading, then what may follow it in the h1.
|
|
121
121
|
expect(loaded.heading?.startsWith(heading), `${path}, signed in, shows ${JSON.stringify(loaded.heading)}, not the heading ${JSON.stringify(heading)}`);
|
|
122
122
|
expect(loaded.tab === tab, `${path}, signed in, shows the tab ${JSON.stringify(loaded.tab)}, not ${JSON.stringify(tab)}`);
|
|
123
123
|
if (path.startsWith('/service-accounts')) expect(!/(?<![\w-])token:[A-Za-z0-9]/.test(loaded.text), `${path} shows a service account as token:<name>`, loaded.text);
|
|
@@ -235,7 +235,7 @@ const typeLines = (steps: { name: string; field: string; first: string; second:
|
|
|
235
235
|
node.dispatchEvent(new Event('input', { bubbles: true }));
|
|
236
236
|
node.setSelectionRange(text.length, text.length);
|
|
237
237
|
};
|
|
238
|
-
button('
|
|
238
|
+
button('Add secret')?.click();
|
|
239
239
|
const named = await shown('Name of the new secret');
|
|
240
240
|
if (named === null) return { field: null };
|
|
241
241
|
typed(named, name);
|
|
@@ -277,7 +277,7 @@ export async function pastedValues(deployment: Deployment, admin: Person, browse
|
|
|
277
277
|
const chrome = await Chrome.open(executable);
|
|
278
278
|
try {
|
|
279
279
|
const caret = added.length;
|
|
280
|
-
const adding = await chrome.load(page, admin.browser.cookies(), undefined, pasteInto({ open: '
|
|
280
|
+
const adding = await chrome.load(page, admin.browser.cookies(), undefined, pasteInto({ open: 'Add secret', name: 'PASTED_KEY', field: 'Value for PASTED_KEY', text: added, save: 'Save PASTED_KEY now' }));
|
|
281
281
|
expect(adding.errors.length === 0, `${page} reported errors in the browser`, adding.errors.join('\n'));
|
|
282
282
|
expect(
|
|
283
283
|
JSON.stringify(adding.answer) === JSON.stringify({ field: 'textarea', label: 'Value for PASTED_KEY', caret: [caret, caret] }),
|
package/src/checks/workloads.ts
CHANGED
|
@@ -175,6 +175,46 @@ export async function cliSignsIn(deployment: Deployment, canaries: Canaries): Pr
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/** A pod of a private cluster, whose issuer coffre cannot reach: a viewer on dev. */
|
|
179
|
+
export const POD = 'token:conformance-pod';
|
|
180
|
+
const CLUSTER = 'https://kubernetes.default.svc.cluster.local';
|
|
181
|
+
const POD_ACCOUNT = { sub: 'system:serviceaccount:ci:deploy', uid: '4f1c8d2a-7b3e-4c1d-9a2f-0e6b5c4d3a21' };
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* A binding that carries its issuer's keys: the dev IdP's, uploaded under an
|
|
185
|
+
* issuer at a `.local` host, which no binding could fetch from. A pod's
|
|
186
|
+
* token buys a credential by its service account's UID, a nested claim; one
|
|
187
|
+
* of another UID, or that lives past the hour, does not. Its keys replaced
|
|
188
|
+
* by the ES256 key alone, an RS256 token is refused and an ES256 one taken.
|
|
189
|
+
*/
|
|
190
|
+
export async function keysUploaded(deployment: Deployment, admin: Person, canaries: Canaries): Promise<string> {
|
|
191
|
+
await admin.api.members.add(POD);
|
|
192
|
+
await admin.api.access.set(POD, { [DEV]: 'viewer' });
|
|
193
|
+
const { keys } = (await (await fetch(deployment.idp.workloads.jwksUrl)).json()) as { keys: Record<string, unknown>[] };
|
|
194
|
+
const claims = { sub: POD_ACCOUNT.sub, 'kubernetes.io.serviceaccount.uid': POD_ACCOUNT.uid };
|
|
195
|
+
const made = await admin.api.bindings.create(POD, { profile: 'custom', issuer: CLUSTER, claims, jwks: { keys }, label: 'conformance pod' });
|
|
196
|
+
expect(made.binding.keys?.length === 2 && /^sha256:/.test(made.binding.jwksUri), 'the binding does not show the keys uploaded with it', made.binding);
|
|
197
|
+
const now = Math.floor(Date.now() / 1000);
|
|
198
|
+
const pod = (alg: 'RS256' | 'ES256', uid = POD_ACCOUNT.uid, times: Record<string, number> = {}) =>
|
|
199
|
+
mint(deployment, { iss: CLUSTER, sub: POD_ACCOUNT.sub, 'kubernetes.io': { namespace: 'ci', serviceaccount: { name: 'deploy', uid } }, ...times }, { alg });
|
|
200
|
+
|
|
201
|
+
const issued = await exchange(deployment, await pod('RS256'), POD);
|
|
202
|
+
expect(issued.status === 200 && typeof issued.token === 'string', "the pod's token bought no credential", shown(issued));
|
|
203
|
+
const { values } = await bearer(deployment.origin, issued.token).secrets.reveal(`${DEV}/API_KEY`);
|
|
204
|
+
expect(values.API_KEY === canaries[`${DEV}/API_KEY`], 'the credential did not read the value as the service');
|
|
205
|
+
const other = await exchange(deployment, await pod('RS256', 'another-uid'), POD);
|
|
206
|
+
expect(other.status === 401 && other.reason === 'no_match', 'a token of another service account under the same name was taken', shown(other));
|
|
207
|
+
const long = await exchange(deployment, await pod('RS256', POD_ACCOUNT.uid, { iat: now, nbf: now, exp: now + 3601 }), POD);
|
|
208
|
+
expect(long.status === 401 && long.reason === 'too_long', 'a token that lives past the hour was taken', shown(long));
|
|
209
|
+
|
|
210
|
+
await admin.api.bindings.replaceKeys(POD, { issuer: CLUSTER, jwks: { keys: keys.filter((key) => key.alg === 'ES256') } });
|
|
211
|
+
const dropped = await exchange(deployment, await pod('RS256'), POD);
|
|
212
|
+
expect(dropped.status === 401 && dropped.reason === 'unknown_key', 'a token signed by a key no longer uploaded was taken', shown(dropped));
|
|
213
|
+
const kept = await exchange(deployment, await pod('ES256'), POD);
|
|
214
|
+
expect(kept.status === 200, 'a token signed by the key kept was refused', shown(kept));
|
|
215
|
+
return `${POD} trusts ${CLUSTER} by its uploaded keys: a pod's token taken by its account's UID; another UID, and a token living past the hour, refused; the RS256 key replaced away, its tokens refused and ES256's taken`;
|
|
216
|
+
}
|
|
217
|
+
|
|
178
218
|
/** Removing the binding ends the credentials it issued at once, and the next run gets none. */
|
|
179
219
|
export async function runUnbound(deployment: Deployment, admin: Person, bindingId: string, credential: string): Promise<string> {
|
|
180
220
|
const me = (token: string) => fetch(`${deployment.origin}/api/me`, { headers: { authorization: `Bearer ${token}` } }).then((response) => response.status);
|
package/src/suite.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { bulkLimit, crossSite, grantScoping, instanceRoles, membersOnly, offboar
|
|
|
7
7
|
import { checkpoints, deletedTail, forgedVaultEntry, missingEntry, noAuditNoValue, revealAudited, rewrittenEntry, verification, writesAgree } from './checks/audit.ts';
|
|
8
8
|
import { earlierCheckpoint } from './checks/checkpoints.ts';
|
|
9
9
|
import { deletion } from './checks/deletion.ts';
|
|
10
|
-
import { folders, forks, missingKeys, references } from './checks/environments.ts';
|
|
10
|
+
import { folders, forks, inheritance, missingKeys, personalConfigs, references } from './checks/environments.ts';
|
|
11
11
|
import { appLogin, vaultLogin } from './checks/logins.ts';
|
|
12
12
|
import { mcpRead, mcpChanges, mcpConnect, mcpValues } from './checks/mcp.ts';
|
|
13
13
|
import { accessAuthorship, memberTampering, noAuditNoAccess, sealingRace } from './checks/members.ts';
|
|
@@ -18,7 +18,7 @@ import { Cli, cliLogin, manageByCli, verifyAsOwner, verifyAsUser, verifyInterrup
|
|
|
18
18
|
import { pageLoad, personas, setUp, setUpLive, signInAdmin } from './checks/people.ts';
|
|
19
19
|
import { pagesInBrowser, pastedValues, signinErrorOnce } from './checks/pages.ts';
|
|
20
20
|
import { browserBundle, headers, health } from './checks/surface.ts';
|
|
21
|
-
import { cliSignsIn, exchangesLimited, runSignsIn, runsRefused, runUnbound, spentOnce, tokensUnlogged, trustRun } from './checks/workloads.ts';
|
|
21
|
+
import { cliSignsIn, exchangesLimited, keysUploaded, runSignsIn, runsRefused, runUnbound, spentOnce, tokensUnlogged, trustRun } from './checks/workloads.ts';
|
|
22
22
|
|
|
23
23
|
/** The names of the checks that failed. */
|
|
24
24
|
export async function conform(deployment: Deployment, options: { bulkLimit: number; browser: string | null }): Promise<string[]> {
|
|
@@ -39,6 +39,8 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
|
|
|
39
39
|
await report.check('grant scoping', all, ({ people, canaries }) => grantScoping(people, canaries));
|
|
40
40
|
await report.check('folders', all, ({ people, canaries }) => folders(people, canaries));
|
|
41
41
|
await report.check('forks', all, ({ people, canaries }) => forks(people, canaries));
|
|
42
|
+
await report.check('inheritance', all, ({ people, canaries }) => inheritance(people, canaries));
|
|
43
|
+
await report.check('personal configs', { people }, ({ people }) => personalConfigs(deployment, people));
|
|
42
44
|
await report.check('references', all, ({ people, canaries }) => references(deployment, people, canaries));
|
|
43
45
|
await report.check('missing keys', { people }, ({ people }) => missingKeys(people));
|
|
44
46
|
// Before offboarding: the leaver's CLI session is one of the credentials /mcp must refuse.
|
|
@@ -81,6 +83,7 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
|
|
|
81
83
|
await report.check('run token spent', { binding }, () => spentOnce(deployment));
|
|
82
84
|
await report.check('runs refused', { admin, binding }, ({ admin }) => runsRefused(deployment, admin));
|
|
83
85
|
await report.check('run signs in by CLI', { canaries, binding }, ({ canaries }) => cliSignsIn(deployment, canaries));
|
|
86
|
+
await report.check('keys uploaded', { admin, canaries, binding }, ({ admin, canaries }) => keysUploaded(deployment, admin, canaries));
|
|
84
87
|
await report.check('run unbound', { admin, binding, credential }, ({ admin, binding, credential }) => runUnbound(deployment, admin, binding, credential));
|
|
85
88
|
await report.check('exchanges limited', { binding }, () => exchangesLimited(deployment));
|
|
86
89
|
await report.check('tokens unlogged', { binding }, () => tokensUnlogged(deployment));
|