@coffre/conformance 0.5.0 → 0.6.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { n as DevIdp, o as defaultGitHubAccount, r as GITHUB_RUN } from "./idp-Dyaj6k5N.js";
1
+ import { c as defaultGitHubAccount, n as DevIdp, r as GITHUB_RUN } from "./idp-B8u4UPA4.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { delimiter, dirname, join, relative, resolve } from "node:path";
4
4
  import { inspect, parseArgs } from "node:util";
@@ -224,7 +224,7 @@ function createClient(options) {
224
224
  },
225
225
  /** Delete an archived environment for good, as a project is. Owners only. */
226
226
  delete: (path) => call("DELETE /projects/:project/:environment", place(path)),
227
- /** The keys its sibling environments have and it lacks, those you can see, and those its team dismissed. */
227
+ /** The keys its sibling environments have and it lacks, read or not, and those its team dismissed. */
228
228
  missing: (path) => call("GET /projects/:project/:environment/missing", place(path)),
229
229
  /** Dismiss missing keys (`true`) or restore them (`null`). */
230
230
  dismiss: (path, patch) => call("PATCH /projects/:project/:environment/dismissals", place(path), patch)
@@ -299,8 +299,10 @@ function createClient(options) {
299
299
  member,
300
300
  id
301
301
  }),
302
- /** A public GitHub repository's or GitLab project's IDs, which bindings name. */
303
- lookup: (input) => call("GET /workloads/lookup", {}, input)
302
+ /** A GitHub repository's or GitLab project's IDs, which bindings name: a public one's, or one the deployment's GitHub App is installed on. */
303
+ lookup: (input) => call("GET /workloads/lookup", {}, input),
304
+ /** The repositories the deployment's GitHub App is installed on, private ones too; `{ app: null }` without one. */
305
+ repositories: () => call("GET /workloads/repositories", {})
304
306
  },
305
307
  access: {
306
308
  /** What they should hold at each place; the server applies the difference. `null` revokes. */
@@ -377,7 +379,7 @@ set: (member, access) => call("PATCH /access/:member", { member }, access) },
377
379
  audit: {
378
380
  list: (query = {}) => call("GET /audit", {}, query),
379
381
  verify: () => call("GET /audit/verification", {}),
380
- /** What an escrowed key is checked against: public material, owners and root admins only. */
382
+ /** What an escrowed key is checked against: public material, for admins and owners of the whole instance. */
381
383
  keys: () => call("GET /audit/keys", {})
382
384
  }
383
385
  };
@@ -472,7 +474,18 @@ var Report = class {
472
474
  };
473
475
  //#endregion
474
476
  //#region src/harness.ts
