@coffre/conformance 0.3.0 → 0.4.1
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 +1360 -82
- package/package.json +4 -4
- package/src/bundle.ts +5 -0
- package/src/checks/access.ts +62 -3
- package/src/checks/canaries.ts +5 -5
- package/src/checks/cli.ts +5 -3
- package/src/checks/deletion.ts +98 -0
- package/src/checks/environments.ts +193 -0
- package/src/checks/mcp.ts +482 -0
- package/src/checks/pages.ts +173 -11
- package/src/checks/people.ts +17 -13
- package/src/checks/workloads.ts +2 -6
- package/src/chrome.ts +48 -10
- package/src/draining.ts +4 -3
- package/src/suite.ts +17 -2
package/dist/main.js
CHANGED
|
@@ -52,9 +52,10 @@ const KEYS = {
|
|
|
52
52
|
* The built app as `wrangler dev` can run it: its own build, behind an entry
|
|
53
53
|
* that, once the app has answered, reads whatever the request still sends
|
|
54
54
|
* before passing the answer on. Locally, and only there, a Worker built
|
|
55
|
-
* unbundled with static assets
|
|
56
|
-
* left unread, which every refusal does
|
|
57
|
-
*
|
|
55
|
+
* unbundled with static assets may fail the request after one whose body it
|
|
56
|
+
* left unread, which every refusal does: wrangler retries a GET, not a POST
|
|
57
|
+
* (cloudflare/workers-sdk#15203). Reading it later, after the answer, is too
|
|
58
|
+
* late; deployed, Cloudflare discards such a body, as
|
|
58
59
|
* `vite dev` and `vite preview` do. The app itself must never wait so on what
|
|
59
60
|
* a caller sends; this harness sends only bodies that end. The entry and its
|
|
60
61
|
* config are written beside the build, which the next `vite build`
|
|
@@ -152,11 +153,29 @@ function createClient(options) {
|
|
|
152
153
|
/** With their environments. */
|
|
153
154
|
list: () => call("GET /projects", {}),
|
|
154
155
|
create: (project, input) => call("PUT /projects/:project", { project }, input),
|
|
155
|
-
update: (project, patch) => call("PATCH /projects/:project", { project }, patch)
|
|
156
|
+
update: (project, patch) => call("PATCH /projects/:project", { project }, patch),
|
|
157
|
+
/** What deleting an archived project would erase and revoke; changes nothing. */
|
|
158
|
+
previewDelete: (project) => {
|
|
159
|
+
const [method, route] = address("DELETE /projects/:project", { project });
|
|
160
|
+
return send(method, `${route}?dryRun=1`, void 0);
|
|
161
|
+
},
|
|
162
|
+
/** Delete an archived project for good: its values erased, its grants revoked, its slug free. Owners only. */
|
|
163
|
+
delete: (project) => call("DELETE /projects/:project", { project })
|
|
156
164
|
},
|
|
157
165
|
environments: {
|
|
158
166
|
create: (path, input) => call("PUT /projects/:project/:environment", place(path), input),
|
|
159
|
-
update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch)
|
|
167
|
+
update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch),
|
|
168
|
+
/** What deleting an archived environment would erase and revoke; changes nothing. */
|
|
169
|
+
previewDelete: (path) => {
|
|
170
|
+
const [method, route] = address("DELETE /projects/:project/:environment", place(path));
|
|
171
|
+
return send(method, `${route}?dryRun=1`, void 0);
|
|
172
|
+
},
|
|
173
|
+
/** Delete an archived environment for good, as a project is. Owners only. */
|
|
174
|
+
delete: (path) => call("DELETE /projects/:project/:environment", place(path)),
|
|
175
|
+
/** The keys its sibling environments have and it lacks, those you can see, and those its team dismissed. */
|
|
176
|
+
missing: (path) => call("GET /projects/:project/:environment/missing", place(path)),
|
|
177
|
+
/** Dismiss missing keys (`true`) or restore them (`null`). */
|
|
178
|
+
dismiss: (path, patch) => call("PATCH /projects/:project/:environment/dismissals", place(path), patch)
|
|
160
179
|
},
|
|
161
180
|
secrets: {
|
|
162
181
|
/** Keys, versions and who changed what; never values. */
|
|
@@ -180,6 +199,16 @@ function createClient(options) {
|
|
|
180
199
|
rename: (path, key) => call("PATCH /secrets/:project/:environment/:key", place(path), { key }),
|
|
181
200
|
update: (path, patch) => call("PATCH /secrets/:project/:environment/:key", place(path), patch)
|
|
182
201
|
},
|
|
202
|
+
/**
|
|
203
|
+
* References: secrets read through others (docs/design/environments.md).
|
|
204
|
+
* A key becomes one with `secrets.set(path, { KEY: { ref: 'market/prod/KEY' } })`.
|
|
205
|
+
*/
|
|
206
|
+
references: {
|
|
207
|
+
/** The live references into and out of a place, `market`, `market/prod` or `market/prod/KEY`, and who reads through them. */
|
|
208
|
+
list: (path) => call("GET /references", {}, { path }),
|
|
209
|
+
/** Break the reference a secret is: its readers stop reading the source through it. */
|
|
210
|
+
break: (path) => call("DELETE /secrets/:project/:environment/:key/reference", place(path))
|
|
211
|
+
},
|
|
183
212
|
members: {
|
|
184
213
|
/** People and tokens, their role and their access; at a place, those who reach it. */
|
|
185
214
|
list: (path) => call("GET /members", {}, { path }),
|
|
@@ -232,6 +261,55 @@ set: (member, access) => call("PATCH /access/:member", { member }, access) },
|
|
|
232
261
|
get: (code) => call("GET /device-logins/:code", { code }),
|
|
233
262
|
decide: (code, approve) => call("POST /device-logins/:code", { code }, { approve })
|
|
234
263
|
},
|
|
264
|
+
/**
|
|
265
|
+
* Folders, which arrange lists and do nothing else: a folder exists while
|
|
266
|
+
* something is filed in it. Renaming one re-files all of it, onto a folder
|
|
267
|
+
* that exists merges the two; removing one takes all of it out, each item
|
|
268
|
+
* staying where it is, in no folder. Moving one item is `projects.update`
|
|
269
|
+
* or `secrets.update` with a `folder`.
|
|
270
|
+
*/
|
|
271
|
+
folders: {
|
|
272
|
+
/** A folder of projects, renamed. Takes managing every project in it. */
|
|
273
|
+
rename: (folder, name) => call("PATCH /folders/:folder", { folder }, { name }),
|
|
274
|
+
/** Every project out of a folder. */
|
|
275
|
+
remove: (folder) => call("DELETE /folders/:folder", { folder }),
|
|
276
|
+
/** One of an environment's key folders, `market/prod`, renamed. Takes writing there. */
|
|
277
|
+
renameKeys: (environment, folder, name) => {
|
|
278
|
+
const { project, environment: slug } = place(environment);
|
|
279
|
+
return call("PATCH /folders/:project/:environment/:folder", {
|
|
280
|
+
project,
|
|
281
|
+
environment: slug,
|
|
282
|
+
folder
|
|
283
|
+
}, { name });
|
|
284
|
+
},
|
|
285
|
+
/** Every key out of one of an environment's folders. */
|
|
286
|
+
removeKeys: (environment, folder) => {
|
|
287
|
+
const { project, environment: slug } = place(environment);
|
|
288
|
+
return call("DELETE /folders/:project/:environment/:folder", {
|
|
289
|
+
project,
|
|
290
|
+
environment: slug,
|
|
291
|
+
folder
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
/**
|
|
296
|
+
* An MCP client asking to connect, by its authorization request, and the
|
|
297
|
+
* person's answer: where to send the browser next.
|
|
298
|
+
*/
|
|
299
|
+
oauth: {
|
|
300
|
+
describe: (request) => call("GET /oauth/authorizations", {}, request),
|
|
301
|
+
decide: (input) => call("POST /oauth/authorizations", {}, input)
|
|
302
|
+
},
|
|
303
|
+
/** The MCP clients I connected. */
|
|
304
|
+
/** A change an MCP client asked for: what it would do, and the person's decision, which makes it. */
|
|
305
|
+
approvals: {
|
|
306
|
+
get: (id) => call("GET /approvals/:id", { id }),
|
|
307
|
+
decide: (id, input) => call("POST /approvals/:id", { id }, input)
|
|
308
|
+
},
|
|
309
|
+
apps: {
|
|
310
|
+
list: () => call("GET /apps", {}),
|
|
311
|
+
disconnect: (id) => call("DELETE /apps/:id", { id })
|
|
312
|
+
},
|
|
235
313
|
audit: {
|
|
236
314
|
list: (query = {}) => call("GET /audit", {}, query),
|
|
237
315
|
verify: () => call("GET /audit/verification", {}),
|
|
@@ -259,7 +337,7 @@ function expect(condition, message, detail) {
|
|
|
259
337
|
* The status coffre turned a call away with. A call that went through
|
|
260
338
|
* fails the check: `what` says what it should not have done.
|
|
261
339
|
*/
|
|
262
|
-
async function refused(what, call) {
|
|
340
|
+
async function refused$1(what, call) {
|
|
263
341
|
const outcome = await call.then((value) => ({ value }), (error) => ({ error }));
|
|
264
342
|
if ("value" in outcome) throw new Failure(`${what}, and was let`, outcome.value);
|
|
265
343
|
if (!(outcome.error instanceof CoffreError)) throw outcome.error;
|
|
@@ -642,13 +720,13 @@ function bearer(origin, token) {
|
|
|
642
720
|
}
|
|
643
721
|
//#endregion
|
|
644
722
|
//#region src/checks/people.ts
|
|
645
|
-
const PROJECT = "conformance";
|
|
646
|
-
const DEV = `${PROJECT}/dev`;
|
|
647
|
-
const PROD = `${PROJECT}/prod`;
|
|
648
|
-
const BULK = `${PROJECT}/bulk`;
|
|
649
|
-
const SERVICE = "token:conformance-ci";
|
|
723
|
+
const PROJECT$1 = "conformance";
|
|
724
|
+
const DEV = `${PROJECT$1}/dev`;
|
|
725
|
+
const PROD = `${PROJECT$1}/prod`;
|
|
726
|
+
const BULK = `${PROJECT$1}/bulk`;
|
|
727
|
+
const SERVICE$2 = "token:conformance-ci";
|
|
650
728
|
/** Where the live checks' token reads, as an operator would set it up. */
|
|
651
|
-
const LIVE = `${PROJECT}/live`;
|
|
729
|
+
const LIVE = `${PROJECT$1}/live`;
|
|
652
730
|
const LIVE_SERVICE = "token:conformance-live";
|
|
653
731
|
function canary() {
|
|
654
732
|
return `coffre-canary-${randomBytes(12).toString("hex")}`;
|
|
@@ -673,10 +751,12 @@ async function signIn(deployment, browser, email) {
|
|
|
673
751
|
expect(approve.status === 302 && callback.startsWith(`${deployment.origin}/auth/callback/github?`), "GitHub did not send the browser back", callback);
|
|
674
752
|
const back = await browser.fetch(callback);
|
|
675
753
|
expect(back.status === 302 || back.status === 303, `the callback answered ${back.status}`, await back.text());
|
|
676
|
-
const
|
|
754
|
+
const location = new URL(back.headers.get("location") ?? "/", deployment.origin);
|
|
755
|
+
const error = location.searchParams.get("error");
|
|
677
756
|
return error === null ? { ok: true } : {
|
|
678
757
|
ok: false,
|
|
679
|
-
error
|
|
758
|
+
error,
|
|
759
|
+
location: `${location.pathname}${location.search}`
|
|
680
760
|
};
|
|
681
761
|
}
|
|
682
762
|
async function signInAdmin(deployment) {
|
|
@@ -698,7 +778,7 @@ async function signInAdmin(deployment) {
|
|
|
698
778
|
};
|
|
699
779
|
}
|
|
700
780
|
async function setUp(admin) {
|
|
701
|
-
await admin.api.projects.create(PROJECT, { name: "Conformance" });
|
|
781
|
+
await admin.api.projects.create(PROJECT$1, { name: "Conformance" });
|
|
702
782
|
for (const [path, name] of [
|
|
703
783
|
[DEV, "Development"],
|
|
704
784
|
[PROD, "Production"],
|
|
@@ -711,7 +791,7 @@ async function setUp(admin) {
|
|
|
711
791
|
};
|
|
712
792
|
for (const path of [DEV, PROD]) await admin.api.secrets.set(path, valuesIn(canaries, path));
|
|
713
793
|
return {
|
|
714
|
-
detail: `${PROJECT}: dev and prod, ${Object.keys(canaries).length} values, and bulk`,
|
|
794
|
+
detail: `${PROJECT$1}: dev and prod, ${Object.keys(canaries).length} values, and bulk`,
|
|
715
795
|
value: canaries
|
|
716
796
|
};
|
|
717
797
|
}
|
|
@@ -728,18 +808,18 @@ async function setUpLive(admin, canaries) {
|
|
|
728
808
|
await admin.api.members.add(LIVE_SERVICE);
|
|
729
809
|
await admin.api.access.set(LIVE_SERVICE, {
|
|
730
810
|
[LIVE]: "viewer",
|
|
731
|
-
[PROJECT]: "auditor"
|
|
811
|
+
[PROJECT$1]: "auditor"
|
|
732
812
|
});
|
|
733
813
|
const { token } = await admin.api.tokens.issue(LIVE_SERVICE, {
|
|
734
814
|
label: "conformance live",
|
|
735
815
|
expiresInDays: 1
|
|
736
816
|
});
|
|
737
817
|
return {
|
|
738
|
-
detail: `${LIVE}/CANARY, and ${LIVE_SERVICE}: viewer there, auditor on ${PROJECT}`,
|
|
818
|
+
detail: `${LIVE}/CANARY, and ${LIVE_SERVICE}: viewer there, auditor on ${PROJECT$1}`,
|
|
739
819
|
value: {
|
|
740
820
|
token,
|
|
741
821
|
canary: {
|
|
742
|
-
project: PROJECT,
|
|
822
|
+
project: PROJECT$1,
|
|
743
823
|
environment: "live",
|
|
744
824
|
key: "CANARY",
|
|
745
825
|
value
|
|
@@ -751,28 +831,30 @@ async function setUpLive(admin, canaries) {
|
|
|
751
831
|
function valuesIn(canaries, environment) {
|
|
752
832
|
return Object.fromEntries(Object.entries(canaries).filter(([path]) => path.startsWith(`${environment}/`)).map(([path, value]) => [path.slice(environment.length + 1), value]));
|
|
753
833
|
}
|
|
834
|
+
/** A person the admin admits with this access, signed in in a browser of their own. */
|
|
835
|
+
async function personaOn(deployment, admin, name, access) {
|
|
836
|
+
const email = `${name}@conformance.example`;
|
|
837
|
+
const member = `user:${email}`;
|
|
838
|
+
await admin.api.members.add(member);
|
|
839
|
+
await admin.api.access.set(member, access);
|
|
840
|
+
const browser = new Browser(deployment.origin);
|
|
841
|
+
const signed = await signIn(deployment, browser, email);
|
|
842
|
+
expect(signed.ok, `${email} was refused: ${"error" in signed ? signed.error : ""}`);
|
|
843
|
+
return {
|
|
844
|
+
email,
|
|
845
|
+
member,
|
|
846
|
+
browser,
|
|
847
|
+
api: browser.client()
|
|
848
|
+
};
|
|
849
|
+
}
|
|
754
850
|
async function personas(deployment, admin) {
|
|
755
|
-
|
|
756
|
-
const email = `${name}@conformance.example`;
|
|
757
|
-
const member = `user:${email}`;
|
|
758
|
-
await admin.api.members.add(member);
|
|
759
|
-
await admin.api.access.set(member, access);
|
|
760
|
-
const browser = new Browser(deployment.origin);
|
|
761
|
-
const signed = await signIn(deployment, browser, email);
|
|
762
|
-
expect(signed.ok, `${email} was refused: ${"error" in signed ? signed.error : ""}`);
|
|
763
|
-
return {
|
|
764
|
-
email,
|
|
765
|
-
member,
|
|
766
|
-
browser,
|
|
767
|
-
api: browser.client()
|
|
768
|
-
};
|
|
769
|
-
}
|
|
851
|
+
const person = (name, access) => personaOn(deployment, admin, name, access);
|
|
770
852
|
const reader = await person("reader", { [DEV]: "viewer" });
|
|
771
853
|
const leaver = await person("leaver", { [DEV]: "developer" });
|
|
772
854
|
const bulk = await person("bulk", { [BULK]: "viewer" });
|
|
773
|
-
await admin.api.members.add(SERVICE);
|
|
774
|
-
await admin.api.access.set(SERVICE, { [DEV]: "viewer" });
|
|
775
|
-
const issued = await admin.api.tokens.issue(SERVICE, {
|
|
855
|
+
await admin.api.members.add(SERVICE$2);
|
|
856
|
+
await admin.api.access.set(SERVICE$2, { [DEV]: "viewer" });
|
|
857
|
+
const issued = await admin.api.tokens.issue(SERVICE$2, {
|
|
776
858
|
label: "conformance",
|
|
777
859
|
expiresInDays: 1
|
|
778
860
|
});
|
|
@@ -788,7 +870,7 @@ async function personas(deployment, admin) {
|
|
|
788
870
|
cliToken
|
|
789
871
|
},
|
|
790
872
|
service: {
|
|
791
|
-
member: SERVICE,
|
|
873
|
+
member: SERVICE$2,
|
|
792
874
|
token: issued.token,
|
|
793
875
|
api: bearer(deployment.origin, issued.token)
|
|
794
876
|
},
|
|
@@ -842,6 +924,588 @@ async function pageLoad(person) {
|
|
|
842
924
|
return `${paths.length} calls at once, each answered`;
|
|
843
925
|
}
|
|
844
926
|
//#endregion
|
|
927
|
+
//#region src/checks/mcp.ts
|
|
928
|
+
const NAME = "Conformance MCP client";
|
|
929
|
+
/** A native client's redirect, on loopback. A custom scheme is left out of a registration (D37). */
|
|
930
|
+
const REDIRECT = "http://127.0.0.1:33418/callback";
|
|
931
|
+
/** A `state` the router would read as a number: it must come back as sent. */
|
|
932
|
+
const STATE = "1e5";
|
|
933
|
+
/** What every 2026-07-28 request carries: its revision and the client's capabilities. */
|
|
934
|
+
const ENVELOPE = {
|
|
935
|
+
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
|
|
936
|
+
"io.modelcontextprotocol/clientCapabilities": {}
|
|
937
|
+
};
|
|
938
|
+
const base64url = (bytes) => bytes.toString("base64url");
|
|
939
|
+
async function json(response) {
|
|
940
|
+
const text = await response.text();
|
|
941
|
+
try {
|
|
942
|
+
return JSON.parse(text);
|
|
943
|
+
} catch {
|
|
944
|
+
return { text };
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
/** A JSON-RPC message to /mcp, with the headers a client sends. */
|
|
948
|
+
function mcp(deployment, headers, method = "server/discover", params = {}) {
|
|
949
|
+
return fetch(`${deployment.origin}/mcp`, {
|
|
950
|
+
method: "POST",
|
|
951
|
+
headers: {
|
|
952
|
+
"content-type": "application/json",
|
|
953
|
+
accept: "application/json, text/event-stream",
|
|
954
|
+
...headers
|
|
955
|
+
},
|
|
956
|
+
body: JSON.stringify({
|
|
957
|
+
jsonrpc: "2.0",
|
|
958
|
+
id: 1,
|
|
959
|
+
method,
|
|
960
|
+
params
|
|
961
|
+
})
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
function token(deployment, fields) {
|
|
965
|
+
return fetch(`${deployment.origin}/api/oauth/token`, {
|
|
966
|
+
method: "POST",
|
|
967
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
968
|
+
body: new URLSearchParams(fields)
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
/** The person approves on the consent page, as its Approve does; the code comes back on the redirect. */
|
|
972
|
+
async function connect(deployment, person, clientId, scope = "browse") {
|
|
973
|
+
const verifier = base64url(randomBytes(32));
|
|
974
|
+
const request = {
|
|
975
|
+
client_id: clientId,
|
|
976
|
+
redirect_uri: REDIRECT,
|
|
977
|
+
response_type: "code",
|
|
978
|
+
code_challenge: base64url(createHash("sha256").update(verifier).digest()),
|
|
979
|
+
code_challenge_method: "S256",
|
|
980
|
+
state: STATE,
|
|
981
|
+
scope,
|
|
982
|
+
resource: `${deployment.origin}/mcp`
|
|
983
|
+
};
|
|
984
|
+
const view = await person.api.oauth.describe(request);
|
|
985
|
+
expect(view.status === "ready", "the consent page refused a good request", view);
|
|
986
|
+
expect(view.client.registration === "dcr" && view.client.name === NAME && view.scopes.join(" ") === scope && view.loopbackOnly, "the consent page does not show the registered client as it is", view);
|
|
987
|
+
const { redirect } = await person.api.oauth.decide({
|
|
988
|
+
request,
|
|
989
|
+
approve: true,
|
|
990
|
+
scopes: scope.split(" ")
|
|
991
|
+
});
|
|
992
|
+
const back = new URL(redirect);
|
|
993
|
+
expect(`${back.origin}${back.pathname}` === REDIRECT, `the answer went to ${back.origin}${back.pathname}, not the redirect`, redirect);
|
|
994
|
+
expect(back.searchParams.get("state") === STATE && back.searchParams.get("iss") === deployment.origin, "the answer does not carry the state as sent and the issuer", redirect);
|
|
995
|
+
const code = back.searchParams.get("code");
|
|
996
|
+
expect(code !== null, "an approval carried no code", redirect);
|
|
997
|
+
return {
|
|
998
|
+
code,
|
|
999
|
+
verifier
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
async function redeem(deployment, clientId, { code, verifier }) {
|
|
1003
|
+
const answer = await token(deployment, {
|
|
1004
|
+
grant_type: "authorization_code",
|
|
1005
|
+
code,
|
|
1006
|
+
code_verifier: verifier,
|
|
1007
|
+
redirect_uri: REDIRECT,
|
|
1008
|
+
client_id: clientId,
|
|
1009
|
+
resource: `${deployment.origin}/mcp`
|
|
1010
|
+
});
|
|
1011
|
+
const body = await json(answer);
|
|
1012
|
+
expect(answer.status === 200 && typeof body.access_token === "string" && typeof body.refresh_token === "string", `redeeming the code answered ${answer.status}`, body);
|
|
1013
|
+
expect(answer.headers.get("cache-control") === "no-store", "tokens were answered without cache-control: no-store");
|
|
1014
|
+
return body;
|
|
1015
|
+
}
|
|
1016
|
+
async function refused(deployment, what, fields) {
|
|
1017
|
+
const answer = await token(deployment, fields);
|
|
1018
|
+
const body = await json(answer);
|
|
1019
|
+
expect(answer.status === 400 && body.error === "invalid_grant", `${what} answered ${answer.status}, not invalid_grant`, body);
|
|
1020
|
+
}
|
|
1021
|
+
/** Whether a connection's access token still reaches /mcp. */
|
|
1022
|
+
async function discovers(deployment, access) {
|
|
1023
|
+
const answer = await mcp(deployment, {
|
|
1024
|
+
authorization: `Bearer ${access}`,
|
|
1025
|
+
"mcp-protocol-version": "2026-07-28",
|
|
1026
|
+
"mcp-method": "server/discover"
|
|
1027
|
+
}, "server/discover", { _meta: ENVELOPE });
|
|
1028
|
+
if (answer.status === 401) return false;
|
|
1029
|
+
const body = await json(answer);
|
|
1030
|
+
expect(answer.status === 200 && Array.isArray(body.result?.supportedVersions), `server/discover answered ${answer.status}`, body);
|
|
1031
|
+
return true;
|
|
1032
|
+
}
|
|
1033
|
+
async function mcpConnect(deployment, people) {
|
|
1034
|
+
const { origin } = deployment;
|
|
1035
|
+
const anonymous = await mcp(deployment, {});
|
|
1036
|
+
const challenge = anonymous.headers.get("www-authenticate") ?? "";
|
|
1037
|
+
expect(anonymous.status === 401, `/mcp answered ${anonymous.status} without a token, not 401`);
|
|
1038
|
+
expect(challenge.includes(`resource_metadata="${origin}/.well-known/oauth-protected-resource/mcp"`) && challenge.includes("scope=\"browse\""), "the 401's challenge does not name the resource metadata and Browse", challenge);
|
|
1039
|
+
const resource = await json(await fetch(`${origin}/.well-known/oauth-protected-resource/mcp`));
|
|
1040
|
+
expect(resource.resource === `${origin}/mcp` && resource.authorization_servers?.[0] === origin, "the protected resource metadata does not name /mcp and coffre as its issuer", resource);
|
|
1041
|
+
const server = await json(await fetch(`${origin}/.well-known/oauth-authorization-server`));
|
|
1042
|
+
expect(server.issuer === origin && server.authorization_endpoint === `${origin}/oauth/authorize`, "the authorization server metadata is wrong", server);
|
|
1043
|
+
for (const [field, value] of [
|
|
1044
|
+
["code_challenge_methods_supported", "S256"],
|
|
1045
|
+
["token_endpoint_auth_methods_supported", "none"],
|
|
1046
|
+
["grant_types_supported", "refresh_token"]
|
|
1047
|
+
]) expect(server[field]?.includes(value), `the authorization server metadata leaves ${value} out of ${field}`, server);
|
|
1048
|
+
expect(server.client_id_metadata_document_supported === true, "the authorization server metadata does not offer metadata documents", server);
|
|
1049
|
+
const registered = await fetch(`${origin}/api/oauth/register`, {
|
|
1050
|
+
method: "POST",
|
|
1051
|
+
headers: { "content-type": "application/json" },
|
|
1052
|
+
body: JSON.stringify({
|
|
1053
|
+
client_name: NAME,
|
|
1054
|
+
redirect_uris: [REDIRECT, "conformance-app://callback"],
|
|
1055
|
+
token_endpoint_auth_method: "none"
|
|
1056
|
+
})
|
|
1057
|
+
});
|
|
1058
|
+
const client = await json(registered);
|
|
1059
|
+
expect(registered.status === 201 && typeof client.client_id === "string", `registering answered ${registered.status}`, client);
|
|
1060
|
+
expect(JSON.stringify(client.redirect_uris) === JSON.stringify([REDIRECT]), "the registration kept a redirect it should have left out", client);
|
|
1061
|
+
const clientId = client.client_id;
|
|
1062
|
+
const page = await people.reader.browser.fetch(`/oauth/authorize?${new URLSearchParams({
|
|
1063
|
+
client_id: clientId,
|
|
1064
|
+
redirect_uri: REDIRECT
|
|
1065
|
+
})}`);
|
|
1066
|
+
expect(page.status === 200, `the consent page answered ${page.status}`);
|
|
1067
|
+
const forged = await people.reader.browser.fetch("/api/oauth/authorizations", {
|
|
1068
|
+
method: "POST",
|
|
1069
|
+
headers: {
|
|
1070
|
+
origin: "https://attacker.example",
|
|
1071
|
+
"sec-fetch-site": "cross-site",
|
|
1072
|
+
"content-type": "application/json"
|
|
1073
|
+
},
|
|
1074
|
+
body: JSON.stringify({
|
|
1075
|
+
request: {
|
|
1076
|
+
client_id: clientId,
|
|
1077
|
+
redirect_uri: REDIRECT
|
|
1078
|
+
},
|
|
1079
|
+
approve: true
|
|
1080
|
+
})
|
|
1081
|
+
});
|
|
1082
|
+
expect(forged.status === 403, `another site's approval answered ${forged.status}, not 403`);
|
|
1083
|
+
const first = await redeem(deployment, clientId, await connect(deployment, people.reader, clientId));
|
|
1084
|
+
expect(first.access_token.startsWith("coffre_mcp_") && first.refresh_token.startsWith("coffre_mcr_") && first.scope === "browse", "the tokens are not the shapes and scope coffre issues", { scope: first.scope });
|
|
1085
|
+
expect(await discovers(deployment, first.access_token), "a fresh access token was refused at /mcp");
|
|
1086
|
+
const atApi = await fetch(`${origin}/api/me`, { headers: { authorization: `Bearer ${first.access_token}` } });
|
|
1087
|
+
expect(atApi.status === 401, `an MCP token at /api answered ${atApi.status}, not 401`);
|
|
1088
|
+
const cli = await mcp(deployment, { authorization: `Bearer ${people.leaver.cliToken}` });
|
|
1089
|
+
expect(cli.status === 401, `a CLI session at /mcp answered ${cli.status}, not 401`);
|
|
1090
|
+
const browser = await people.reader.browser.fetch("/mcp", {
|
|
1091
|
+
method: "POST",
|
|
1092
|
+
headers: {
|
|
1093
|
+
"content-type": "application/json",
|
|
1094
|
+
origin
|
|
1095
|
+
},
|
|
1096
|
+
body: JSON.stringify({
|
|
1097
|
+
jsonrpc: "2.0",
|
|
1098
|
+
id: 1,
|
|
1099
|
+
method: "server/discover"
|
|
1100
|
+
})
|
|
1101
|
+
});
|
|
1102
|
+
expect(browser.status === 401, `a browser's cookie at /mcp answered ${browser.status}, not 401`);
|
|
1103
|
+
const foreign = await mcp(deployment, {
|
|
1104
|
+
authorization: `Bearer ${first.access_token}`,
|
|
1105
|
+
origin: "https://attacker.example"
|
|
1106
|
+
});
|
|
1107
|
+
expect(foreign.status === 403, `/mcp answered ${foreign.status} to another site's page, not 403`);
|
|
1108
|
+
const rotate = (refresh) => token(deployment, {
|
|
1109
|
+
grant_type: "refresh_token",
|
|
1110
|
+
refresh_token: refresh,
|
|
1111
|
+
client_id: clientId
|
|
1112
|
+
});
|
|
1113
|
+
const rotated = await rotate(first.refresh_token);
|
|
1114
|
+
const next = await json(rotated);
|
|
1115
|
+
expect(rotated.status === 200 && next.refresh_token !== first.refresh_token, `refreshing answered ${rotated.status}, or the same refresh token`);
|
|
1116
|
+
expect(await discovers(deployment, next.access_token), "a refreshed access token was refused");
|
|
1117
|
+
await refused(deployment, "a replaced refresh token", {
|
|
1118
|
+
grant_type: "refresh_token",
|
|
1119
|
+
refresh_token: first.refresh_token,
|
|
1120
|
+
client_id: clientId
|
|
1121
|
+
});
|
|
1122
|
+
await refused(deployment, "the current refresh token, after a reuse", {
|
|
1123
|
+
grant_type: "refresh_token",
|
|
1124
|
+
refresh_token: next.refresh_token,
|
|
1125
|
+
client_id: clientId
|
|
1126
|
+
});
|
|
1127
|
+
expect(!await discovers(deployment, next.access_token), "an access token outlived its connection, ended by a reused refresh token");
|
|
1128
|
+
const asked = await connect(deployment, people.reader, clientId);
|
|
1129
|
+
const second = await redeem(deployment, clientId, asked);
|
|
1130
|
+
await refused(deployment, "a code redeemed already", {
|
|
1131
|
+
grant_type: "authorization_code",
|
|
1132
|
+
code: asked.code,
|
|
1133
|
+
code_verifier: asked.verifier,
|
|
1134
|
+
redirect_uri: REDIRECT,
|
|
1135
|
+
client_id: clientId
|
|
1136
|
+
});
|
|
1137
|
+
expect(!await discovers(deployment, second.access_token), "an access token outlived its connection, ended by a reused code");
|
|
1138
|
+
const third = await redeem(deployment, clientId, await connect(deployment, people.reader, clientId));
|
|
1139
|
+
const listed = (await people.reader.api.apps.list()).apps;
|
|
1140
|
+
expect(listed.length === 1 && listed[0].name === NAME && listed[0].registration === "dcr", "Connected apps does not list the one live connection", listed);
|
|
1141
|
+
await people.reader.api.apps.disconnect(listed[0].id);
|
|
1142
|
+
expect(!await discovers(deployment, third.access_token), "an access token outlived its disconnection");
|
|
1143
|
+
expect((await people.reader.api.apps.list()).apps.length === 0, "a disconnected app is still listed");
|
|
1144
|
+
const { entries } = await people.admin.api.audit.list({
|
|
1145
|
+
actor: people.reader.member,
|
|
1146
|
+
detail: "1",
|
|
1147
|
+
limit: 500
|
|
1148
|
+
});
|
|
1149
|
+
const mine = entries.filter((entry) => entry.metadata.clientId === clientId);
|
|
1150
|
+
const count = (action) => mine.filter((entry) => entry.action === action && entry.decision === "allow").length;
|
|
1151
|
+
const counts = {
|
|
1152
|
+
connect: count("mcp.connect"),
|
|
1153
|
+
token: count("mcp.token"),
|
|
1154
|
+
disconnect: count("mcp.disconnect")
|
|
1155
|
+
};
|
|
1156
|
+
expect(counts.connect === 3 && counts.token === 4 && counts.disconnect === 3, "the log does not hold each connection, token and disconnection", counts);
|
|
1157
|
+
const reasons = mine.filter((entry) => entry.action === "mcp.disconnect").map((entry) => entry.metadata.reason).sort();
|
|
1158
|
+
expect(JSON.stringify(reasons) === JSON.stringify([
|
|
1159
|
+
"code_reused",
|
|
1160
|
+
"person",
|
|
1161
|
+
"refresh_reused"
|
|
1162
|
+
]), "the disconnections do not say why", reasons);
|
|
1163
|
+
return "401 and both metadata documents; registered, approved, redeemed and discovered; only at /mcp, and only its token there; a reused refresh token, a reused code and a disconnection each end the connection, and the log says so";
|
|
1164
|
+
}
|
|
1165
|
+
/** A 2026-07-28 request as a client sends it: its headers say what its body does; `capabilities` are the client's. */
|
|
1166
|
+
async function modern(deployment, access, method, params = {}, name, capabilities = {}) {
|
|
1167
|
+
const response = await mcp(deployment, {
|
|
1168
|
+
authorization: `Bearer ${access}`,
|
|
1169
|
+
"mcp-protocol-version": "2026-07-28",
|
|
1170
|
+
"mcp-method": method,
|
|
1171
|
+
...name === void 0 ? {} : { "mcp-name": name }
|
|
1172
|
+
}, method, {
|
|
1173
|
+
...params,
|
|
1174
|
+
_meta: {
|
|
1175
|
+
...ENVELOPE,
|
|
1176
|
+
"io.modelcontextprotocol/clientCapabilities": capabilities
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
return {
|
|
1180
|
+
response,
|
|
1181
|
+
body: await json(response)
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
/** A client registered for one check, by the name every check's client has. */
|
|
1185
|
+
async function register(deployment) {
|
|
1186
|
+
return (await json(await fetch(`${deployment.origin}/api/oauth/register`, {
|
|
1187
|
+
method: "POST",
|
|
1188
|
+
headers: { "content-type": "application/json" },
|
|
1189
|
+
body: JSON.stringify({
|
|
1190
|
+
client_name: NAME,
|
|
1191
|
+
redirect_uris: [REDIRECT]
|
|
1192
|
+
})
|
|
1193
|
+
}))).client_id;
|
|
1194
|
+
}
|
|
1195
|
+
/** A client registered and connected as the person, with Browse, for a check of another's: its access token. */
|
|
1196
|
+
async function connectedApp(deployment, person) {
|
|
1197
|
+
const clientId = await register(deployment);
|
|
1198
|
+
return (await redeem(deployment, clientId, await connect(deployment, person, clientId))).access_token;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* The Browse tools, as a client calls them (design section 14, checks 1, 4
|
|
1202
|
+
* and 5): on 2026-07-28 and through a 2025-11-25 `initialize`, as the
|
|
1203
|
+
* reader, who sees dev and not prod. No value appears in any answer, the
|
|
1204
|
+
* headers must agree with the body, and every call is in the log under the
|
|
1205
|
+
* client, the API's own entries naming the connection.
|
|
1206
|
+
*/
|
|
1207
|
+
async function mcpBrowse(deployment, people, canaries) {
|
|
1208
|
+
const clientId = await register(deployment);
|
|
1209
|
+
const { access_token: access } = await redeem(deployment, clientId, await connect(deployment, people.reader, clientId));
|
|
1210
|
+
const answers = [];
|
|
1211
|
+
const discovered = await modern(deployment, access, "server/discover");
|
|
1212
|
+
answers.push(JSON.stringify(discovered.body));
|
|
1213
|
+
expect(discovered.response.status === 200, `server/discover answered ${discovered.response.status}`, discovered.body);
|
|
1214
|
+
const listed = await modern(deployment, access, "tools/list");
|
|
1215
|
+
const result = listed.body.result;
|
|
1216
|
+
const names = result?.tools?.map((tool) => tool.name) ?? [];
|
|
1217
|
+
expect(names.includes("list_secrets") && names.includes("run_with_secrets") && result?.cacheScope === "public" && typeof result.ttlMs === "number", "tools/list does not list the Browse tools, cacheable", listed.body);
|
|
1218
|
+
const callTool = async (tool, args) => {
|
|
1219
|
+
const { response, body } = await modern(deployment, access, "tools/call", {
|
|
1220
|
+
name: tool,
|
|
1221
|
+
arguments: args
|
|
1222
|
+
}, tool);
|
|
1223
|
+
answers.push(JSON.stringify(body));
|
|
1224
|
+
expect(response.status === 200, `tools/call ${tool} answered ${response.status}`, body);
|
|
1225
|
+
return body.result;
|
|
1226
|
+
};
|
|
1227
|
+
const keys = ((await callTool("list_secrets", { environment: DEV })).structuredContent?.keys ?? []).map((key) => key.key);
|
|
1228
|
+
expect(["API_KEY", "DATABASE_URL"].every((key) => keys.includes(key)), `list_secrets on ${DEV} does not list its keys`, keys);
|
|
1229
|
+
const prod = await callTool("list_secrets", { environment: PROD });
|
|
1230
|
+
expect(prod.isError === true, `the reader listed ${PROD}'s keys through MCP, which they cannot`, prod);
|
|
1231
|
+
const run = await callTool("run_with_secrets", {
|
|
1232
|
+
environment: DEV,
|
|
1233
|
+
command: "npm test"
|
|
1234
|
+
});
|
|
1235
|
+
expect(run.content?.[0]?.text?.includes(`coffre run ${DEV} -- npm test`) === true, "run_with_secrets does not say how to run the command", run);
|
|
1236
|
+
for (const tool of ["whoami", "list_projects"]) await callTool(tool, {});
|
|
1237
|
+
await callTool("secret_history", { secret: `${DEV}/API_KEY` });
|
|
1238
|
+
const mismatched = await mcp(deployment, {
|
|
1239
|
+
authorization: `Bearer ${access}`,
|
|
1240
|
+
"mcp-protocol-version": "2026-07-28",
|
|
1241
|
+
"mcp-method": "tools/call",
|
|
1242
|
+
"mcp-name": "list_projects"
|
|
1243
|
+
}, "tools/call", {
|
|
1244
|
+
name: "whoami",
|
|
1245
|
+
arguments: {},
|
|
1246
|
+
_meta: ENVELOPE
|
|
1247
|
+
});
|
|
1248
|
+
const mismatch = await json(mismatched);
|
|
1249
|
+
expect(mismatched.status === 400 && mismatch.error?.code === -32020, `a Mcp-Name naming another tool answered ${mismatched.status}`, mismatch);
|
|
1250
|
+
const initialized = await mcp(deployment, { authorization: `Bearer ${access}` }, "initialize", {
|
|
1251
|
+
protocolVersion: "2025-11-25",
|
|
1252
|
+
capabilities: {},
|
|
1253
|
+
clientInfo: {
|
|
1254
|
+
name: "coffre-conformance",
|
|
1255
|
+
version: "1"
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
const init = await json(initialized);
|
|
1259
|
+
expect(initialized.status === 200 && init.result?.protocolVersion === "2025-11-25", `initialize for 2025-11-25 answered ${initialized.status}`, init);
|
|
1260
|
+
expect(initialized.headers.get("mcp-session-id") === null, "initialize minted a session: coffre keeps none");
|
|
1261
|
+
const legacy = await mcp(deployment, {
|
|
1262
|
+
authorization: `Bearer ${access}`,
|
|
1263
|
+
"mcp-protocol-version": "2025-11-25"
|
|
1264
|
+
}, "tools/call", {
|
|
1265
|
+
name: "list_secrets",
|
|
1266
|
+
arguments: { environment: DEV }
|
|
1267
|
+
});
|
|
1268
|
+
const legacyBody = await json(legacy);
|
|
1269
|
+
answers.push(JSON.stringify(legacyBody));
|
|
1270
|
+
expect(legacy.status === 200 && legacyBody.result?.isError !== true, `a 2025-11-25 tools/call answered ${legacy.status}`, legacyBody);
|
|
1271
|
+
const leaked = Object.entries(canaries).filter(([, value]) => answers.some((answer) => answer.includes(value))).map(([path]) => path);
|
|
1272
|
+
expect(leaked.length === 0, "a Browse tool answered with a secret value", leaked);
|
|
1273
|
+
const { entries } = await people.admin.api.audit.list({
|
|
1274
|
+
actor: people.reader.member,
|
|
1275
|
+
detail: "1",
|
|
1276
|
+
limit: 500
|
|
1277
|
+
});
|
|
1278
|
+
const mine = entries.filter((entry) => entry.metadata.via?.clientId === clientId);
|
|
1279
|
+
const reads = mine.filter((entry) => entry.action === "mcp.read").length;
|
|
1280
|
+
const refused = mine.filter((entry) => entry.action === "mcp.call" && entry.decision === "deny").length;
|
|
1281
|
+
expect(reads === 6 && refused === 1, "the log does not hold each call under the client", {
|
|
1282
|
+
reads,
|
|
1283
|
+
refused
|
|
1284
|
+
});
|
|
1285
|
+
expect(mine.filter((entry) => !entry.action.startsWith("mcp.")).length > 0, "the API's own entries for the calls do not name the connection", mine.map((entry) => entry.action));
|
|
1286
|
+
const shown = (await people.admin.api.audit.list({
|
|
1287
|
+
actor: people.reader.member,
|
|
1288
|
+
limit: 500
|
|
1289
|
+
})).entries;
|
|
1290
|
+
expect(!shown.some((entry) => entry.action === "mcp.read"), "read-only calls are not detail");
|
|
1291
|
+
return `on 2026-07-28 and 2025-11-25, the Browse tools as the reader: ${DEV} listed, ${PROD} refused, no value in any answer; headers held to the body; ${reads} reads as detail and the refusal shown, each under the client`;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Changes, as a client asks for them (design section 14, checks 2 and 3):
|
|
1295
|
+
* Browse cannot ask at all, and with Write nothing changes until the person
|
|
1296
|
+
* approves on coffre's page. A client without URL elicitation gets the link
|
|
1297
|
+
* and calls again; one with it is asked to open the page, and retries with
|
|
1298
|
+
* its requestState, which no other call may use. Only the person decides,
|
|
1299
|
+
* with the digest the page showed; the page makes the change, once, and its
|
|
1300
|
+
* entries name the client and the approval. A value comes from the page.
|
|
1301
|
+
*/
|
|
1302
|
+
async function mcpChanges(deployment, people, canaries) {
|
|
1303
|
+
const { admin } = people;
|
|
1304
|
+
const place = `${PROJECT$1}-mcp/dev`;
|
|
1305
|
+
await admin.api.projects.create(`${PROJECT$1}-mcp`, { name: "MCP changes" });
|
|
1306
|
+
await admin.api.environments.create(place, { name: "Development" });
|
|
1307
|
+
const values = {
|
|
1308
|
+
KEEP: canary(),
|
|
1309
|
+
OLD: canary()
|
|
1310
|
+
};
|
|
1311
|
+
for (const [key, value] of Object.entries(values)) canaries[`${place}/${key}`] = value;
|
|
1312
|
+
await admin.api.secrets.set(place, values);
|
|
1313
|
+
const changer = await personaOn(deployment, admin, "changer", { [`${PROJECT$1}-mcp`]: "maintainer" });
|
|
1314
|
+
const clientId = await register(deployment);
|
|
1315
|
+
const answers = [];
|
|
1316
|
+
const call = async (access, tool, args, more = {}, capabilities = {}) => {
|
|
1317
|
+
const { response, body } = await modern(deployment, access, "tools/call", {
|
|
1318
|
+
name: tool,
|
|
1319
|
+
arguments: args,
|
|
1320
|
+
...more
|
|
1321
|
+
}, tool, capabilities);
|
|
1322
|
+
answers.push(JSON.stringify(body));
|
|
1323
|
+
return {
|
|
1324
|
+
status: response.status,
|
|
1325
|
+
challenge: response.headers.get("www-authenticate") ?? "",
|
|
1326
|
+
result: body.result,
|
|
1327
|
+
error: body.error
|
|
1328
|
+
};
|
|
1329
|
+
};
|
|
1330
|
+
const archived = async (key) => (await admin.api.secrets.history(`${place}/${key}`)).archived;
|
|
1331
|
+
const browse = (await redeem(deployment, clientId, await connect(deployment, changer, clientId))).access_token;
|
|
1332
|
+
const stepUp = await call(browse, "archive_secret", { secret: `${place}/OLD` });
|
|
1333
|
+
expect(stepUp.status === 403 && stepUp.challenge.includes("error=\"insufficient_scope\"") && stepUp.challenge.includes("scope=\"browse write\""), `archive_secret with Browse answered ${stepUp.status}, not a step-up to Write`, stepUp.challenge);
|
|
1334
|
+
expect(!await archived("OLD"), "archive_secret with Browse archived the secret");
|
|
1335
|
+
const write = (await redeem(deployment, clientId, await connect(deployment, changer, clientId, "browse write"))).access_token;
|
|
1336
|
+
const linked = await call(write, "archive_secret", { secret: `${place}/OLD` });
|
|
1337
|
+
const approval = linked.result?.structuredContent?.approval;
|
|
1338
|
+
expect(linked.status === 200 && linked.result?.structuredContent?.status === "pending" && approval?.url === `${deployment.origin}/approvals/${approval?.id}`, "a change without URL elicitation was not answered with its approval link", linked.result);
|
|
1339
|
+
expect(linked.result?.content?.[0]?.text?.includes(approval.url) === true, "the link is not in the text the model reads", linked.result);
|
|
1340
|
+
expect(!await archived("OLD"), "a change was made before its approval");
|
|
1341
|
+
const theirs = await people.reader.api.approvals.get(approval.id).then(() => null, (error) => error);
|
|
1342
|
+
expect(theirs instanceof CoffreError && theirs.status === 403, "another person opened someone else's approval", theirs);
|
|
1343
|
+
const page = await changer.browser.fetch(`/approvals/${approval.id}`);
|
|
1344
|
+
expect(page.status === 200, `the approval page answered ${page.status}`);
|
|
1345
|
+
const shown = (await changer.api.approvals.get(approval.id)).approval;
|
|
1346
|
+
expect(shown.status === "pending" && shown.summary === `archive ${place}/OLD` && shown.client.name === NAME, "the approval page does not show the change asked for", shown);
|
|
1347
|
+
const forgedDigest = await changer.api.approvals.decide(approval.id, {
|
|
1348
|
+
approve: true,
|
|
1349
|
+
digest: "0".repeat(64)
|
|
1350
|
+
}).then(() => null, (error) => error);
|
|
1351
|
+
expect(forgedDigest instanceof CoffreError && forgedDigest.status === 409, "a decision on a change the page did not show was taken", forgedDigest);
|
|
1352
|
+
const forgedSite = await changer.browser.fetch(`/api/approvals/${approval.id}`, {
|
|
1353
|
+
method: "POST",
|
|
1354
|
+
headers: {
|
|
1355
|
+
origin: "https://attacker.example",
|
|
1356
|
+
"sec-fetch-site": "cross-site",
|
|
1357
|
+
"content-type": "application/json"
|
|
1358
|
+
},
|
|
1359
|
+
body: JSON.stringify({
|
|
1360
|
+
approve: true,
|
|
1361
|
+
digest: shown.digest
|
|
1362
|
+
})
|
|
1363
|
+
});
|
|
1364
|
+
expect(forgedSite.status === 403, `another site's approval answered ${forgedSite.status}, not 403`);
|
|
1365
|
+
expect(!await archived("OLD"), "a refused decision changed something");
|
|
1366
|
+
const decided = await changer.api.approvals.decide(approval.id, {
|
|
1367
|
+
approve: true,
|
|
1368
|
+
digest: shown.digest
|
|
1369
|
+
});
|
|
1370
|
+
expect(decided.status === "approved" && await archived("OLD"), "Approve did not make the change", decided);
|
|
1371
|
+
const again = await changer.api.approvals.decide(approval.id, {
|
|
1372
|
+
approve: true,
|
|
1373
|
+
digest: shown.digest
|
|
1374
|
+
}).then(() => null, (error) => error);
|
|
1375
|
+
expect(again instanceof CoffreError && again.status === 409, "an approval was decided twice", again);
|
|
1376
|
+
const reported = await call(write, "archive_secret", { secret: `${place}/OLD` });
|
|
1377
|
+
expect(reported.result?.structuredContent?.status === "approved" && reported.result.isError !== true, "calling again does not report the approved change", reported.result);
|
|
1378
|
+
const elicits = { elicitation: { url: {} } };
|
|
1379
|
+
const asked = await call(write, "rename_secret", {
|
|
1380
|
+
secret: `${place}/KEEP`,
|
|
1381
|
+
newKey: "KEPT"
|
|
1382
|
+
}, {}, elicits);
|
|
1383
|
+
const request = asked.result?.inputRequests?.approve;
|
|
1384
|
+
expect(asked.result?.resultType === "input_required" && request?.method === "elicitation/create" && request.params.mode === "url" && typeof asked.result.requestState === "string", "a change with URL elicitation was not answered with an input_required URL elicitation", asked.result);
|
|
1385
|
+
const id = request.params.url.split("/").at(-1);
|
|
1386
|
+
const replayed = await call(write, "rename_secret", {
|
|
1387
|
+
secret: `${place}/KEEP`,
|
|
1388
|
+
newKey: "OTHER"
|
|
1389
|
+
}, {
|
|
1390
|
+
requestState: asked.result.requestState,
|
|
1391
|
+
inputResponses: { approve: { action: "accept" } }
|
|
1392
|
+
}, elicits);
|
|
1393
|
+
expect(replayed.error?.code === -32602, "a requestState was accepted for another call", replayed);
|
|
1394
|
+
const renamedEarly = await admin.api.secrets.list(place);
|
|
1395
|
+
expect(renamedEarly.keys.some((key) => key.key === "KEEP"), "a change was made before its approval", renamedEarly.keys);
|
|
1396
|
+
const second = (await changer.api.approvals.get(id)).approval;
|
|
1397
|
+
expect((await changer.api.approvals.decide(id, {
|
|
1398
|
+
approve: true,
|
|
1399
|
+
digest: second.digest
|
|
1400
|
+
})).status === "approved", "the second approval was not made");
|
|
1401
|
+
const retried = await call(write, "rename_secret", {
|
|
1402
|
+
secret: `${place}/KEEP`,
|
|
1403
|
+
newKey: "KEPT"
|
|
1404
|
+
}, {
|
|
1405
|
+
requestState: asked.result.requestState,
|
|
1406
|
+
inputResponses: { approve: { action: "accept" } }
|
|
1407
|
+
}, elicits);
|
|
1408
|
+
expect(retried.result?.structuredContent?.status === "approved", "the retry does not report the approved change", retried.result);
|
|
1409
|
+
const typed = canary();
|
|
1410
|
+
canaries[`${place}/TYPED`] = typed;
|
|
1411
|
+
const valueId = (await call(write, "request_secret_value", { secret: `${place}/TYPED` })).result.structuredContent.approval.id;
|
|
1412
|
+
const valuePage = (await changer.api.approvals.get(valueId)).approval;
|
|
1413
|
+
expect(valuePage.asks?.value !== void 0, "the approval page does not ask for the value");
|
|
1414
|
+
await changer.api.approvals.decide(valueId, {
|
|
1415
|
+
approve: true,
|
|
1416
|
+
digest: valuePage.digest,
|
|
1417
|
+
value: typed
|
|
1418
|
+
});
|
|
1419
|
+
expect((await admin.api.secrets.reveal(`${place}/TYPED`)).values.TYPED === typed, "the value typed on the page was not written");
|
|
1420
|
+
await call(write, "request_secret_value", { secret: `${place}/TYPED` });
|
|
1421
|
+
const generatedId = (await call(write, "generate_secret_value", {
|
|
1422
|
+
secret: `${place}/GENERATED`,
|
|
1423
|
+
alphabet: "hex"
|
|
1424
|
+
})).result.structuredContent.approval.id;
|
|
1425
|
+
const generatedPage = (await changer.api.approvals.get(generatedId)).approval;
|
|
1426
|
+
const generated = await changer.api.approvals.decide(generatedId, {
|
|
1427
|
+
approve: true,
|
|
1428
|
+
digest: generatedPage.digest
|
|
1429
|
+
});
|
|
1430
|
+
const made = (await admin.api.secrets.reveal(`${place}/GENERATED`)).values.GENERATED ?? "";
|
|
1431
|
+
canaries[`${place}/GENERATED`] = made;
|
|
1432
|
+
expect(/^[0-9a-f]{64}$/.test(made) && generated.shown.length === 0 && !JSON.stringify(generated).includes(made), "generate_secret_value did not make a 64-character hex value, shown to no one");
|
|
1433
|
+
await call(write, "generate_secret_value", {
|
|
1434
|
+
secret: `${place}/GENERATED`,
|
|
1435
|
+
alphabet: "hex"
|
|
1436
|
+
});
|
|
1437
|
+
const leaked = Object.entries(canaries).filter(([, value]) => answers.some((answer) => answer.includes(value))).map(([path]) => path);
|
|
1438
|
+
expect(leaked.length === 0, "a change tool answered with a secret value", leaked);
|
|
1439
|
+
const { entries } = await admin.api.audit.list({
|
|
1440
|
+
actor: changer.member,
|
|
1441
|
+
limit: 500
|
|
1442
|
+
});
|
|
1443
|
+
const viaApproval = (action) => entries.filter((entry) => entry.action === action && entry.decision === "allow" && typeof entry.metadata.via?.approvalId === "string");
|
|
1444
|
+
const once = {
|
|
1445
|
+
archive: viaApproval("secret.archive").length,
|
|
1446
|
+
rename: viaApproval("secret.rename").length,
|
|
1447
|
+
write: viaApproval("secret.write").length
|
|
1448
|
+
};
|
|
1449
|
+
expect(once.archive === 1 && once.rename === 1 && once.write === 2, "the changes are not each made once, via the client and its approval", once);
|
|
1450
|
+
const decisions = entries.filter((entry) => entry.action === "mcp.approve").map((entry) => `${entry.decision} ${entry.reason ?? ""}`.trim()).sort();
|
|
1451
|
+
expect(JSON.stringify(decisions) === JSON.stringify([
|
|
1452
|
+
"allow",
|
|
1453
|
+
"allow",
|
|
1454
|
+
"allow",
|
|
1455
|
+
"allow",
|
|
1456
|
+
"deny approved",
|
|
1457
|
+
"deny changed"
|
|
1458
|
+
]), "the decisions, and the two refused, are not in the log", decisions);
|
|
1459
|
+
return `Browse stepped up to Write; with Write, the link without URL elicitation and an elicitation with it; nothing changed until ${changer.email} approved on coffre's page, another person and another site refused, a replayed requestState refused; each change made once, via the client and its approval; a value typed on the page only, and one coffre made reaching no one`;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Values (design section 14, checks 2 and 4): Browse cannot read one, Read
|
|
1463
|
+
* values reads what the person may, a value shown on coffre's page goes to
|
|
1464
|
+
* the person and not the client, and one a client asks coffre to make
|
|
1465
|
+
* reaches no one.
|
|
1466
|
+
*/
|
|
1467
|
+
async function mcpValues(deployment, people, canaries) {
|
|
1468
|
+
const { reader } = people;
|
|
1469
|
+
const clientId = await register(deployment);
|
|
1470
|
+
const answers = [];
|
|
1471
|
+
const call = async (access, tool, args) => {
|
|
1472
|
+
const { response, body } = await modern(deployment, access, "tools/call", {
|
|
1473
|
+
name: tool,
|
|
1474
|
+
arguments: args
|
|
1475
|
+
}, tool);
|
|
1476
|
+
answers.push(JSON.stringify(body));
|
|
1477
|
+
return {
|
|
1478
|
+
status: response.status,
|
|
1479
|
+
challenge: response.headers.get("www-authenticate") ?? "",
|
|
1480
|
+
result: body.result
|
|
1481
|
+
};
|
|
1482
|
+
};
|
|
1483
|
+
const dev = valuesIn(canaries, DEV);
|
|
1484
|
+
const browse = (await redeem(deployment, clientId, await connect(deployment, reader, clientId))).access_token;
|
|
1485
|
+
const stepUp = await call(browse, "read_secret_values", { path: DEV });
|
|
1486
|
+
expect(stepUp.status === 403 && stepUp.challenge.includes("scope=\"browse read-values\""), `read_secret_values with Browse answered ${stepUp.status}, not a step-up`, stepUp.challenge);
|
|
1487
|
+
const show = await call(browse, "show_secret_value", { secret: `${DEV}/API_KEY` });
|
|
1488
|
+
const id = show.result?.structuredContent?.approval?.id;
|
|
1489
|
+
expect(show.result?.structuredContent?.status === "pending" && id !== void 0, "show_secret_value did not open an approval", show.result);
|
|
1490
|
+
const page = (await reader.api.approvals.get(id)).approval;
|
|
1491
|
+
expect(page.kind === "reveal", "the approval page does not say it shows a value", page);
|
|
1492
|
+
expect((await reader.api.approvals.decide(id, {
|
|
1493
|
+
approve: true,
|
|
1494
|
+
digest: page.digest
|
|
1495
|
+
})).shown.some((line) => line.value === dev.API_KEY), "Reveal did not show the person the value");
|
|
1496
|
+
const told = await call(browse, "show_secret_value", { secret: `${DEV}/API_KEY` });
|
|
1497
|
+
expect(told.result?.structuredContent?.status === "approved", "show_secret_value does not report the value as shown", told.result);
|
|
1498
|
+
const browseLeaks = Object.entries(canaries).filter(([, value]) => answers.some((answer) => answer.includes(value))).map(([path]) => path);
|
|
1499
|
+
expect(browseLeaks.length === 0, "a Browse answer held a value", browseLeaks);
|
|
1500
|
+
const reading = (await redeem(deployment, clientId, await connect(deployment, reader, clientId, "browse read-values"))).access_token;
|
|
1501
|
+
const read = await call(reading, "read_secret_values", { path: DEV });
|
|
1502
|
+
expect(JSON.stringify(read.result?.structuredContent?.values) === JSON.stringify(dev), `read_secret_values on ${DEV} did not answer its values`);
|
|
1503
|
+
expect(read.result?.content?.[0]?.text?.startsWith("These values are now part of this conversation") === true, "read_secret_values does not warn first", read.result?.content);
|
|
1504
|
+
const prod = await call(reading, "read_secret_values", { path: PROD });
|
|
1505
|
+
expect(prod.result?.isError === true && !JSON.stringify(prod.result).includes(canaries[`${PROD}/API_KEY`]), `the reader read ${PROD} through MCP`, prod.result);
|
|
1506
|
+
return `Browse stepped up for values and showed ${DEV}/API_KEY to ${reader.email} on coffre's page only; Read values answered ${DEV}'s values, warning first, and refused ${PROD}`;
|
|
1507
|
+
}
|
|
1508
|
+
//#endregion
|
|
845
1509
|
//#region src/checks/storage.ts
|
|
846
1510
|
const TABLES = [
|
|
847
1511
|
"projects",
|
|
@@ -1284,7 +1948,7 @@ async function membersOnly(deployment, { stranger }) {
|
|
|
1284
1948
|
expect(!attempt.ok, "someone never admitted signed in");
|
|
1285
1949
|
expect(!stranger.browser.hasCookies, "the refused sign-in left the browser a cookie");
|
|
1286
1950
|
expect((await stranger.browser.fetch("/api/me")).status === 401, "the refused sign-in left a session");
|
|
1287
|
-
await refused("a made-up token read secrets", bearer(deployment.origin, "coffre_cli_conformanceforgedtokenconformanceforged").secrets.list(DEV));
|
|
1951
|
+
await refused$1("a made-up token read secrets", bearer(deployment.origin, "coffre_cli_conformanceforgedtokenconformanceforged").secrets.list(DEV));
|
|
1288
1952
|
for (const [method, path, body] of [
|
|
1289
1953
|
[
|
|
1290
1954
|
"GET",
|
|
@@ -1322,18 +1986,18 @@ async function membersOnly(deployment, { stranger }) {
|
|
|
1322
1986
|
async function grantScoping({ reader, service, bulk }, canaries) {
|
|
1323
1987
|
const read = await reader.api.secrets.reveal(DEV);
|
|
1324
1988
|
expect(same(read.values, valuesIn(canaries, DEV)), "a viewer on dev did not get dev's values", read.values);
|
|
1325
|
-
await refused("a viewer on dev revealed prod", reader.api.secrets.reveal(PROD));
|
|
1326
|
-
await refused("a viewer on dev listed prod", reader.api.secrets.list(PROD));
|
|
1327
|
-
await refused("a viewer wrote a value", reader.api.secrets.set(DEV, { API_KEY: "from the reader" }));
|
|
1328
|
-
await refused("a viewer granted themselves more", reader.api.access.set(reader.member, { [PROD]: "owner" }));
|
|
1329
|
-
await refused("a viewer added a member", reader.api.members.add("user:friend@conformance.example"));
|
|
1330
|
-
await refused("a viewer issued a service token", reader.api.tokens.issue(service.member, { expiresInDays: 1 }));
|
|
1989
|
+
await refused$1("a viewer on dev revealed prod", reader.api.secrets.reveal(PROD));
|
|
1990
|
+
await refused$1("a viewer on dev listed prod", reader.api.secrets.list(PROD));
|
|
1991
|
+
await refused$1("a viewer wrote a value", reader.api.secrets.set(DEV, { API_KEY: "from the reader" }));
|
|
1992
|
+
await refused$1("a viewer granted themselves more", reader.api.access.set(reader.member, { [PROD]: "owner" }));
|
|
1993
|
+
await refused$1("a viewer added a member", reader.api.members.add("user:friend@conformance.example"));
|
|
1994
|
+
await refused$1("a viewer issued a service token", reader.api.tokens.issue(service.member, { expiresInDays: 1 }));
|
|
1331
1995
|
const places = (await reader.api.me()).environments.map((place) => `${place.project}/${place.environment}`);
|
|
1332
1996
|
expect(places.length === 1 && places[0] === DEV, "a viewer on dev is told of other places", places);
|
|
1333
1997
|
const served = await service.api.secrets.reveal(DEV);
|
|
1334
1998
|
expect(same(served.values, valuesIn(canaries, DEV)), "a service viewer on dev did not get dev's values", served.values);
|
|
1335
|
-
await refused("a service viewer on dev revealed prod", service.api.secrets.reveal(PROD));
|
|
1336
|
-
await refused("a viewer on bulk revealed dev", bulk.api.secrets.reveal(DEV));
|
|
1999
|
+
await refused$1("a service viewer on dev revealed prod", service.api.secrets.reveal(PROD));
|
|
2000
|
+
await refused$1("a viewer on bulk revealed dev", bulk.api.secrets.reveal(DEV));
|
|
1337
2001
|
return "a viewer on dev reads dev and nothing else, in a browser or with a token, and changes nothing";
|
|
1338
2002
|
}
|
|
1339
2003
|
/**
|
|
@@ -1392,33 +2056,93 @@ async function offboarding(deployment, { admin, leaver, service }, canaries) {
|
|
|
1392
2056
|
const device = await startDevice(deployment);
|
|
1393
2057
|
await leaver.api.deviceLogins.decide(device.user_code, true);
|
|
1394
2058
|
await leaver.cli.secrets.reveal(DEV);
|
|
1395
|
-
const
|
|
2059
|
+
const app = await connectedApp(deployment, leaver);
|
|
2060
|
+
const before = await admin.api.members.get(leaver.member);
|
|
2061
|
+
expect(before.live.apps === 1 && before.apps.length === 1, "the owner's report does not list the app the leaver connected", before.apps);
|
|
2062
|
+
const { revoked, report } = await admin.api.members.remove(leaver.member);
|
|
2063
|
+
expect(revoked.apps === 1 && report.live.apps === 0 && report.apps.length === 0, "removal does not say it disconnected their app", {
|
|
2064
|
+
revoked,
|
|
2065
|
+
apps: report.apps
|
|
2066
|
+
});
|
|
2067
|
+
expect(!await discovers(deployment, app), "a removed member's app still reaches /mcp");
|
|
1396
2068
|
const exposed = report.exposed.map((entry) => `${entry.project}/${entry.environment}/${entry.key}`).sort();
|
|
1397
2069
|
expect(same(exposed, Object.keys(valuesIn(canaries, DEV)).map((key) => `${DEV}/${key}`).sort()), "the offboarding report does not name what they read", report.exposed);
|
|
1398
2070
|
expect((await leaver.browser.fetch("/api/me")).status === 401, "a removed member's browser session still works");
|
|
1399
|
-
await refused("a removed member's CLI session read secrets", leaver.cli.secrets.list(DEV));
|
|
2071
|
+
await refused$1("a removed member's CLI session read secrets", leaver.cli.secrets.list(DEV));
|
|
1400
2072
|
expect(!(await signIn(deployment, leaver.browser, leaver.email)).ok, "a removed member signed in again");
|
|
1401
2073
|
await admin.api.members.remove(service.member);
|
|
1402
|
-
await refused("a removed service's token read secrets", service.api.secrets.reveal(DEV));
|
|
2074
|
+
await refused$1("a removed service's token read secrets", service.api.secrets.reveal(DEV));
|
|
1403
2075
|
await admin.api.members.add(leaver.member);
|
|
1404
2076
|
await admin.api.access.set(leaver.member, { [DEV]: "developer" });
|
|
1405
2077
|
await admin.api.members.add(service.member);
|
|
1406
2078
|
await admin.api.access.set(service.member, { [DEV]: "viewer" });
|
|
1407
2079
|
expect((await leaver.browser.fetch("/api/me")).status === 401, "re-admission revived the browser session");
|
|
1408
|
-
await refused("re-admission revived the CLI session", leaver.cli.secrets.reveal(DEV));
|
|
1409
|
-
await refused("re-admission revived the service token", service.api.secrets.reveal(DEV));
|
|
2080
|
+
await refused$1("re-admission revived the CLI session", leaver.cli.secrets.reveal(DEV));
|
|
2081
|
+
await refused$1("re-admission revived the service token", service.api.secrets.reveal(DEV));
|
|
1410
2082
|
expect(!(await pollDevice(deployment, device.device_code)).ok, "re-admission revived the old device approval");
|
|
1411
2083
|
expect((await signIn(deployment, leaver.browser, leaver.email)).ok, "a fresh provider callback could not sign the re-admitted member in");
|
|
1412
2084
|
await admin.api.members.remove(leaver.member);
|
|
1413
2085
|
await admin.api.members.remove(service.member);
|
|
1414
|
-
return `the report names ${exposed.length} values; re-admission revives no old session, token or approval; a fresh provider callback works`;
|
|
2086
|
+
return `the report names ${exposed.length} values and their connected app, which removal disconnects; re-admission revives no old session, token or approval; a fresh provider callback works`;
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Grants on every project: one on `*` reaches a project made after it; one
|
|
2090
|
+
* on `*` and a slug reaches that environment in every project and never
|
|
2091
|
+
* another; nobody but an owner gives one; and removing a member takes
|
|
2092
|
+
* them. Its services are removed, and its project archived, as it ends.
|
|
2093
|
+
*/
|
|
2094
|
+
async function everyProject(deployment, { admin, reader }, canaries) {
|
|
2095
|
+
const services = {
|
|
2096
|
+
everything: "token:conformance-everywhere",
|
|
2097
|
+
dev: "token:conformance-every-dev",
|
|
2098
|
+
manager: "token:conformance-manager"
|
|
2099
|
+
};
|
|
2100
|
+
const client = async (member) => bearer(deployment.origin, (await admin.api.tokens.issue(member, { expiresInDays: 1 })).token);
|
|
2101
|
+
for (const member of Object.values(services)) await admin.api.members.add(member);
|
|
2102
|
+
await admin.api.access.set(services.manager, { [PROJECT$1]: "access-manager" });
|
|
2103
|
+
await refused$1("a project's access manager granted on every project", (await client(services.manager)).access.set(services.everything, { "*": "viewer" }));
|
|
2104
|
+
await refused$1("a viewer granted themselves every project", reader.api.access.set(reader.member, { "*/prod": "viewer" }));
|
|
2105
|
+
await admin.api.access.set(services.everything, { "*": "viewer" });
|
|
2106
|
+
await admin.api.access.set(services.dev, { "*/dev": "viewer" });
|
|
2107
|
+
const [everything, dev] = [await client(services.everything), await client(services.dev)];
|
|
2108
|
+
const later = `${PROJECT$1}-later`;
|
|
2109
|
+
const made = await admin.api.projects.create(later, { name: "Made later" });
|
|
2110
|
+
expect(made.inherited.some((grant) => grant.member === services.everything && grant.place === "*"), "making a project did not say who reaches it", made.inherited);
|
|
2111
|
+
for (const environment of ["dev", "prod"]) {
|
|
2112
|
+
const path = `${later}/${environment}`;
|
|
2113
|
+
const { inherited } = await admin.api.environments.create(path, { name: environment });
|
|
2114
|
+
const reaches = inherited.filter((grant) => grant.member === services.dev).length;
|
|
2115
|
+
expect(reaches === (environment === "dev" ? 1 : 0), `making ${path} misnamed who reaches it through dev in every project`, inherited);
|
|
2116
|
+
canaries[`${path}/API_KEY`] = canary();
|
|
2117
|
+
await admin.api.secrets.set(path, valuesIn(canaries, path));
|
|
2118
|
+
}
|
|
2119
|
+
for (const path of [
|
|
2120
|
+
`${later}/prod`,
|
|
2121
|
+
`${later}/dev`,
|
|
2122
|
+
PROD
|
|
2123
|
+
]) {
|
|
2124
|
+
const read = await everything.secrets.reveal(path);
|
|
2125
|
+
expect(read.values.API_KEY === canaries[`${path}/API_KEY`], `viewer on every project could not read ${path}`, read.values);
|
|
2126
|
+
}
|
|
2127
|
+
await refused$1("viewer on every project wrote a value", everything.secrets.set(`${later}/prod`, { API_KEY: "from everywhere" }));
|
|
2128
|
+
const devRead = await dev.secrets.reveal(`${later}/dev`);
|
|
2129
|
+
expect(devRead.values.API_KEY === canaries[`${later}/dev/API_KEY`], "viewer on dev in every project could not read a dev made later", devRead.values);
|
|
2130
|
+
await refused$1("viewer on dev in every project read a prod made later", dev.secrets.reveal(`${later}/prod`));
|
|
2131
|
+
await refused$1("viewer on dev in every project read prod", dev.secrets.reveal(PROD));
|
|
2132
|
+
for (const member of Object.values(services)) await admin.api.members.remove(member);
|
|
2133
|
+
await refused$1("a removed member read through a grant on every project", everything.secrets.reveal(`${later}/prod`));
|
|
2134
|
+
await refused$1("a removed member read through a grant on dev in every project", dev.secrets.reveal(`${later}/dev`));
|
|
2135
|
+
const left = (await admin.api.members.list("*")).members.filter((member) => Object.values(services).includes(member.member));
|
|
2136
|
+
expect(left.length === 0, "grants on every project outlived their members", left);
|
|
2137
|
+
await admin.api.projects.update(later, { archived: true });
|
|
2138
|
+
return "a grant on every project reaches a project made after it; one on dev, every dev and nothing else; refused to non-owners; gone with its member";
|
|
1415
2139
|
}
|
|
1416
2140
|
/** Reading more values at once than the vault allows in its window is refused. */
|
|
1417
2141
|
async function bulkLimit$1({ admin, bulk }, limit) {
|
|
1418
2142
|
const values = {};
|
|
1419
2143
|
for (let i = 0; i <= limit; i++) values[`BULK_${i}`] = `bulk-${i}`;
|
|
1420
2144
|
await admin.api.secrets.set(BULK, values);
|
|
1421
|
-
const refusal = await refused(`${limit + 1} values were revealed at once`, bulk.api.secrets.reveal(BULK));
|
|
2145
|
+
const refusal = await refused$1(`${limit + 1} values were revealed at once`, bulk.api.secrets.reveal(BULK));
|
|
1422
2146
|
expect(refusal.status === 403 && refusal.code === "bulk_limit" && refusal.reason === "bulk_limit", "the bulk read was not refused as bulk_limit", refusal);
|
|
1423
2147
|
const one = await bulk.api.secrets.reveal(`${BULK}/BULK_0`);
|
|
1424
2148
|
expect(one.values.BULK_0 === "bulk-0", "a viewer on bulk could not read one of its values", one.values);
|
|
@@ -1547,7 +2271,7 @@ async function writesAgree(deployment) {
|
|
|
1547
2271
|
});
|
|
1548
2272
|
}
|
|
1549
2273
|
const versions = await query(sql, `SELECT v.secret_id, v.version FROM secret_versions v JOIN secrets s ON s.id = v.secret_id
|
|
1550
|
-
JOIN projects p ON p.id = s.project_id WHERE p.slug = $1`, [PROJECT]);
|
|
2274
|
+
JOIN projects p ON p.id = s.project_id WHERE p.slug = $1`, [PROJECT$1]);
|
|
1551
2275
|
expect(versions.length > 0, "no stored versions were inspected");
|
|
1552
2276
|
for (const version of versions) {
|
|
1553
2277
|
const matching = writes.filter((entry) => entry.secret_id === version.secret_id && JSON.parse(entry.metadata).version === version.version);
|
|
@@ -1763,6 +2487,285 @@ async function earlierCheckpoint(deployment, { admin }) {
|
|
|
1763
2487
|
return "an invalid earlier checkpoint was caught despite valid MACs and a valid later checkpoint";
|
|
1764
2488
|
}
|
|
1765
2489
|
//#endregion
|
|
2490
|
+
//#region src/checks/deletion.ts
|
|
2491
|
+
const PROJECT = "conformance-gone";
|
|
2492
|
+
const SERVICE$1 = "token:conformance-gone-ci";
|
|
2493
|
+
/** Each version under a project, by whether it still holds a ciphertext or a wrapped key. */
|
|
2494
|
+
async function sealed(deployment, projectId) {
|
|
2495
|
+
const rows = await using(deployment.database(), (sql) => query(sql, `SELECT length(v.ciphertext) AS ciphertext, length(v.wrapped_dek) AS wrapped
|
|
2496
|
+
FROM secret_versions v JOIN secrets s ON s.id = v.secret_id WHERE s.project_id = $1`, [projectId]));
|
|
2497
|
+
return {
|
|
2498
|
+
versions: rows.length,
|
|
2499
|
+
sealed: rows.filter((row) => Number(row.ciphertext) > 0 || Number(row.wrapped) > 0).length
|
|
2500
|
+
};
|
|
2501
|
+
}
|
|
2502
|
+
async function projectId(deployment, slug) {
|
|
2503
|
+
const [row] = await using(deployment.database(), (sql) => query(sql, "SELECT id FROM projects WHERE slug = $1", [slug]));
|
|
2504
|
+
return row?.id;
|
|
2505
|
+
}
|
|
2506
|
+
async function deletion(deployment, cli, admin) {
|
|
2507
|
+
const run = async (args, code = 0) => {
|
|
2508
|
+
const result = await cli.run(args);
|
|
2509
|
+
expect(result.code === code, `coffre ${args.join(" ")} exited ${result.code}, not ${code}`, result.output);
|
|
2510
|
+
return result.output;
|
|
2511
|
+
};
|
|
2512
|
+
const value = () => `deleted-value-${randomBytes(8).toString("hex")}`;
|
|
2513
|
+
await admin.api.projects.create(PROJECT, { name: "Gone" });
|
|
2514
|
+
for (const environment of ["prod", "dev"]) {
|
|
2515
|
+
await admin.api.environments.create(`${PROJECT}/${environment}`, { name: environment });
|
|
2516
|
+
await admin.api.secrets.set(`${PROJECT}/${environment}`, {
|
|
2517
|
+
API_KEY: value(),
|
|
2518
|
+
DATABASE_URL: value()
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2521
|
+
await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: value() });
|
|
2522
|
+
await admin.api.members.add(SERVICE$1);
|
|
2523
|
+
await admin.api.access.set(SERVICE$1, { [`${PROJECT}/prod`]: "viewer" });
|
|
2524
|
+
const id = await projectId(deployment, PROJECT);
|
|
2525
|
+
const live = await run([
|
|
2526
|
+
"projects",
|
|
2527
|
+
"delete",
|
|
2528
|
+
PROJECT,
|
|
2529
|
+
"--apply"
|
|
2530
|
+
], 1);
|
|
2531
|
+
expect(/not archived/.test(live), "deleting a live project was not refused as not archived", live);
|
|
2532
|
+
await run([
|
|
2533
|
+
"projects",
|
|
2534
|
+
"archive",
|
|
2535
|
+
PROJECT
|
|
2536
|
+
]);
|
|
2537
|
+
const preview = await run([
|
|
2538
|
+
"projects",
|
|
2539
|
+
"delete",
|
|
2540
|
+
PROJECT
|
|
2541
|
+
]);
|
|
2542
|
+
expect(/erased: 5 versions/.test(preview) && /revoked: 1 grant/.test(preview) && preview.includes("service:conformance-gone-ci would hold nothing anywhere"), "the preview does not say what the deletion takes", preview);
|
|
2543
|
+
expect(/Backups taken before the deletion still hold the encrypted values/.test(preview) && /Nothing changed/.test(preview), "the preview does not warn of backups, or changed something", preview);
|
|
2544
|
+
expect((await sealed(deployment, id)).sealed === 5, "the preview erased something");
|
|
2545
|
+
const done = await run([
|
|
2546
|
+
"projects",
|
|
2547
|
+
"delete",
|
|
2548
|
+
PROJECT,
|
|
2549
|
+
"--apply"
|
|
2550
|
+
]);
|
|
2551
|
+
expect(/^deleted conformance-gone, for good/.test(done), "the deletion did not say it was done", done);
|
|
2552
|
+
const after = await sealed(deployment, id);
|
|
2553
|
+
expect(after.versions === 5 && after.sealed === 0, "a deleted project still holds a ciphertext or a wrapped key", after);
|
|
2554
|
+
const [tombstone] = await using(deployment.database(), (sql) => query(sql, "SELECT slug FROM projects WHERE id = $1", [id]));
|
|
2555
|
+
expect(/^conformance-gone~deleted-\d{4}-\d{2}-\d{2}$/.test(tombstone?.slug ?? ""), "the tombstone is not named for the day", tombstone);
|
|
2556
|
+
expect((await admin.api.projects.list()).projects.every((project) => !project.slug.startsWith(PROJECT)), "a deleted project is still listed");
|
|
2557
|
+
expect((await admin.api.members.get(SERVICE$1)).live.grants === 0, "a grant on the deleted project is still live");
|
|
2558
|
+
const revealed = await admin.api.secrets.reveal(`${tombstone.slug}/prod`).then(() => null, (error) => error);
|
|
2559
|
+
expect(revealed instanceof CoffreError && revealed.status === 404, "a deleted project is still revealed by its tombstone", revealed);
|
|
2560
|
+
const fresh = value();
|
|
2561
|
+
await admin.api.projects.create(PROJECT, { name: "Gone, again" });
|
|
2562
|
+
await admin.api.environments.create(`${PROJECT}/prod`, { name: "prod" });
|
|
2563
|
+
await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: fresh });
|
|
2564
|
+
expect(await projectId(deployment, PROJECT) !== id, "the new project took the deleted one's row");
|
|
2565
|
+
expect((await admin.api.secrets.reveal(`${PROJECT}/prod/API_KEY`)).values.API_KEY === fresh, "the new project does not read its own value");
|
|
2566
|
+
const { entries } = await admin.api.audit.list({
|
|
2567
|
+
path: tombstone.slug,
|
|
2568
|
+
limit: 500
|
|
2569
|
+
});
|
|
2570
|
+
expect(entries.some((entry) => entry.action === "project.delete" && entry.decision === "allow"), "the deletion is not in the log under its tombstone", entries.slice(0, 5));
|
|
2571
|
+
await admin.api.environments.update(`${PROJECT}/prod`, { archived: true });
|
|
2572
|
+
await run([
|
|
2573
|
+
"environments",
|
|
2574
|
+
"delete",
|
|
2575
|
+
`${PROJECT}/prod`,
|
|
2576
|
+
"--apply"
|
|
2577
|
+
]);
|
|
2578
|
+
await admin.api.environments.create(`${PROJECT}/prod`, { name: "prod, again" });
|
|
2579
|
+
const environments = (await admin.api.projects.list()).projects.find((project) => project.slug === PROJECT)?.environments ?? [];
|
|
2580
|
+
expect(environments.length === 1 && environments[0].name === "prod, again", "a deleted environment is still listed, or its slug is not free", environments);
|
|
2581
|
+
expect((await sealed(deployment, await projectId(deployment, PROJECT))).sealed === 0, "a deleted environment still holds a value");
|
|
2582
|
+
const verified = await admin.api.audit.verify();
|
|
2583
|
+
expect(verified.ok, "the log does not verify after the deletions", verified);
|
|
2584
|
+
return `${PROJECT} and ${PROJECT}/prod deleted by the CLI: 5 versions erased, a grant revoked, both unlisted and their slugs reused; ${verified.entries} entries verify`;
|
|
2585
|
+
}
|
|
2586
|
+
//#endregion
|
|
2587
|
+
//#region src/checks/environments.ts
|
|
2588
|
+
/** Where the fork check copies dev to; archived once checked. */
|
|
2589
|
+
const FORKED = `${PROJECT$1}/forked`;
|
|
2590
|
+
/**
|
|
2591
|
+
* A folder grants, hides and renames nothing: a secret filed in one is
|
|
2592
|
+
* still read, run and exported by its own name, by the same people, and
|
|
2593
|
+
* only those who may write may file it.
|
|
2594
|
+
*/
|
|
2595
|
+
async function folders({ admin, reader }, canaries) {
|
|
2596
|
+
const keys = Object.keys(valuesIn(canaries, DEV));
|
|
2597
|
+
const key = keys[0];
|
|
2598
|
+
expect(key !== void 0, "dev holds no secret to file");
|
|
2599
|
+
await admin.api.projects.update(PROJECT$1, { folder: "Conformance" });
|
|
2600
|
+
await admin.api.secrets.update(`${DEV}/${key}`, { folder: "filed" });
|
|
2601
|
+
try {
|
|
2602
|
+
const project = (await reader.api.projects.list()).projects.find((each) => each.slug === PROJECT$1);
|
|
2603
|
+
expect(project?.folder === "Conformance", "a project filed in a folder is not listed in it", project);
|
|
2604
|
+
const listed = (await reader.api.secrets.list(DEV)).keys.find((each) => each.key === key);
|
|
2605
|
+
expect(listed?.folder === "filed", "a secret filed in a folder is not listed in it", listed);
|
|
2606
|
+
const read = await reader.api.secrets.reveal(DEV);
|
|
2607
|
+
expect(JSON.stringify(Object.keys(read.values).sort()) === JSON.stringify([...keys].sort()), "filing a secret changed the names a run injects", Object.keys(read.values));
|
|
2608
|
+
expect(read.values[key] === canaries[`${DEV}/${key}`], "filing a secret changed its value");
|
|
2609
|
+
await refused$1("a viewer filed a secret", reader.api.secrets.update(`${DEV}/${key}`, { folder: "elsewhere" }));
|
|
2610
|
+
await refused$1("a viewer filed a project", reader.api.projects.update(PROJECT$1, { folder: "Elsewhere" }));
|
|
2611
|
+
await refused$1("a folder name with a slash was taken", admin.api.secrets.update(`${DEV}/${key}`, { folder: "a/b" }));
|
|
2612
|
+
} finally {
|
|
2613
|
+
await admin.api.secrets.update(`${DEV}/${key}`, { folder: null });
|
|
2614
|
+
await admin.api.projects.update(PROJECT$1, { folder: null });
|
|
2615
|
+
}
|
|
2616
|
+
return "a filed secret is read and run by its own name, by the same people; only writers file it";
|
|
2617
|
+
}
|
|
2618
|
+
/**
|
|
2619
|
+
* A fork copies dev's values into a new environment, and nothing of who
|
|
2620
|
+
* may read dev: a viewer on dev reads neither the fork nor makes one.
|
|
2621
|
+
*/
|
|
2622
|
+
async function forks({ admin, reader }, canaries) {
|
|
2623
|
+
const dev = valuesIn(canaries, DEV);
|
|
2624
|
+
await refused$1("a viewer forked an environment", reader.api.environments.create(FORKED, {
|
|
2625
|
+
name: "Forked",
|
|
2626
|
+
from: DEV.split("/")[1]
|
|
2627
|
+
}));
|
|
2628
|
+
const made = await admin.api.environments.create(FORKED, {
|
|
2629
|
+
name: "Forked",
|
|
2630
|
+
from: DEV.split("/")[1]
|
|
2631
|
+
});
|
|
2632
|
+
try {
|
|
2633
|
+
expect(made.forked?.keys === Object.keys(dev).length, "the fork did not copy each of dev's keys", made);
|
|
2634
|
+
const read = await admin.api.secrets.reveal(FORKED);
|
|
2635
|
+
expect(JSON.stringify(Object.entries(read.values).sort()) === JSON.stringify(Object.entries(dev).sort()), "the fork's values are not dev's");
|
|
2636
|
+
const history = await admin.api.secrets.history(`${FORKED}/${Object.keys(dev)[0]}`);
|
|
2637
|
+
expect(history.versions.length === 1, "the fork carried history", history.versions);
|
|
2638
|
+
await refused$1("a viewer on dev read dev's fork", reader.api.secrets.reveal(FORKED));
|
|
2639
|
+
} finally {
|
|
2640
|
+
await admin.api.environments.update(FORKED, { archived: true });
|
|
2641
|
+
}
|
|
2642
|
+
return "a fork holds dev's values and no history, and a viewer on dev neither makes one nor reads it";
|
|
2643
|
+
}
|
|
2644
|
+
/** The key in dev the reference check makes, archived once checked. */
|
|
2645
|
+
const HELD = "CONFORMANCE_REFERENCE";
|
|
2646
|
+
const FORGED = "CONFORMANCE_FORGED";
|
|
2647
|
+
/** The status a call failed with and its reason, the vault's or the app's, or that it went through. */
|
|
2648
|
+
async function outcome(call) {
|
|
2649
|
+
try {
|
|
2650
|
+
await call;
|
|
2651
|
+
return "let through";
|
|
2652
|
+
} catch (error) {
|
|
2653
|
+
if (!(error instanceof CoffreError)) throw error;
|
|
2654
|
+
return `${error.status} ${error.reason ?? error.code}`;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* A reference lets whoever reads its holder read its source, so only the
|
|
2659
|
+
* vault makes one, and a read through one is checked against the vault's
|
|
2660
|
+
* own entry: the reader, a viewer on dev with no grant on prod, reads
|
|
2661
|
+
* prod's value through dev's reference, and the read is in prod's log and
|
|
2662
|
+
* dev's; a reference row the vault never made, written straight into the
|
|
2663
|
+
* database, reads nothing; a developer on dev who cannot read prod makes
|
|
2664
|
+
* none; and once broken, it reads no more.
|
|
2665
|
+
*/
|
|
2666
|
+
async function references(deployment, { admin, reader, leaver }, canaries) {
|
|
2667
|
+
const [sourceKey] = Object.keys(valuesIn(canaries, PROD));
|
|
2668
|
+
expect(sourceKey !== void 0, "prod holds no secret to refer to");
|
|
2669
|
+
const source = `${PROD}/${sourceKey}`;
|
|
2670
|
+
await refused$1("a viewer on dev read prod directly", reader.api.secrets.reveal(source));
|
|
2671
|
+
expect(await outcome(leaver.api.secrets.set(DEV, { [HELD]: { ref: source } })) === "403 missing_secret_read", "a developer on dev who cannot read prod made a reference to prod's secret");
|
|
2672
|
+
await admin.api.secrets.set(DEV, { [HELD]: { ref: source } });
|
|
2673
|
+
try {
|
|
2674
|
+
expect((await reader.api.secrets.reveal(`${DEV}/${HELD}`)).values[HELD] === canaries[source], "a viewer on dev did not read prod's value through dev's reference");
|
|
2675
|
+
const logged = async (path) => (await admin.api.audit.list({
|
|
2676
|
+
path,
|
|
2677
|
+
limit: 200
|
|
2678
|
+
})).entries.filter((entry) => entry.action === "secret.read" && entry.actorId === reader.email && entry.metadata.via !== void 0).length;
|
|
2679
|
+
expect(await logged(PROD) >= 1 && await logged(DEV) >= 1, "the read through the reference is not in both the source's log and the holder's");
|
|
2680
|
+
const archives = [[source, (archived) => admin.api.secrets.update(source, { archived })], [PROD, (archived) => admin.api.environments.update(PROD, { archived })]];
|
|
2681
|
+
for (const [what, archive] of archives) {
|
|
2682
|
+
const refusal = await archive(true).then(() => null, (error) => error);
|
|
2683
|
+
if (refusal === null) await archive(false);
|
|
2684
|
+
expect(refusal instanceof CoffreError && refusal.status === 409 && refusal.message.includes(`${DEV}/${HELD} reads ${source}`), `${what} was archived, or refused without naming the reference, while a reference read it`, refusal instanceof Error ? refusal.message : refusal);
|
|
2685
|
+
}
|
|
2686
|
+
await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
|
|
2687
|
+
const underArchived = await outcome(admin.api.secrets.update(source, { archived: true })).finally(() => admin.api.secrets.update(`${DEV}/${HELD}`, { archived: false }));
|
|
2688
|
+
try {
|
|
2689
|
+
expect(underArchived === "let through", `${source} could not be archived while only an archived key referred to it: ${underArchived}`);
|
|
2690
|
+
const restored = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
|
|
2691
|
+
expect(restored.startsWith("409 "), `a reference read a source archived while its holder was: ${restored}`);
|
|
2692
|
+
} finally {
|
|
2693
|
+
if (underArchived === "let through") await admin.api.secrets.update(source, { archived: false });
|
|
2694
|
+
}
|
|
2695
|
+
expect((await reader.api.secrets.reveal(`${DEV}/${HELD}`)).values[HELD] === canaries[source], "a reference did not read its source again once both were restored");
|
|
2696
|
+
const forged = await using(deployment.database(), async (sql) => {
|
|
2697
|
+
const [holder] = await query(sql, "SELECT id, project_id, environment_id FROM secrets WHERE key = $1", [HELD]);
|
|
2698
|
+
const [target] = await query(sql, "SELECT s.id, s.project_id, s.environment_id FROM secrets s JOIN environments e ON e.id = s.environment_id WHERE s.key = $1 AND e.slug = $2", [sourceKey, PROD.split("/")[1]]);
|
|
2699
|
+
const [entry] = await query(sql, "SELECT seq FROM audit_log WHERE author = 'vault' AND action = 'access.grant' AND decision = 'allow' ORDER BY seq DESC LIMIT 1");
|
|
2700
|
+
const id = randomUUID();
|
|
2701
|
+
await query(sql, "INSERT INTO secrets (id, project_id, environment_id, key, current_version) VALUES ($1, $2, $3, $4, 0)", [
|
|
2702
|
+
id,
|
|
2703
|
+
holder.project_id,
|
|
2704
|
+
holder.environment_id,
|
|
2705
|
+
FORGED
|
|
2706
|
+
]);
|
|
2707
|
+
await query(sql, `INSERT INTO secret_references (id, project_id, environment_id, secret_id, source_project_id, source_environment_id, source_secret_id, created_seq, created_by)
|
|
2708
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [
|
|
2709
|
+
randomUUID(),
|
|
2710
|
+
holder.project_id,
|
|
2711
|
+
holder.environment_id,
|
|
2712
|
+
id,
|
|
2713
|
+
target.project_id,
|
|
2714
|
+
target.environment_id,
|
|
2715
|
+
target.id,
|
|
2716
|
+
String(entry.seq),
|
|
2717
|
+
admin.member
|
|
2718
|
+
]);
|
|
2719
|
+
return id;
|
|
2720
|
+
});
|
|
2721
|
+
try {
|
|
2722
|
+
const forgedRead = await outcome(reader.api.secrets.reveal(`${DEV}/${FORGED}`));
|
|
2723
|
+
expect([
|
|
2724
|
+
"404 no_value",
|
|
2725
|
+
"404 not_found",
|
|
2726
|
+
"403 bad_claim"
|
|
2727
|
+
].includes(forgedRead), `a reference row the vault never made was read: ${forgedRead}`);
|
|
2728
|
+
} finally {
|
|
2729
|
+
await using(deployment.database(), async (sql) => {
|
|
2730
|
+
await query(sql, "DELETE FROM secret_references WHERE secret_id = $1", [forged]);
|
|
2731
|
+
await query(sql, "DELETE FROM secrets WHERE id = $1", [forged]);
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
await admin.api.references.break(`${DEV}/${HELD}`);
|
|
2735
|
+
const after = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
|
|
2736
|
+
expect(after.startsWith("409 "), `a broken reference still read: ${after}`);
|
|
2737
|
+
} finally {
|
|
2738
|
+
await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
|
|
2739
|
+
}
|
|
2740
|
+
return "a viewer on dev reads prod's value through a reference, logged in both; prod and its key cannot be archived while it reads them, but can once its holder is archived, which then reads nothing until they are back; a forged row is refused, a broken one reads no more, and none is made without read on the source";
|
|
2741
|
+
}
|
|
2742
|
+
/** A key prod has and dev does not, for the missing-keys check; archived once checked. */
|
|
2743
|
+
const PROD_ONLY = "CONFORMANCE_PROD_ONLY";
|
|
2744
|
+
/**
|
|
2745
|
+
* Key names are metadata: what dev is missing is compared only with the
|
|
2746
|
+
* environments the viewer reads. The admin sees prod's key missing from dev;
|
|
2747
|
+
* the reader, a viewer on dev alone, sees nothing of prod, and dismisses
|
|
2748
|
+
* nothing. A dismissal is the team's, and restoring undoes it.
|
|
2749
|
+
*/
|
|
2750
|
+
async function missingKeys({ admin, reader }) {
|
|
2751
|
+
await admin.api.secrets.set(PROD, { [PROD_ONLY]: canary() });
|
|
2752
|
+
try {
|
|
2753
|
+
const seen = await admin.api.environments.missing(DEV);
|
|
2754
|
+
expect(seen.missing.some((key) => key.key === PROD_ONLY), "the admin was not told dev lacks prod's key", seen);
|
|
2755
|
+
const hidden = await reader.api.environments.missing(DEV);
|
|
2756
|
+
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);
|
|
2757
|
+
await refused$1("a viewer dismissed a missing key", reader.api.environments.dismiss(DEV, { [PROD_ONLY]: true }));
|
|
2758
|
+
await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: true });
|
|
2759
|
+
const dismissed = await admin.api.environments.missing(DEV);
|
|
2760
|
+
expect(dismissed.dismissed.some((key) => key.key === PROD_ONLY) && !dismissed.missing.some((key) => key.key === PROD_ONLY), "a dismissed key was still listed as missing", dismissed);
|
|
2761
|
+
await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: null });
|
|
2762
|
+
expect((await admin.api.environments.missing(DEV)).missing.some((key) => key.key === PROD_ONLY), "a restored key was not missing again");
|
|
2763
|
+
} finally {
|
|
2764
|
+
await admin.api.secrets.update(`${PROD}/${PROD_ONLY}`, { archived: true });
|
|
2765
|
+
}
|
|
2766
|
+
return "only who reads prod learns what dev lacks of it; a viewer dismisses nothing; a dismissal is listed, and restored";
|
|
2767
|
+
}
|
|
2768
|
+
//#endregion
|
|
1766
2769
|
//#region src/checks/logins.ts
|
|
1767
2770
|
const ZEROS = "decode(repeat('00', 32), 'hex')";
|
|
1768
2771
|
const appendAs = (author) => `INSERT INTO audit_log
|
|
@@ -1962,11 +2965,19 @@ function getCalls({ places, secrets, members, services }) {
|
|
|
1962
2965
|
"GET /me": [{ params: {} }],
|
|
1963
2966
|
"GET /projects": [{ params: {} }],
|
|
1964
2967
|
"GET /secrets/:project/:environment": places.map((params) => ({ params })),
|
|
2968
|
+
"GET /projects/:project/:environment/missing": places.map((params) => ({ params })),
|
|
1965
2969
|
"GET /secrets/:project/:environment/:key/versions": secrets.map((params) => ({ params })),
|
|
1966
2970
|
"GET /members": [{ params: {} }, ...first === void 0 ? [] : [{
|
|
1967
2971
|
params: {},
|
|
1968
2972
|
input: { path: `${first.project}/${first.environment}` }
|
|
1969
2973
|
}]],
|
|
2974
|
+
"GET /references": [...first === void 0 ? [] : [{
|
|
2975
|
+
params: {},
|
|
2976
|
+
input: { path: first.project }
|
|
2977
|
+
}, {
|
|
2978
|
+
params: {},
|
|
2979
|
+
input: { path: `${first.project}/${first.environment}` }
|
|
2980
|
+
}]],
|
|
1970
2981
|
"GET /members/:member": members.map((member) => ({ params: { member } })),
|
|
1971
2982
|
"GET /members/:member/tokens": services.map((member) => ({ params: { member } })),
|
|
1972
2983
|
"GET /members/:member/bindings": services.map((member) => ({ params: { member } })),
|
|
@@ -1977,6 +2988,15 @@ function getCalls({ places, secrets, members, services }) {
|
|
|
1977
2988
|
"GET /sessions": [{ params: {} }],
|
|
1978
2989
|
"GET /identities": [{ params: {} }],
|
|
1979
2990
|
"GET /device-logins/:code": [{ params: { code: "BCDF-GHJK" } }],
|
|
2991
|
+
"GET /oauth/authorizations": [{
|
|
2992
|
+
params: {},
|
|
2993
|
+
input: {
|
|
2994
|
+
client_id: "00000000-0000-4000-8000-000000000000",
|
|
2995
|
+
redirect_uri: "https://conformance.invalid/callback"
|
|
2996
|
+
}
|
|
2997
|
+
}],
|
|
2998
|
+
"GET /approvals/:id": [{ params: { id: "00000000-0000-4000-8000-000000000000" } }],
|
|
2999
|
+
"GET /apps": [{ params: {} }],
|
|
1980
3000
|
"GET /audit": [{
|
|
1981
3001
|
params: {},
|
|
1982
3002
|
input: { limit: 500 }
|
|
@@ -2031,8 +3051,8 @@ function calls(people) {
|
|
|
2031
3051
|
people.reader,
|
|
2032
3052
|
people.leaver,
|
|
2033
3053
|
people.bulk
|
|
2034
|
-
].map((person) => person.member), SERVICE],
|
|
2035
|
-
services: [SERVICE]
|
|
3054
|
+
].map((person) => person.member), SERVICE$2],
|
|
3055
|
+
services: [SERVICE$2]
|
|
2036
3056
|
});
|
|
2037
3057
|
}
|
|
2038
3058
|
function pages(people) {
|
|
@@ -2047,21 +3067,30 @@ function pages(people) {
|
|
|
2047
3067
|
"/login",
|
|
2048
3068
|
"/unregistered",
|
|
2049
3069
|
"/account",
|
|
2050
|
-
"/access",
|
|
2051
3070
|
"/audit",
|
|
2052
3071
|
"/settings",
|
|
2053
3072
|
"/auth/device",
|
|
3073
|
+
"/oauth/authorize",
|
|
2054
3074
|
"/projects",
|
|
2055
|
-
|
|
3075
|
+
...[
|
|
3076
|
+
"",
|
|
3077
|
+
"/users",
|
|
3078
|
+
"/service-accounts",
|
|
3079
|
+
"/settings"
|
|
3080
|
+
].map((tab) => `/projects/${PROJECT$1}${tab}`),
|
|
2056
3081
|
...[
|
|
2057
3082
|
DEV,
|
|
2058
3083
|
PROD,
|
|
2059
3084
|
BULK
|
|
2060
3085
|
].map((path) => `/projects/${path}`),
|
|
2061
3086
|
"/users",
|
|
2062
|
-
...users.
|
|
2063
|
-
"/
|
|
2064
|
-
|
|
3087
|
+
...users.flatMap((person) => ["", "/activity"].map((tab) => `/users/${encodeURIComponent(person.email)}${tab}`)),
|
|
3088
|
+
"/service-accounts",
|
|
3089
|
+
...[
|
|
3090
|
+
"",
|
|
3091
|
+
"/access",
|
|
3092
|
+
"/activity"
|
|
3093
|
+
].map((tab) => `/service-accounts/${SERVICE$2.slice(6)}${tab}`)
|
|
2065
3094
|
];
|
|
2066
3095
|
}
|
|
2067
3096
|
async function canaryScan(deployment, people, canaries) {
|
|
@@ -2339,7 +3368,7 @@ async function verifyInterrupted(cli, admin) {
|
|
|
2339
3368
|
* else changed; the runs' reads are in the audit log.
|
|
2340
3369
|
*/
|
|
2341
3370
|
async function verifyLeftovers(cli, admin, setups, before, kept) {
|
|
2342
|
-
expect(setups[0].includes(`the service ${PROBE.service}`), "the first run did not make its service", setups[0]);
|
|
3371
|
+
expect(setups[0].includes(`the service account ${PROBE.service.replace(/^token:/, "service:")}`), "the first run did not make its service account", setups[0]);
|
|
2343
3372
|
expect(setups.slice(1).every((line) => line.startsWith("all found")), "a later run made something again", setups);
|
|
2344
3373
|
const { tokens } = await admin.api.tokens.list(PROBE.service);
|
|
2345
3374
|
expect(tokens.length === 0, `${PROBE.service} still holds ${tokens.length} credential(s)`, tokens);
|
|
@@ -2456,12 +3485,13 @@ async function manageByCli(cli) {
|
|
|
2456
3485
|
"ci",
|
|
2457
3486
|
"--service"
|
|
2458
3487
|
], void 0, 1);
|
|
2459
|
-
expect(refused.includes("admit them first, `coffre admit conformance-deploy
|
|
3488
|
+
expect(refused.includes("admit them first, `coffre admit service:conformance-deploy`"), "grant to a service not yet admitted did not say to admit it", refused);
|
|
2460
3489
|
const admitted = await coffre([
|
|
2461
3490
|
"admit",
|
|
2462
3491
|
"conformance-deploy",
|
|
2463
3492
|
"--service"
|
|
2464
3493
|
]);
|
|
3494
|
+
expect(admitted.includes("admitted service:conformance-deploy") && !admitted.includes("token:"), "admit --service did not name the service account as service:<name>", admitted);
|
|
2465
3495
|
expect(admitted.includes("next: coffre grant <project> conformance-deploy"), "admit --service did not say what comes next", admitted);
|
|
2466
3496
|
await coffre([
|
|
2467
3497
|
"grant",
|
|
@@ -2517,7 +3547,7 @@ async function manageByCli(cli) {
|
|
|
2517
3547
|
"--apply"
|
|
2518
3548
|
]);
|
|
2519
3549
|
const gone = await service(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
|
|
2520
|
-
expect(/does not know this
|
|
3550
|
+
expect(/does not know this bearer token/.test(gone), "a revoked token was not refused plainly", gone);
|
|
2521
3551
|
await coffre([
|
|
2522
3552
|
"revoke",
|
|
2523
3553
|
"conformance-cli",
|
|
@@ -2549,6 +3579,8 @@ async function manageByCli(cli) {
|
|
|
2549
3579
|
}
|
|
2550
3580
|
//#endregion
|
|
2551
3581
|
//#region src/chrome.ts
|
|
3582
|
+
/** How long one DevTools call may take: a Chrome stalled on a loaded host fails the call rather than hang whoever waits on it. */
|
|
3583
|
+
const ANSWER_MS = 6e4;
|
|
2552
3584
|
const NAMES = [
|
|
2553
3585
|
"google-chrome",
|
|
2554
3586
|
"google-chrome-stable",
|
|
@@ -2636,9 +3668,17 @@ var Chrome = class Chrome {
|
|
|
2636
3668
|
#send(method, params = {}, sessionId) {
|
|
2637
3669
|
const id = ++this.#next;
|
|
2638
3670
|
return new Promise((resolve, reject) => {
|
|
3671
|
+
const timer = setTimeout(() => {
|
|
3672
|
+
this.#pending.delete(id);
|
|
3673
|
+
reject(/* @__PURE__ */ new Error(`Chrome did not answer ${method} within ${ANSWER_MS / 1e3} s`));
|
|
3674
|
+
}, ANSWER_MS);
|
|
3675
|
+
const settled = (then) => (value) => {
|
|
3676
|
+
clearTimeout(timer);
|
|
3677
|
+
then(value);
|
|
3678
|
+
};
|
|
2639
3679
|
this.#pending.set(id, {
|
|
2640
|
-
resolve,
|
|
2641
|
-
reject
|
|
3680
|
+
resolve: settled(resolve),
|
|
3681
|
+
reject: settled(reject)
|
|
2642
3682
|
});
|
|
2643
3683
|
this.#socket.send(JSON.stringify({
|
|
2644
3684
|
id,
|
|
@@ -2651,9 +3691,11 @@ var Chrome = class Chrome {
|
|
|
2651
3691
|
/**
|
|
2652
3692
|
* `url` in a tab of its own, with `cookies` for its origin: the heading it
|
|
2653
3693
|
* shows once its scripts have run and settled, and every uncaught error,
|
|
2654
|
-
* console error and failed load along the way.
|
|
3694
|
+
* console error and failed load along the way. `then`, a script run once
|
|
3695
|
+
* the page settles, does what a person would next, such as open a dialog,
|
|
3696
|
+
* whose text is read with the rest.
|
|
2655
3697
|
*/
|
|
2656
|
-
async load(url, cookies, settle = 2e3) {
|
|
3698
|
+
async load(url, cookies, settle = 2e3, then) {
|
|
2657
3699
|
const { targetId } = await this.#send("Target.createTarget", { url: "about:blank" });
|
|
2658
3700
|
const { sessionId } = await this.#send("Target.attachToTarget", {
|
|
2659
3701
|
targetId,
|
|
@@ -2692,12 +3734,26 @@ var Chrome = class Chrome {
|
|
|
2692
3734
|
await this.#send("Page.navigate", { url }, sessionId);
|
|
2693
3735
|
await Promise.race([load, new Promise((resolve) => setTimeout(resolve, 3e4))]);
|
|
2694
3736
|
await new Promise((resolve) => setTimeout(resolve, settle));
|
|
3737
|
+
if (then !== void 0) {
|
|
3738
|
+
await this.#send("Runtime.evaluate", {
|
|
3739
|
+
expression: then,
|
|
3740
|
+
awaitPromise: true
|
|
3741
|
+
}, sessionId);
|
|
3742
|
+
await new Promise((resolve) => setTimeout(resolve, settle));
|
|
3743
|
+
}
|
|
2695
3744
|
const { result } = await this.#send("Runtime.evaluate", {
|
|
2696
|
-
expression:
|
|
3745
|
+
expression: `({
|
|
3746
|
+
heading: document.querySelector('h1')?.textContent?.trim() || null,
|
|
3747
|
+
tab: document.querySelector('.tabs [aria-current=page]')?.textContent?.trim() || null,
|
|
3748
|
+
cards: [...document.querySelectorAll('h2.card-title')].map((title) => title.textContent.trim()),
|
|
3749
|
+
text: document.body.innerText,
|
|
3750
|
+
href: location.href,
|
|
3751
|
+
dialog: document.querySelector('[role=alertdialog], [role=dialog]')?.innerText ?? null,
|
|
3752
|
+
})`,
|
|
2697
3753
|
returnByValue: true
|
|
2698
3754
|
}, sessionId);
|
|
2699
3755
|
return {
|
|
2700
|
-
|
|
3756
|
+
...result.value,
|
|
2701
3757
|
errors
|
|
2702
3758
|
};
|
|
2703
3759
|
} finally {
|
|
@@ -2720,26 +3776,231 @@ var Chrome = class Chrome {
|
|
|
2720
3776
|
};
|
|
2721
3777
|
//#endregion
|
|
2722
3778
|
//#region src/checks/pages.ts
|
|
2723
|
-
/** Each page, and the
|
|
3779
|
+
/** Each page, the heading it shows, and the tab it is, for a page with tabs. */
|
|
2724
3780
|
const PAGES = [
|
|
2725
|
-
[
|
|
2726
|
-
|
|
2727
|
-
|
|
3781
|
+
[
|
|
3782
|
+
"/projects",
|
|
3783
|
+
"Projects",
|
|
3784
|
+
null
|
|
3785
|
+
],
|
|
3786
|
+
[
|
|
3787
|
+
`/projects/${PROJECT$1}`,
|
|
3788
|
+
"Conformance",
|
|
3789
|
+
"Environments"
|
|
3790
|
+
],
|
|
3791
|
+
[
|
|
3792
|
+
`/projects/${PROJECT$1}/users`,
|
|
3793
|
+
"Conformance",
|
|
3794
|
+
"Users"
|
|
3795
|
+
],
|
|
3796
|
+
[
|
|
3797
|
+
`/projects/${PROJECT$1}/service-accounts`,
|
|
3798
|
+
"Conformance",
|
|
3799
|
+
"Service accounts"
|
|
3800
|
+
],
|
|
3801
|
+
[
|
|
3802
|
+
`/projects/${PROJECT$1}/settings`,
|
|
3803
|
+
"Conformance",
|
|
3804
|
+
"Settings"
|
|
3805
|
+
],
|
|
3806
|
+
[
|
|
3807
|
+
"/audit",
|
|
3808
|
+
"Audit",
|
|
3809
|
+
null
|
|
3810
|
+
]
|
|
2728
3811
|
];
|
|
2729
|
-
|
|
3812
|
+
/**
|
|
3813
|
+
* A project's tabs walked as a person would: Users, then Settings, by their
|
|
3814
|
+
* links, then back twice and forward once, which ends on Users.
|
|
3815
|
+
*/
|
|
3816
|
+
const WALK_TABS = `(async () => {
|
|
3817
|
+
const wait = () => new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3818
|
+
const open = (label) => [...document.querySelectorAll('.tabs a')].find((link) => link.textContent.trim() === label)?.click();
|
|
3819
|
+
open('Users');
|
|
3820
|
+
await wait();
|
|
3821
|
+
open('Settings');
|
|
3822
|
+
await wait();
|
|
3823
|
+
history.back();
|
|
3824
|
+
await wait();
|
|
3825
|
+
history.back();
|
|
3826
|
+
await wait();
|
|
3827
|
+
history.forward();
|
|
3828
|
+
})()`;
|
|
3829
|
+
/**
|
|
3830
|
+
* A menu item's dialog opened as a person would: the menu by its button,
|
|
3831
|
+
* then the item, by its words. Base UI's menu opens on a pointer press, not
|
|
3832
|
+
* a bare click.
|
|
3833
|
+
*/
|
|
3834
|
+
const openFromMenu = (menu, item) => `(async () => {
|
|
3835
|
+
const press = { bubbles: true, cancelable: true, pointerType: 'mouse', button: 0 };
|
|
3836
|
+
const trigger = document.querySelector(${JSON.stringify(menu)});
|
|
3837
|
+
for (const [Kind, type] of [[PointerEvent, 'pointerdown'], [MouseEvent, 'mousedown'], [PointerEvent, 'pointerup'], [MouseEvent, 'mouseup'], [MouseEvent, 'click']]) {
|
|
3838
|
+
trigger?.dispatchEvent(new Kind(type, press));
|
|
3839
|
+
}
|
|
3840
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
3841
|
+
[...document.querySelectorAll('[role=menuitem]')].find((entry) => entry.textContent.includes(${JSON.stringify(item)}))?.click();
|
|
3842
|
+
})()`;
|
|
3843
|
+
/** A service account of the pages' own, whose page shows how it signs in. */
|
|
3844
|
+
const SERVICE = "token:conformance-pages";
|
|
3845
|
+
const CONSENT_CLIENT = "Conformance pages client";
|
|
3846
|
+
/** A registered client's authorization request, as the consent page receives it. */
|
|
3847
|
+
async function consentUrl(deployment) {
|
|
3848
|
+
const redirect = "http://127.0.0.1:33419/callback";
|
|
3849
|
+
const registered = await fetch(`${deployment.origin}/api/oauth/register`, {
|
|
3850
|
+
method: "POST",
|
|
3851
|
+
headers: { "content-type": "application/json" },
|
|
3852
|
+
body: JSON.stringify({
|
|
3853
|
+
client_name: CONSENT_CLIENT,
|
|
3854
|
+
redirect_uris: [redirect]
|
|
3855
|
+
})
|
|
3856
|
+
});
|
|
3857
|
+
const { client_id: clientId } = await registered.json();
|
|
3858
|
+
expect(registered.status === 201 && clientId !== void 0, `registering an MCP client answered ${registered.status}`);
|
|
3859
|
+
const request = new URLSearchParams({
|
|
3860
|
+
client_id: clientId,
|
|
3861
|
+
redirect_uri: redirect,
|
|
3862
|
+
response_type: "code",
|
|
3863
|
+
code_challenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
|
|
3864
|
+
code_challenge_method: "S256",
|
|
3865
|
+
state: "pages",
|
|
3866
|
+
scope: "browse write"
|
|
3867
|
+
});
|
|
3868
|
+
return `${deployment.origin}/oauth/authorize?${request}`;
|
|
3869
|
+
}
|
|
3870
|
+
/** The Chrome to run, the one given or the one found; skips the check when there is none. */
|
|
3871
|
+
function chromeOrSkip(browser) {
|
|
2730
3872
|
const executable = browser ?? findChrome();
|
|
2731
3873
|
if (executable === null) throw new Skip("no Chrome or Chromium here: --browser <path> names one");
|
|
3874
|
+
return executable;
|
|
3875
|
+
}
|
|
3876
|
+
async function pagesInBrowser(deployment, admin, browser) {
|
|
3877
|
+
const executable = chromeOrSkip(browser);
|
|
3878
|
+
await admin.api.members.add(SERVICE);
|
|
3879
|
+
const name = SERVICE.slice(6);
|
|
3880
|
+
const account = `/service-accounts/${name}`;
|
|
3881
|
+
const person = `/users/${encodeURIComponent(admin.email)}`;
|
|
3882
|
+
const pages = [
|
|
3883
|
+
...PAGES,
|
|
3884
|
+
[
|
|
3885
|
+
"/settings",
|
|
3886
|
+
"Settings",
|
|
3887
|
+
null
|
|
3888
|
+
],
|
|
3889
|
+
[
|
|
3890
|
+
person,
|
|
3891
|
+
admin.email,
|
|
3892
|
+
"Access"
|
|
3893
|
+
],
|
|
3894
|
+
[
|
|
3895
|
+
`${person}/activity`,
|
|
3896
|
+
admin.email,
|
|
3897
|
+
"Activity"
|
|
3898
|
+
],
|
|
3899
|
+
[
|
|
3900
|
+
"/service-accounts",
|
|
3901
|
+
"Service accounts",
|
|
3902
|
+
null
|
|
3903
|
+
],
|
|
3904
|
+
[
|
|
3905
|
+
account,
|
|
3906
|
+
`service:${name}`,
|
|
3907
|
+
"Sign-in"
|
|
3908
|
+
],
|
|
3909
|
+
[
|
|
3910
|
+
`${account}/activity`,
|
|
3911
|
+
`service:${name}`,
|
|
3912
|
+
"Activity"
|
|
3913
|
+
]
|
|
3914
|
+
];
|
|
2732
3915
|
const chrome = await Chrome.open(executable);
|
|
2733
3916
|
try {
|
|
2734
|
-
for (const [path, heading] of
|
|
2735
|
-
const
|
|
3917
|
+
for (const [path, heading, tab] of pages) {
|
|
3918
|
+
const then = path === account ? openFromMenu("button[aria-label^=\"Actions for\"]", "Remove") : void 0;
|
|
3919
|
+
const loaded = await chrome.load(new URL(path, deployment.origin).href, admin.browser.cookies(), void 0, then);
|
|
2736
3920
|
expect(loaded.errors.length === 0, `${path}, signed in, reported errors in the browser`, loaded.errors.join("\n"));
|
|
2737
3921
|
expect(loaded.heading?.startsWith(heading), `${path}, signed in, shows ${JSON.stringify(loaded.heading)}, not the heading ${JSON.stringify(heading)}`);
|
|
3922
|
+
expect(loaded.tab === tab, `${path}, signed in, shows the tab ${JSON.stringify(loaded.tab)}, not ${JSON.stringify(tab)}`);
|
|
3923
|
+
if (path.startsWith("/service-accounts")) expect(!/(?<![\w-])token:[A-Za-z0-9]/.test(loaded.text), `${path} shows a service account as token:<name>`, loaded.text);
|
|
3924
|
+
if (path === account) {
|
|
3925
|
+
expect(loaded.cards.filter((title) => title === "Sign in with OIDC" || title === "Bearer tokens").join(" then ") === "Sign in with OIDC then Bearer tokens", `${path} does not show OIDC, then bearer tokens`, loaded.cards);
|
|
3926
|
+
expect(loaded.dialog?.includes("Removing revokes 0 grants, 0 bearer tokens") === true, `${path}: Remove… does not preview what it would revoke`, loaded.dialog);
|
|
3927
|
+
}
|
|
3928
|
+
if (path === "/settings") expect(loaded.cards.includes("Keys"), "/settings does not show what the keys are checked against", loaded.cards);
|
|
3929
|
+
if (path === person) expect(loaded.cards.includes("Connected apps"), `${path} does not show an owner the person's connected apps`, loaded.cards);
|
|
3930
|
+
}
|
|
3931
|
+
const project = new URL(`/projects/${PROJECT$1}`, deployment.origin).href;
|
|
3932
|
+
const walked = await chrome.load(project, admin.browser.cookies(), void 0, WALK_TABS);
|
|
3933
|
+
expect(walked.errors.length === 0, `${project}'s tabs reported errors in the browser`, walked.errors.join("\n"));
|
|
3934
|
+
expect(walked.href === `${project}/users` && walked.tab === "Users", `Users, Settings, back, back and forward from ${project} ended on ${walked.href}, the tab ${JSON.stringify(walked.tab)}`);
|
|
3935
|
+
const access = `${account}/access`;
|
|
3936
|
+
await admin.api.access.set(SERVICE, { "*/dev": "viewer" });
|
|
3937
|
+
try {
|
|
3938
|
+
const loaded = await chrome.load(new URL(access, deployment.origin).href, admin.browser.cookies());
|
|
3939
|
+
expect(loaded.errors.length === 0, `${access} reported errors in the browser`, loaded.errors.join("\n"));
|
|
3940
|
+
expect(loaded.tab === "Access", `${access} shows the tab ${JSON.stringify(loaded.tab)}, not "Access"`);
|
|
3941
|
+
for (const shown of ["dev in every project", "Grant on every project"]) expect(loaded.text.includes(shown), `${access}, to an owner, does not show "${shown}"`, loaded.text);
|
|
3942
|
+
} finally {
|
|
3943
|
+
await admin.api.access.set(SERVICE, { "*/dev": null });
|
|
2738
3944
|
}
|
|
3945
|
+
const consent = await consentUrl(deployment);
|
|
3946
|
+
const loaded = await chrome.load(consent, admin.browser.cookies());
|
|
3947
|
+
expect(loaded.errors.length === 0, "/oauth/authorize reported errors in the browser", loaded.errors.join("\n"));
|
|
3948
|
+
expect(loaded.heading === `Connect ${CONSENT_CLIENT} to coffre?`, `/oauth/authorize shows ${JSON.stringify(loaded.heading)}`);
|
|
3949
|
+
for (const shown of [
|
|
3950
|
+
"Unverified",
|
|
3951
|
+
"localhost",
|
|
3952
|
+
admin.email,
|
|
3953
|
+
"Browse",
|
|
3954
|
+
"Approve",
|
|
3955
|
+
"Deny"
|
|
3956
|
+
]) expect(loaded.text.includes(shown), `/oauth/authorize does not show "${shown}"`, loaded.text);
|
|
2739
3957
|
} finally {
|
|
2740
3958
|
await chrome.close();
|
|
2741
3959
|
}
|
|
2742
|
-
return `${
|
|
3960
|
+
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 in every project with an owner's grant button; the MCP consent page, a registered client shown as unverified`;
|
|
3961
|
+
}
|
|
3962
|
+
/**
|
|
3963
|
+
* A refused sign-in, said once: the page coffre sends the browser back to
|
|
3964
|
+
* shows why, rendered by the server, then takes it out of the address, so a
|
|
3965
|
+
* reload is a clean retry. The refusal is a real one: a member's address
|
|
3966
|
+
* that GitHub now gives another account, which names the provider the
|
|
3967
|
+
* address already signs in with.
|
|
3968
|
+
*/
|
|
3969
|
+
async function signinErrorOnce(deployment, admin, browser) {
|
|
3970
|
+
const executable = chromeOrSkip(browser);
|
|
3971
|
+
const email = "recycled@conformance.example";
|
|
3972
|
+
await admin.api.members.add(`user:${email}`);
|
|
3973
|
+
const first = await signIn(deployment, new Browser(deployment.origin), email);
|
|
3974
|
+
expect(first.ok, `${email} was refused before anything changed: ${"error" in first ? first.error : ""}`);
|
|
3975
|
+
deployment.idp.setGitHubUser(email, { id: deployment.idp.gitHubUserFor(email).id + 1e6 });
|
|
3976
|
+
const visitor = new Browser(deployment.origin);
|
|
3977
|
+
const refused = await signIn(deployment, visitor, email);
|
|
3978
|
+
expect(!refused.ok && refused.error === "account_mismatch", "another GitHub account with a member's address was not refused as account_mismatch", refused);
|
|
3979
|
+
const back = new URL(refused.location, deployment.origin);
|
|
3980
|
+
expect(back.searchParams.get("with") === "github", `the refusal does not name the provider the address signs in with: ${refused.location}`);
|
|
3981
|
+
const said = "already signs in with another GitHub account";
|
|
3982
|
+
const html = await visitor.fetch(refused.location);
|
|
3983
|
+
expect(html.status === 200 && (await html.text()).includes(said), `${refused.location}, without scripts, does not say the address ${said}`, html.status);
|
|
3984
|
+
const chrome = await Chrome.open(executable);
|
|
3985
|
+
let clean;
|
|
3986
|
+
try {
|
|
3987
|
+
const shown = await chrome.load(back.href, visitor.cookies());
|
|
3988
|
+
expect(shown.errors.length === 0, `${refused.location} reported errors in the browser`, shown.errors.join("\n"));
|
|
3989
|
+
expect(shown.text.includes(said), `${refused.location} does not say the address ${said}`, shown.text);
|
|
3990
|
+
const after = new URL(shown.href);
|
|
3991
|
+
clean = `${after.pathname}${after.search}`;
|
|
3992
|
+
expect([
|
|
3993
|
+
"error",
|
|
3994
|
+
"with",
|
|
3995
|
+
"via"
|
|
3996
|
+
].every((name) => !after.searchParams.has(name)), `${refused.location} kept the refusal in its address`, shown.href);
|
|
3997
|
+
const reloaded = await chrome.load(shown.href, visitor.cookies());
|
|
3998
|
+
expect(!reloaded.text.includes(said), `${clean}, reloaded, still says the address ${said}`, reloaded.text);
|
|
3999
|
+
expect(reloaded.heading !== null, `${clean}, reloaded, rendered no heading`);
|
|
4000
|
+
} finally {
|
|
4001
|
+
await chrome.close();
|
|
4002
|
+
}
|
|
4003
|
+
return `${refused.location}: said by the server, once: Chrome then shows ${clean}, and a reload shows no error`;
|
|
2743
4004
|
}
|
|
2744
4005
|
/** What only server code carries. */
|
|
2745
4006
|
const MARKERS = [
|
|
@@ -2752,6 +4013,11 @@ const MARKERS = [
|
|
|
2752
4013
|
"audit_log",
|
|
2753
4014
|
"consumed_tokens",
|
|
2754
4015
|
"device_authorizations",
|
|
4016
|
+
"dismissed_keys",
|
|
4017
|
+
"mcp_approvals",
|
|
4018
|
+
"mcp_connections",
|
|
4019
|
+
"oauth_clients",
|
|
4020
|
+
"secret_references",
|
|
2755
4021
|
"secret_versions",
|
|
2756
4022
|
"service_bindings",
|
|
2757
4023
|
"vault_grants",
|
|
@@ -2941,6 +4207,7 @@ function twin(jwt) {
|
|
|
2941
4207
|
}
|
|
2942
4208
|
/** A viewer on dev, and a binding that trusts deploy.yml pushed to main of acme/api. */
|
|
2943
4209
|
async function trustRun(deployment, admin) {
|
|
4210
|
+
if (!(await admin.api.me()).features.workloads) throw new Skip("this deployment trusts no workloads: its signin({ workloads }) is off");
|
|
2944
4211
|
await admin.api.members.add(RUNNER);
|
|
2945
4212
|
await admin.api.access.set(RUNNER, { [DEV]: "viewer" });
|
|
2946
4213
|
const made = await admin.api.bindings.create(RUNNER, {
|
|
@@ -2948,9 +4215,6 @@ async function trustRun(deployment, admin) {
|
|
|
2948
4215
|
issuer: deployment.idp.workloads.issuer,
|
|
2949
4216
|
claims: DEPLOY,
|
|
2950
4217
|
label: "conformance"
|
|
2951
|
-
}).catch((error) => {
|
|
2952
|
-
if (error.status === 404) throw new Skip(`this deployment trusts no workloads: ${error.message}`);
|
|
2953
|
-
throw error;
|
|
2954
4218
|
});
|
|
2955
4219
|
return {
|
|
2956
4220
|
detail: `${RUNNER}, viewer on ${DEV}, trusts deploy.yml pushed to main of acme/api, from the dev IdP`,
|
|
@@ -3156,6 +4420,7 @@ async function conform(deployment, options) {
|
|
|
3156
4420
|
admin,
|
|
3157
4421
|
canaries
|
|
3158
4422
|
}, ({ admin }) => pagesInBrowser(deployment, admin, options.browser));
|
|
4423
|
+
await report.check("sign-in error, once", { admin }, ({ admin }) => signinErrorOnce(deployment, admin, options.browser));
|
|
3159
4424
|
const people = await report.check("personas", {
|
|
3160
4425
|
admin,
|
|
3161
4426
|
canaries
|
|
@@ -3166,6 +4431,14 @@ async function conform(deployment, options) {
|
|
|
3166
4431
|
};
|
|
3167
4432
|
await report.check("members only", { people }, ({ people }) => membersOnly(deployment, people));
|
|
3168
4433
|
await report.check("grant scoping", all, ({ people, canaries }) => grantScoping(people, canaries));
|
|
4434
|
+
await report.check("folders", all, ({ people, canaries }) => folders(people, canaries));
|
|
4435
|
+
await report.check("forks", all, ({ people, canaries }) => forks(people, canaries));
|
|
4436
|
+
await report.check("references", all, ({ people, canaries }) => references(deployment, people, canaries));
|
|
4437
|
+
await report.check("missing keys", { people }, ({ people }) => missingKeys(people));
|
|
4438
|
+
await report.check("MCP connect", { people }, ({ people }) => mcpConnect(deployment, people));
|
|
4439
|
+
await report.check("MCP browse", all, ({ people, canaries }) => mcpBrowse(deployment, people, canaries));
|
|
4440
|
+
await report.check("MCP changes", all, ({ people, canaries }) => mcpChanges(deployment, people, canaries));
|
|
4441
|
+
await report.check("MCP values", all, ({ people, canaries }) => mcpValues(deployment, people, canaries));
|
|
3169
4442
|
await report.check("reveals audited", all, ({ people, canaries }) => revealAudited(deployment, people, canaries, "reveal"));
|
|
3170
4443
|
await report.check("runs audited", all, ({ people, canaries }) => revealAudited(deployment, people, canaries, "run"));
|
|
3171
4444
|
await report.check("cross-site", all, ({ people, canaries }) => crossSite(people, canaries));
|
|
@@ -3210,10 +4483,15 @@ async function conform(deployment, options) {
|
|
|
3210
4483
|
}, ({ admin, owner, before, first, second, live }) => verifyLeftovers(owner, admin, [first, second], before, live.canary));
|
|
3211
4484
|
await report.check("verify keys", { owner }, ({ owner }) => verifyKeys(owner));
|
|
3212
4485
|
await report.check("manage by CLI", { owner }, ({ owner }) => manageByCli(owner));
|
|
4486
|
+
await report.check("delete by CLI", {
|
|
4487
|
+
owner,
|
|
4488
|
+
admin
|
|
4489
|
+
}, ({ owner, admin }) => deletion(deployment, owner, admin));
|
|
3213
4490
|
} finally {
|
|
3214
4491
|
for (const cli of clis) cli.remove();
|
|
3215
4492
|
}
|
|
3216
4493
|
await report.check("offboarding", all, ({ people, canaries }) => offboarding(deployment, people, canaries));
|
|
4494
|
+
await report.check("grants on every project", all, ({ people, canaries }) => everyProject(deployment, people, canaries));
|
|
3217
4495
|
await report.check("bulk limit", { people }, ({ people }) => bulkLimit$1(people, options.bulkLimit));
|
|
3218
4496
|
const binding = await report.check("trust a run", { admin }, ({ admin }) => trustRun(deployment, admin));
|
|
3219
4497
|
const credential = await report.check("run signs in", {
|