@coffre/conformance 0.1.5 → 0.1.6

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,7 +1,7 @@
1
1
  import { i as defaultGitHubAccount, n as DevIdp } from "./idp-DJlqS-JW.js";
2
2
  import { join, resolve } from "node:path";
3
3
  import { inspect, parseArgs } from "node:util";
4
- import { setTimeout } from "node:timers/promises";
4
+ import { setTimeout as setTimeout$1 } from "node:timers/promises";
5
5
  import { spawn } from "node:child_process";
6
6
  import { createHash, createHmac, createPrivateKey, hkdfSync, randomBytes, randomUUID, sign } from "node:crypto";
7
7
  import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
@@ -259,19 +259,26 @@ async function until(what, probe, seconds, alive = () => true) {
259
259
  for (let i = 0; i < seconds * 10; i++) {
260
260
  if (!alive()) throw new Failure(`a process exited while waiting for ${what}`);
261
261
  if (await probe().catch(() => false)) return;
262
- await setTimeout(100);
262
+ await setTimeout$1(100);
263
263
  }
264
264
  throw new Failure(`timed out waiting for ${what}`);
265
265
  }
266
266
  var Report = class {
267
267
  #results = [];
268
268
  #width;
269
- constructor(width = 19) {
269
+ #quiet;
270
+ /** `quiet`: keep the lines rather than print them, for a check made of checks to sum up. */
271
+ constructor(width = 19, quiet = false) {
270
272
  this.#width = width;
273
+ this.#quiet = quiet;
271
274
  }
272
275
  get failed() {
273
276
  return this.#results.filter((result) => result.status === "FAIL").map((result) => result.name);
274
277
  }
278
+ /** Each check's name, what came of it, and its line. */
279
+ get results() {
280
+ return this.#results;
281
+ }
275
282
  /**
276
283
  * Run one check, and print what came of it. `needs` holds what earlier
277
284
  * checks produced: if any is missing, this one is skipped rather than run
@@ -300,8 +307,10 @@ var Report = class {
300
307
  #print(name, status, line, detail) {
301
308
  this.#results.push({
302
309
  name,
303
- status
310
+ status,
311
+ line
304
312
  });
313
+ if (this.#quiet) return;
305
314
  const text = ` ${status.padEnd(5)} ${name.padEnd(this.#width)} ${line}`;
306
315
  if (status !== "FAIL") {
307
316
  console.log(text);
@@ -521,10 +530,10 @@ async function anonymousChecks(report, origin, options) {
521
530
  await report.check("sign-in info", {}, () => signinInfo(origin));
522
531
  await report.check("anonymous answers", {}, () => anonymousAnswers(origin));
523
532
  }
524
- /** The checks with a service token that reads the canary, and audits its project. */
525
- async function tokenChecks(report, origin, setup) {
533
+ /** The checks with a service token that reads the canary, and audits its project. `prefix` names them apart, run twice. */
534
+ async function tokenChecks(report, origin, setup, prefix = "") {
526
535
  const api = setup.token === void 0 ? void 0 : bearer(origin, setup.token);
527
- const token = await report.check("token", {
536
+ const token = await report.check(`${prefix}token`, {
528
537
  api,
529
538
  canary: setup.canary
530
539
  }, ({ api, canary }) => whoIsToken(origin, api, canary));
@@ -534,10 +543,10 @@ async function tokenChecks(report, origin, setup) {
534
543
  token,
535
544
  secret: setup.token
536
545
  };
537
- await report.check("token reveal", needs, ({ api, canary, token }) => tokenReveal(api, canary, token));
538
- await report.check("token scan", needs, ({ canary, secret }) => tokenScan(origin, secret, canary));
539
- await report.check("token scope", needs, ({ api, canary }) => tokenScope(api, canary));
540
- await report.check("token verification", { api }, ({ api }) => tokenVerification(api));
546
+ await report.check(`${prefix}token reveal`, needs, ({ api, canary, token }) => tokenReveal(api, canary, token));
547
+ await report.check(`${prefix}token scan`, needs, ({ canary, secret }) => tokenScan(origin, secret, canary));
548
+ await report.check(`${prefix}token scope`, needs, ({ api, canary }) => tokenScope(api, canary));
549
+ await report.check(`${prefix}token verification`, { api }, ({ api }) => tokenVerification(api));
541
550
  }
542
551
  /** Every route, whatever its method, turns away a caller with no credential, and says nothing else. */
543
552
  async function anonymousApi(origin) {
@@ -792,6 +801,513 @@ function sameKeys(value, keys) {
792
801
  return typeof value === "object" && value !== null && JSON.stringify(Object.keys(value).sort()) === JSON.stringify(keys);
793
802
  }
794
803
  //#endregion
804
+ //#region src/checks/people.ts
805
+ const PROJECT = "conformance";
806
+ const DEV = `${PROJECT}/dev`;
807
+ const PROD = `${PROJECT}/prod`;
808
+ const BULK = `${PROJECT}/bulk`;
809
+ const SERVICE = "token:conformance-ci";
810
+ /** Where the live checks' token reads, as an operator would set it up. */
811
+ const LIVE = `${PROJECT}/live`;
812
+ const LIVE_SERVICE = "token:conformance-live";
813
+ function canary() {
814
+ return `coffre-canary-${randomBytes(12).toString("hex")}`;
815
+ }
816
+ /**
817
+ * Sign in the way a browser does: to the stand-in GitHub, which asks for no
818
+ * password, and back. The error is the one coffre sent the browser back to
819
+ * /login with.
820
+ */
821
+ async function signIn$1(deployment, browser, email) {
822
+ const leave = await browser.fetch("/auth/signin/github");
823
+ const authorize = new URL(leave.headers.get("location") ?? "", deployment.origin);
824
+ expect(leave.status === 302 && authorize.origin === deployment.idp.origin, "sign-in did not send the browser to GitHub", `${leave.status} ${leave.headers.get("location")}`);
825
+ const form = new URLSearchParams(authorize.searchParams);
826
+ form.set("email", email);
827
+ const approve = await fetch(authorize.origin + authorize.pathname, {
828
+ method: "POST",
829
+ body: form,
830
+ redirect: "manual"
831
+ });
832
+ const callback = approve.headers.get("location") ?? "";
833
+ expect(approve.status === 302 && callback.startsWith(`${deployment.origin}/auth/callback/github?`), "GitHub did not send the browser back", callback);
834
+ const back = await browser.fetch(callback);
835
+ expect(back.status === 302 || back.status === 303, `the callback answered ${back.status}`, await back.text());
836
+ const error = new URL(back.headers.get("location") ?? "/", deployment.origin).searchParams.get("error");
837
+ return error === null ? { ok: true } : {
838
+ ok: false,
839
+ error
840
+ };
841
+ }
842
+ async function signInAdmin(deployment) {
843
+ const browser = new Browser(deployment.origin);
844
+ const signed = await signIn$1(deployment, browser, deployment.rootAdmin);
845
+ expect(signed.ok, `the root admin was refused: ${"error" in signed ? signed.error : ""}`);
846
+ const api = browser.client();
847
+ const me = await api.me();
848
+ expect(me.principal.id === deployment.rootAdmin && me.isRootAdmin, "signed in as someone else", me);
849
+ const admin = {
850
+ email: deployment.rootAdmin,
851
+ member: `user:${deployment.rootAdmin}`,
852
+ browser,
853
+ api
854
+ };
855
+ return {
856
+ detail: `${admin.email}, root admin, through GitHub`,
857
+ value: admin
858
+ };
859
+ }
860
+ async function setUp$1(admin) {
861
+ await admin.api.projects.create(PROJECT, { name: "Conformance" });
862
+ for (const [path, name] of [
863
+ [DEV, "Development"],
864
+ [PROD, "Production"],
865
+ [BULK, "Bulk"]
866
+ ]) await admin.api.environments.create(path, { name });
867
+ const canaries = {
868
+ [`${DEV}/API_KEY`]: canary(),
869
+ [`${DEV}/DATABASE_URL`]: canary(),
870
+ [`${PROD}/API_KEY`]: canary()
871
+ };
872
+ for (const path of [DEV, PROD]) await admin.api.secrets.set(path, valuesIn(canaries, path));
873
+ return {
874
+ detail: `${PROJECT}: dev and prod, ${Object.keys(canaries).length} values, and bulk`,
875
+ value: canaries
876
+ };
877
+ }
878
+ /**
879
+ * What `probe --token` asks an operator for: an environment holding one
880
+ * canary, and a service that reads it there and audits the project. Its
881
+ * value joins the others, for the scans that follow.
882
+ */
883
+ async function setUpLive(admin, canaries) {
884
+ await admin.api.environments.create(LIVE, { name: "Live" });
885
+ const value = canary();
886
+ await admin.api.secrets.set(LIVE, { CANARY: value });
887
+ canaries[`${LIVE}/CANARY`] = value;
888
+ await admin.api.members.add(LIVE_SERVICE);
889
+ await admin.api.access.set(LIVE_SERVICE, {
890
+ [LIVE]: "viewer",
891
+ [PROJECT]: "auditor"
892
+ });
893
+ const { token } = await admin.api.tokens.issue(LIVE_SERVICE, {
894
+ label: "conformance live",
895
+ expiresInDays: 1
896
+ });
897
+ return {
898
+ detail: `${LIVE}/CANARY, and ${LIVE_SERVICE}: viewer there, auditor on ${PROJECT}`,
899
+ value: {
900
+ token,
901
+ canary: {
902
+ project: PROJECT,
903
+ environment: "live",
904
+ key: "CANARY",
905
+ value
906
+ }
907
+ }
908
+ };
909
+ }
910
+ /** The canaries in one environment, by key. */
911
+ function valuesIn(canaries, environment) {
912
+ return Object.fromEntries(Object.entries(canaries).filter(([path]) => path.startsWith(`${environment}/`)).map(([path, value]) => [path.slice(environment.length + 1), value]));
913
+ }
914
+ async function personas(deployment, admin) {
915
+ async function person(name, access) {
916
+ const email = `${name}@conformance.example`;
917
+ const member = `user:${email}`;
918
+ await admin.api.members.add(member);
919
+ await admin.api.access.set(member, access);
920
+ const browser = new Browser(deployment.origin);
921
+ const signed = await signIn$1(deployment, browser, email);
922
+ expect(signed.ok, `${email} was refused: ${"error" in signed ? signed.error : ""}`);
923
+ return {
924
+ email,
925
+ member,
926
+ browser,
927
+ api: browser.client()
928
+ };
929
+ }
930
+ const reader = await person("reader", { [DEV]: "viewer" });
931
+ const leaver = await person("leaver", { [DEV]: "developer" });
932
+ const bulk = await person("bulk", { [BULK]: "viewer" });
933
+ await admin.api.members.add(SERVICE);
934
+ await admin.api.access.set(SERVICE, { [DEV]: "viewer" });
935
+ const issued = await admin.api.tokens.issue(SERVICE, {
936
+ label: "conformance",
937
+ expiresInDays: 1
938
+ });
939
+ const cliToken = await deviceLogin(deployment, leaver.browser);
940
+ return {
941
+ detail: "a reader, a leaver in a browser and the CLI, a bulk reader, a service with a token, and a stranger",
942
+ value: {
943
+ admin,
944
+ reader,
945
+ leaver: {
946
+ ...leaver,
947
+ cli: bearer(deployment.origin, cliToken),
948
+ cliToken
949
+ },
950
+ service: {
951
+ member: SERVICE,
952
+ token: issued.token,
953
+ api: bearer(deployment.origin, issued.token)
954
+ },
955
+ stranger: {
956
+ email: "stranger@conformance.example",
957
+ browser: new Browser(deployment.origin)
958
+ },
959
+ bulk
960
+ }
961
+ };
962
+ }
963
+ /** `coffre login`: a device code, approved in a signed-in browser, for a CLI session. */
964
+ async function deviceLogin(deployment, browser) {
965
+ const json = { "content-type": "application/json" };
966
+ const started = await fetch(`${deployment.origin}/api/auth/device`, {
967
+ method: "POST",
968
+ headers: json,
969
+ body: JSON.stringify({ client_label: "coffre-conformance" })
970
+ });
971
+ expect(started.ok, `the device login did not start: ${started.status}`, await started.clone().text());
972
+ const device = await started.json();
973
+ await browser.client().deviceLogins.decide(device.user_code, true);
974
+ const polled = await fetch(`${deployment.origin}/api/auth/device/token`, {
975
+ method: "POST",
976
+ headers: json,
977
+ body: JSON.stringify({ device_code: device.device_code })
978
+ });
979
+ const session = await polled.json();
980
+ expect(polled.ok && session.access_token, `the approved device login gave no token: ${polled.status}`, session);
981
+ return session.access_token;
982
+ }
983
+ /**
984
+ * A page's worth of API calls at once, as the pages fire them on a load,
985
+ * right after sign-in, while the vault is fresh: every one answers. A call
986
+ * that waited on another's work in the vault would be cancelled on
987
+ * Cloudflare as hung, and the page would read the 503 or 401 as signed out.
988
+ */
989
+ async function pageLoad(person) {
990
+ const paths = [
991
+ "/api/me",
992
+ "/api/sessions",
993
+ "/api/projects",
994
+ "/api/members",
995
+ "/api/audit",
996
+ "/api/identities",
997
+ "/api/me",
998
+ "/api/projects"
999
+ ];
1000
+ const failed = (await Promise.all(paths.map(async (path) => [path, (await person.browser.fetch(path)).status]))).filter(([, status]) => status !== 200);
1001
+ expect(failed.length === 0, "a call of the page load did not answer 200", failed.map(([path, status]) => `${path}: ${status}`).join(", "));
1002
+ return `${paths.length} calls at once, each answered`;
1003
+ }
1004
+ //#endregion
1005
+ //#region src/checks/probe.ts
1006
+ /** The probe's own place on an instance, made the first time, and found after. Nothing else is touched. */
1007
+ const PROBE = {
1008
+ project: "conformance",
1009
+ environment: "live",
1010
+ service: "token:conformance-probe",
1011
+ key: "SIGN_IN_CANARY"
1012
+ };
1013
+ /** A device login, approved by `approve`, polled until it is, as `coffre login` polls. */
1014
+ async function deviceSignIn(origin, approve) {
1015
+ const json = { "content-type": "application/json" };
1016
+ const started = await fetch(`${origin}/api/auth/device`, {
1017
+ method: "POST",
1018
+ headers: json,
1019
+ body: JSON.stringify({ client_label: "coffre-conformance probe" })
1020
+ });
1021
+ expect(started.ok, `${origin} did not start a device login: ${started.status}`);
1022
+ const device = await started.json();
1023
+ await approve({
1024
+ url: device.verification_uri_complete,
1025
+ code: device.user_code
1026
+ });
1027
+ const deadline = Date.now() + device.expires_in * 1e3;
1028
+ let wait = Math.max(device.interval, 1) * 1e3;
1029
+ for (let first = true; Date.now() < deadline; first = false) {
1030
+ if (!first) await new Promise((resolve) => setTimeout(resolve, wait));
1031
+ const polled = await fetch(`${origin}/api/auth/device/token`, {
1032
+ method: "POST",
1033
+ headers: json,
1034
+ body: JSON.stringify({ device_code: device.device_code })
1035
+ }).catch(() => null);
1036
+ if (polled === null) continue;
1037
+ const answer = await polled.json().catch(() => ({}));
1038
+ if (polled.ok && answer.access_token !== void 0) return answer.access_token;
1039
+ if (polled.status === 429 || answer.error === "slow_down") wait += 5e3;
1040
+ else if (answer.error === "access_denied") throw new Failure("the device login was declined in the browser: nothing was made");
1041
+ else if (answer.error === "expired_token") break;
1042
+ else if (answer.error !== "authorization_pending") throw new Failure(`the device login failed: ${answer.error ?? polled.status}`);
1043
+ }
1044
+ throw new Failure("the device login expired before it was approved: nothing was made");
1045
+ }
1046
+ /** End a session, as `coffre logout` does. One already ended is ended. */
1047
+ async function endSession(origin, token) {
1048
+ const response = await fetch(`${origin}/api/auth/logout`, {
1049
+ method: "POST",
1050
+ headers: {
1051
+ authorization: `Bearer ${token}`,
1052
+ "content-type": "application/json"
1053
+ }
1054
+ });
1055
+ expect(response.ok || response.status === 401, `${origin} did not end the session: ${response.status}`);
1056
+ }
1057
+ /** Signed in, as an owner or a root admin, or stopped, the session ended, before anything is made. */
1058
+ async function signIn(origin, approve) {
1059
+ const token = await deviceSignIn(origin, approve);
1060
+ const api = bearer(origin, token);
1061
+ const me = await api.me();
1062
+ const who = me.principal.id;
1063
+ if (me.instanceRole === "user") {
1064
+ await endSession(origin, token);
1065
+ throw new Failure(`${who} is neither an owner nor a root admin of ${origin}: the probe made nothing, and ended the session`);
1066
+ }
1067
+ return {
1068
+ detail: `${who}, ${me.instanceRole === "owner" ? "an owner" : "a root admin"}, through a device login`,
1069
+ value: {
1070
+ token,
1071
+ api,
1072
+ who
1073
+ }
1074
+ };
1075
+ }
1076
+ /** Make what is missing of the probe's place, and the service's two grants; then a fresh canary, and a fresh credential. */
1077
+ async function setUp(api, issued) {
1078
+ const place = `${PROBE.project}/${PROBE.environment}`;
1079
+ const made = [];
1080
+ const { projects } = await api.projects.list();
1081
+ const project = projects.find(({ slug }) => slug === PROBE.project);
1082
+ expect(project?.archivedAt == null, `${PROBE.project} is archived: unarchive it, or the probe has nowhere to run`);
1083
+ if (project === void 0) {
1084
+ await api.projects.create(PROBE.project, { name: "Conformance" });
1085
+ made.push(`the project ${PROBE.project}`);
1086
+ }
1087
+ const environment = project?.environments.find(({ slug }) => slug === PROBE.environment);
1088
+ expect(environment?.details?.archivedAt == null, `${place} is archived: unarchive it, or the probe has nowhere to run`);
1089
+ if (environment === void 0) {
1090
+ await api.environments.create(place, { name: "Live" });
1091
+ made.push(`the environment ${place}`);
1092
+ }
1093
+ if ((await api.members.add(PROBE.service)).created) made.push(`the service ${PROBE.service}`);
1094
+ const { changes } = await api.access.set(PROBE.service, {
1095
+ [place]: "viewer",
1096
+ [PROBE.project]: "auditor"
1097
+ });
1098
+ const granted = Object.entries(changes).filter(([, change]) => change !== "unchanged");
1099
+ if (granted.length > 0) made.push(`its grants on ${granted.map(([where]) => where).join(" and ")}`);
1100
+ const value = canary();
1101
+ await api.secrets.set(place, { [PROBE.key]: value });
1102
+ const credential = await api.tokens.issue(PROBE.service, {
1103
+ label: "coffre-conformance probe, one run",
1104
+ expiresInDays: 1
1105
+ });
1106
+ issued.push({
1107
+ member: PROBE.service,
1108
+ id: credential.id
1109
+ });
1110
+ return {
1111
+ detail: `${made.length === 0 ? "all found" : `made ${made.join(", ")}`}; a fresh ${place}/${PROBE.key} and a fresh credential for ${PROBE.service}`,
1112
+ value: {
1113
+ token: credential.token,
1114
+ canary: {
1115
+ project: PROBE.project,
1116
+ environment: PROBE.environment,
1117
+ key: PROBE.key,
1118
+ value
1119
+ },
1120
+ made
1121
+ }
1122
+ };
1123
+ }
1124
+ /** What the whole audit chain says, read by the owner, which a token cannot be. */
1125
+ async function verification$1(api) {
1126
+ const verified = await api.audit.verify();
1127
+ expect(verified.ok, "the audit log does not verify", verified);
1128
+ return `the whole chain verifies, as the signed-in owner: ${verified.entries} entries, through entry ${verified.through}`;
1129
+ }
1130
+ /**
1131
+ * The signed-in tier: sign in, set up, the token tier, verification as the
1132
+ * owner; and, however it ends, a Ctrl-C included, the credential revoked and
1133
+ * the session ended. `prefix` names its checks apart from the local run's
1134
+ * own. Returns the session's credential, ended, for the local run to check.
1135
+ */
1136
+ async function signedInChecks(report, origin, approve, prefix = "") {
1137
+ const session = await report.check(`${prefix}sign-in`, {}, () => signIn(origin, approve));
1138
+ if (session === void 0) return void 0;
1139
+ const issued = [];
1140
+ let ended = null;
1141
+ const end = () => ended ??= cleanUp(origin, session, issued);
1142
+ const interrupted = (code) => () => void end().finally(() => process.exit(code));
1143
+ const onInt = interrupted(130);
1144
+ const onTerm = interrupted(143);
1145
+ process.once("SIGINT", onInt);
1146
+ process.once("SIGTERM", onTerm);
1147
+ let live;
1148
+ try {
1149
+ live = await report.check(`${prefix}probe setup`, {}, () => setUp(session.api, issued));
1150
+ await tokenChecks(report, origin, live ?? {}, prefix);
1151
+ await report.check(`${prefix}owner verification`, {}, () => verification$1(session.api));
1152
+ } finally {
1153
+ process.off("SIGINT", onInt);
1154
+ process.off("SIGTERM", onTerm);
1155
+ await report.check(`${prefix}clean-up`, {}, end);
1156
+ }
1157
+ return live === void 0 ? void 0 : {
1158
+ session: session.token,
1159
+ credential: live.token,
1160
+ made: live.made
1161
+ };
1162
+ }
1163
+ /** Revoke what the run issued, end its session, and say what stays. */
1164
+ async function cleanUp(origin, session, issued) {
1165
+ for (const { member, id } of issued) await session.api.tokens.revoke(member, id);
1166
+ const { tokens } = await session.api.tokens.list(PROBE.service).catch(() => ({ tokens: [] }));
1167
+ await endSession(origin, session.token);
1168
+ const others = tokens.length === 0 ? "no working credential" : `${tokens.length} credential${tokens.length === 1 ? "" : "s"} this run did not issue, left as they are`;
1169
+ return `${issued.length === 0 ? "nothing issued" : "the credential revoked"}, the session ended. Staying: ${PROBE.project}/${PROBE.environment} and its ${PROBE.key}, ${PROBE.service} with ${others}, and this run's entries in the audit log`;
1170
+ }
1171
+ /** Open `url` in this machine's browser, if it has one: on a server, the printed address serves. */
1172
+ function openBrowser(url) {
1173
+ const [command, ...args] = process.platform === "darwin" ? ["open", url] : process.platform === "win32" ? [
1174
+ "cmd",
1175
+ "/c",
1176
+ "start",
1177
+ "",
1178
+ url
1179
+ ] : ["xdg-open", url];
1180
+ try {
1181
+ const child = spawn(command, args, {
1182
+ stdio: "ignore",
1183
+ detached: true
1184
+ });
1185
+ child.on("error", () => {});
1186
+ child.unref();
1187
+ } catch {}
1188
+ }
1189
+ /** The local run approves as the person signing in: their own session approves the code, as their browser would. */
1190
+ function approvedBy(person) {
1191
+ return async ({ code }) => {
1192
+ await person.api.deviceLogins.decide(code, true);
1193
+ };
1194
+ }
1195
+ /** What the probe must leave as it was: every member and their grants, but its service; every project and environment. */
1196
+ async function everythingElse(api) {
1197
+ const { members } = await api.members.list();
1198
+ const { projects } = await api.projects.list();
1199
+ return JSON.stringify({
1200
+ members: members.filter(({ member }) => member !== PROBE.service),
1201
+ projects: projects.map(({ slug, archivedAt, environments }) => ({
1202
+ slug,
1203
+ archivedAt,
1204
+ environments: environments.map(({ slug: env }) => env)
1205
+ }))
1206
+ });
1207
+ }
1208
+ /** Signed in as a user, the probe says so, and makes nothing: no service, no session left. Returns what it must leave as it was. */
1209
+ async function probeAsUser(origin, user, admin) {
1210
+ const before = await everythingElse(admin.api);
1211
+ const quiet = new Report(19, true);
1212
+ await signedInChecks(quiet, origin, approvedBy(user));
1213
+ const [signIn] = quiet.results;
1214
+ expect(quiet.results.length === 1 && signIn?.status === "FAIL", "the probe went on past a user", quiet.results);
1215
+ expect(signIn.line.includes("is neither an owner nor a root admin") && signIn.line.includes("made nothing"), "the probe did not say plainly why it stopped", signIn.line);
1216
+ 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`);
1217
+ const { sessions } = await user.api.sessions.list();
1218
+ expect(!sessions.some(({ label }) => label === "coffre-conformance probe"), "the user's probe session was left open", sessions);
1219
+ expect(await everythingElse(admin.api) === before, "the probe changed a member, a grant, a project or an environment for a user");
1220
+ return {
1221
+ detail: `${user.email}, a user, is told plainly; nothing made, the session ended`,
1222
+ value: before
1223
+ };
1224
+ }
1225
+ /** One run of `probe --sign-in`, as the admin: every check of it passes. Its lines, summed up. */
1226
+ async function probeRun(origin, admin) {
1227
+ const quiet = new Report(19, true);
1228
+ const run = await signedInChecks(quiet, origin, approvedBy(admin));
1229
+ const failed = quiet.results.filter(({ status }) => status === "FAIL");
1230
+ expect(run !== void 0 && failed.length === 0, `the probe failed: ${failed.map(({ name }) => name).join(", ")}`, quiet.results);
1231
+ const said = JSON.stringify(quiet.results);
1232
+ expect(!said.includes(run.credential) && !said.includes(run.session) && !/coffre-canary-/.test(said), "the probe's lines show its credential, its session or its canary");
1233
+ const skipped = quiet.results.filter(({ status }) => status === "skip").map(({ name }) => name);
1234
+ return {
1235
+ detail: `${quiet.results.length - skipped.length} checks ok${skipped.length === 0 ? "" : `, ${skipped.join(", ")} skipped`}; ${run.made.length === 0 ? "all found" : `made ${run.made.join(", ")}`}`,
1236
+ value: run
1237
+ };
1238
+ }
1239
+ /**
1240
+ * After two runs: the second found everything the first made; each run's
1241
+ * credential and session refuse, and the service holds no credential; the
1242
+ * canary an operator keeps beside is as it was; nothing else changed; the
1243
+ * runs' reads are in the audit log.
1244
+ */
1245
+ async function probeLeftovers(origin, admin, runs, before, kept) {
1246
+ expect(runs[0].made.includes(`the service ${PROBE.service}`), "the first run did not make its service", runs[0].made);
1247
+ expect(runs.slice(1).every(({ made }) => made.length === 0), "a later run made something again", runs.map(({ made }) => made));
1248
+ for (const { session, credential } of runs) for (const [what, token] of [["session", session], ["credential", credential]]) await refused(`a run's ${what} still worked after it`, bearer(origin, token).me());
1249
+ const { tokens } = await admin.api.tokens.list(PROBE.service);
1250
+ expect(tokens.length === 0, `${PROBE.service} still holds ${tokens.length} credential(s)`, tokens);
1251
+ const place = `${kept.project}/${kept.environment}`;
1252
+ const { values } = await admin.api.secrets.reveal(`${place}/${kept.key}`);
1253
+ expect(values[kept.key] === kept.value, `${place}/${kept.key}, kept beside the probe's own, was changed`);
1254
+ expect(await everythingElse(admin.api) === before, "the runs changed a member, a grant, a project or an environment besides their own");
1255
+ const { entries } = await admin.api.audit.list({
1256
+ actor: PROBE.service,
1257
+ limit: 50
1258
+ });
1259
+ expect(entries.length > 0, `the audit log holds no entry by ${PROBE.service}`);
1260
+ return `the second run found all; ${runs.length} sessions and credentials refuse; ${PROBE.service} holds none; ${place}/${kept.key} untouched; nothing else changed; ${entries.length} entries by ${PROBE.service} stay`;
1261
+ }
1262
+ /** What a credential coffre issues, or a canary, looks like in a run's output. */
1263
+ const SHOWN = /coffre_(svc|cli|web)_[A-Za-z0-9_-]{8,}|coffre-canary-[0-9a-f]{8,}/;
1264
+ /**
1265
+ * The command itself, `coffre-conformance probe <url> --sign-in`, as the
1266
+ * admin approves it, interrupted mid-run by a Ctrl-C: it exits 130 with its
1267
+ * credential revoked and its session ended, and nothing it printed shows
1268
+ * either, or its canary.
1269
+ */
1270
+ async function probeInterrupted(origin, admin) {
1271
+ const child = spawn(process.execPath, [
1272
+ ...process.execArgv,
1273
+ process.argv[1],
1274
+ "probe",
1275
+ origin,
1276
+ "--sign-in"
1277
+ ], { stdio: [
1278
+ "ignore",
1279
+ "pipe",
1280
+ "pipe"
1281
+ ] });
1282
+ let output = "";
1283
+ child.stdout.setEncoding("utf8").on("data", (chunk) => output += chunk);
1284
+ child.stderr.setEncoding("utf8").on("data", (chunk) => output += chunk);
1285
+ const exited = new Promise((resolve) => child.on("exit", (code) => resolve(code)));
1286
+ try {
1287
+ const waitFor = async (pattern, what) => {
1288
+ for (let tries = 0; !pattern.test(output); tries += 1) {
1289
+ expect(tries < 600 && child.exitCode === null, `the probe never got to ${what}`, output);
1290
+ await setTimeout$1(50);
1291
+ }
1292
+ return pattern.exec(output);
1293
+ };
1294
+ const [, code] = await waitFor(/shows the code (\S+)\./, "its device login");
1295
+ await admin.api.deviceLogins.decide(code, true);
1296
+ await waitFor(/ok {4}token reveal/, "its token checks");
1297
+ child.kill("SIGINT");
1298
+ const status = await exited;
1299
+ expect(status === 130, `the interrupted probe exited ${status}, not 130`, output);
1300
+ } finally {
1301
+ if (child.exitCode === null) child.kill("SIGKILL");
1302
+ }
1303
+ const { tokens } = await admin.api.tokens.list(PROBE.service);
1304
+ expect(tokens.length === 0, `the interrupted run left ${PROBE.service} ${tokens.length} credential(s)`, tokens);
1305
+ const { sessions } = await admin.api.sessions.list();
1306
+ expect(!sessions.some(({ label }) => label === "coffre-conformance probe"), "the interrupted run's session was left open", sessions);
1307
+ expect(!SHOWN.test(output), "the probe printed a credential or a canary", SHOWN.exec(output)?.[0]);
1308
+ return "Ctrl-C mid-run: exit 130, its credential revoked and its session ended; nothing it printed shows either, or its canary";
1309
+ }
1310
+ //#endregion
795
1311
  //#region src/database.ts
796
1312
  async function postgres(url) {
797
1313
  const client = new pg.Client(postgresConnection(url));
@@ -905,7 +1421,7 @@ async function boot(kind, at, options) {
905
1421
  for (const { child, exited } of children) if (!exited) try {
906
1422
  process.kill(-child.pid, signal);
907
1423
  } catch {}
908
- await setTimeout(500);
1424
+ await setTimeout$1(500);
909
1425
  }
910
1426
  await idp.stop().catch(() => {});
911
1427
  await cleanup().catch(() => {});
@@ -1040,207 +1556,6 @@ function withDatabase(url, database) {
1040
1556
  return parsed.href;
1041
1557
  }
1042
1558
  //#endregion
1043
- //#region src/checks/people.ts
1044
- const PROJECT = "conformance";
1045
- const DEV = `${PROJECT}/dev`;
1046
- const PROD = `${PROJECT}/prod`;
1047
- const BULK = `${PROJECT}/bulk`;
1048
- const SERVICE = "token:conformance-ci";
1049
- /** Where the live checks' token reads, as an operator would set it up. */
1050
- const LIVE = `${PROJECT}/live`;
1051
- const LIVE_SERVICE = "token:conformance-live";
1052
- function canary() {
1053
- return `coffre-canary-${randomBytes(12).toString("hex")}`;
1054
- }
1055
- /**
1056
- * Sign in the way a browser does: to the stand-in GitHub, which asks for no
1057
- * password, and back. The error is the one coffre sent the browser back to
1058
- * /login with.
1059
- */
1060
- async function signIn(deployment, browser, email) {
1061
- const leave = await browser.fetch("/auth/signin/github");
1062
- const authorize = new URL(leave.headers.get("location") ?? "", deployment.origin);
1063
- expect(leave.status === 302 && authorize.origin === deployment.idp.origin, "sign-in did not send the browser to GitHub", `${leave.status} ${leave.headers.get("location")}`);
1064
- const form = new URLSearchParams(authorize.searchParams);
1065
- form.set("email", email);
1066
- const approve = await fetch(authorize.origin + authorize.pathname, {
1067
- method: "POST",
1068
- body: form,
1069
- redirect: "manual"
1070
- });
1071
- const callback = approve.headers.get("location") ?? "";
1072
- expect(approve.status === 302 && callback.startsWith(`${deployment.origin}/auth/callback/github?`), "GitHub did not send the browser back", callback);
1073
- const back = await browser.fetch(callback);
1074
- expect(back.status === 302 || back.status === 303, `the callback answered ${back.status}`, await back.text());
1075
- const error = new URL(back.headers.get("location") ?? "/", deployment.origin).searchParams.get("error");
1076
- return error === null ? { ok: true } : {
1077
- ok: false,
1078
- error
1079
- };
1080
- }
1081
- async function signInAdmin(deployment) {
1082
- const browser = new Browser(deployment.origin);
1083
- const signed = await signIn(deployment, browser, deployment.rootAdmin);
1084
- expect(signed.ok, `the root admin was refused: ${"error" in signed ? signed.error : ""}`);
1085
- const api = browser.client();
1086
- const me = await api.me();
1087
- expect(me.principal.id === deployment.rootAdmin && me.isRootAdmin, "signed in as someone else", me);
1088
- const admin = {
1089
- email: deployment.rootAdmin,
1090
- member: `user:${deployment.rootAdmin}`,
1091
- browser,
1092
- api
1093
- };
1094
- return {
1095
- detail: `${admin.email}, root admin, through GitHub`,
1096
- value: admin
1097
- };
1098
- }
1099
- async function setUp(admin) {
1100
- await admin.api.projects.create(PROJECT, { name: "Conformance" });
1101
- for (const [path, name] of [
1102
- [DEV, "Development"],
1103
- [PROD, "Production"],
1104
- [BULK, "Bulk"]
1105
- ]) await admin.api.environments.create(path, { name });
1106
- const canaries = {
1107
- [`${DEV}/API_KEY`]: canary(),
1108
- [`${DEV}/DATABASE_URL`]: canary(),
1109
- [`${PROD}/API_KEY`]: canary()
1110
- };
1111
- for (const path of [DEV, PROD]) await admin.api.secrets.set(path, valuesIn(canaries, path));
1112
- return {
1113
- detail: `${PROJECT}: dev and prod, ${Object.keys(canaries).length} values, and bulk`,
1114
- value: canaries
1115
- };
1116
- }
1117
- /**
1118
- * What `probe --token` asks an operator for: an environment holding one
1119
- * canary, and a service that reads it there and audits the project. Its
1120
- * value joins the others, for the scans that follow.
1121
- */
1122
- async function setUpLive(admin, canaries) {
1123
- await admin.api.environments.create(LIVE, { name: "Live" });
1124
- const value = canary();
1125
- await admin.api.secrets.set(LIVE, { CANARY: value });
1126
- canaries[`${LIVE}/CANARY`] = value;
1127
- await admin.api.members.add(LIVE_SERVICE);
1128
- await admin.api.access.set(LIVE_SERVICE, {
1129
- [LIVE]: "viewer",
1130
- [PROJECT]: "auditor"
1131
- });
1132
- const { token } = await admin.api.tokens.issue(LIVE_SERVICE, {
1133
- label: "conformance live",
1134
- expiresInDays: 1
1135
- });
1136
- return {
1137
- detail: `${LIVE}/CANARY, and ${LIVE_SERVICE}: viewer there, auditor on ${PROJECT}`,
1138
- value: {
1139
- token,
1140
- canary: {
1141
- project: PROJECT,
1142
- environment: "live",
1143
- key: "CANARY",
1144
- value
1145
- }
1146
- }
1147
- };
1148
- }
1149
- /** The canaries in one environment, by key. */
1150
- function valuesIn(canaries, environment) {
1151
- return Object.fromEntries(Object.entries(canaries).filter(([path]) => path.startsWith(`${environment}/`)).map(([path, value]) => [path.slice(environment.length + 1), value]));
1152
- }
1153
- async function personas(deployment, admin) {
1154
- async function person(name, access) {
1155
- const email = `${name}@conformance.example`;
1156
- const member = `user:${email}`;
1157
- await admin.api.members.add(member);
1158
- await admin.api.access.set(member, access);
1159
- const browser = new Browser(deployment.origin);
1160
- const signed = await signIn(deployment, browser, email);
1161
- expect(signed.ok, `${email} was refused: ${"error" in signed ? signed.error : ""}`);
1162
- return {
1163
- email,
1164
- member,
1165
- browser,
1166
- api: browser.client()
1167
- };
1168
- }
1169
- const reader = await person("reader", { [DEV]: "viewer" });
1170
- const leaver = await person("leaver", { [DEV]: "developer" });
1171
- const bulk = await person("bulk", { [BULK]: "viewer" });
1172
- await admin.api.members.add(SERVICE);
1173
- await admin.api.access.set(SERVICE, { [DEV]: "viewer" });
1174
- const issued = await admin.api.tokens.issue(SERVICE, {
1175
- label: "conformance",
1176
- expiresInDays: 1
1177
- });
1178
- const cliToken = await deviceLogin(deployment, leaver.browser);
1179
- return {
1180
- detail: "a reader, a leaver in a browser and the CLI, a bulk reader, a service with a token, and a stranger",
1181
- value: {
1182
- admin,
1183
- reader,
1184
- leaver: {
1185
- ...leaver,
1186
- cli: bearer(deployment.origin, cliToken),
1187
- cliToken
1188
- },
1189
- service: {
1190
- member: SERVICE,
1191
- token: issued.token,
1192
- api: bearer(deployment.origin, issued.token)
1193
- },
1194
- stranger: {
1195
- email: "stranger@conformance.example",
1196
- browser: new Browser(deployment.origin)
1197
- },
1198
- bulk
1199
- }
1200
- };
1201
- }
1202
- /** `coffre login`: a device code, approved in a signed-in browser, for a CLI session. */
1203
- async function deviceLogin(deployment, browser) {
1204
- const json = { "content-type": "application/json" };
1205
- const started = await fetch(`${deployment.origin}/api/auth/device`, {
1206
- method: "POST",
1207
- headers: json,
1208
- body: JSON.stringify({ client_label: "coffre-conformance" })
1209
- });
1210
- expect(started.ok, `the device login did not start: ${started.status}`, await started.clone().text());
1211
- const device = await started.json();
1212
- await browser.client().deviceLogins.decide(device.user_code, true);
1213
- const polled = await fetch(`${deployment.origin}/api/auth/device/token`, {
1214
- method: "POST",
1215
- headers: json,
1216
- body: JSON.stringify({ device_code: device.device_code })
1217
- });
1218
- const session = await polled.json();
1219
- expect(polled.ok && session.access_token, `the approved device login gave no token: ${polled.status}`, session);
1220
- return session.access_token;
1221
- }
1222
- /**
1223
- * A page's worth of API calls at once, as the pages fire them on a load,
1224
- * right after sign-in, while the vault is fresh: every one answers. A call
1225
- * that waited on another's work in the vault would be cancelled on
1226
- * Cloudflare as hung, and the page would read the 503 or 401 as signed out.
1227
- */
1228
- async function pageLoad(person) {
1229
- const paths = [
1230
- "/api/me",
1231
- "/api/sessions",
1232
- "/api/projects",
1233
- "/api/members",
1234
- "/api/audit",
1235
- "/api/identities",
1236
- "/api/me",
1237
- "/api/projects"
1238
- ];
1239
- const failed = (await Promise.all(paths.map(async (path) => [path, (await person.browser.fetch(path)).status]))).filter(([, status]) => status !== 200);
1240
- expect(failed.length === 0, "a call of the page load did not answer 200", failed.map(([path, status]) => `${path}: ${status}`).join(", "));
1241
- return `${paths.length} calls at once, each answered`;
1242
- }
1243
- //#endregion
1244
1559
  //#region src/checks/storage.ts
1245
1560
  const TABLES = [
1246
1561
  "projects",
@@ -1385,7 +1700,7 @@ async function member(deployment, { admin }, name) {
1385
1700
  await admin.api.members.add(principal);
1386
1701
  await admin.api.access.set(principal, { [DEV]: "viewer" });
1387
1702
  const browser = new Browser(deployment.origin);
1388
- expect((await signIn(deployment, browser, email)).ok, "the fixture member could not sign in");
1703
+ expect((await signIn$1(deployment, browser, email)).ok, "the fixture member could not sign in");
1389
1704
  return {
1390
1705
  email,
1391
1706
  member: principal,
@@ -1592,7 +1907,7 @@ async function forgedIdentity(deployment, people) {
1592
1907
  };
1593
1908
  await insertRow(sql, "identities", forged);
1594
1909
  try {
1595
- await signIn(deployment, browser, email).catch(() => {});
1910
+ await signIn$1(deployment, browser, email).catch(() => {});
1596
1911
  expect((await browser.fetch("/api/me")).status === 401, "an owner-forged identity minted a session");
1597
1912
  await reported(deployment, forged.id);
1598
1913
  } finally {
@@ -1681,7 +1996,7 @@ async function editedGeneration(deployment, people) {
1681
1996
  //#endregion
1682
1997
  //#region src/checks/access.ts
1683
1998
  async function membersOnly(deployment, { stranger }) {
1684
- const attempt = await signIn(deployment, stranger.browser, stranger.email);
1999
+ const attempt = await signIn$1(deployment, stranger.browser, stranger.email);
1685
2000
  expect(!attempt.ok, "someone never admitted signed in");
1686
2001
  expect(!stranger.browser.hasCookies, "the refused sign-in left the browser a cookie");
1687
2002
  expect((await stranger.browser.fetch("/api/me")).status === 401, "the refused sign-in left a session");
@@ -1798,7 +2113,7 @@ async function offboarding(deployment, { admin, leaver, service }, canaries) {
1798
2113
  expect(same(exposed, Object.keys(valuesIn(canaries, DEV)).map((key) => `${DEV}/${key}`).sort()), "the offboarding report does not name what they read", report.exposed);
1799
2114
  expect((await leaver.browser.fetch("/api/me")).status === 401, "a removed member's browser session still works");
1800
2115
  await refused("a removed member's CLI session read secrets", leaver.cli.secrets.list(DEV));
1801
- expect(!(await signIn(deployment, leaver.browser, leaver.email)).ok, "a removed member signed in again");
2116
+ expect(!(await signIn$1(deployment, leaver.browser, leaver.email)).ok, "a removed member signed in again");
1802
2117
  await admin.api.members.remove(service.member);
1803
2118
  await refused("a removed service's token read secrets", service.api.secrets.reveal(DEV));
1804
2119
  await admin.api.members.add(leaver.member);
@@ -1809,7 +2124,7 @@ async function offboarding(deployment, { admin, leaver, service }, canaries) {
1809
2124
  await refused("re-admission revived the CLI session", leaver.cli.secrets.reveal(DEV));
1810
2125
  await refused("re-admission revived the service token", service.api.secrets.reveal(DEV));
1811
2126
  expect(!(await pollDevice(deployment, device.device_code)).ok, "re-admission revived the old device approval");
1812
- expect((await signIn(deployment, leaver.browser, leaver.email)).ok, "a fresh provider callback could not sign the re-admitted member in");
2127
+ expect((await signIn$1(deployment, leaver.browser, leaver.email)).ok, "a fresh provider callback could not sign the re-admitted member in");
1813
2128
  await admin.api.members.remove(leaver.member);
1814
2129
  await admin.api.members.remove(service.member);
1815
2130
  return `the report names ${exposed.length} values; re-admission revives no old session, token or approval; a fresh provider callback works`;
@@ -2500,7 +2815,7 @@ async function conform(deployment, options) {
2500
2815
  await anonymousChecks(report, deployment.origin, { health: false });
2501
2816
  const admin = await report.check("sign-in", {}, () => signInAdmin(deployment));
2502
2817
  await report.check("page load", { admin }, ({ admin }) => pageLoad(admin));
2503
- const canaries = await report.check("setup", { admin }, ({ admin }) => setUp(admin));
2818
+ const canaries = await report.check("setup", { admin }, ({ admin }) => setUp$1(admin));
2504
2819
  const people = await report.check("personas", {
2505
2820
  admin,
2506
2821
  canaries
@@ -2519,6 +2834,30 @@ async function conform(deployment, options) {
2519
2834
  canaries
2520
2835
  }, ({ admin, canaries }) => setUpLive(admin, canaries));
2521
2836
  await tokenChecks(report, deployment.origin, live ?? {});
2837
+ const origin = deployment.origin;
2838
+ const before = await report.check("probe as a user", {
2839
+ admin,
2840
+ people
2841
+ }, ({ admin, people }) => probeAsUser(origin, people.reader, admin));
2842
+ const first = await report.check("probe --sign-in", {
2843
+ admin,
2844
+ before
2845
+ }, ({ admin }) => probeRun(origin, admin));
2846
+ const second = await report.check("probe again", {
2847
+ admin,
2848
+ first
2849
+ }, ({ admin }) => probeRun(origin, admin));
2850
+ await report.check("probe interrupted", {
2851
+ admin,
2852
+ second
2853
+ }, ({ admin }) => probeInterrupted(origin, admin));
2854
+ await report.check("probe leftovers", {
2855
+ admin,
2856
+ before,
2857
+ first,
2858
+ second,
2859
+ live
2860
+ }, ({ admin, before, first, second, live }) => probeLeftovers(origin, admin, [first, second], before, live.canary));
2522
2861
  await report.check("offboarding", all, ({ people, canaries }) => offboarding(deployment, people, canaries));
2523
2862
  await report.check("bulk limit", { people }, ({ people }) => bulkLimit$1(people, options.bulkLimit));
2524
2863
  await report.check("checkpoints", { people }, ({ people }) => checkpoints(deployment, people));
@@ -2552,13 +2891,15 @@ async function conform(deployment, options) {
2552
2891
  }
2553
2892
  /**
2554
2893
  * What can be checked of an instance someone else runs: as no one, and with
2555
- * a token that reads a canary when given one. Nothing is written but the
2556
- * audit log's entries for the token's reads.
2894
+ * a token that reads a canary when given one, or, with `signIn`, as an owner
2895
+ * who signs the probe in and lets it set up its own token. With a token,
2896
+ * nothing is written but the audit log's entries for the token's reads.
2557
2897
  */
2558
2898
  async function probe(origin, live) {
2559
2899
  const report = new Report();
2560
2900
  await anonymousChecks(report, origin, { health: true });
2561
- if (live.token !== void 0) await tokenChecks(report, origin, live);
2901
+ if (live.signIn !== void 0) await signedInChecks(report, origin, live.signIn);
2902
+ else if (live.token !== void 0) await tokenChecks(report, origin, live);
2562
2903
  return report.failed;
2563
2904
  }
2564
2905
  //#endregion
@@ -2568,6 +2909,7 @@ const USAGE = `usage:
2568
2909
  --vault-runtime <coffre_vault_runtime URL> [options]
2569
2910
  coffre-conformance node [<dir>] [options]
2570
2911
  coffre-conformance probe <url> [--token <service token> --canary <project>/<env>/<KEY>[=<value>]]
2912
+ coffre-conformance probe <url> --sign-in
2571
2913
 
2572
2914
  <dir> the deployment, as \`coffre init\` wrote it (default: here)
2573
2915
  --port <n> coffre's port; the IdP gets the next, wrangler's inspector the one after (3082)
@@ -2577,7 +2919,7 @@ const USAGE = `usage:
2577
2919
  --vault-runtime <url>
2578
2920
  workers: the same server as coffre_vault_runtime, the login the vault runs as
2579
2921
 
2580
- probe checks a running instance from outside, and writes nothing to it:
2922
+ probe checks a running instance from outside:
2581
2923
  as no one health, headers, every route refusing no one, changes from
2582
2924
  another site refused, /api/auth, nothing like a value shown
2583
2925
  with --token a service token that reads the canary's environment and
@@ -2586,10 +2928,18 @@ probe checks a running instance from outside, and writes nothing to it:
2586
2928
  --token or COFFRE_TOKEN
2587
2929
  --canary the value after =, or in COFFRE_CONFORMANCE_CANARY, or on
2588
2930
  stdin, so it stays out of the shell's history
2931
+ with --sign-in an owner approves a device login in the browser, as for
2932
+ \`coffre login\`; the probe finds or makes conformance/live
2933
+ and token:conformance-probe, issues it a credential, writes
2934
+ a fresh canary, runs the token's checks, then verifies the
2935
+ whole audit log as the owner. The credential is revoked and
2936
+ the session ended however the run ends; neither it nor the
2937
+ canary is ever shown
2589
2938
 
2590
2939
  Each run with a token adds a few entries to the instance's audit log, which
2591
2940
  is append-only, so they stay: the canary's read, and the reads it was refused.
2592
- It changes nothing else.`;
2941
+ It changes nothing else. A run with --sign-in leaves its project, environment
2942
+ and service for the next, and writes its canary and its grants.`;
2593
2943
  const { values, positionals } = parseArgs({
2594
2944
  allowPositionals: true,
2595
2945
  options: {
@@ -2606,6 +2956,10 @@ const { values, positionals } = parseArgs({
2606
2956
  "vault-runtime": { type: "string" },
2607
2957
  token: { type: "string" },
2608
2958
  canary: { type: "string" },
2959
+ "sign-in": {
2960
+ type: "boolean",
2961
+ default: false
2962
+ },
2609
2963
  help: {
2610
2964
  type: "boolean",
2611
2965
  short: "h"
@@ -2617,6 +2971,16 @@ if (values.help || command === void 0) exit(values.help ? 0 : 2, USAGE);
2617
2971
  if (command === "probe") {
2618
2972
  if (target === void 0) exit(2, USAGE);
2619
2973
  const origin = new URL(target).origin;
2974
+ if (values["sign-in"]) {
2975
+ if (values.token !== void 0 || values.canary !== void 0) exit(2, "--sign-in sets up its own token and canary: no --token or --canary with it");
2976
+ console.log(`coffre-conformance: probing ${origin}, as no one and signed in`);
2977
+ console.log(` (it keeps ${PROBE.project}/${PROBE.environment} and ${PROBE.service} for the next run, and its reads stay in the audit log, for good)`);
2978
+ const failed = await probe(origin, { signIn: ({ url, code }) => {
2979
+ console.log(`\n Approve the probe's sign-in, as an owner, at\n\n ${url}\n\n and check that it shows the code ${code}. Waiting for you…\n`);
2980
+ if (process.stdout.isTTY) openBrowser(url);
2981
+ } });
2982
+ exit(failed.length === 0 ? 0 : 1, summary(failed));
2983
+ }
2620
2984
  const token = values.token ?? process.env.COFFRE_TOKEN;
2621
2985
  let canary;
2622
2986
  if (token !== void 0) {