475
- const ROOT_ADMIN = "root@conformance.example";
477
+ const OWNER = "root@conformance.example";
478
+ /**
479
+ * The vault's Owners, under each name a deployment's vault may read them by:
480
+ * `OWNERS`, and `BOOTSTRAP_OWNERS` and 0.5's `ROOT_ADMINS`, read until 0.7,
481
+ * as an older deployment's vault entry still does. Each Worker gets only the
482
+ * vars its wrangler.jsonc declares.
483
+ */
484
+ const OWNER_VARS = {
485
+ OWNERS: OWNER,
486
+ BOOTSTRAP_OWNERS: OWNER,
487
+ ROOT_ADMINS: OWNER
488
+ };
476
489
  /**
477
490
  * The CLI the deployment pins, as its pipeline runs it: `pnpm exec coffre`,
478
491
  * found from its folder, so only as one of its own packages. Its entry is
@@ -636,7 +649,7 @@ async function boot(kind, at, options) {
636
649
  APP_KEY: KEYS.APP_KEY,
637
650
  VAULT_KEY_ID: KEYS.VAULT_KEY_ID,
638
651
  VAULT_KEY: KEYS.VAULT_KEY,
639
- ROOT_ADMINS: ROOT_ADMIN,
652
+ ...OWNER_VARS,
640
653
  CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: runtime,
641
654
  CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_VAULT_HYPERDRIVE: vaultRuntime,
642
655
  WRANGLER_SEND_METRICS: "false"
@@ -645,7 +658,7 @@ async function boot(kind, at, options) {
645
658
  kind,
646
659
  origin,
647
660
  idp,
648
- rootAdmin: ROOT_ADMIN,
661
+ owner: OWNER,
649
662
  beforeFirstBeat: true,
650
663
  async scheduled(options = {}) {
651
664
  const response = await fetch(`${origin}/cdn-cgi/local/scheduled?cron=*/5+*+*+*+*`);
@@ -669,7 +682,7 @@ async function boot(kind, at, options) {
669
682
  DATABASE_URL: `file:${database}`,
670
683
  VAULT_KEY_ID: KEYS.VAULT_KEY_ID,
671
684
  VAULT_KEY: KEYS.VAULT_KEY,
672
- ROOT_ADMINS: ROOT_ADMIN
685
+ ...OWNER_VARS
673
686
  });
674
687
  await until("the vault socket", async () => existsSync(socket), 30, alive);
675
688
  await run(bin("vite"), ["build", "app"]);
@@ -691,7 +704,7 @@ async function boot(kind, at, options) {
691
704
  kind,
692
705
  origin,
693
706
  idp,
694
- rootAdmin: ROOT_ADMIN,
707
+ owner: OWNER,
695
708
  beforeFirstBeat: false,
696
709
  async scheduled() {
697
710
  const exited = new Promise((done) => server.child.once("exit", done));
@@ -825,19 +838,19 @@ async function signIn(deployment, browser, email) {
825
838
  }
826
839
  async function signInAdmin(deployment) {
827
840
  const browser = new Browser(deployment.origin);
828
- const signed = await signIn(deployment, browser, deployment.rootAdmin);
829
- expect(signed.ok, `the root admin was refused: ${"error" in signed ? signed.error : ""}`);
841
+ const signed = await signIn(deployment, browser, deployment.owner);
842
+ expect(signed.ok, `the bootstrap Owner was refused: ${"error" in signed ? signed.error : ""}`);
830
843
  const api = browser.client();
831
844
  const me = await api.me();
832
- expect(me.principal.id === deployment.rootAdmin && me.isRootAdmin, "signed in as someone else", me);
845
+ expect(me.principal.id === deployment.owner && me.instanceRole === "owner" && me.runsInstance, "signed in as someone else, or not as the Owner", me);
833
846
  const admin = {
834
- email: deployment.rootAdmin,
835
- member: `user:${deployment.rootAdmin}`,
847
+ email: deployment.owner,
848
+ member: `user:${deployment.owner}`,
836
849
  browser,
837
850
  api
838
851
  };
839
852
  return {
840
- detail: `${admin.email}, root admin, through GitHub`,
853
+ detail: `${admin.email}, the bootstrap Owner, through GitHub`,
841
854
  value: admin
842
855
  };
843
856
  }
@@ -2174,8 +2187,9 @@ async function offboarding(deployment, { admin, leaver, service }, canaries) {
2174
2187
  /**
2175
2188
  * Instance roles: a Developer scoped to dev reads and writes the dev of a
2176
2189
  * project made after it, and no prod; an Admin scoped to one environment
2177
- * grants there and nowhere else, and sets no role, its own or anyone's;
2178
- * and no grant is on every project. The reader is a member again as it
2190
+ * grants there and nowhere else, and sets no role, its own or anyone's; an
2191
+ * Admin of the whole instance changes no Owner's; and no grant is on every
2192
+ * project. The reader is a member again as it
2179
2193
  * ends, its service removed, its project archived.
2180
2194
  */
2181
2195
  async function instanceRoles(deployment, { admin, reader }, canaries) {
@@ -2218,12 +2232,16 @@ async function instanceRoles(deployment, { admin, reader }, canaries) {
2218
2232
  await refused$1("a scoped admin read a value no grant of its gives", reader.api.secrets.reveal(PROD));
2219
2233
  await admin.api.members.add(reader.member, { role: "admin" });
2220
2234
  await refused$1("an admin made itself an owner", reader.api.members.add(reader.member, { role: "owner" }));
2235
+ for (const [what, call] of [["an admin demoted the Owner", () => reader.api.members.add(admin.member, { role: "admin" })], ["an admin removed the Owner", () => reader.api.members.remove(admin.member)]]) {
2236
+ const refusal = await refused$1(what, call());
2237
+ expect(refusal.status === 403 && refusal.reason === "not_allowed", `${what}, or was refused for another reason`, refusal);
2238
+ }
2221
2239
  await admin.api.members.add(reader.member, { role: "member" });
2222
2240
  await admin.api.members.remove(scoped);
2223
2241
  await admin.api.projects.update(later, { archived: true });
2224
2242
  const me = await reader.api.me();
2225
2243
  expect(me.instanceRole === "member" && me.environments.length === 1, "the reader is not back as it was", me);
2226
- return "a Developer scoped to dev reaches a dev made later and no prod; a scoped admin grants only inside its scope and sets no role; no grant is on every project";
2244
+ return "a Developer scoped to dev reaches a dev made later and no prod; a scoped admin grants only inside its scope and sets no role; an admin demotes and removes no Owner; no grant is on every project";
2227
2245
  }
2228
2246
  /** Reading more values at once than the vault allows in its window is refused. */
2229
2247
  async function bulkLimit$1({ admin, bulk }, limit) {
@@ -2830,18 +2848,21 @@ async function references(deployment, { admin, reader, leaver }, canaries) {
2830
2848
  /** A key prod has and dev does not, for the missing-keys check; archived once checked. */
2831
2849
  const PROD_ONLY = "CONFORMANCE_PROD_ONLY";
2832
2850
  /**
2833
- * Key names are metadata: what dev is missing is compared only with the
2834
- * environments the viewer reads. The admin sees prod's key missing from dev;
2835
- * the reader, a viewer on dev alone, sees nothing of prod, and dismisses
2836
- * nothing. A dismissal is the team's, and restoring undoes it.
2851
+ * Within a project, key names are not secret; values are. What dev is
2852
+ * missing is compared with every sibling: the reader, a viewer on dev who
2853
+ * cannot read prod, is told prod has the key, as the admin is, and nothing
2854
+ * of its value, and dismisses nothing. A dismissal is the team's, and
2855
+ * restoring undoes it.
2837
2856
  */
2838
2857
  async function missingKeys({ admin, reader }) {
2839
- await admin.api.secrets.set(PROD, { [PROD_ONLY]: canary() });
2858
+ const value = canary();
2859
+ await admin.api.secrets.set(PROD, { [PROD_ONLY]: value });
2840
2860
  try {
2841
2861
  const seen = await admin.api.environments.missing(DEV);
2842
2862
  expect(seen.missing.some((key) => key.key === PROD_ONLY), "the admin was not told dev lacks prod's key", seen);
2843
- const hidden = await reader.api.environments.missing(DEV);
2844
- expect(![...hidden.missing, ...hidden.dismissed].some((key) => key.key === PROD_ONLY), "a viewer on dev learned a key name from prod, which they cannot read", hidden);
2863
+ const told = await reader.api.environments.missing(DEV);
2864
+ expect(told.missing.some((key) => key.key === PROD_ONLY && key.in.includes("prod")), "a viewer on dev was not told dev lacks prod's key, by name", told);
2865
+ expect(!JSON.stringify(told).includes(value), "a viewer on dev was told prod's value with its key's name");
2845
2866
  await refused$1("a viewer dismissed a missing key", reader.api.environments.dismiss(DEV, { [PROD_ONLY]: true }));
2846
2867
  await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: true });
2847
2868
  const dismissed = await admin.api.environments.missing(DEV);
@@ -2851,7 +2872,7 @@ async function missingKeys({ admin, reader }) {
2851
2872
  } finally {
2852
2873
  await admin.api.secrets.update(`${PROD}/${PROD_ONLY}`, { archived: true });
2853
2874
  }
2854
- return "only who reads prod learns what dev lacks of it; a viewer dismisses nothing; a dismissal is listed, and restored";
2875
+ return "a viewer on dev learns prod's key name, not its value, and dismisses nothing; a dismissal is listed, and restored";
2855
2876
  }
2856
2877
  //#endregion
2857
2878
  //#region src/checks/logins.ts
@@ -3074,6 +3095,7 @@ function getCalls({ places, secrets, members, services }) {
3074
3095
  params: {},
3075
3096
  input: { github: "acme/api" }
3076
3097
  }],
3098
+ "GET /workloads/repositories": [{ params: {} }],
3077
3099
  "GET /settings": [{ params: {} }],
3078
3100
  "GET /sessions": [{ params: {} }],
3079
3101
  "GET /identities": [{ params: {} }],
@@ -3202,7 +3224,7 @@ async function canaryScan(deployment, people, canaries) {
3202
3224
  };
3203
3225
  const token = (value) => (url) => fetch(url, { headers: { authorization: `Bearer ${value}` } });
3204
3226
  const browsers = {
3205
- "the root admin": people.admin.browser,
3227
+ "the Owner": people.admin.browser,
3206
3228
  "the reader": people.reader.browser,
3207
3229
  "the bulk reader": people.bulk.browser,
3208
3230
  "the leaver, removed": people.leaver.browser,
@@ -3412,7 +3434,7 @@ async function verifyAsUser(cli, user, admin) {
3412
3434
  const run = await cli.run(["verify", "instance"]);
3413
3435
  expect(run.code === 1, `coffre verify instance as a user exited ${run.code}, not 1`, run.output);
3414
3436
  expect(marks(run.output).owner === "✗", "the run went on past a user", run.output);
3415
- expect(/is not an admin or owner of all of \S+, nor a root admin: nothing was made/.test(run.output), "the run did not say plainly why it stopped", run.output);
3437
+ expect(/is not an admin or owner of all of \S+: nothing was made/.test(run.output), "the run did not say plainly why it stopped", run.output);
3416
3438
  expect(await admin.api.members.get(PROBE.service).then(() => "there", (error) => error instanceof CoffreError && error.status === 404 ? "absent" : Promise.reject(error)) === "absent", `${PROBE.service} was made for a user`);
3417
3439
  await bearer(cli.origin, cli.session()).me();
3418
3440
  expect(await everythingElse(admin.api) === before, "the run changed a member, a grant, a project or an environment for a user");
@@ -3792,7 +3814,7 @@ var Chrome = class Chrome {
3792
3814
  * shows once its scripts have run and settled, and every uncaught error,
3793
3815
  * console error and failed load along the way. `then`, a script run once
3794
3816
  * the page settles, does what a person would next, such as open a dialog,
3795
- * whose text is read with the rest.
3817
+ * whose text is read with the rest, and may answer what it saw.
3796
3818
  */
3797
3819
  async load(url, cookies, settle = 2e3, then) {
3798
3820
  const { targetId } = await this.#send("Target.createTarget", { url: "about:blank" });
@@ -3833,11 +3855,14 @@ var Chrome = class Chrome {
3833
3855
  await this.#send("Page.navigate", { url }, sessionId);
3834
3856
  await Promise.race([load, new Promise((resolve) => setTimeout(resolve, 3e4))]);
3835
3857
  await new Promise((resolve) => setTimeout(resolve, settle));
3858
+ let answer = null;
3836
3859
  if (then !== void 0) {
3837
- await this.#send("Runtime.evaluate", {
3860
+ const { result } = await this.#send("Runtime.evaluate", {
3838
3861
  expression: then,
3839
- awaitPromise: true
3862
+ awaitPromise: true,
3863
+ returnByValue: true
3840
3864
  }, sessionId);
3865
+ answer = result.value ?? null;
3841
3866
  await new Promise((resolve) => setTimeout(resolve, settle));
3842
3867
  }
3843
3868
  const { result } = await this.#send("Runtime.evaluate", {
@@ -3853,6 +3878,7 @@ var Chrome = class Chrome {
3853
3878
  }, sessionId);
3854
3879
  return {
3855
3880
  ...result.value,
3881
+ answer,
3856
3882
  errors
3857
3883
  };
3858
3884
  } finally {
@@ -4095,6 +4121,107 @@ async function pagesInBrowser(deployment, admin, browser) {
4095
4121
  }
4096
4122
  return `${pages.map(([path]) => path).join(", ")}, signed in, in Chrome: each rendered, on its tab, no error from their scripts; a project's tabs by their links, back and forward; a service account shown as service:${name}, OIDC then bearer tokens, its removal previewed; the keys' checks in Settings; its grant on dev, project by project; the account's Connected apps tab, with this instance's MCP URL and Claude Code's command; the MCP consent page, a registered client shown as unverified`;
