@coffre/ui 0.4.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/chunks/{affordances-DAvsVz7u.js → affordances-Bqdevf7w.js} +10 -5
  2. package/dist/chunks/affordances-Bqdevf7w.js.map +1 -0
  3. package/dist/chunks/{audit-sentence-DIztXvbU.js → audit-sentence-Cm5nby5k.js} +105 -7
  4. package/dist/chunks/audit-sentence-Cm5nby5k.js.map +1 -0
  5. package/dist/chunks/{connected-apps-AZsX9Zvv.js → connected-apps-DTNS7YmY.js} +2 -2
  6. package/dist/chunks/{connected-apps-AZsX9Zvv.js.map → connected-apps-DTNS7YmY.js.map} +1 -1
  7. package/dist/chunks/{delete-place-D6LIZkg9.js → delete-place-CIaOq0mt.js} +3 -3
  8. package/dist/chunks/{delete-place-D6LIZkg9.js.map → delete-place-CIaOq0mt.js.map} +1 -1
  9. package/dist/chunks/{directory-B6FuiCir.js → directory-DSVt5Tya.js} +54 -60
  10. package/dist/chunks/directory-DSVt5Tya.js.map +1 -0
  11. package/dist/chunks/{folders-DvSqBhuu.js → folders-CoGK9oqg.js} +2 -2
  12. package/dist/chunks/{folders-DvSqBhuu.js.map → folders-CoGK9oqg.js.map} +1 -1
  13. package/dist/chunks/grants-CRU7yZhL.js +164 -0
  14. package/dist/chunks/grants-CRU7yZhL.js.map +1 -0
  15. package/dist/chunks/{offboarding-CLJaNTcD.js → offboarding-DVBSiJRZ.js} +7 -3
  16. package/dist/chunks/offboarding-DVBSiJRZ.js.map +1 -0
  17. package/dist/chunks/{principal-page-1yMztIcc.js → principal-page-BEBr_zW7.js} +350 -91
  18. package/dist/chunks/principal-page-BEBr_zW7.js.map +1 -0
  19. package/dist/chunks/{project-page-C4cEaRFa.js → project-page-B3TZ5_ig.js} +2 -2
  20. package/dist/chunks/{project-page-C4cEaRFa.js.map → project-page-B3TZ5_ig.js.map} +1 -1
  21. package/dist/chunks/{queries-Dew8mIeo.js → queries-DE5nK2y4.js} +132 -54
  22. package/dist/chunks/queries-DE5nK2y4.js.map +1 -0
  23. package/dist/chunks/{references-DWDnXNoW.js → references-uv4Mli9z.js} +4 -3
  24. package/dist/chunks/{references-DWDnXNoW.js.map → references-uv4Mli9z.js.map} +1 -1
  25. package/dist/chunks/role-field-DWhkRY6n.js +192 -0
  26. package/dist/chunks/role-field-DWhkRY6n.js.map +1 -0
  27. package/dist/chunks/use-action-BRgvbUWt.js +49 -0
  28. package/dist/chunks/use-action-BRgvbUWt.js.map +1 -0
  29. package/dist/chunks/{use-change-C4bGRhHY.js → use-change-BJ3dCFHb.js} +40 -14
  30. package/dist/chunks/use-change-BJ3dCFHb.js.map +1 -0
  31. package/dist/chunks/{use-shell-Dkv89nW1.js → use-shell-BO4ZTr1y.js} +2 -2
  32. package/dist/chunks/{use-shell-Dkv89nW1.js.map → use-shell-BO4ZTr1y.js.map} +1 -1
  33. package/dist/chunks/validation-DiHIwZRA.js +37 -0
  34. package/dist/chunks/validation-DiHIwZRA.js.map +1 -0
  35. package/dist/index.d.ts +111 -88
  36. package/dist/index.js +40 -21
  37. package/dist/index.js.map +1 -1
  38. package/dist/pages/account.js +8 -7
  39. package/dist/pages/account.js.map +1 -1
  40. package/dist/pages/audit.js +2 -2
  41. package/dist/pages/environment.js +8 -7
  42. package/dist/pages/environment.js.map +1 -1
  43. package/dist/pages/login.js +2 -2
  44. package/dist/pages/login.js.map +1 -1
  45. package/dist/pages/project-access.js +7 -7
  46. package/dist/pages/project-environments.js +26 -21
  47. package/dist/pages/project-environments.js.map +1 -1
  48. package/dist/pages/project-settings.js +9 -8
  49. package/dist/pages/project-settings.js.map +1 -1
  50. package/dist/pages/project.js +1 -1
  51. package/dist/pages/projects.js +8 -13
  52. package/dist/pages/projects.js.map +1 -1
  53. package/dist/pages/service-account.js +294 -88
  54. package/dist/pages/service-account.js.map +1 -1
  55. package/dist/pages/service-accounts.js +7 -7
  56. package/dist/pages/service-accounts.js.map +1 -1
  57. package/dist/pages/settings.js +91 -9
  58. package/dist/pages/settings.js.map +1 -1
  59. package/dist/pages/unregistered.d.ts +1 -1
  60. package/dist/pages/unregistered.js +4 -4
  61. package/dist/pages/unregistered.js.map +1 -1
  62. package/dist/pages/user.d.ts +2 -0
  63. package/dist/pages/user.js +21 -3
  64. package/dist/pages/user.js.map +1 -1
  65. package/dist/pages/users.js +4 -4
  66. package/package.json +3 -3
  67. package/src/components/affordances.ts +7 -3
  68. package/src/components/command-palette.tsx +2 -0
  69. package/src/components/directory.tsx +58 -63
  70. package/src/components/grants.tsx +9 -9
  71. package/src/components/offboarding.tsx +3 -1
  72. package/src/components/principal-page.tsx +124 -74
  73. package/src/components/role-field.tsx +183 -0
  74. package/src/components/scope-picker.tsx +73 -0
  75. package/src/components/service-tokens.tsx +20 -9
  76. package/src/components/shell.tsx +6 -10
  77. package/src/components/trusted-workloads.tsx +121 -42
  78. package/src/index.ts +1 -0
  79. package/src/lib/audit-sentences.ts +104 -3
  80. package/src/lib/bindings.ts +33 -10
  81. package/src/lib/capabilities.ts +28 -8
  82. package/src/lib/changes.ts +22 -13
  83. package/src/lib/project-access.ts +21 -0
  84. package/src/lib/queries.ts +121 -44
  85. package/src/lib/service-setup.ts +41 -0
  86. package/src/lib/validation.ts +7 -0
  87. package/src/options.ts +31 -11
  88. package/src/pages/account.tsx +3 -2
  89. package/src/pages/login.tsx +1 -1
  90. package/src/pages/project-environments.tsx +12 -15
  91. package/src/pages/project-settings.tsx +3 -3
  92. package/src/pages/projects.tsx +1 -5
  93. package/src/pages/service-account.tsx +7 -5
  94. package/src/pages/service-accounts.tsx +8 -4
  95. package/src/pages/settings.tsx +80 -4
  96. package/src/pages/unregistered.tsx +3 -3
  97. package/src/pages/user.tsx +24 -1
  98. package/src/parity.ts +5 -1
  99. package/src/register.ts +3 -1
  100. package/src/shared/models.ts +8 -4
  101. package/src/styles/globals.css +100 -27
  102. package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
  103. package/dist/chunks/audit-sentence-DIztXvbU.js.map +0 -1
  104. package/dist/chunks/directory-B6FuiCir.js.map +0 -1
  105. package/dist/chunks/grants-9kIV6uZ7.js +0 -669
  106. package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
  107. package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
  108. package/dist/chunks/principal-page-1yMztIcc.js.map +0 -1
  109. package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
  110. package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
  111. package/dist/chunks/validation-DvPinn8V.js +0 -87
  112. package/dist/chunks/validation-DvPinn8V.js.map +0 -1
  113. package/src/components/every-project.tsx +0 -287
