@coffre/ui 0.4.5 → 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 (117) 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-BhHmvQX_.js → audit-sentence-Cm5nby5k.js} +115 -8
  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-UtNWKCf8.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 +116 -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/approval.js +53 -21
  41. package/dist/pages/approval.js.map +1 -1
  42. package/dist/pages/audit.js +2 -2
  43. package/dist/pages/environment.js +8 -7
  44. package/dist/pages/environment.js.map +1 -1
  45. package/dist/pages/login.js +2 -2
  46. package/dist/pages/login.js.map +1 -1
  47. package/dist/pages/project-access.js +7 -7
  48. package/dist/pages/project-environments.js +26 -21
  49. package/dist/pages/project-environments.js.map +1 -1
  50. package/dist/pages/project-settings.js +9 -8
  51. package/dist/pages/project-settings.js.map +1 -1
  52. package/dist/pages/project.js +1 -1
  53. package/dist/pages/projects.js +8 -13
  54. package/dist/pages/projects.js.map +1 -1
  55. package/dist/pages/service-account.js +294 -88
  56. package/dist/pages/service-account.js.map +1 -1
  57. package/dist/pages/service-accounts.js +7 -7
  58. package/dist/pages/service-accounts.js.map +1 -1
  59. package/dist/pages/settings.js +91 -9
  60. package/dist/pages/settings.js.map +1 -1
  61. package/dist/pages/unregistered.d.ts +1 -1
  62. package/dist/pages/unregistered.js +4 -4
  63. package/dist/pages/unregistered.js.map +1 -1
  64. package/dist/pages/user.d.ts +2 -0
  65. package/dist/pages/user.js +21 -3
  66. package/dist/pages/user.js.map +1 -1
  67. package/dist/pages/users.js +4 -4
  68. package/package.json +3 -3
  69. package/src/components/affordances.ts +7 -3
  70. package/src/components/command-palette.tsx +2 -0
  71. package/src/components/directory.tsx +58 -63
  72. package/src/components/grants.tsx +9 -9
  73. package/src/components/offboarding.tsx +3 -1
  74. package/src/components/principal-page.tsx +124 -74
  75. package/src/components/role-field.tsx +183 -0
  76. package/src/components/scope-picker.tsx +73 -0
  77. package/src/components/service-tokens.tsx +20 -9
  78. package/src/components/shell.tsx +6 -10
  79. package/src/components/trusted-workloads.tsx +121 -42
  80. package/src/index.ts +1 -0
  81. package/src/lib/approval.ts +23 -0
  82. package/src/lib/audit-sentences.ts +109 -3
  83. package/src/lib/bindings.ts +33 -10
  84. package/src/lib/capabilities.ts +28 -8
  85. package/src/lib/changes.ts +22 -13
  86. package/src/lib/project-access.ts +21 -0
  87. package/src/lib/queries.ts +121 -44
  88. package/src/lib/service-setup.ts +41 -0
  89. package/src/lib/validation.ts +7 -0
  90. package/src/options.ts +31 -11
  91. package/src/pages/account.tsx +3 -2
  92. package/src/pages/approval.tsx +18 -17
  93. package/src/pages/login.tsx +1 -1
  94. package/src/pages/project-environments.tsx +12 -15
  95. package/src/pages/project-settings.tsx +3 -3
  96. package/src/pages/projects.tsx +1 -5
  97. package/src/pages/service-account.tsx +7 -5
  98. package/src/pages/service-accounts.tsx +8 -4
  99. package/src/pages/settings.tsx +80 -4
  100. package/src/pages/unregistered.tsx +3 -3
  101. package/src/pages/user.tsx +24 -1
  102. package/src/parity.ts +5 -1
  103. package/src/register.ts +3 -1
  104. package/src/shared/models.ts +8 -4
  105. package/src/styles/globals.css +111 -28
  106. package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
  107. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +0 -1
  108. package/dist/chunks/directory-B6FuiCir.js.map +0 -1
  109. package/dist/chunks/grants-9kIV6uZ7.js +0 -669
  110. package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
  111. package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
  112. package/dist/chunks/principal-page-UtNWKCf8.js.map +0 -1
  113. package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
  114. package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
  115. package/dist/chunks/validation-DvPinn8V.js +0 -87
  116. package/dist/chunks/validation-DvPinn8V.js.map +0 -1
  117. package/src/components/every-project.tsx +0 -287