4097
4123
  }
4124
+ /** Where values are pasted in: an environment of their own, the others' values being the canaries'. */
4125
+ const PASTED = `${PROJECT$1}/pasted`;
4126
+ /** A private key as a PEM file holds it, made up: random base64 in lines of 64, each ending in a line break, the last too. */
4127
+ function pem() {
4128
+ return `-----BEGIN PRIVATE KEY-----\n${randomBytes(120).toString("base64").match(/.{1,64}/g).join("\n")}\n-----END PRIVATE KEY-----\n`;
4129
+ }
4130
+ /**
4131
+ * A row's value field, opened by the button `open` names, and `text`
4132
+ * pasted into it as the clipboard would, over the characters `select`
4133
+ * picks; then the row saved by its own button. A new secret is named first.
4134
+ * Answers which field has the focus after the paste, and where its caret is.
4135
+ */
4136
+ const pasteInto = (steps) => `(async () => {
4137
+ const { open, name, field, select, text, save } = ${JSON.stringify(steps)};
4138
+ const wait = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
4139
+ // What the page shows once it has it: an edit first reads the value it starts from.
4140
+ const shown = async (label) => {
4141
+ for (let tries = 0; tries < 50; tries++, await wait()) {
4142
+ const found = document.querySelector(\`[aria-label="\${label}"]\`);
4143
+ if (found !== null) return found;
4144
+ }
4145
+ return null;
4146
+ };
4147
+ const button = (words) => [...document.querySelectorAll('button')].find((each) => each.getAttribute('aria-label') === words || each.textContent.trim() === words);
4148
+ button(open)?.click();
4149
+ if (name !== undefined) {
4150
+ const named = await shown('Name of the new secret');
4151
+ if (named === null) return { field: null };
4152
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set.call(named, name);
4153
+ named.dispatchEvent(new Event('input', { bubbles: true }));
4154
+ }
4155
+ const input = await shown(field);
4156
+ if (input === null) return { field: null };
4157
+ input.focus();
4158
+ if (select !== undefined) input.setSelectionRange(...select);
4159
+ const clipboard = new DataTransfer();
4160
+ clipboard.setData('text/plain', text);
4161
+ input.dispatchEvent(new ClipboardEvent('paste', { clipboardData: clipboard, bubbles: true, cancelable: true }));
4162
+ await wait(300);
4163
+ const focused = document.activeElement;
4164
+ const answer = { field: focused.tagName.toLowerCase(), label: focused.getAttribute('aria-label'), caret: [focused.selectionStart, focused.selectionEnd] };
4165
+ button(save)?.click();
4166
+ return answer;
4167
+ })()`;
4168
+ /**
4169
+ * A multi-line value pasted into a secret's value field keeps its line
4170
+ * breaks. A text input drops them, so the page puts the paste into the
4171
+ * value itself and turns the field into a textarea, the caret after the
4172
+ * paste. A new secret's PEM key saves byte for byte; one pasted over part
4173
+ * of an existing value replaces just that part, its \r\n saved as \n.
4174
+ * Values never shown: a failure says their lengths and line counts.
4175
+ */
4176
+ async function pastedValues(deployment, admin, browser) {
4177
+ const executable = chromeOrSkip(browser);
4178
+ await admin.api.environments.create(PASTED, { name: "Pasted" });
4179
+ const before = `coffre-paste-${randomBytes(12).toString("hex")}`;
4180
+ await admin.api.secrets.set(PASTED, { EDITED_KEY: before });
4181
+ const page = new URL(`/projects/${PASTED}`, deployment.origin).href;
4182
+ const added = pem();
4183
+ const edit = pem();
4184
+ const shape = (value) => value === void 0 ? "nothing" : `${value.length} characters, ${value.split("\n").length} lines`;
4185
+ const chrome = await Chrome.open(executable);
4186
+ try {
4187
+ const caret = added.length;
4188
+ const adding = await chrome.load(page, admin.browser.cookies(), void 0, pasteInto({
4189
+ open: "New secret",
4190
+ name: "PASTED_KEY",
4191
+ field: "Value for PASTED_KEY",
4192
+ text: added,
4193
+ save: "Save PASTED_KEY now"
4194
+ }));
4195
+ expect(adding.errors.length === 0, `${page} reported errors in the browser`, adding.errors.join("\n"));
4196
+ expect(JSON.stringify(adding.answer) === JSON.stringify({
4197
+ field: "textarea",
4198
+ label: "Value for PASTED_KEY",
4199
+ caret: [caret, caret]
4200
+ }), "a PEM key pasted into a new secret's value did not leave a textarea focused, its caret after the paste", adding.answer);
4201
+ const at = [8, 20];
4202
+ const editing = await chrome.load(page, admin.browser.cookies(), void 0, pasteInto({
4203
+ open: "Edit EDITED_KEY",
4204
+ field: "New value for EDITED_KEY",
4205
+ select: [...at],
4206
+ text: edit.replaceAll("\n", "\r\n"),
4207
+ save: "Save EDITED_KEY now"
4208
+ }));
4209
+ expect(editing.errors.length === 0, `${page} reported errors in the browser`, editing.errors.join("\n"));
4210
+ const after = at[0] + edit.length;
4211
+ expect(JSON.stringify(editing.answer) === JSON.stringify({
4212
+ field: "textarea",
4213
+ label: "New value for EDITED_KEY",
4214
+ caret: [after, after]
4215
+ }), "a PEM key pasted into an edited value did not leave a textarea focused, its caret after the paste", editing.answer);
4216
+ } finally {
4217
+ await chrome.close();
4218
+ }
4219
+ const { values } = await admin.api.secrets.reveal(PASTED);
4220
+ expect(values.PASTED_KEY === added, `the new secret saved ${shape(values.PASTED_KEY)}, not the ${shape(added)} pasted`);
4221
+ const edited = before.slice(0, 8) + edit + before.slice(20);
4222
+ expect(values.EDITED_KEY === edited, `the edited secret saved ${shape(values.EDITED_KEY)}, not the ${shape(edited)} of its value with the paste in characters 8 to 20`);
4223
+ return `in Chrome, a ${added.split("\n").length - 1}-line PEM key pasted into a new secret's value and into part of an edited one: each field a textarea after, focused, its caret after the paste; the new value saved byte for byte, the edited one with the paste in place and its \r\n as \n`;
4224
+ }
4098
4225
  /**
4099
4226
  * A refused sign-in, said once: the page coffre sends the browser back to
4100
4227
  * shows why, rendered by the server, then takes it out of the address, so a
@@ -4562,6 +4689,7 @@ async function conform(deployment, options) {
4562
4689
  admin,
4563
4690
  canaries
4564
4691
  }, ({ admin }) => pagesInBrowser(deployment, admin, options.browser));
4692
+ await report.check("pasted values", { admin }, ({ admin }) => pastedValues(deployment, admin, options.browser));
4565
4693
  await report.check("sign-in error, once", { admin }, ({ admin }) => signinErrorOnce(deployment, admin, options.browser));
4566
4694
  const people = await report.check("personas", {
4567
4695
  admin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/conformance",
3
- "version": "0.5.0",
3
+ "version": "0.6.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.5.0",
35
- "@coffre/db": "0.5.0"
34
+ "@coffre/cli": "0.6.0",
35
+ "@coffre/db": "0.6.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.5.0"
44
+ "@coffre/client": "0.6.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsdown",
@@ -131,8 +131,9 @@ export async function offboarding(deployment: Deployment, { admin, leaver, servi
131
131
  /**
132
132
  * Instance roles: a Developer scoped to dev reads and writes the dev of a
133
133
  * project made after it, and no prod; an Admin scoped to one environment
134
- * grants there and nowhere else, and sets no role, its own or anyone's;
135
- * and no grant is on every project. The reader is a member again as it
134
+ * grants there and nowhere else, and sets no role, its own or anyone's; an
135
+ * Admin of the whole instance changes no Owner's; and no grant is on every
136
+ * project. The reader is a member again as it
136
137
  * ends, its service removed, its project archived.
137
138
  */