@@ -1,16 +1,86 @@
1
1
  import { a as ErrorLine, c as Notice, i as EmptyState, l as Spinner, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-DJje3gST.js";
2
2
  import { A as Key, E as GitHub, N as Link, U as Plus, it as X, s as memberRef, t as Card, u as useCoffre } from "../chunks/page-DvsgZ2Hd.js";
3
3
  import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-DOPUsjQK.js";
4
- import { g as signInWays, p as queries, t as affects } from "../chunks/queries-Dew8mIeo.js";
5
- import { t as useShell } from "../chunks/use-shell-Dkv89nW1.js";
6
- import { C as revokeCredential, n as useChangeStatus, t as useChange, y as removeBinding } from "../chunks/use-change-C4bGRhHY.js";
4
+ import { a as listsAccess, g as queries, t as affects, y as signInWays } from "../chunks/queries-DE5nK2y4.js";
5
+ import { t as useShell } from "../chunks/use-shell-BO4ZTr1y.js";
6
+ import { C as revokeCredential, n as useChangeStatus, t as useChange, y as removeBinding } from "../chunks/use-change-BJ3dCFHb.js";
7
7
  import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
8
- import { a as useAction } from "../chunks/validation-DvPinn8V.js";
9
- import { n as PrincipalLayout, r as ActionsLog, t as PrincipalAccess } from "../chunks/principal-page-1yMztIcc.js";
8
+ import { t as useAction } from "../chunks/use-action-BRgvbUWt.js";
9
+ import { n as PrincipalLayout, r as ActionsLog, t as PrincipalAccess } from "../chunks/principal-page-BEBr_zW7.js";
10
10
  import { Fragment, useState } from "react";
11
+ import { ROLES, ROLE_NAMES, assignableToEnvironment, credentialScopeInWords } from "@coffre/core/access";
11
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
13
  import { useSuspenseQuery } from "@tanstack/react-query";
13
- import { GITHUB_EVENTS, GITLAB_PIPELINE_SOURCES, fullRef, githubReusable, githubWorkflow, gitlabProject } from "@coffre/core/workloads";
14
+ import { EVENT_EXPOSURE, GITLAB_PIPELINE_SOURCES, claimValues, fullRef, githubEventsAt, githubReusable, githubWorkflow, gitlabProject } from "@coffre/core/workloads";
15
+ //#region src/components/scope-picker.tsx
16
+ var pathOf = (grant) => grant.environment === null ? grant.project : `${grant.project}/${grant.environment}`;
17
+ /** Everything the account holds, each grant as it is: what a new token or binding reaches unless narrowed. */
18
+ function wholeScope(grants) {
19
+ return Object.fromEntries(grants.map((grant) => [pathOf(grant), grant.role]));
20
+ }
21
+ /** The roles a credential may hold where its account holds `grant`: those it holds all of, and that the place takes. */
22
+ function within(grant) {
23
+ const held = ROLES[grant.role].permissions;
24
+ return ROLE_NAMES.filter((role) => (grant.environment === null || assignableToEnvironment(role)) && ROLES[role].permissions.every((permission) => held.includes(permission)));
25
+ }
26
+ /**
27
+ * What a new token or trust binding reaches: each of its account's grants,
28
+ * kept or left out, at its role or a smaller one. Nothing the account is
29
+ * given later reaches it, and it never changes after.
30
+ */
31
+ function ScopePicker({ grants, value, onChange }) {
32
+ if (grants.length === 0) return /* @__PURE__ */ jsx("p", {
33
+ className: "hint",
34
+ children: "The account holds nothing yet: give it a grant first, since nothing it is given later reaches a token or binding made before."
35
+ });
36
+ const set = (path, role) => {
37
+ const { [path]: _, ...rest } = value;
38
+ const next = role === null ? rest : {
39
+ ...rest,
40
+ [path]: role
41
+ };
42
+ onChange(Object.fromEntries(grants.map(pathOf).flatMap((each) => next[each] === void 0 ? [] : [[each, next[each]]])));
43
+ };
44
+ return /* @__PURE__ */ jsxs("fieldset", {
45
+ className: "field checks",
46
+ children: [
47
+ /* @__PURE__ */ jsx("legend", {
48
+ className: "label",
49
+ children: "Reaches"
50
+ }),
51
+ grants.map((grant) => {
52
+ const path = pathOf(grant);
53
+ const chosen = value[path];
54
+ return /* @__PURE__ */ jsxs("div", {
55
+ className: "form-row",
56
+ children: [/* @__PURE__ */ jsxs("label", {
57
+ className: "check mono",
58
+ children: [/* @__PURE__ */ jsx("input", {
59
+ type: "checkbox",
60
+ checked: chosen !== void 0,
61
+ onChange: (event) => set(path, event.target.checked ? grant.role : null)
62
+ }), path]
63
+ }), /* @__PURE__ */ jsx("select", {
64
+ className: "select",
65
+ "aria-label": `Role on ${path}`,
66
+ value: chosen ?? grant.role,
67
+ disabled: chosen === void 0,
68
+ onChange: (event) => set(path, event.target.value),
69
+ children: within(grant).map((role) => /* @__PURE__ */ jsx("option", {
70
+ value: role,
71
+ children: ROLES[role].name
72
+ }, role))
73
+ })]
74
+ }, path);
75
+ }),
76
+ /* @__PURE__ */ jsxs("span", {
77
+ className: "hint",
78
+ children: [Object.keys(value).length === 0 ? "Choose at least one." : `${credentialScopeInWords(value)}.`, " At most what the account holds; nothing it is given later reaches it, and to change it, make another and remove this one."]
79
+ })
80
+ ]
81
+ });
82
+ }
83
+ //#endregion
14
84
  //#region src/components/service-tokens.tsx
15
85
  var LIFETIMES = [
16
86
  30,
@@ -23,23 +93,32 @@ var LIFETIMES = [
23
93
  * OIDC. A value exists in exactly
24
94
  * one place, this dialog, for as long as it stays open: coffre keeps a hash.
25
95
  */
26
- function ServiceTokens({ serviceId, tokens }) {
96
+ function ServiceTokens({ serviceId, tokens, grants }) {
27
97
  const change = revokeCredential(useCoffre(), serviceId);
28
98
  const revoke = useChange(change);
29
99
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
30
100
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Card, {
31
101
  labelledBy: "service-tokens",
32
102
  title: "Bearer tokens",
33
- description: "For CI without OIDC: tokens this service account presents to the API. Each is shown once, when it is issued; coffre keeps only a hash.",
103
+ description: /* @__PURE__ */ jsxs(Fragment$1, { children: [
104
+ "A long-lived secret, for CI that can't use OIDC. For example, a cron job on your own server runs",
105
+ " ",
106
+ /* @__PURE__ */ jsx("span", {
107
+ className: "mono nowrap",
108
+ children: "coffre login <url> --token"
109
+ }),
110
+ " with one. coffre shows it once."
111
+ ] }),
34
112
  children: tokens.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
35
113
  title: "No bearer tokens",
36
- children: "None is needed for CI that signs in with OIDC; issue one for CI that cannot."
114
+ children: "CI that signs in with OIDC needs none."
37
115
  }) : /* @__PURE__ */ jsx("div", {
38
116
  className: "dt-wrap",
39
117
  children: /* @__PURE__ */ jsxs("table", {
40
118
  className: "dt",
41
119
  children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
42
120
  /* @__PURE__ */ jsx("th", { children: "Token" }),
121
+ /* @__PURE__ */ jsx("th", { children: "Reaches" }),
43
122
  /* @__PURE__ */ jsx("th", {
44
123
  className: "col-shrink",
45
124
  children: "Issued (UTC)"
@@ -74,6 +153,7 @@ function ServiceTokens({ serviceId, tokens }) {
74
153
  })]
75
154
  })]
76
155
  }) }),
156
+ /* @__PURE__ */ jsx("td", { children: token.scope === null ? "All its account holds" : credentialScopeInWords(token.scope) }),
77
157
  /* @__PURE__ */ jsx("td", {
78
158
  className: "nowrap",
79
159
  children: /* @__PURE__ */ jsxs("span", {
@@ -135,7 +215,7 @@ function ServiceTokens({ serviceId, tokens }) {
135
215
  ]
136
216
  }), /* @__PURE__ */ jsx(RowFailure, {
137
217
  status: state,
138
- columns: 5,
218
+ columns: 6,
139
219
  onDismiss: () => state.state === "failed" && dismiss(state.mutationId)
140
220
  })] }, token.id);