@@ -1,4 +1,5 @@
1
1
  import type { ServiceTokenRow } from '@coffre/client';
2
+ import { credentialScopeInWords } from '@coffre/core/access';
2
3
  import { Fragment, useState } from 'react';
3
4
  import { revokeCredential } from '../lib/changes';
4
5
  import { memberRef, useCoffre } from '../lib/coffre';
@@ -7,6 +8,7 @@ import { useAction } from '../lib/use-action';
7
8
  import { useChange, useChangeStatus } from '../lib/use-change';
8
9
  import { RowFailure, RowPending, rowClass } from './row-state';
9
10
  import { Card } from './page';
11
+ import { ScopePicker, wholeScope, type HeldGrant } from './scope-picker';
10
12
  import { ConfirmButton, CopyButton, EmptyState, ErrorLine, Modal, Notice, Spinner, Timestamp } from './ui';
11
13
  import { Key, Plus, X } from './icons';
12
14
 
@@ -17,7 +19,7 @@ const LIFETIMES = [30, 90, 180, 365] as const;
17
19
  * OIDC. A value exists in exactly
18
20
  * one place, this dialog, for as long as it stays open: coffre keeps a hash.
19
21
  */
20
- export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens: ServiceTokenRow[] }) {
22
+ export function ServiceTokens({ serviceId, tokens, grants }: { serviceId: string; tokens: ServiceTokenRow[]; grants: HeldGrant[] }) {
21
23
  const change = revokeCredential(useCoffre(), serviceId);
22
24
  const revoke = useChange(change);
23
25
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
@@ -27,18 +29,22 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
27
29
  <Card
28
30
  labelledBy="service-tokens"
29
31
  title="Bearer tokens"
30
- 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."
32
+ description={
33
+ <>
34
+ A long-lived secret, for CI that can't use OIDC. For example, a cron job on your own server runs{' '}
35
+ <span className="mono nowrap">coffre login &lt;url&gt; --token</span> with one. coffre shows it once.
36
+ </>
37
+ }
31
38
  >
32
39
  {tokens.length === 0 ? (
33
- <EmptyState title="No bearer tokens">
34
- None is needed for CI that signs in with OIDC; issue one for CI that cannot.
35
- </EmptyState>
40
+ <EmptyState title="No bearer tokens">CI that signs in with OIDC needs none.</EmptyState>
36
41
  ) : (
37
42
  <div className="dt-wrap">
38
43
  <table className="dt">
39
44
  <thead>
40
45
  <tr>
41
46
  <th>Token</th>
47
+ <th>Reaches</th>
42
48
  <th className="col-shrink">Issued (UTC)</th>
43
49
  <th className="col-shrink">Last used</th>
44
50
  <th className="col-shrink">Expires</th>
@@ -62,6 +68,7 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
62
68
  </span>
63
69
  </span>
64
70
  </td>
71
+ <td>{token.scope === null ? 'All its account holds' : credentialScopeInWords(token.scope)}</td>
65
72
  <td className="nowrap">
66
73
  <span className="cell-stack">
67
74
  <Timestamp iso={token.createdAt} />
@@ -120,7 +127,7 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
120
127
  </tr>
121
128
  <RowFailure
122
129
  status={state}
123
- columns={5}
130
+ columns={6}
124
131
  onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
125
132
  />
126
133
  </Fragment>
@@ -132,16 +139,17 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
132
139
  )}
133
140
  </Card>
134
141
  <div className="table-actions">
135
- <IssueToken serviceId={serviceId} />
142
+ <IssueToken serviceId={serviceId} grants={grants} />
136
143
  </div>
137
144
  </>
138
145
  );
139
146
  }
140
147
 