138
139
  export async function instanceRoles(deployment: Deployment, { admin, reader }: People, canaries: Canaries): Promise<string> {
@@ -168,9 +169,17 @@ export async function instanceRoles(deployment: Deployment, { admin, reader }: P
168
169
  await refused('a scoped admin promoted someone', reader.api.members.add(scoped, { role: 'member' }));
169
170
  await refused('a scoped admin made a project', reader.api.projects.create(`${PROJECT}-scoped`, { name: 'Scoped' }));
170
171
  await refused('a scoped admin read a value no grant of its gives', reader.api.secrets.reveal(PROD));
171
- // Nor does an admin of the whole instance set its own.
172
+ // Nor does an admin of the whole instance set its own, nor make, change or remove an Owner: only an Owner does.
172
173
  await admin.api.members.add(reader.member, { role: 'admin' });
173
174
  await refused('an admin made itself an owner', reader.api.members.add(reader.member, { role: 'owner' }));
175
+ for (const [what, call] of [
176
+ ['an admin demoted the Owner', () => reader.api.members.add(admin.member, { role: 'admin' })],
177
+ ['an admin removed the Owner', () => reader.api.members.remove(admin.member)],
178
+ ] as const) {
179
+ // Not that the Owner is the last, which an Owner hears too: that only an Owner may.
180
+ const refusal = await refused(what, call());
181
+ expect(refusal.status === 403 && refusal.reason === 'not_allowed', `${what}, or was refused for another reason`, refusal);
182
+ }
174
183
 
175
184
  // As it was: a member, with its viewer on dev; the service and the project gone.
176
185
  await admin.api.members.add(reader.member, { role: 'member' });
@@ -178,7 +187,7 @@ export async function instanceRoles(deployment: Deployment, { admin, reader }: P
178
187
  await admin.api.projects.update(later, { archived: true });
179
188
  const me = await reader.api.me();
180
189
  expect(me.instanceRole === 'member' && me.environments.length === 1, 'the reader is not back as it was', me);
181
- return 'a Developer scoped to dev reaches a dev made later and no prod; a scoped admin grants only inside its scope and sets no role; no grant is on every project';
190
+ return 'a Developer scoped to dev reaches a dev made later and no prod; a scoped admin grants only inside its scope and sets no role; an admin demotes and removes no Owner; no grant is on every project';
182
191
  }
183
192
 
184
193
  /** Reading more values at once than the vault allows in its window is refused. */
@@ -55,7 +55,7 @@ export async function canaryScan(deployment: Deployment, people: People, canarie
55
55
 
56
56
  const token = (value: string) => (url: string) => fetch(url, { headers: { authorization: `Bearer ${value}` } });
57
57
  const browsers = {
58
- 'the root admin': people.admin.browser,
58
+ 'the Owner': people.admin.browser,
59
59
  'the reader': people.reader.browser,
60
60
  'the bulk reader': people.bulk.browser,
61
61
  'the leaver, removed': people.leaver.browser,
package/src/checks/cli.ts CHANGED
@@ -146,7 +146,7 @@ export async function verifyAsUser(cli: Cli, user: Person, admin: Person): Promi
146
146
  const run = await cli.run(['verify', 'instance']);
147
147
  expect(run.code === 1, `coffre verify instance as a user exited ${run.code}, not 1`, run.output);
148
148
  expect(marks(run.output).owner === '✗', 'the run went on past a user', run.output);
149
- expect(/is not an admin or owner of all of \S+, nor a root admin: nothing was made/.test(run.output), 'the run did not say plainly why it stopped', run.output);
149
+ expect(/is not an admin or owner of all of \S+: nothing was made/.test(run.output), 'the run did not say plainly why it stopped', run.output);
150
150
  const service = await admin.api.members.get(PROBE.service).then(
151
151
  () => 'there',
152
152
  (error: unknown) => (error instanceof CoffreError && error.status === 404 ? 'absent' : Promise.reject(error)),
@@ -168,18 +168,21 @@ export async function references(deployment: Deployment, { admin, reader, leaver
168
168
  const PROD_ONLY = 'CONFORMANCE_PROD_ONLY';
169
169
 
170
170
  /**
171
- * Key names are metadata: what dev is missing is compared only with the
172
- * environments the viewer reads. The admin sees prod's key missing from dev;
173
- * the reader, a viewer on dev alone, sees nothing of prod, and dismisses
174
- * nothing. A dismissal is the team's, and restoring undoes it.
171
+ * Within a project, key names are not secret; values are. What dev is
172
+ * missing is compared with every sibling: the reader, a viewer on dev who
173
+ * cannot read prod, is told prod has the key, as the admin is, and nothing
174
+ * of its value, and dismisses nothing. A dismissal is the team's, and
175
+ * restoring undoes it.
175
176
  */
176
177
  export async function missingKeys({ admin, reader }: People): Promise<string> {
177
- await admin.api.secrets.set(PROD, { [PROD_ONLY]: canary() });
178
+ const value = canary();
179
+ await admin.api.secrets.set(PROD, { [PROD_ONLY]: value });
178
180
  try {
179
181
  const seen = await admin.api.environments.missing(DEV);
180
182
  expect(seen.missing.some((key) => key.key === PROD_ONLY), "the admin was not told dev lacks prod's key", seen);
181
- const hidden = await reader.api.environments.missing(DEV);
182
- expect(![...hidden.missing, ...hidden.dismissed].some((key) => key.key === PROD_ONLY), "a viewer on dev learned a key name from prod, which they cannot read", hidden);
183
+ const told = await reader.api.environments.missing(DEV);
184
+ expect(told.missing.some((key) => key.key === PROD_ONLY && key.in.includes('prod')), "a viewer on dev was not told dev lacks prod's key, by name", told);
185
+ expect(!JSON.stringify(told).includes(value), "a viewer on dev was told prod's value with its key's name");
183
186
  await refused('a viewer dismissed a missing key', reader.api.environments.dismiss(DEV, { [PROD_ONLY]: true }));
184
187
  await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: true });
185
188
  const dismissed = await admin.api.environments.missing(DEV);
@@ -189,5 +192,5 @@ export async function missingKeys({ admin, reader }: People): Promise<string> {
189
192
  } finally {
190
193
  await admin.api.secrets.update(`${PROD}/${PROD_ONLY}`, { archived: true });
191
194
  }
192
- return "only who reads prod learns what dev lacks of it; a viewer dismisses nothing; a dismissal is listed, and restored";
195
+ return "a viewer on dev learns prod's key name, not its value, and dismisses nothing; a dismissal is listed, and restored";
193
196
  }
@@ -3,6 +3,8 @@
3
3
  // page receives shows only there: wrangler's keep_names once wrapped the
4
4
  // functions seroval writes into a page in an `__name` that only the Worker
5
5
  // had, and a signed-in page rendered, then went blank.
6
+ import { randomBytes } from 'node:crypto';
7
+
6
8
  import { Browser } from '../browser.ts';
7
9
  import { Chrome, findChrome } from '../chrome.ts';
8
10
  import type { Deployment } from '../harness.ts';
@@ -164,6 +166,100 @@ export async function pagesInBrowser(deployment: Deployment, admin: Person, brow
164
166
  return `${pages.map(([path]) => path).join(', ')}, signed in, in Chrome: each rendered, on its tab, no error from their scripts; a project's tabs by their links, back and forward; a service account shown as service:${name}, OIDC then bearer tokens, its removal previewed; the keys' checks in Settings; its grant on dev, project by project; the account's Connected apps tab, with this instance's MCP URL and Claude Code's command; the MCP consent page, a registered client shown as unverified`;
165
167
  }
166
168
 
169
+ /** Where values are pasted in: an environment of their own, the others' values being the canaries'. */
170
+ const PASTED = `${PROJECT}/pasted`;
171
+
172
+ /** A private key as a PEM file holds it, made up: random base64 in lines of 64, each ending in a line break, the last too. */
173
+ function pem(): string {
174
+ const body = randomBytes(120).toString('base64').match(/.{1,64}/g)!.join('\n');
175
+ return `-----BEGIN PRIVATE KEY-----\n${body}\n-----END PRIVATE KEY-----\n`;
176
+ }
177
+
178
+ /**
179
+ * A row's value field, opened by the button `open` names, and `text`
180
+ * pasted into it as the clipboard would, over the characters `select`
181
+ * picks; then the row saved by its own button. A new secret is named first.
182
+ * Answers which field has the focus after the paste, and where its caret is.
183
+ */
184
+ const pasteInto = (steps: { open: string; name?: string; field: string; select?: [number, number]; text: string; save: string }) => `(async () => {
185
+ const { open, name, field, select, text, save } = ${JSON.stringify(steps)};
186
+ const wait = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
187
+ // What the page shows once it has it: an edit first reads the value it starts from.
188
+ const shown = async (label) => {
189
+ for (let tries = 0; tries < 50; tries++, await wait()) {
190
+ const found = document.querySelector(\`[aria-label="\${label}"]\`);
191
+ if (found !== null) return found;
192
+ }
193
+ return null;
194
+ };
195
+ const button = (words) => [...document.querySelectorAll('button')].find((each) => each.getAttribute('aria-label') === words || each.textContent.trim() === words);
196
+ button(open)?.click();
197
+ if (name !== undefined) {
198
+ const named = await shown('Name of the new secret');
199
+ if (named === null) return { field: null };
200
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set.call(named, name);
201
+ named.dispatchEvent(new Event('input', { bubbles: true }));
202
+ }
203
+ const input = await shown(field);
204
+ if (input === null) return { field: null };
205
+ input.focus();
206
+ if (select !== undefined) input.setSelectionRange(...select);
207
+ const clipboard = new DataTransfer();
208
+ clipboard.setData('text/plain', text);
209
+ input.dispatchEvent(new ClipboardEvent('paste', { clipboardData: clipboard, bubbles: true, cancelable: true }));
210
+ await wait(300);
211
+ const focused = document.activeElement;
212
+ const answer = { field: focused.tagName.toLowerCase(), label: focused.getAttribute('aria-label'), caret: [focused.selectionStart, focused.selectionEnd] };
213
+ button(save)?.click();
214
+ return answer;
215
+ })()`;
216
+
217
+ /**
218
+ * A multi-line value pasted into a secret's value field keeps its line
219
+ * breaks. A text input drops them, so the page puts the paste into the
220
+ * value itself and turns the field into a textarea, the caret after the
221
+ * paste. A new secret's PEM key saves byte for byte; one pasted over part
222
+ * of an existing value replaces just that part, its \r\n saved as \n.
223
+ * Values never shown: a failure says their lengths and line counts.
224
+ */
225
+ export async function pastedValues(deployment: Deployment, admin: Person, browser: string | null): Promise<string> {
226
+ const executable = chromeOrSkip(browser);
227
+ await admin.api.environments.create(PASTED, { name: 'Pasted' });
228
+ const before = `coffre-paste-${randomBytes(12).toString('hex')}`;
229
+ await admin.api.secrets.set(PASTED, { EDITED_KEY: before });
230
+ const page = new URL(`/projects/${PASTED}`, deployment.origin).href;
231
+ const added = pem();
232
+ const edit = pem();
233
+ const shape = (value: string | undefined) => (value === undefined ? 'nothing' : `${value.length} characters, ${value.split('\n').length} lines`);
234
+ const chrome = await Chrome.open(executable);
235
+ try {
236
+ const caret = added.length;
237
+ const adding = await chrome.load(page, admin.browser.cookies(), undefined, pasteInto({ open: 'New secret', name: 'PASTED_KEY', field: 'Value for PASTED_KEY', text: added, save: 'Save PASTED_KEY now' }));
238
+ expect(adding.errors.length === 0, `${page} reported errors in the browser`, adding.errors.join('\n'));
239
+ expect(
240
+ JSON.stringify(adding.answer) === JSON.stringify({ field: 'textarea', label: 'Value for PASTED_KEY', caret: [caret, caret] }),
241
+ "a PEM key pasted into a new secret's value did not leave a textarea focused, its caret after the paste",
242
+ adding.answer,
243
+ );
244
+ const at = [8, 20] as const;
245
+ const editing = await chrome.load(page, admin.browser.cookies(), undefined, pasteInto({ open: 'Edit EDITED_KEY', field: 'New value for EDITED_KEY', select: [...at], text: edit.replaceAll('\n', '\r\n'), save: 'Save EDITED_KEY now' }));
246
+ expect(editing.errors.length === 0, `${page} reported errors in the browser`, editing.errors.join('\n'));
247
+ const after = at[0] + edit.length;
248
+ expect(
249
+ JSON.stringify(editing.answer) === JSON.stringify({ field: 'textarea', label: 'New value for EDITED_KEY', caret: [after, after] }),
250
+ "a PEM key pasted into an edited value did not leave a textarea focused, its caret after the paste",
251
+ editing.answer,
252
+ );
253
+ } finally {
254
+ await chrome.close();
255
+ }
256
+ const { values } = await admin.api.secrets.reveal(PASTED);
257
+ expect(values.PASTED_KEY === added, `the new secret saved ${shape(values.PASTED_KEY)}, not the ${shape(added)} pasted`);
258
+ const edited = before.slice(0, 8) + edit + before.slice(20);
259
+ expect(values.EDITED_KEY === edited, `the edited secret saved ${shape(values.EDITED_KEY)}, not the ${shape(edited)} of its value with the paste in characters 8 to 20`);
260
+ return `in Chrome, a ${added.split('\n').length - 1}-line PEM key pasted into a new secret's value and into part of an edited one: each field a textarea after, focused, its caret after the paste; the new value saved byte for byte, the edited one with the paste in place and its \r\n as \n`;
261
+ }
262
+
167
263
  /**
168
264
  * A refused sign-in, said once: the page coffre sends the browser back to
169
265
  * shows why, rendered by the server, then takes it out of the address, so a
@@ -75,13 +75,14 @@ export async function signIn(
75
75
 
76
76
  export async function signInAdmin(deployment: Deployment) {
77
77
  const browser = new Browser(deployment.origin);
78
- const signed = await signIn(deployment, browser, deployment.rootAdmin);
79
- expect(signed.ok, `the root admin was refused: ${'error' in signed ? signed.error : ''}`);
78
+ const signed = await signIn(deployment, browser, deployment.owner);
79
+ expect(signed.ok, `the bootstrap Owner was refused: ${'error' in signed ? signed.error : ''}`);
80
80
  const api = browser.client();
81
81
  const me = await api.me();
82
- expect(me.principal.id === deployment.rootAdmin && me.isRootAdmin, 'signed in as someone else', me);
83
- const admin: Person = { email: deployment.rootAdmin, member: `user:${deployment.rootAdmin}`, browser, api };
84
- return { detail: `${admin.email}, root admin, through GitHub`, value: admin };
82
+ // Signing in first, with no Owner yet, made them the instance's Owner.
83
+ expect(me.principal.id === deployment.owner && me.instanceRole === 'owner' && me.runsInstance, 'signed in as someone else, or not as the Owner', me);
84
+ const admin: Person = { email: deployment.owner, member: `user:${deployment.owner}`, browser, api };
85
+ return { detail: `${admin.email}, the bootstrap Owner, through GitHub`, value: admin };
85
86
  }
86
87
 
87
88
  export async function setUp(admin: Person) {