141
221
  }) })]
@@ -143,13 +223,17 @@ function ServiceTokens({ serviceId, tokens }) {
143
223
  })
144
224
  }), /* @__PURE__ */ jsx("div", {
145
225
  className: "table-actions",
146
- children: /* @__PURE__ */ jsx(IssueToken, { serviceId })
226
+ children: /* @__PURE__ */ jsx(IssueToken, {
227
+ serviceId,
228
+ grants
229
+ })
147
230
  })] });
148
231
  }
149
- function IssueToken({ serviceId }) {
232
+ function IssueToken({ serviceId, grants }) {
150
233
  const [open, setOpen] = useState(false);
151
234
  const [label, setLabel] = useState("");
152
235
  const [days, setDays] = useState(90);
236
+ const [scope, setScope] = useState(() => wholeScope(grants));
153
237
  const [issued, setIssued] = useState(null);
154
238
  const coffre = useCoffre();
155
239
  const { pending, error, setError, run } = useAction();
@@ -157,6 +241,7 @@ function IssueToken({ serviceId }) {
157
241
  setOpen(false);
158
242
  setIssued(null);
159
243
  setLabel("");
244
+ setScope(wholeScope(grants));
160
245
  setError(null);
161
246
  }
162
247
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
@@ -173,7 +258,8 @@ function IssueToken({ serviceId }) {
173
258
  event.preventDefault();
174
259
  run(() => coffre.tokens.issue(memberRef("service", serviceId), {
175
260
  label: label.trim() === "" ? null : label.trim(),
176
- expiresInDays: days
261
+ expiresInDays: days,
262
+ scope
177
263
  }), {
178
264
  affects: affects.credentials(memberRef("service", serviceId)),
179
265
  onSuccess: (credential) => setIssued(credential)
@@ -211,6 +297,11 @@ function IssueToken({ serviceId }) {
211
297
  })]
212
298
  })]