141
- function IssueToken({ serviceId }: { serviceId: string }) {
148
+ function IssueToken({ serviceId, grants }: { serviceId: string; grants: HeldGrant[] }) {
142
149
  const [open, setOpen] = useState(false);
143
150
  const [label, setLabel] = useState('');
144
151
  const [days, setDays] = useState<number>(90);
152
+ const [scope, setScope] = useState(() => wholeScope(grants));
145
153
  const [issued, setIssued] = useState<{ token: string; expiresAt: string } | null>(null);
146
154
  const coffre = useCoffre();
147
155
  const { pending, error, setError, run } = useAction();
@@ -150,6 +158,7 @@ function IssueToken({ serviceId }: { serviceId: string }) {
150
158
  setOpen(false);
151
159
  setIssued(null);
152
160
  setLabel('');
161
+ setScope(wholeScope(grants));
153
162
  setError(null);
154
163
  }
155
164
 
@@ -174,6 +183,7 @@ function IssueToken({ serviceId }: { serviceId: string }) {
174
183
  coffre.tokens.issue(memberRef('service', serviceId), {
175
184
  label: label.trim() === '' ? null : label.trim(),
176
185
  expiresInDays: days,
186
+ scope,
177
187
  }),
178
188
  {
179
189
  affects: affects.credentials(memberRef('service', serviceId)),
@@ -204,12 +214,13 @@ function IssueToken({ serviceId }: { serviceId: string }) {
204
214
  </select>
205
215
  </label>
206
216
  </div>
217
+ <ScopePicker grants={grants} value={scope} onChange={setScope} />
207
218
  <ErrorLine error={error} />
208
219
  <div className="dialog-actions">
209
220
  <button className="btn" type="button" onClick={close}>
210
221
  Cancel
211
222
  </button>
212
- <button className="btn btn-primary" type="submit" disabled={pending}>
223
+ <button className="btn btn-primary" type="submit" disabled={pending || Object.keys(scope).length === 0}>
213
224
  {pending && <Spinner />}
214
225
  Issue token
215
226
  </button>
@@ -8,8 +8,9 @@ import {
8
8
  import { Link, useNavigate, useRouterState } from '@tanstack/react-router';
9
9
  import { Dialog } from '@base-ui/react/dialog';
10
10
  import { Menu } from '@base-ui/react/menu';
11
+ import { INSTANCE_ROLES } from '@coffre/core/access';
11
12
  import { PROJECT_PAGES } from '@coffre/core/pages';
12
- import type { ProjectSummary } from '../shared/models';
13
+ import type { Me, ProjectSummary } from '../shared/models';
13
14
  import type { UiCapabilities } from '../lib/capabilities';
14
15
  import { isActiveAccessibleEnvironment } from '../lib/project-environments';
15
16
  import { useMounted } from '../lib/mounted';
@@ -37,7 +38,7 @@ import {
37
38
  } from './icons';
38
39
 
39
40
  type Principal = { type: 'user' | 'service'; id: string } | null;
40
- type InstanceRole = 'user' | 'owner' | 'root-admin' | null;
41
+ type InstanceRole = Me['instanceRole'] | null;
41
42
 
42
43
  type ShellProps = {
43
44
  projects: ProjectSummary[];
@@ -65,8 +66,7 @@ const CURRENT = { 'aria-current': 'page' } as const;
65
66
  function roleLabel(principal: Principal, instanceRole: InstanceRole): string {
66
67
  if (principal?.type === 'service') return 'Token';
67
68
  if (instanceRole === 'root-admin') return 'Root admin';
68
- if (instanceRole === 'owner') return 'Owner';
69
- return 'Member';
69
+ return INSTANCE_ROLES[instanceRole ?? 'member'].name;
70
70
  }
71
71
 
72
72
  /** The product's mark and name, for the pages you see before signing in. */
@@ -242,12 +242,8 @@ function Sidebar({
242
242
  />
243
243
  <AdministrationItems
244
244
  capabilities={capabilities}
245
- users={
246
- <>
247
- <NavLink to="/users" label="Users" icon={<Users size={16} />} collapsed={collapsed} />
248
- <NavLink to="/service-accounts" label="Service accounts" icon={<Key size={16} />} collapsed={collapsed} />
249
- </>
250
- }
245
+ users={<NavLink to="/users" label="Users" icon={<Users size={16} />} collapsed={collapsed} />}
246
+ services={<NavLink to="/service-accounts" label="Service accounts" icon={<Key size={16} />} collapsed={collapsed} />}
251
247
  audit={
252
248
  <NavLink to="/audit" label="Audit" icon={<Ledger size={16} />} collapsed={collapsed} />
253
249
  }
@@ -1,7 +1,8 @@
1
1
  import type { BindingPlan, BindingView } from '@coffre/client';
2
- import { GITHUB_EVENTS, GITLAB_PIPELINE_SOURCES } from '@coffre/core/workloads';
2
+ import { credentialScopeInWords } from '@coffre/core/access';
3
+ import { claimValues, EVENT_EXPOSURE, githubEventsAt, GITLAB_PIPELINE_SOURCES } from '@coffre/core/workloads';
3
4
  import { Fragment, useState } from 'react';
4
- import { bindingOf, EMPTY_FORM, summary, type Form, type RefKind } from '../lib/bindings';
5
+ import { askedScope, bindingOf, EMPTY_FORM, planned, summary, type Form, type RefKind, type ScopeChoice } from '../lib/bindings';
5
6
  import { removeBinding } from '../lib/changes';
6
7
  import { memberRef, useCoffre } from '../lib/coffre';
7
8
  import { affects } from '../lib/queries';
@@ -9,16 +10,17 @@ import { useAction } from '../lib/use-action';
9
10
  import { useChange, useChangeStatus } from '../lib/use-change';
10
11
  import { RowFailure, RowPending, rowClass } from './row-state';
11
12
  import { Card } from './page';
13
+ import { ScopePicker, wholeScope, type HeldGrant } from './scope-picker';
12
14
  import { ConfirmButton, EmptyState, ErrorLine, Modal, Notice, Spinner, Timestamp } from './ui';
13
15
  import { GitHub, Link, Plus, X } from './icons';
14
16
 
15
17
  /**
16
18
  * The CI runs that may sign in as a service, by the ID token their platform
17
19
  * signs for each run (docs/design/oidc.md). A run is trusted only when
18
- * every claim of a binding matches exactly, so the claims are what the page
19
- * shows, in full, before anything is saved.
20
+ * every claim of a binding matches, so the claims are what the page shows,
21
+ * in full, before anything is saved.
20
22
  */
21
- export function TrustedWorkloads({ serviceId, bindings }: { serviceId: string; bindings: BindingView[] }) {
23
+ export function TrustedWorkloads({ serviceId, bindings, grants }: { serviceId: string; bindings: BindingView[]; grants: HeldGrant[] }) {
22
24
  const change = removeBinding(useCoffre(), serviceId);
23
25
  const remove = useChange(change);
24
26
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
@@ -28,18 +30,22 @@ export function TrustedWorkloads({ serviceId, bindings }: { serviceId: string; b
28
30
  <Card
29
31
  labelledBy="trusted-workloads"
30
32
  title="Sign in with OIDC"
31
- 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."
33
+ description={
34
+ <>
35
+ A CI run signs in with the ID token GitHub Actions or GitLab gives it, so there is no secret to store. For example,{' '}
36
+ <span className="mono">deploy.yml</span> in <span className="mono">acme/api</span>, on pushes to <span className="mono">main</span>.
37
+ </>
38
+ }
32
39
  >
33
40
  {bindings.length === 0 ? (
34
- <EmptyState title="No trust bindings">
35
- 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.
36
- </EmptyState>
41
+ <EmptyState title="No trust bindings">Trust a workflow to let its runs sign in.</EmptyState>
37
42
  ) : (
38
43
  <div className="dt-wrap">
39
44
  <table className="dt">
40
45
  <thead>
41
46
  <tr>
42
47
  <th>Workload</th>
48
+ <th>Reaches</th>
43
49
  <th className="col-shrink">Added (UTC)</th>
44
50
  <th className="col-shrink">Last used</th>
45
51
  <th className="col-actions">
@@ -67,6 +73,7 @@ export function TrustedWorkloads({ serviceId, bindings }: { serviceId: string; b
67
73
  </span>
68
74
  </span>
69
75
  </td>
76
+ <td>{binding.scope === null ? 'All its account holds' : credentialScopeInWords(binding.scope)}</td>
70
77
  <td className="nowrap">
71
78
  <span className="cell-stack">
72
79
  <Timestamp iso={binding.createdAt} />
@@ -109,7 +116,7 @@ export function TrustedWorkloads({ serviceId, bindings }: { serviceId: string; b
109
116
  )}
110
117
  </td>
111
118
  </tr>
112
- <RowFailure status={state} columns={4} onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)} />
119
+ <RowFailure status={state} columns={5} onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)} />
113
120
  </Fragment>
114
121
  );
115
122
  })}
@@ -119,7 +126,7 @@ export function TrustedWorkloads({ serviceId, bindings }: { serviceId: string; b
119
126
  )}
120
127
  </Card>
121
128
  <div className="table-actions">
122
- <TrustWorkload serviceId={serviceId} />
129
+ <TrustWorkload serviceId={serviceId} grants={grants} bindings={bindings} />
123
130
  </div>
124
131
  </>
125
132
  );
@@ -136,7 +143,7 @@ function Claims({ binding }: { binding: Pick<BindingPlan, 'issuer' | 'jwksUri' |
136
143
  {Object.entries(binding.claims).map(([name, value]) => (
137
144
  <tr key={name}>
138
145
  <th className="mono">{name}</th>
139
- <td className="mono">{value}</td>
146
+ <td className="mono">{claimValues(value).join(', ')}</td>
140
147
  </tr>
141
148
  ))}
142
149
  <tr>
@@ -148,9 +155,61 @@ function Claims({ binding }: { binding: Pick<BindingPlan, 'issuer' | 'jwksUri' |
148
155
  );
149
156
  }
150
157
 
151
- function TrustWorkload({ serviceId }: { serviceId: string }) {
158
+ /** Checkboxes for what may start a run: GitHub's events, or GitLab's pipeline sources. */
159
+ function Choices(props: { label: string; options: readonly string[]; chosen: string[]; onChange: (chosen: string[]) => void; hint?: string }) {
160
+ const { options, chosen } = props;
161
+ return (
162
+ <fieldset className="field checks">
163
+ <legend className="label">{props.label}</legend>
164
+ <div className="checks-row">
165
+ {options.map((option) => (
166
+ <label key={option} className="check mono">
167
+ <input
168
+ type="checkbox"
169
+ checked={chosen.includes(option)}
170
+ // Kept in the options' order, as the server stores them.
171
+ onChange={(event) => props.onChange(options.filter((each) => (each === option ? event.target.checked : chosen.includes(each))))}
172
+ />
173
+ {option}
174
+ </label>
175
+ ))}
176
+ </div>
177
+ {props.hint !== undefined && <span className="hint">{props.hint}</span>}
178
+ </fieldset>
179
+ );
180
+ }
181
+
182
+ /** What trusting `pull_request` or `workflow_run` exposes, said where the owner chooses it and again before saving. */
183
+ function Exposure({ events }: { events: string[] }) {
184
+ const exposed = events.filter((event) => EVENT_EXPOSURE[event] !== undefined);
185
+ if (exposed.length === 0) return null;
186
+ return (
187
+ <Notice tone="warn">
188
+ {exposed.map((event) => (
189
+ <p key={event}>
190
+ <span className="mono">{event}</span>: {EVENT_EXPOSURE[event]}
191
+ </p>
192
+ ))}
193
+ <p>Give this service account only the secrets CI needs.</p>
194
+ </Notice>
195
+ );
196
+ }
197
+
198
+ /** What the bindings a plan replaces reached, beside what the new one reaches: the same, unless the person chose again. */
199
+ function Reached({ plan, bindings }: { plan: BindingPlan; bindings: BindingView[] }) {
200
+ const reached = [...new Set(plan.replaces.flatMap((replaced) => {
201
+ const scope = bindings.find((binding) => binding.id === replaced.id)?.scope;
202
+ return scope === undefined ? [] : [scope === null ? 'all its account holds' : credentialScopeInWords(scope)];
203
+ }))];
204
+ if (reached.every((words) => words === credentialScopeInWords(plan.scope))) return <> This one reaches what {plan.replaces.length === 1 ? 'it' : 'they'} did.</>;
205
+ return <> {plan.replaces.length === 1 ? 'It' : 'They'} reached {reached.join('; ')}: this one reaches what it says above.</>;
206
+ }
207
+
208
+ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; grants: HeldGrant[]; bindings: BindingView[] }) {
152
209
  const [open, setOpen] = useState(false);
153
210
  const [form, setForm] = useState<Form>(EMPTY_FORM);
211
+ const whole = (): ScopeChoice => ({ scope: wholeScope(grants), chosen: false });
212
+ const [choice, setChoice] = useState(whole);
154
213
  const [plan, setPlan] = useState<BindingPlan | null>(null);
155
214
  const coffre = useCoffre();
156
215
  const member = memberRef('service', serviceId);
@@ -160,11 +219,12 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
160
219
  setForm((current) => ({ ...current, ...changes }));
161
220
  setPlan(null);
162
221
  };
163
- const input = () => ({ ...bindingOf(form), label: form.label.trim() === '' ? null : form.label.trim(), replaces: [] });
222
+ const input = () => ({ ...bindingOf(form), ...askedScope(choice), label: form.label.trim() === '' ? null : form.label.trim(), replaces: [] });
164
223
 
165
224
  function close() {
166
225
  setOpen(false);
167
226
  setForm(EMPTY_FORM);
227
+ setChoice(whole());
168
228
  setPlan(null);
169
229
  setError(null);
170
230
  lookup.setError(null);
@@ -178,7 +238,14 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
178
238
  setError((problem as Error).message);
179
239
  return;
180
240
  }
181
- void run(() => coffre.bindings.preview(member, request), { affects: [], onSuccess: setPlan });
241
+ void run(() => coffre.bindings.preview(member, request), {
242
+ affects: [],
243
+ // One that replaces bindings reaches what they did unless told: the picker says so, should the person go back.
244
+ onSuccess: (next) => {
245
+ setPlan(next);
246
+ setChoice((current) => planned(current, next));
247
+ },
248
+ });
182
249
  }
183
250
 
184
251
  const field = (label: string, key: keyof Form, props: { placeholder?: string; mono?: boolean; hint?: string } = {}) => (
@@ -198,7 +265,15 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
198
265
  <div className="form-row">
199
266
  <label className="field" style={{ flex: '0 0 8rem' }}>
200
267
  <span className="label">At</span>
201
- <select className="select" value={form.refKind} onChange={(event) => set({ refKind: event.target.value as RefKind })}>
268
+ <select
269
+ className="select"
270
+ value={form.refKind}
271
+ onChange={(event) => {
272
+ const refKind = event.target.value as RefKind;
273
+ // A release runs at a tag; a schedule, a pull request or a workflow_run on a branch.
274
+ set({ refKind, events: form.events.filter((each) => githubEventsAt(refKind).includes(each)) });
275
+ }}
276
+ >
202
277
  <option value="branch">Branch</option>
203
278
  <option value="tag">Tag</option>
204
279
  </select>
@@ -281,18 +356,15 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
281
356
  ) : (
282
357
  field('Workflow file', 'workflow', { placeholder: 'deploy.yml', mono: true })
283
358
  )}
284
- <label className="field">
285
- <span className="label">Event</span>
286
- <select className="select" value={form.event} onChange={(event) => set({ event: event.target.value })}>
287
- {GITHUB_EVENTS.map((event) => (
288
- <option key={event} value={event}>
289
- {event}
290
- </option>
291
- ))}
292
- </select>
293
- <span className="hint">Pull requests and workflow_run are never trusted: their runs can carry a stranger's code.</span>
294
- </label>
295
359
  {ref}
360
+ <Choices
361
+ label="Events"
362
+ options={githubEventsAt(form.refKind)}
363
+ chosen={form.events}
364
+ onChange={(events) => set({ events })}
365
+ hint={form.events.includes('pull_request') ? `A pull request matches by the branch it merges into: ${form.refName.trim() || 'main'}.` : undefined}
366
+ />
367
+ <Exposure events={form.events} />
296
368
  </>
297
369
  )}
298
370
 
@@ -324,17 +396,13 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
324
396
  </div>
325
397
  <ErrorLine error={lookup.error} />
326
398
  {ref}
327
- <label className="field">
328
- <span className="label">Pipeline source</span>
329
- <select className="select" value={form.source} onChange={(event) => set({ source: event.target.value })}>
330
- {GITLAB_PIPELINE_SOURCES.map((source) => (
331
- <option key={source} value={source}>
332
- {source}
333
- </option>
334
- ))}
335
- </select>
336
- <span className="hint">Merge-request pipelines are never trusted: they name another project.</span>
337
- </label>
399
+ <Choices
400
+ label="Pipeline sources"
401
+ options={GITLAB_PIPELINE_SOURCES}
402
+ chosen={form.sources}
403
+ onChange={(sources) => set({ sources })}
404
+ hint="Merge-request pipelines are never trusted: they name another project."
405
+ />
338
406
  </>
339
407
  )}
340
408
 
@@ -349,13 +417,21 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
349
417
  </>
350
418
  )}
351
419
 
420
+ <ScopePicker
421
+ grants={grants}
422
+ value={choice.scope}
423
+ onChange={(next) => {
424
+ setChoice({ scope: next, chosen: true });
425
+ setPlan(null);
426
+ }}
427
+ />
352
428
  {field('Label (optional)', 'label', { placeholder: 'Deploys to production' })}
353
429
  <ErrorLine error={error} />
354
430
  <div className="dialog-actions">
355
431
  <button className="btn" type="button" onClick={close}>
356
432
  Cancel
357
433
  </button>
358
- <button className="btn btn-primary" type="submit" disabled={pending}>
434
+ <button className="btn btn-primary" type="submit" disabled={pending || Object.keys(choice.scope).length === 0}>
359
435
  {pending && <Spinner />}
360
436
  Review
361
437
  </button>
@@ -364,14 +440,16 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
364
440
  ) : (
365
441
  <div className="form">
366
442
  <p>
367
- Runs whose ID token carries exactly these claims will sign in as <span className="mono">{member}</span>, and read
368
- what it may read.
443
+ Runs whose ID token matches these claims sign in as <span className="mono">service:{serviceId}</span> and reach{' '}
444
+ {credentialScopeInWords(plan.scope)}, as long as the account holds it.
369
445
  </p>
370
446
  <Claims binding={plan} />
447
+ <Exposure events={claimValues(plan.claims.event_name)} />
371
448
  {plan.replaces.length > 0 && (
372
449
  <Notice tone="info">
373
450
  This replaces {plan.replaces.length === 1 ? 'a binding' : `${plan.replaces.length} bindings`}
374
451
  {plan.replaces.some((replaced) => replaced.why === 'keys_moved') ? ', since the issuer moved its keys' : ''}.
452
+ <Reached plan={plan} bindings={bindings} />
375
453
  </Notice>
376
454
  )}
377
455
  <ErrorLine error={error} />
@@ -383,7 +461,8 @@ function TrustWorkload({ serviceId }: { serviceId: string }) {
383
461
  className="btn btn-primary"
384
462
  type="button"
385
463
  disabled={pending}
386
- onClick={() => void run(() => coffre.bindings.create(member, input()), { affects: affects.bindings(member), onSuccess: close })}
464
+ // What the review said it reaches, whatever the account holds by now.
465
+ onClick={() => void run(() => coffre.bindings.create(member, { ...input(), scope: plan.scope }), { affects: affects.bindings(member), onSuccess: close })}
387
466
  >
388
467
  {pending && <Spinner />}
389
468
  Save binding
package/src/index.ts CHANGED
@@ -38,6 +38,7 @@ export {
38
38
  user,
39
39
  userAccess,
40
40
  userActivity,
41
+ userApps,
41
42
  users,
42
43
  type CoffreContext,
43
44
  } from './options.ts';
@@ -0,0 +1,23 @@
1
+ import type { ApprovalView } from '@coffre/client';
2
+
3
+ /**
4
+ * What the approval page says once an approval no longer waits: its title,
5
+ * and what became of it. Approved with no outcome yet, coffre is making
6
+ * the change; a minute on with none, the server reports it failed, its
7
+ * outcome unknown, and the page says coffre doesn't know whether it was made.
8
+ */
9
+ export function settled(view: Pick<ApprovalView, 'status' | 'outcome'>): { title: string; text: string } {
10
+ if (view.outcome?.error === 'unknown_outcome') {
11
+ return { title: 'This change may not have been made', text: "You approved it, but coffre doesn't know whether it was made. Check before approving it again." };
12
+ }
13
+ if (view.status === 'approved' && view.outcome === null) return { title: 'You approved this', text: 'coffre is making the change. Refresh in a moment to see how it went.' };
14
+ const title = {
15
+ pending: 'Waiting for you',
16
+ approved: 'You approved this',
17
+ denied: 'You denied this',
18
+ cancelled: 'The app cancelled this',
19
+ failed: 'This change failed',
20
+ expired: 'This approval expired',
21
+ }[view.status];
22
+ return { title, text: view.outcome?.text ?? (view.status === 'expired' ? 'Nothing changed. The app can ask again.' : 'Nothing changed.') };
23
+ }