@coffre/conformance 0.6.2 → 0.8.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 +263 -22
- 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/workloads.ts +40 -0
- package/src/suite.ts +5 -2
package/dist/main.js
CHANGED
|
@@ -228,6 +228,14 @@ function createClient(options) {
|
|
|
228
228
|
delete: (path) => call("DELETE /projects/:project/:environment", place(path)),
|
|
229
229
|
/** The keys its sibling environments have and it lacks, read or not, and those its team dismissed. */
|
|
230
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)),
|
|
231
239
|
/** Dismiss missing keys (`true`) or restore them (`null`). */
|
|
232
240
|
dismiss: (path, patch) => call("PATCH /projects/:project/:environment/dismissals", place(path), patch)
|
|
233
241
|
},
|
|
@@ -251,7 +259,12 @@ function createClient(options) {
|
|
|
251
259
|
/** A new version holding the old one's value. */
|
|
252
260
|
restore: (path, version) => call("POST /secrets/:project/:environment/:key/restore", place(path), { version }),
|
|
253
261
|
rename: (path, key) => call("PATCH /secrets/:project/:environment/:key", place(path), { key }),
|
|
254
|
-
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 })
|
|
255
268
|
},
|
|
256
269
|
/**
|
|
257
270
|
* References: secrets read through others (docs/design/environments.md).
|
|
@@ -274,6 +287,10 @@ function createClient(options) {
|
|
|
274
287
|
/** Offboards; returns what to rotate. */
|
|
275
288
|
remove: (member) => call("DELETE /members/:member", { member })
|
|
276
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
|
+
*/
|
|
277
294
|
tokens: {
|
|
278
295
|
list: (member) => call("GET /members/:member/tokens", { member }),
|
|
279
296
|
/** What the token would reach, as the server would issue it now; issues nothing. */
|
|
@@ -288,6 +305,12 @@ function createClient(options) {
|
|
|
288
305
|
id
|
|
289
306
|
})
|
|
290
307
|
},
|
|
308
|
+
/**
|
|
309
|
+
* Handles: stand-ins a person's app holds in place of an environment's
|
|
310
|
+
* values, which only the credential proxy (`/use`) takes. The value is
|
|
311
|
+
* in the answer, and only there; it is revoked as a token is.
|
|
312
|
+
*/
|
|
313
|
+
handles: { create: (input) => call("POST /handles", {}, input) },
|
|
291
314
|
/** Trust bindings: which CI runs may sign in as a service, by their platform's ID token. */
|
|
292
315
|
bindings: {
|
|
293
316
|
list: (member) => call("GET /members/:member/bindings", { member }),
|
|
@@ -297,6 +320,13 @@ function createClient(options) {
|
|
|
297
320
|
return send(method, `${route}?dryRun=1`, input);
|
|
298
321
|
},
|
|
299
322
|
create: (member, input) => call("POST /members/:member/bindings", { member }, input),
|
|
323
|
+
/** The service's bindings on an issuer that new keys would replace, and the keys as checked; writes nothing. */
|
|
324
|
+
previewKeys: (member, input) => {
|
|
325
|
+
const [method, route] = address("POST /members/:member/bindings/keys", { member });
|
|
326
|
+
return send(method, `${route}?dryRun=1`, input);
|
|
327
|
+
},
|
|
328
|
+
/** New keys, uploaded, for every binding of the service on the issuer: each replaced by one the same but for them. */
|
|
329
|
+
replaceKeys: (member, input) => call("POST /members/:member/bindings/keys", { member }, input),
|
|
300
330
|
remove: (member, id) => call("DELETE /members/:member/bindings/:id", {
|
|
301
331
|
member,
|
|
302
332
|
id
|
|
@@ -2265,7 +2295,11 @@ function sorted(value) {
|
|
|
2265
2295
|
}
|
|
2266
2296
|
//#endregion
|
|
2267
2297
|
//#region src/checks/audit.ts
|
|
2268
|
-
/**
|
|
2298
|
+
/**
|
|
2299
|
+
* Every returned value read, committed by the vault under the response's
|
|
2300
|
+
* operation: one entry for the place, which lists each secret of a read of
|
|
2301
|
+
* several, and which a look for any one of them finds.
|
|
2302
|
+
*/
|
|
2269
2303
|
async function revealAudited(deployment, { admin, reader }, canaries, purpose) {
|
|
2270
2304
|
const path = purpose === "reveal" ? `${DEV}/API_KEY` : DEV;
|
|
2271
2305
|
const { operationId, values } = await reader.api.secrets.reveal(path);
|
|
@@ -2273,24 +2307,41 @@ async function revealAudited(deployment, { admin, reader }, canaries, purpose) {
|
|
|
2273
2307
|
const expected = purpose === "reveal" ? { API_KEY: canaries[`${DEV}/API_KEY`] } : valuesIn(canaries, DEV);
|
|
2274
2308
|
expect(JSON.stringify(Object.entries(values).sort()) === JSON.stringify(Object.entries(expected).sort()), "the read returned different values", values);
|
|
2275
2309
|
const bundle = (await everyAuditEntry(admin.api)).filter((entry) => entry.operationId === operationId);
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2310
|
+
expect(bundle.length === 1, "the read of one place is not logged as one entry", bundle);
|
|
2311
|
+
const [entry] = bundle;
|
|
2312
|
+
const read = entry.secrets ?? [{
|
|
2313
|
+
key: entry.key,
|
|
2314
|
+
version: entry.version
|
|
2315
|
+
}];
|
|
2316
|
+
expect(JSON.stringify(read.map((secret) => secret.key).sort()) === JSON.stringify(Object.keys(expected).sort()), "the read does not list each value once", entry);
|
|
2317
|
+
expect(entry.author === "vault" && entry.action === "secret.read" && entry.decision === "allow", "the read's entry is not the vault's allowed read", entry);
|
|
2318
|
+
expect(entry.metadata.purpose === purpose && entry.requestId !== null, "the read does not name its request and its purpose", entry);
|
|
2280
2319
|
const { keys: listed } = await admin.api.secrets.list(DEV);
|
|
2281
|
-
for (const
|
|
2320
|
+
for (const secret of read) {
|
|
2321
|
+
expect(secret.version === listed.find((key) => key.key === secret.key)?.version, `the entry for ${String(secret.key)} names another version`, entry);
|
|
2322
|
+
const own = await admin.api.audit.list({
|
|
2323
|
+
path: `${DEV}/${String(secret.key)}`,
|
|
2324
|
+
limit: 200
|
|
2325
|
+
});
|
|
2326
|
+
expect(own.entries.some((found) => found.seq === entry.seq), `the read is not in ${String(secret.key)}'s log`, own.entries.slice(0, 5));
|
|
2327
|
+
}
|
|
2282
2328
|
await using(deployment.database(), async (sql) => {
|
|
2283
|
-
const rows = await query(sql,
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2329
|
+
const rows = await query(sql, "SELECT author, action, decision, request_id, secret_id, metadata FROM audit_log WHERE operation_id = $1", [operationId]);
|
|
2330
|
+
expect(rows.length === 1, "the committed read is not one entry", rows);
|
|
2331
|
+
const [row] = rows;
|
|
2332
|
+
expect(row.author === "vault" && row.action === "secret.read" && row.decision === "allow" && row.request_id !== null, "the committed read is not the vault release", row);
|
|
2333
|
+
const metadata = JSON.parse(row.metadata);
|
|
2334
|
+
const committed = metadata.secrets ?? [{
|
|
2335
|
+
secretId: row.secret_id,
|
|
2336
|
+
version: metadata.version
|
|
2337
|
+
}];
|
|
2338
|
+
expect(metadata.purpose === purpose && committed.length === Object.keys(expected).length, "the committed read does not name its purpose and each secret", row);
|
|
2339
|
+
for (const secret of committed) {
|
|
2340
|
+
const [current] = await query(sql, "SELECT current_version FROM secrets WHERE id = $1", [secret.secretId]);
|
|
2341
|
+
expect(current?.current_version === secret.version, "the committed read names another version", row);
|
|
2291
2342
|
}
|
|
2292
2343
|
});
|
|
2293
|
-
return `${
|
|
2344
|
+
return `${read.length} values read by the vault for ${purpose}, in one entry under ${operationId}`;
|
|
2294
2345
|
}
|
|
2295
2346
|
/** Full verification must reach the stored head, not just some intact prefix. */
|
|
2296
2347
|
async function verification(deployment, { admin }) {
|
|
@@ -2521,13 +2572,13 @@ async function deletedTail(deployment, { admin }) {
|
|
|
2521
2572
|
async function everyAuditEntry(api) {
|
|
2522
2573
|
const all = [];
|
|
2523
2574
|
for (let before;;) {
|
|
2524
|
-
const { entries } = await api.audit.list({
|
|
2575
|
+
const { entries, more } = await api.audit.list({
|
|
2525
2576
|
before,
|
|
2526
2577
|
limit: 500,
|
|
2527
2578
|
detail: "1"
|
|
2528
2579
|
});
|
|
2529
2580
|
all.push(...entries);
|
|
2530
|
-
if (entries.length
|
|
2581
|
+
if (!more || entries.length === 0) return all;
|
|
2531
2582
|
before = entries.at(-1).seq;
|
|
2532
2583
|
}
|
|
2533
2584
|
}
|
|
@@ -2749,6 +2800,72 @@ async function forks({ admin, reader }, canaries) {
|
|
|
2749
2800
|
}
|
|
2750
2801
|
return "a fork holds dev's values and no history, and a viewer on dev neither makes one nor reads it";
|
|
2751
2802
|
}
|
|
2803
|
+
/** Where the inheritance check forks prod; archived once checked. */
|
|
2804
|
+
const INHERITS = `${PROJECT$1}/prod-inherits`;
|
|
2805
|
+
/**
|
|
2806
|
+
* A fork that inherits reads its parent's values live and copies none, and
|
|
2807
|
+
* lends nothing (docs/design/forking.md): the reader, a viewer on dev given
|
|
2808
|
+
* the fork alone, reads none of what it inherits from prod.
|
|
2809
|
+
*/
|
|
2810
|
+
async function inheritance({ admin, reader }, canaries) {
|
|
2811
|
+
const prod = valuesIn(canaries, PROD);
|
|
2812
|
+
const [key] = Object.keys(prod);
|
|
2813
|
+
expect(key !== void 0, "prod holds no secret to inherit");
|
|
2814
|
+
const made = await admin.api.environments.create(INHERITS, {
|
|
2815
|
+
from: PROD.split("/")[1],
|
|
2816
|
+
inherit: true
|
|
2817
|
+
});
|
|
2818
|
+
try {
|
|
2819
|
+
expect(made.forked?.inherits === true && made.forked.keys === 0, "a fork that inherits copied something", made);
|
|
2820
|
+
const read = await admin.api.secrets.reveal(INHERITS);
|
|
2821
|
+
expect(JSON.stringify(Object.entries(read.values).sort()) === JSON.stringify(Object.entries(prod).sort()), "the fork does not read prod's values");
|
|
2822
|
+
const listed = await admin.api.secrets.list(INHERITS);
|
|
2823
|
+
expect(listed.keys.every((each) => each.parent?.state === "inherited"), "a key the fork inherits is not listed as inherited", listed.keys);
|
|
2824
|
+
await admin.api.access.set(reader.member, { [INHERITS]: "viewer" });
|
|
2825
|
+
try {
|
|
2826
|
+
await refused$1("a reader of the fork alone read what it inherits from prod", reader.api.secrets.reveal(INHERITS));
|
|
2827
|
+
await refused$1("a reader of the fork alone read one key it inherits from prod", reader.api.secrets.reveal(`${INHERITS}/${key}`));
|
|
2828
|
+
} finally {
|
|
2829
|
+
await admin.api.access.set(reader.member, { [INHERITS]: null });
|
|
2830
|
+
}
|
|
2831
|
+
} finally {
|
|
2832
|
+
await admin.api.environments.update(INHERITS, { archived: true });
|
|
2833
|
+
}
|
|
2834
|
+
return "a fork that inherits prod reads prod's values, copies none, and lends none to a reader of the fork alone";
|
|
2835
|
+
}
|
|
2836
|
+
/** The key the reader keeps in their personal dev, which goes with it once checked. */
|
|
2837
|
+
const PERSONAL = "CONFORMANCE_PERSONAL";
|
|
2838
|
+
/**
|
|
2839
|
+
* A personal config's values are its owner's alone (docs/design/forking.md,
|
|
2840
|
+
* R8): the reader, a viewer on dev, keeps a value in `dev@me` and reads it;
|
|
2841
|
+
* the admin, an Owner of the whole instance, sees that it exists and its
|
|
2842
|
+
* key's name, and reads none of it, and their own `dev@me` is dev; and a
|
|
2843
|
+
* row made the admin's around coffre, in the database, opens nothing,
|
|
2844
|
+
* since the vault bound the value to its owner.
|
|
2845
|
+
*/
|
|
2846
|
+
async function personalConfigs(deployment, { admin, reader }) {
|
|
2847
|
+
const mine = `${DEV}@me`;
|
|
2848
|
+
const value = canary();
|
|
2849
|
+
await reader.api.secrets.set(mine, { [PERSONAL]: value });
|
|
2850
|
+
try {
|
|
2851
|
+
expect((await reader.api.secrets.reveal(`${mine}/${PERSONAL}`)).values[PERSONAL] === value, "the reader did not read their own personal value");
|
|
2852
|
+
const config = (await admin.api.environments.personal(PROJECT$1)).configs.find((each) => each.owner === reader.member);
|
|
2853
|
+
expect(config?.keys.includes(PERSONAL) === true, "the reader's personal config, or its key's name, is not listed to the admin", config);
|
|
2854
|
+
expect((await outcome(admin.api.secrets.reveal(`${PROJECT$1}/${config.slug}`))).startsWith("403 "), "an Owner of the instance read a member's personal config");
|
|
2855
|
+
const theirs = await admin.api.secrets.reveal(mine);
|
|
2856
|
+
expect(!(PERSONAL in theirs.values), "the admin's dev@me read the reader's personal value");
|
|
2857
|
+
const owner = async (member) => using(deployment.database(), (sql) => query(sql, "UPDATE environments SET owner = $1 WHERE slug = $2", [member, config.slug]));
|
|
2858
|
+
await owner(admin.member);
|
|
2859
|
+
try {
|
|
2860
|
+
expect(await outcome(admin.api.secrets.reveal(`${mine}/${PERSONAL}`)) !== "let through", "a personal config made the admin's in the database opened for them");
|
|
2861
|
+
} finally {
|
|
2862
|
+
await owner(reader.member);
|
|
2863
|
+
}
|
|
2864
|
+
} finally {
|
|
2865
|
+
await reader.api.environments.delete(mine);
|
|
2866
|
+
}
|
|
2867
|
+
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";
|
|
2868
|
+
}
|
|
2752
2869
|
/** The key in dev the reference check makes, archived once checked. */
|
|
2753
2870
|
const HELD = "CONFORMANCE_REFERENCE";
|
|
2754
2871
|
const FORGED = "CONFORMANCE_FORGED";
|
|
@@ -3077,6 +3194,8 @@ function getCalls({ places, secrets, members, services }) {
|
|
|
3077
3194
|
"GET /projects": [{ params: {} }],
|
|
3078
3195
|
"GET /secrets/:project/:environment": places.map((params) => ({ params })),
|
|
3079
3196
|
"GET /projects/:project/:environment/missing": places.map((params) => ({ params })),
|
|
3197
|
+
"GET /personal/:project": [...new Set(places.map((params) => params.project))].map((project) => ({ params: { project } })),
|
|
3198
|
+
"GET /projects/:project/:environment/version": places.map((params) => ({ params })),
|
|
3080
3199
|
"GET /secrets/:project/:environment/:key/versions": secrets.map((params) => ({ params })),
|
|
3081
3200
|
"GET /members": [{ params: {} }, ...first === void 0 ? [] : [{
|
|
3082
3201
|
params: {},
|
|
@@ -3565,19 +3684,26 @@ async function verifyKeys(cli) {
|
|
|
3565
3684
|
* service admitted and granted, a token issued into a 0600 file, then
|
|
3566
3685
|
* piped to `coffre login --token` in a CLI of the service's own, read
|
|
3567
3686
|
* with, revoked after its preview, and refused from then on; the grant
|
|
3568
|
-
* revoked, the secret and the project archived.
|
|
3569
|
-
*
|
|
3687
|
+
* revoked, the secret and the project archived. A personal token too, for
|
|
3688
|
+
* an agent's CLI of its own: it reads within its scope, writes nothing
|
|
3689
|
+
* past it, makes no token, and is refused once revoked. No token shows in
|
|
3690
|
+
* what any prints.
|
|
3570
3691
|
*/
|
|
3571
3692
|
async function manageByCli(cli) {
|
|
3572
3693
|
const steps = [];
|
|
3573
3694
|
const ci = new Cli(cli.origin);
|
|
3695
|
+
const helper = new Cli(cli.origin);
|
|
3574
3696
|
const as = (who, label) => async (args, input, code = 0) => {
|
|
3575
3697
|
const run = await who.run(args, {}, input);
|
|
3576
3698
|
expect(run.code === code, `coffre ${args.join(" ")}${label} exited ${run.code}, not ${code}`, run.output);
|
|
3577
3699
|
steps.push(`${args.slice(0, 2).join(" ")}${label}`);
|
|
3578
3700
|
return run.output;
|
|
3579
3701
|
};
|
|
3580
|
-
const [coffre, service] = [
|
|
3702
|
+
const [coffre, service, agent] = [
|
|
3703
|
+
as(cli, ""),
|
|
3704
|
+
as(ci, ", as the service"),
|
|
3705
|
+
as(helper, ", with a personal token")
|
|
3706
|
+
];
|
|
3581
3707
|
try {
|
|
3582
3708
|
const value = `cli-value-${randomBytes(8).toString("hex")}`;
|
|
3583
3709
|
await coffre([
|
|
@@ -3671,6 +3797,48 @@ async function manageByCli(cli) {
|
|
|
3671
3797
|
]);
|
|
3672
3798
|
const gone = await service(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
|
|
3673
3799
|
expect(/does not know this bearer token/.test(gone), "a revoked token was not refused plainly", gone);
|
|
3800
|
+
const personal = join(cli.home, "agent-token");
|
|
3801
|
+
await coffre([
|
|
3802
|
+
"tokens",
|
|
3803
|
+
"issue",
|
|
3804
|
+
"--label",
|
|
3805
|
+
"conformance-agent",
|
|
3806
|
+
"--scope",
|
|
3807
|
+
"conformance-cli/ci=viewer",
|
|
3808
|
+
"--expires-in",
|
|
3809
|
+
"30m",
|
|
3810
|
+
"--output-file",
|
|
3811
|
+
personal
|
|
3812
|
+
]);
|
|
3813
|
+
const pat = readFileSync(personal, "utf8").trim();
|
|
3814
|
+
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);
|
|
3815
|
+
expect(!(await agent([
|
|
3816
|
+
"login",
|
|
3817
|
+
cli.origin,
|
|
3818
|
+
"--token"
|
|
3819
|
+
], `${pat}\n`)).includes(pat), "coffre login --token printed a personal token");
|
|
3820
|
+
const whoami = await agent(["whoami"]);
|
|
3821
|
+
expect(whoami.includes("personal token \"conformance-agent\""), "whoami does not name the personal token it signed in with", whoami);
|
|
3822
|
+
expect((await agent(["get", "conformance-cli/ci/API_TOKEN"])).trim() === value, "the personal token did not read within its scope");
|
|
3823
|
+
await agent(["set", "conformance-cli/ci/OTHER"], "x\n", 1);
|
|
3824
|
+
const minted = await agent([
|
|
3825
|
+
"tokens",
|
|
3826
|
+
"issue",
|
|
3827
|
+
"--label",
|
|
3828
|
+
"again",
|
|
3829
|
+
"--scope",
|
|
3830
|
+
"conformance-cli/ci=viewer"
|
|
3831
|
+
], void 0, 1);
|
|
3832
|
+
expect(/a personal token cannot do this/.test(minted), "a personal token made another, or was not refused plainly", minted);
|
|
3833
|
+
const [mine] = JSON.parse(await coffre(["tokens", "--json"]));
|
|
3834
|
+
expect(mine?.label === "conformance-agent", "tokens --json does not list the personal token", mine);
|
|
3835
|
+
await coffre([
|
|
3836
|
+
"tokens",
|
|
3837
|
+
"revoke",
|
|
3838
|
+
mine.id,
|
|
3839
|
+
"--apply"
|
|
3840
|
+
]);
|
|
3841
|
+
await agent(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
|
|
3674
3842
|
await coffre([
|
|
3675
3843
|
"revoke",
|
|
3676
3844
|
"conformance-cli",
|
|
@@ -3695,9 +3863,10 @@ async function manageByCli(cli) {
|
|
|
3695
3863
|
expect(projects.find(({ slug }) => slug === "conformance-cli")?.archivedAt !== null, "the project is not archived", projects);
|
|
3696
3864
|
const sessions = JSON.parse(await coffre(["sessions", "--json"]));
|
|
3697
3865
|
expect(sessions.some(({ kind, current }) => kind === "cli" && current), "sessions --json does not mark this CLI's session", sessions);
|
|
3698
|
-
return `${steps.length} commands: ${[...new Set(steps)].join(", ")};
|
|
3866
|
+
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`;
|
|
3699
3867
|
} finally {
|
|
3700
3868
|
ci.remove();
|
|
3869
|
+
helper.remove();
|
|
3701
3870
|
}
|
|
3702
3871
|
}
|
|
3703
3872
|
//#endregion
|
|
@@ -4696,6 +4865,71 @@ async function cliSignsIn(deployment, canaries) {
|
|
|
4696
4865
|
cli.remove();
|
|
4697
4866
|
}
|
|
4698
4867
|
}
|
|
4868
|
+
/** A pod of a private cluster, whose issuer coffre cannot reach: a viewer on dev. */
|
|
4869
|
+
const POD = "token:conformance-pod";
|
|
4870
|
+
const CLUSTER = "https://kubernetes.default.svc.cluster.local";
|
|
4871
|
+
const POD_ACCOUNT = {
|
|
4872
|
+
sub: "system:serviceaccount:ci:deploy",
|
|
4873
|
+
uid: "4f1c8d2a-7b3e-4c1d-9a2f-0e6b5c4d3a21"
|
|
4874
|
+
};
|
|
4875
|
+
/**
|
|
4876
|
+
* A binding that carries its issuer's keys: the dev IdP's, uploaded under an
|
|
4877
|
+
* issuer at a `.local` host, which no binding could fetch from. A pod's
|
|
4878
|
+
* token buys a credential by its service account's UID, a nested claim; one
|
|
4879
|
+
* of another UID, or that lives past the hour, does not. Its keys replaced
|
|
4880
|
+
* by the ES256 key alone, an RS256 token is refused and an ES256 one taken.
|
|
4881
|
+
*/
|
|
4882
|
+
async function keysUploaded(deployment, admin, canaries) {
|
|
4883
|
+
await admin.api.members.add(POD);
|
|
4884
|
+
await admin.api.access.set(POD, { [DEV]: "viewer" });
|
|
4885
|
+
const { keys } = await (await fetch(deployment.idp.workloads.jwksUrl)).json();
|
|
4886
|
+
const claims = {
|
|
4887
|
+
sub: POD_ACCOUNT.sub,
|
|
4888
|
+
"kubernetes.io.serviceaccount.uid": POD_ACCOUNT.uid
|
|
4889
|
+
};
|
|
4890
|
+
const made = await admin.api.bindings.create(POD, {
|
|
4891
|
+
profile: "custom",
|
|
4892
|
+
issuer: CLUSTER,
|
|
4893
|
+
claims,
|
|
4894
|
+
jwks: { keys },
|
|
4895
|
+
label: "conformance pod"
|
|
4896
|
+
});
|
|
4897
|
+
expect(made.binding.keys?.length === 2 && /^sha256:/.test(made.binding.jwksUri), "the binding does not show the keys uploaded with it", made.binding);
|
|
4898
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
4899
|
+
const pod = (alg, uid = POD_ACCOUNT.uid, times = {}) => mint(deployment, {
|
|
4900
|
+
iss: CLUSTER,
|
|
4901
|
+
sub: POD_ACCOUNT.sub,
|
|
4902
|
+
"kubernetes.io": {
|
|
4903
|
+
namespace: "ci",
|
|
4904
|
+
serviceaccount: {
|
|
4905
|
+
name: "deploy",
|
|
4906
|
+
uid
|
|
4907
|
+
}
|
|
4908
|
+
},
|
|
4909
|
+
...times
|
|
4910
|
+
}, { alg });
|
|
4911
|
+
const issued = await exchange(deployment, await pod("RS256"), POD);
|
|
4912
|
+
expect(issued.status === 200 && typeof issued.token === "string", "the pod's token bought no credential", shown(issued));
|
|
4913
|
+
const { values } = await bearer(deployment.origin, issued.token).secrets.reveal(`${DEV}/API_KEY`);
|
|
4914
|
+
expect(values.API_KEY === canaries[`${DEV}/API_KEY`], "the credential did not read the value as the service");
|
|
4915
|
+
const other = await exchange(deployment, await pod("RS256", "another-uid"), POD);
|
|
4916
|
+
expect(other.status === 401 && other.reason === "no_match", "a token of another service account under the same name was taken", shown(other));
|
|
4917
|
+
const long = await exchange(deployment, await pod("RS256", POD_ACCOUNT.uid, {
|
|
4918
|
+
iat: now,
|
|
4919
|
+
nbf: now,
|
|
4920
|
+
exp: now + 3601
|
|
4921
|
+
}), POD);
|
|
4922
|
+
expect(long.status === 401 && long.reason === "too_long", "a token that lives past the hour was taken", shown(long));
|
|
4923
|
+
await admin.api.bindings.replaceKeys(POD, {
|
|
4924
|
+
issuer: CLUSTER,
|
|
4925
|
+
jwks: { keys: keys.filter((key) => key.alg === "ES256") }
|
|
4926
|
+
});
|
|
4927
|
+
const dropped = await exchange(deployment, await pod("RS256"), POD);
|
|
4928
|
+
expect(dropped.status === 401 && dropped.reason === "unknown_key", "a token signed by a key no longer uploaded was taken", shown(dropped));
|
|
4929
|
+
const kept = await exchange(deployment, await pod("ES256"), POD);
|
|
4930
|
+
expect(kept.status === 200, "a token signed by the key kept was refused", shown(kept));
|
|
4931
|
+
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`;
|
|
4932
|
+
}
|
|
4699
4933
|
/** Removing the binding ends the credentials it issued at once, and the next run gets none. */
|
|
4700
4934
|
async function runUnbound(deployment, admin, bindingId, credential) {
|
|
4701
4935
|
const me = (token) => fetch(`${deployment.origin}/api/me`, { headers: { authorization: `Bearer ${token}` } }).then((response) => response.status);
|
|
@@ -4762,6 +4996,8 @@ async function conform(deployment, options) {
|
|
|
4762
4996
|
await report.check("grant scoping", all, ({ people, canaries }) => grantScoping(people, canaries));
|
|
4763
4997
|
await report.check("folders", all, ({ people, canaries }) => folders(people, canaries));
|
|
4764
4998
|
await report.check("forks", all, ({ people, canaries }) => forks(people, canaries));
|
|
4999
|
+
await report.check("inheritance", all, ({ people, canaries }) => inheritance(people, canaries));
|
|
5000
|
+
await report.check("personal configs", { people }, ({ people }) => personalConfigs(deployment, people));
|
|
4765
5001
|
await report.check("references", all, ({ people, canaries }) => references(deployment, people, canaries));
|
|
4766
5002
|
await report.check("missing keys", { people }, ({ people }) => missingKeys(people));
|
|
4767
5003
|
await report.check("MCP connect", { people }, ({ people }) => mcpConnect(deployment, people));
|
|
@@ -4837,6 +5073,11 @@ async function conform(deployment, options) {
|
|
|
4837
5073
|
canaries,
|
|
4838
5074
|
binding
|
|
4839
5075
|
}, ({ canaries }) => cliSignsIn(deployment, canaries));
|
|
5076
|
+
await report.check("keys uploaded", {
|
|
5077
|
+
admin,
|
|
5078
|
+
canaries,
|
|
5079
|
+
binding
|
|
5080
|
+
}, ({ admin, canaries }) => keysUploaded(deployment, admin, canaries));
|
|
4840
5081
|
await report.check("run unbound", {
|
|
4841
5082
|
admin,
|
|
4842
5083
|
binding,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffre/conformance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.8.0",
|
|
35
|
+
"@coffre/db": "0.8.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.8.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/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));
|