213
299
  }),
300
+ /* @__PURE__ */ jsx(ScopePicker, {
301
+ grants,
302
+ value: scope,
303
+ onChange: setScope
304
+ }),
214
305
  /* @__PURE__ */ jsx(ErrorLine, { error }),
215
306
  /* @__PURE__ */ jsxs("div", {
216
307
  className: "dialog-actions",
@@ -222,7 +313,7 @@ function IssueToken({ serviceId }) {
222
313
  }), /* @__PURE__ */ jsxs("button", {
223
314
  className: "btn btn-primary",
224
315
  type: "submit",
225
- disabled: pending,
316
+ disabled: pending || Object.keys(scope).length === 0,
226
317
  children: [pending && /* @__PURE__ */ jsx(Spinner, {}), "Issue token"]
227
318
  })]
228
319
  })
@@ -287,14 +378,15 @@ function IssueToken({ serviceId }) {
287
378
  */
288
379
  /** A binding in a line: what it trusts, and at which ref. */
289
380
  function summary(binding) {
290
- const { claims } = binding;
381
+ const claims = binding.claims;
382
+ const events = claimValues(binding.claims.event_name).join(", ");
291
383
  const short = (ref) => ref?.replace(/^refs\/(heads|tags)\//, "") ?? "";
292
384
  const [workflow, at] = (claims.workflow_ref ?? "").split("@");
293
385
  if (binding.profile === "github") {
294
386
  const [owner, repository, , , file] = (workflow ?? "").split("/");
295
387
  return {
296
388
  title: `${owner}/${repository} · ${file}`,
297
- detail: `${claims.event_name} at ${short(at)}`
389
+ detail: `${events} at ${short(at)}`
298
390
  };
299
391
  }
300
392
  if (binding.profile.startsWith("github-reusable")) {
@@ -302,18 +394,29 @@ function summary(binding) {
302
394
  const from = binding.profile === "github-reusable-organization" ? "any repository of the organization" : `repository ${claims.repository_id}`;
303
395
  return {
304
396
  title: `${called} @ ${claims.job_workflow_sha?.slice(0, 7)}`,
305
- detail: `${claims.event_name} at ${short(claims.ref)}, from ${from}`
397
+ detail: `${events} at ${short(claims.ref)}, from ${from}`
306
398
  };
307
399
  }
308
400
  if (binding.profile === "gitlab") return {
309
401
  title: `GitLab project ${claims.project_id}`,
310
- detail: `${claims.pipeline_source} at ${claims.ref_type} ${claims.ref}`
402
+ detail: `${claimValues(binding.claims.pipeline_source).join(", ")} at ${claims.ref_type} ${claims.ref}`
311
403
  };
312
404
  return {
313
405
  title: new URL(binding.issuer).host,
314
406
  detail: `sub ${claims.sub}`
315
407
  };
316
408
  }
409
+ /** The scope the dialog asks for: the person's, or none, for the server's own. */
410
+ function askedScope(choice) {
411
+ return choice.chosen ? { scope: choice.scope } : {};
412
+ }
413
+ /** The picker once a plan came back: what the server would make, unless the person chose. */
414
+ function planned(choice, plan) {
415
+ return choice.chosen ? choice : {
416
+ scope: plan.scope,
417
+ chosen: false
418
+ };
419
+ }
317
420
  var EMPTY_FORM = {
318
421
  platform: "github",
319
422
  label: "",
@@ -322,7 +425,7 @@ var EMPTY_FORM = {
322
425
  repositoryId: "",
323
426
  ownerId: "",
324
427
  workflow: "",
325
- event: "push",
428
+ events: ["push"],
326
429
  refKind: "branch",
327
430
  refName: "main",
328
431
  called: "",
@@ -332,7 +435,7 @@ var EMPTY_FORM = {
332
435
  project: "",
333
436
  projectId: "",
334
437
  namespaceId: "",
335
- source: "push",
438
+ sources: ["push"],
336
439
  issuer: "",
337
440
  sub: "",
338
441
  extra: ""
@@ -343,6 +446,10 @@ function bindingOf(form) {
343
446
  if (value.trim() === "") throw new Error(`${what} is needed`);
344
447
  return value.trim();
345
448
  };
449
+ const some = (values, what) => {
450
+ if (values.length === 0) throw new Error(`Choose at least one ${what}`);
451
+ return values;
452
+ };
346
453
  if (form.platform === "github") {
347
454
  const ref = fullRef(form.refKind, needed(form.refName, form.refKind === "branch" ? "The branch" : "The tag"));
348
455
  if (form.reusable) {
@@ -358,7 +465,7 @@ function bindingOf(form) {
358
465
  repositoryId: form.anyRepository ? null : needed(form.repositoryId, "The repository's ID"),
359
466
  ownerId,
360
467
  ref,
361
- event: form.event,
468
+ events: some(form.events, "event"),
362
469
  called,
363
470
  sha,
364
471
  caller
@@ -373,7 +480,7 @@ function bindingOf(form) {
373
480
  ownerId: needed(form.ownerId, "The owner's ID"),
374
481
  workflow: needed(form.workflow, "The workflow file"),
375
482
  ref,
376
- event: form.event
483
+ events: some(form.events, "event")
377
484
  }),
378
485
  issuer: null
379
486
  };
@@ -384,7 +491,7 @@ function bindingOf(form) {
384
491
  projectId: needed(form.projectId, "The project's ID"),
385
492
  refType: form.refKind,
386
493
  ref: needed(form.refName, form.refKind === "branch" ? "The branch" : "The tag"),
387
- source: form.source
494
+ sources: some(form.sources, "pipeline source")
388
495
  }),
389
496
  issuer: form.gitlabUrl.trim() === "" ? null : form.gitlabUrl.trim()
390
497
  };
@@ -405,26 +512,45 @@ function bindingOf(form) {
405
512
  /**
406
513
  * The CI runs that may sign in as a service, by the ID token their platform
407
514
  * signs for each run (docs/design/oidc.md). A run is trusted only when
408
- * every claim of a binding matches exactly, so the claims are what the page
409
- * shows, in full, before anything is saved.
515
+ * every claim of a binding matches, so the claims are what the page shows,
516
+ * in full, before anything is saved.
410
517
  */
411
- function TrustedWorkloads({ serviceId, bindings }) {
518
+ function TrustedWorkloads({ serviceId, bindings, grants }) {
412
519
  const change = removeBinding(useCoffre(), serviceId);
413
520
  const remove = useChange(change);
414
521
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
415
522
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Card, {
416
523
  labelledBy: "trusted-workloads",
417
524
  title: "Sign in with OIDC",
418
- description: "CI runs sign in as this service account with their platform's ID token, when it matches a trust binding. There is nothing to store, so prefer it wherever the CI supports it.",
525
+ description: /* @__PURE__ */ jsxs(Fragment$1, { children: [
526
+ "A CI run signs in with the ID token GitHub Actions or GitLab gives it, so there is no secret to store. For example,",
527
+ " ",
528
+ /* @__PURE__ */ jsx("span", {
529
+ className: "mono",
530
+ children: "deploy.yml"
531
+ }),
532
+ " in ",
533
+ /* @__PURE__ */ jsx("span", {
534
+ className: "mono",
535
+ children: "acme/api"
536
+ }),
537
+ ", on pushes to ",
538
+ /* @__PURE__ */ jsx("span", {
539
+ className: "mono",
540
+ children: "main"
541
+ }),
542
+ "."
543
+ ] }),
419
544
  children: bindings.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
420
545
  title: "No trust bindings",
421
- children: "Trust a CI workflow to let its runs sign in as this service account with no stored secret. Until then, CI needs a bearer token."
546
+ children: "Trust a workflow to let its runs sign in."
422
547
  }) : /* @__PURE__ */ jsx("div", {
423
548
  className: "dt-wrap",
424
549
  children: /* @__PURE__ */ jsxs("table", {
425
550
  className: "dt",
426
551
  children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
427
552
  /* @__PURE__ */ jsx("th", { children: "Workload" }),
553
+ /* @__PURE__ */ jsx("th", { children: "Reaches" }),
428
554
  /* @__PURE__ */ jsx("th", {
429
555
  className: "col-shrink",
430
556
  children: "Added (UTC)"
@@ -460,6 +586,7 @@ function TrustedWorkloads({ serviceId, bindings }) {
460
586
  ]
461
587
  })]
462
588
  }) }),
589
+ /* @__PURE__ */ jsx("td", { children: binding.scope === null ? "All its account holds" : credentialScopeInWords(binding.scope) }),
463
590
  /* @__PURE__ */ jsx("td", {
464
591
  className: "nowrap",
465
592
  children: /* @__PURE__ */ jsxs("span", {
@@ -517,7 +644,7 @@ function TrustedWorkloads({ serviceId, bindings }) {
517
644
  ]
518
645
  }), /* @__PURE__ */ jsx(RowFailure, {
519
646
  status: state,
520
- columns: 4,
647
+ columns: 5,
521
648
  onDismiss: () => state.state === "failed" && dismiss(state.mutationId)
522
649
  })] }, binding.id);
523
650
  }) })]
@@ -525,7 +652,11 @@ function TrustedWorkloads({ serviceId, bindings }) {
525
652
  })
526
653
  }), /* @__PURE__ */ jsx("div", {
527
654
  className: "table-actions",
528
- children: /* @__PURE__ */ jsx(TrustWorkload, { serviceId })
655
+ children: /* @__PURE__ */ jsx(TrustWorkload, {
656
+ serviceId,
657
+ grants,
658
+ bindings
659
+ })
529
660
  })] });
530
661
  }
531
662
  function Claims({ binding }) {
@@ -541,7 +672,7 @@ function Claims({ binding }) {
541
672
  children: name
542
673
  }), /* @__PURE__ */ jsx("td", {
543
674
  className: "mono",
544
- children: value
675
+ children: claimValues(value).join(", ")
545
676
  })] }, name)),
546
677
  /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", { children: "keys" }), /* @__PURE__ */ jsx("td", {
547
678
  className: "mono",
@@ -550,9 +681,77 @@ function Claims({ binding }) {
550
681
  ] })
551
682
  });
552
683
  }
553
- function TrustWorkload({ serviceId }) {
684
+ /** Checkboxes for what may start a run: GitHub's events, or GitLab's pipeline sources. */
685
+ function Choices(props) {
686
+ const { options, chosen } = props;
687
+ return /* @__PURE__ */ jsxs("fieldset", {
688
+ className: "field checks",
689
+ children: [
690
+ /* @__PURE__ */ jsx("legend", {
691
+ className: "label",
692
+ children: props.label
693
+ }),
694
+ /* @__PURE__ */ jsx("div", {
695
+ className: "checks-row",
696
+ children: options.map((option) => /* @__PURE__ */ jsxs("label", {
697
+ className: "check mono",
698
+ children: [/* @__PURE__ */ jsx("input", {
699
+ type: "checkbox",
700
+ checked: chosen.includes(option),
701
+ onChange: (event) => props.onChange(options.filter((each) => each === option ? event.target.checked : chosen.includes(each)))
702
+ }), option]
703
+ }, option))
704
+ }),
705
+ props.hint !== void 0 && /* @__PURE__ */ jsx("span", {
706
+ className: "hint",
707
+ children: props.hint
708
+ })
709
+ ]
710
+ });
711
+ }
712
+ /** What trusting `pull_request` or `workflow_run` exposes, said where the owner chooses it and again before saving. */
713
+ function Exposure({ events }) {
714
+ const exposed = events.filter((event) => EVENT_EXPOSURE[event] !== void 0);
715
+ if (exposed.length === 0) return null;
716
+ return /* @__PURE__ */ jsxs(Notice, {
717
+ tone: "warn",
718
+ children: [exposed.map((event) => /* @__PURE__ */ jsxs("p", { children: [
719
+ /* @__PURE__ */ jsx("span", {
720
+ className: "mono",
721
+ children: event
722
+ }),
723
+ ": ",
724
+ EVENT_EXPOSURE[event]
725
+ ] }, event)), /* @__PURE__ */ jsx("p", { children: "Give this service account only the secrets CI needs." })]
726
+ });
727
+ }
728
+ /** What the bindings a plan replaces reached, beside what the new one reaches: the same, unless the person chose again. */
729
+ function Reached({ plan, bindings }) {
730
+ const reached = [...new Set(plan.replaces.flatMap((replaced) => {
731
+ const scope = bindings.find((binding) => binding.id === replaced.id)?.scope;
732
+ return scope === void 0 ? [] : [scope === null ? "all its account holds" : credentialScopeInWords(scope)];
733
+ }))];
734
+ if (reached.every((words) => words === credentialScopeInWords(plan.scope))) return /* @__PURE__ */ jsxs(Fragment$1, { children: [
735
+ " This one reaches what ",
736
+ plan.replaces.length === 1 ? "it" : "they",
737
+ " did."
738
+ ] });
739
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
740
+ " ",
741
+ plan.replaces.length === 1 ? "It" : "They",
742
+ " reached ",
743
+ reached.join("; "),
744
+ ": this one reaches what it says above."
745
+ ] });
746
+ }
747
+ function TrustWorkload({ serviceId, grants, bindings }) {
554
748
  const [open, setOpen] = useState(false);
555
749
  const [form, setForm] = useState(EMPTY_FORM);
750
+ const whole = () => ({
751
+ scope: wholeScope(grants),
752
+ chosen: false
753
+ });
754
+ const [choice, setChoice] = useState(whole);
556
755
  const [plan, setPlan] = useState(null);
557
756
  const coffre = useCoffre();
558
757
  const member = memberRef("service", serviceId);
@@ -567,12 +766,14 @@ function TrustWorkload({ serviceId }) {
567
766
  };
568
767
  const input = () => ({
569
768
  ...bindingOf(form),
769
+ ...askedScope(choice),
570
770
  label: form.label.trim() === "" ? null : form.label.trim(),
571
771
  replaces: []
572
772
  });
573
773
  function close() {
574
774
  setOpen(false);
575
775
  setForm(EMPTY_FORM);
776
+ setChoice(whole());
576
777
  setPlan(null);
577
778
  setError(null);
578
779
  lookup.setError(null);
@@ -587,7 +788,10 @@ function TrustWorkload({ serviceId }) {
587
788
  }
588
789
  run(() => coffre.bindings.preview(member, request), {
589
790
  affects: [],
590
- onSuccess: setPlan
791
+ onSuccess: (next) => {
792
+ setPlan(next);
793
+ setChoice((current) => planned(current, next));
794
+ }
591
795
  });
592
796
  }
593
797
  const field = (label, key, props = {}) => /* @__PURE__ */ jsxs("label", {
@@ -620,7 +824,13 @@ function TrustWorkload({ serviceId }) {
620
824
  }), /* @__PURE__ */ jsxs("select", {
621
825
  className: "select",
622
826
  value: form.refKind,
623
- onChange: (event) => set({ refKind: event.target.value }),
827
+ onChange: (event) => {
828
+ const refKind = event.target.value;
829
+ set({
830
+ refKind,
831
+ events: form.events.filter((each) => githubEventsAt(refKind).includes(each))
832
+ });
833
+ },
624
834
  children: [/* @__PURE__ */ jsx("option", {
625
835
  value: "branch",
626
836
  children: "Branch"
@@ -749,29 +959,15 @@ function TrustWorkload({ serviceId }) {
749
959
  placeholder: "deploy.yml",
750
960
  mono: true
751
961
  }),
752
- /* @__PURE__ */ jsxs("label", {
753
- className: "field",
754
- children: [
755
- /* @__PURE__ */ jsx("span", {
756
- className: "label",
757
- children: "Event"
758
- }),
759
- /* @__PURE__ */ jsx("select", {
760
- className: "select",
761
- value: form.event,
762
- onChange: (event) => set({ event: event.target.value }),
763
- children: GITHUB_EVENTS.map((event) => /* @__PURE__ */ jsx("option", {
764
- value: event,
765
- children: event
766
- }, event))
767
- }),
768
- /* @__PURE__ */ jsx("span", {
769
- className: "hint",
770
- children: "Pull requests and workflow_run are never trusted: their runs can carry a stranger's code."
771
- })
772
- ]
962
+ ref,
963
+ /* @__PURE__ */ jsx(Choices, {
964
+ label: "Events",
965
+ options: githubEventsAt(form.refKind),
966
+ chosen: form.events,
967
+ onChange: (events) => set({ events }),
968
+ hint: form.events.includes("pull_request") ? `A pull request matches by the branch it merges into: ${form.refName.trim() || "main"}.` : void 0
773
969
  }),
774
- ref
970
+ /* @__PURE__ */ jsx(Exposure, { events: form.events })
775
971
  ] }),
776
972
  form.platform === "gitlab" && /* @__PURE__ */ jsxs(Fragment$1, { children: [
777
973
  field("GitLab", "gitlabUrl", {
@@ -813,27 +1009,12 @@ function TrustWorkload({ serviceId }) {
813
1009
  }),
814
1010
  /* @__PURE__ */ jsx(ErrorLine, { error: lookup.error }),
815
1011
  ref,
816
- /* @__PURE__ */ jsxs("label", {
817
- className: "field",
818
- children: [
819
- /* @__PURE__ */ jsx("span", {
820
- className: "label",
821
- children: "Pipeline source"
822
- }),
823
- /* @__PURE__ */ jsx("select", {
824
- className: "select",
825
- value: form.source,
826
- onChange: (event) => set({ source: event.target.value }),
827
- children: GITLAB_PIPELINE_SOURCES.map((source) => /* @__PURE__ */ jsx("option", {
828
- value: source,
829
- children: source
830
- }, source))
831
- }),
832
- /* @__PURE__ */ jsx("span", {
833
- className: "hint",
834
- children: "Merge-request pipelines are never trusted: they name another project."
835
- })
836
- ]
1012
+ /* @__PURE__ */ jsx(Choices, {
1013
+ label: "Pipeline sources",
1014
+ options: GITLAB_PIPELINE_SOURCES,
1015
+ chosen: form.sources,
1016
+ onChange: (sources) => set({ sources }),
1017
+ hint: "Merge-request pipelines are never trusted: they name another project."
837
1018
  })
838
1019
  ] }),
839
1020
  form.platform === "other" && /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -862,6 +1043,17 @@ function TrustWorkload({ serviceId }) {
862
1043
  })]
863
1044
  })
864
1045
  ] }),
1046
+ /* @__PURE__ */ jsx(ScopePicker, {
1047
+ grants,
1048
+ value: choice.scope,
1049
+ onChange: (next) => {
1050
+ setChoice({
1051
+ scope: next,
1052
+ chosen: true
1053
+ });
1054
+ setPlan(null);
1055
+ }
1056
+ }),
865
1057
  field("Label (optional)", "label", { placeholder: "Deploys to production" }),
866
1058
  /* @__PURE__ */ jsx(ErrorLine, { error }),
867
1059
  /* @__PURE__ */ jsxs("div", {
@@ -874,7 +1066,7 @@ function TrustWorkload({ serviceId }) {
874
1066
  }), /* @__PURE__ */ jsxs("button", {
875
1067
  className: "btn btn-primary",
876
1068
  type: "submit",
877
- disabled: pending,
1069
+ disabled: pending || Object.keys(choice.scope).length === 0,
878
1070
  children: [pending && /* @__PURE__ */ jsx(Spinner, {}), "Review"]
879
1071
  })]
880
1072
  })
@@ -883,21 +1075,29 @@ function TrustWorkload({ serviceId }) {
883
1075
  className: "form",
884
1076
  children: [
885
1077
  /* @__PURE__ */ jsxs("p", { children: [
886
- "Runs whose ID token carries exactly these claims will sign in as ",
887
- /* @__PURE__ */ jsx("span", {
1078
+ "Runs whose ID token matches these claims sign in as ",
1079
+ /* @__PURE__ */ jsxs("span", {
888
1080
  className: "mono",
889
- children: member
1081
+ children: ["service:", serviceId]
890
1082
  }),
891
- ", and read what it may read."
1083
+ " and reach",
1084
+ " ",
1085
+ credentialScopeInWords(plan.scope),
1086
+ ", as long as the account holds it."
892
1087
  ] }),
893
1088
  /* @__PURE__ */ jsx(Claims, { binding: plan }),
1089
+ /* @__PURE__ */ jsx(Exposure, { events: claimValues(plan.claims.event_name) }),
894
1090
  plan.replaces.length > 0 && /* @__PURE__ */ jsxs(Notice, {
895
1091
  tone: "info",
896
1092
  children: [
897
1093
  "This replaces ",
898
1094
  plan.replaces.length === 1 ? "a binding" : `${plan.replaces.length} bindings`,
899
1095
  plan.replaces.some((replaced) => replaced.why === "keys_moved") ? ", since the issuer moved its keys" : "",
900
- "."
1096
+ ".",
1097
+ /* @__PURE__ */ jsx(Reached, {
1098
+ plan,
1099
+ bindings
1100
+ })
901
1101
  ]
902
1102
  }),
903
1103
  /* @__PURE__ */ jsx(ErrorLine, { error }),
@@ -912,7 +1112,10 @@ function TrustWorkload({ serviceId }) {
912
1112
  className: "btn btn-primary",
913
1113
  type: "button",
914
1114
  disabled: pending,
915
- onClick: () => void run(() => coffre.bindings.create(member, input()), {
1115
+ onClick: () => void run(() => coffre.bindings.create(member, {
1116
+ ...input(),
1117
+ scope: plan.scope
1118
+ }), {
916
1119
  affects: affects.bindings(member),
917
1120
  onSuccess: close
918
1121
  }),
@@ -939,22 +1142,25 @@ function ServiceAccountSignInPage() {
939
1142
  const client = useCoffre();
940
1143
  const shell = useShell();
941
1144
  const member = memberRef("service", account);
942
- const { data: report } = useSuspenseQuery(queries.report(client, member, shell.capabilities.canManageGrants));
943
- const ways = signInWays(shell, report) ?? {
1145
+ const { data: access } = useSuspenseQuery(queries.memberAccess(client, member, listsAccess(shell)));
1146
+ const ways = signInWays(shell, access) ?? {
944
1147
  tokens: false,
945
1148
  workloads: false
946
1149
  };
947
1150
  const { data: credentials } = useSuspenseQuery(queries.credentials(client, member, ways.tokens));
948
1151
  const { data: bindings } = useSuspenseQuery(queries.bindings(client, member, ways.workloads));
1152
+ const grants = access?.ok === true ? access.grants : [];
949
1153
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [bindings !== null && (bindings.ok ? /* @__PURE__ */ jsx(TrustedWorkloads, {
950
1154
  serviceId: account,
951
- bindings: bindings.bindings
1155
+ bindings: bindings.bindings,
1156
+ grants
952
1157
  }) : /* @__PURE__ */ jsx(Notice, {
953
1158
  tone: "bad",
954
1159
  children: bindings.error
955
1160
  })), credentials !== null && (credentials.ok ? /* @__PURE__ */ jsx(ServiceTokens, {
956
1161
  serviceId: account,
957
- tokens: credentials.tokens
1162
+ tokens: credentials.tokens,
1163
+ grants
958
1164
  }) : /* @__PURE__ */ jsx(Notice, {
959
1165
  tone: "bad",
960
1166
  children: credentials.error