@coffre/ui 0.2.0 → 0.4.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 (177) hide show
  1. package/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
  2. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
  3. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  4. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  5. package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
  6. package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
  7. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  8. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  9. package/dist/chunks/grants-Cw1FyGID.js +669 -0
  10. package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
  11. package/dist/chunks/offboarding-CE6d7um1.js +305 -0
  12. package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
  13. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  14. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  15. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  16. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  17. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  18. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  19. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
  20. package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
  21. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  22. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  23. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  24. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  25. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  26. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  27. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  28. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  29. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  30. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  31. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  32. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  33. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  34. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  35. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  36. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  37. package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
  38. package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
  39. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  40. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  41. package/dist/chunks/validation-D312_NLf.js +87 -0
  42. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  43. package/dist/index.d.ts +361 -27
  44. package/dist/index.js +188 -98
  45. package/dist/index.js.map +1 -1
  46. package/dist/pages/account.d.ts +2 -2
  47. package/dist/pages/account.js +297 -135
  48. package/dist/pages/account.js.map +1 -1
  49. package/dist/pages/approval.d.ts +9 -0
  50. package/dist/pages/approval.js +207 -0
  51. package/dist/pages/approval.js.map +1 -0
  52. package/dist/pages/audit.js +17 -542
  53. package/dist/pages/audit.js.map +1 -1
  54. package/dist/pages/device-login.js +2 -3
  55. package/dist/pages/device-login.js.map +1 -1
  56. package/dist/pages/environment.js +647 -257
  57. package/dist/pages/environment.js.map +1 -1
  58. package/dist/pages/login.js +18 -7
  59. package/dist/pages/login.js.map +1 -1
  60. package/dist/pages/oauth-authorize.d.ts +10 -0
  61. package/dist/pages/oauth-authorize.js +249 -0
  62. package/dist/pages/oauth-authorize.js.map +1 -0
  63. package/dist/pages/project-access.d.ts +6 -0
  64. package/dist/pages/project-access.js +370 -0
  65. package/dist/pages/project-access.js.map +1 -0
  66. package/dist/pages/project-environments.d.ts +4 -0
  67. package/dist/pages/project-environments.js +593 -0
  68. package/dist/pages/project-environments.js.map +1 -0
  69. package/dist/pages/project-settings.d.ts +4 -0
  70. package/dist/pages/project-settings.js +242 -0
  71. package/dist/pages/project-settings.js.map +1 -0
  72. package/dist/pages/project.d.ts +10 -2
  73. package/dist/pages/project.js +57 -934
  74. package/dist/pages/project.js.map +1 -1
  75. package/dist/pages/projects.js +53 -21
  76. package/dist/pages/projects.js.map +1 -1
  77. package/dist/pages/service-account.d.ts +10 -0
  78. package/dist/pages/{token.js → service-account.js} +115 -56
  79. package/dist/pages/service-account.js.map +1 -0
  80. package/dist/pages/service-accounts.d.ts +3 -0
  81. package/dist/pages/service-accounts.js +38 -0
  82. package/dist/pages/service-accounts.js.map +1 -0
  83. package/dist/pages/settings.d.ts +1 -0
  84. package/dist/pages/settings.js +104 -42
  85. package/dist/pages/settings.js.map +1 -1
  86. package/dist/pages/unregistered.js +2 -3
  87. package/dist/pages/unregistered.js.map +1 -1
  88. package/dist/pages/user.d.ts +6 -1
  89. package/dist/pages/user.js +18 -6
  90. package/dist/pages/user.js.map +1 -1
  91. package/dist/pages/users.js +6 -10
  92. package/dist/pages/users.js.map +1 -1
  93. package/package.json +3 -3
  94. package/src/components/actions-log.tsx +117 -0
  95. package/src/components/audit-sentence.tsx +55 -0
  96. package/src/components/command-palette.tsx +4 -4
  97. package/src/components/delete-place.tsx +180 -0
  98. package/src/components/directory.tsx +259 -110
  99. package/src/components/every-project.tsx +287 -0
  100. package/src/components/expiry-field.tsx +42 -0
  101. package/src/components/folders.tsx +219 -0
  102. package/src/components/grants.tsx +11 -4
  103. package/src/components/icons.tsx +2 -0
  104. package/src/components/missing.tsx +110 -0
  105. package/src/components/offboarding.tsx +61 -33
  106. package/src/components/page.tsx +4 -1
  107. package/src/components/principal-page.tsx +136 -106
  108. package/src/components/principal-picker.tsx +5 -5
  109. package/src/components/principal.tsx +4 -4
  110. package/src/components/references.tsx +323 -0
  111. package/src/components/service-tokens.tsx +115 -95
  112. package/src/components/shell.tsx +11 -32
  113. package/src/components/tabs.tsx +18 -0
  114. package/src/components/trusted-workloads.tsx +97 -79
  115. package/src/components/ui.tsx +8 -1
  116. package/src/index.ts +13 -2
  117. package/src/layout.tsx +2 -2
  118. package/src/lib/access-plan.ts +2 -2
  119. package/src/lib/audit-sentences.ts +161 -77
  120. package/src/lib/changes.ts +56 -5
  121. package/src/lib/coffre.ts +3 -2
  122. package/src/lib/one-time.ts +32 -0
  123. package/src/lib/project-access.ts +11 -23
  124. package/src/lib/project-page.ts +14 -0
  125. package/src/lib/queries.ts +126 -32
  126. package/src/lib/search.ts +25 -0
  127. package/src/lib/signin-errors.ts +45 -1
  128. package/src/lib/validation.ts +14 -0
  129. package/src/options.ts +187 -35
  130. package/src/pages/account.tsx +274 -129
  131. package/src/pages/approval.tsx +197 -0
  132. package/src/pages/audit.tsx +9 -61
  133. package/src/pages/environment.tsx +585 -286
  134. package/src/pages/login.tsx +8 -2
  135. package/src/pages/oauth-authorize.tsx +233 -0
  136. package/src/pages/project-access.tsx +219 -0
  137. package/src/pages/project-environments.tsx +582 -0
  138. package/src/pages/project-settings.tsx +259 -0
  139. package/src/pages/project.tsx +52 -879
  140. package/src/pages/projects.tsx +55 -18
  141. package/src/pages/service-account.tsx +50 -0
  142. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  143. package/src/pages/settings.tsx +62 -8
  144. package/src/pages/user.tsx +16 -4
  145. package/src/pages/users.tsx +2 -2
  146. package/src/parity.ts +160 -0
  147. package/src/register.ts +58 -9
  148. package/src/router.tsx +4 -0
  149. package/src/shared/models.ts +6 -2
  150. package/src/styles/globals.css +536 -31
  151. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  152. package/dist/chunks/grants-saMQagmG.js +0 -160
  153. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  154. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  155. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  156. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  157. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  158. package/dist/chunks/page-C5HcNqf2.js +0 -190
  159. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  160. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  161. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  162. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  163. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  164. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  165. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  166. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  167. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  168. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  169. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  170. package/dist/pages/token.d.ts +0 -3
  171. package/dist/pages/token.js.map +0 -1
  172. package/dist/pages/tokens.d.ts +0 -3
  173. package/dist/pages/tokens.js +0 -39
  174. package/dist/pages/tokens.js.map +0 -1
  175. package/dist/project-BqIy8gYR.d.ts +0 -5
  176. package/src/lib/instance.ts +0 -13
  177. package/src/pages/token.tsx +0 -34
@@ -0,0 +1,323 @@
1
+ import { useEffect, useId, useState } from 'react';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { Link } from '@tanstack/react-router';
4
+ import type { ListedReference, ReferenceView, SecretKey } from '@coffre/client';
5
+
6
+ import { useCoffre } from '../lib/coffre';
7
+ import { queries } from '../lib/queries';
8
+ import { useAction } from '../lib/use-action';
9
+ import { secretKeyProblem } from '../lib/validation';
10
+ import { ArrowRight } from './icons';
11
+ import { Card } from './page';
12
+ import { ConfirmDialog, ErrorLine, Modal, Notice, Timestamp } from './ui';
13
+
14
+ /**
15
+ * References: a secret read live through another (docs/design/environments.md).
16
+ * The vault makes and checks each one; these only show them.
17
+ */
18
+
19
+ /** Why a reference does not read, in a few words; null while it does. */
20
+ export function referenceProblem(state: ReferenceView['state']): string | null {
21
+ switch (state) {
22
+ case 'live':
23
+ return null;
24
+ case 'broken':
25
+ return 'Broken';
26
+ case 'replaced':
27
+ return 'No value';
28
+ case 'source_archived':
29
+ return 'Source archived';
30
+ case 'source_deleted':
31
+ return 'Source deleted';
32
+ case 'source_is_reference':
33
+ return 'Source is a reference';
34
+ case 'source_empty':
35
+ return 'Source has no value';
36
+ }
37
+ }
38
+
39
+ /** A secret's path as a link to it, when you can open it there. */
40
+ function SecretPath({ path, open }: { path: string; open: boolean }) {
41
+ const [project, environment, key] = path.split('/') as [string, string, string];
42
+ if (!open) {
43
+ return (
44
+ <span className="mono" title="You can't open the source">
45
+ {path}
46
+ </span>
47
+ );
48
+ }
49
+ return (
50
+ <Link className="mono" to="/projects/$project/$environment" params={{ project, environment }} search={{ filter: key }}>
51
+ {path}
52
+ </Link>
53
+ );
54
+ }
55
+
56
+ /**
57
+ * What a key that is a reference shows where its value would be: what it
58
+ * reads, and, when it does not read, why. Reading it is a reveal like any
59
+ * other, logged as a read of the source.
60
+ */
61
+ export function ReferenceValue({ reference }: { reference: NonNullable<SecretKey['reference']> }) {
62
+ const problem = referenceProblem(reference.state);
63
+ return (
64
+ <span className="reference-value">
65
+ <ArrowRight size={13} aria-label="A reference to" />
66
+ <SecretPath path={reference.source} open={reference.canOpenSource} />
67
+ {problem !== null && (
68
+ <span className="tag tag-red" title={reference.endedBy === null ? undefined : `By ${reference.endedBy}`}>
69
+ {problem}
70
+ </span>
71
+ )}
72
+ </span>
73
+ );
74
+ }
75
+
76
+ /**
77
+ * The references that read a secret from elsewhere, under its row: where
78
+ * each is held, who made it, who reads through it, and Break for those who
79
+ * may.
80
+ */
81
+ export function LentReferences({ references, onBreak }: { references: ListedReference[]; onBreak: (reference: ListedReference) => void }) {
82
+ return (
83
+ <ul className="lent-references" aria-label="Read through references">
84
+ {references.map((reference) => (
85
+ <li key={reference.id}>
86
+ <span>
87
+ Read through <SecretPath path={reference.holder} open={false} />, made by {reference.createdBy.replace(/^user:/, '')}{' '}
88
+ <Timestamp iso={reference.createdAt} display="relative" />
89
+ {reference.readers !== null && (
90
+ <span className="cell-muted">
91
+ {' '}
92
+ · {reference.readers.length === 0 ? 'no one reads it by a grant' : `${reference.readers.length} ${reference.readers.length === 1 ? 'person reads' : 'people read'} it: ${reference.readers.map((reader) => reader.replace(/^user:/, '').replace(/^token:/, 'service:')).join(', ')}`}
93
+ </span>
94
+ )}
95
+ </span>
96
+ {reference.canBreak && (
97
+ <button type="button" className="btn btn-sm btn-danger-outline" onClick={() => onBreak(reference)}>
98
+ Break
99
+ </button>
100
+ )}
101
+ </li>
102
+ ))}
103
+ </ul>
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Make a key a reference to a secret you read, by path: whoever reads its
109
+ * environment reads that secret through it, as it changes. Paths you can
110
+ * read are offered as you type.
111
+ */
112
+ export function MakeReference({
113
+ open,
114
+ onOpenChange,
115
+ holder,
116
+ environments,
117
+ onMake,
118
+ }: {
119
+ open: boolean;
120
+ onOpenChange: (open: boolean) => void;
121
+ /** `billing/prod/DATABASE_URL`. */
122
+ holder: string;
123
+ /** `market/prod`, each environment you read. */
124
+ environments: readonly string[];
125
+ onMake: (source: string) => void;
126
+ }) {
127
+ const [source, setSource] = useState('');
128
+ const listId = useId();
129
+ useEffect(() => {
130
+ if (open) setSource('');
131
+ }, [open]);
132
+ const [project, environment, key] = source.split('/');
133
+ const problem =
134
+ source === '' ? null
135
+ : source.split('/').length !== 3 || project === '' || environment === '' ? 'A secret, as project/environment/KEY.'
136
+ : secretKeyProblem(key!);
137
+ const holderEnvironment = holder.split('/').slice(0, 2).join('/');
138
+
139
+ return (
140
+ <Modal
141
+ open={open}
142
+ onOpenChange={onOpenChange}
143
+ title={`Make ${holder.split('/')[2]} a reference`}
144
+ description={`Whoever can read ${holderEnvironment} will read the secret you name, as it changes, even without access to its project. It takes your own read on that secret.`}
145
+ >
146
+ <form
147
+ className="form"
148
+ onSubmit={(event) => {
149
+ event.preventDefault();
150
+ if (problem !== null || source === '') return;
151
+ onMake(source);
152
+ onOpenChange(false);
153
+ }}
154
+ >
155
+ <label className="field">
156
+ <span className="label">Secret to read</span>
157
+ <input
158
+ className="input input-mono"
159
+ autoFocus
160
+ spellCheck={false}
161
+ autoComplete="off"
162
+ list={listId}
163
+ placeholder="market/prod/DATABASE_URL"
164
+ value={source}
165
+ aria-invalid={problem !== null}
166
+ onChange={(event) => setSource(event.target.value)}
167
+ />
168
+ <datalist id={listId}>
169
+ {environments.map((each) => (
170
+ <option key={each} value={`${each}/`} />
171
+ ))}
172
+ </datalist>
173
+ <span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
174
+ {problem ?? 'A reference cannot point at a reference: name the secret it reads.'}
175
+ </span>
176
+ </label>
177
+ <div className="dialog-actions">
178
+ <button className="btn" type="button" onClick={() => onOpenChange(false)}>
179
+ Cancel
180
+ </button>
181
+ <button className="btn btn-primary" type="submit" disabled={source === '' || problem !== null}>
182
+ Make reference
183
+ </button>
184
+ </div>
185
+ </form>
186
+ </Modal>
187
+ );
188
+ }
189
+
190
+ /**
191
+ * A project's secrets that others read through references held elsewhere,
192
+ * and who: on its access tab, beside the grants, since "who can read this"
193
+ * includes them. Those who may break one, its source's access managers or
194
+ * whoever writes where it is held, do it here.
195
+ */
196
+ export function ReferencesInto({ project }: { project: string }) {
197
+ const coffre = useCoffre();
198
+ const { data } = useQuery(queries.references(coffre, project));
199
+ const { run, error } = useAction();
200
+ const [breaking, setBreaking] = useState<ListedReference | null>(null);
201
+ const into = data?.ok === true ? data.references.filter((reference) => reference.source.startsWith(`${project}/`)) : [];
202
+ if (into.length === 0) return null;
203
+ return (
204
+ <Card
205
+ labelledBy="references-into"
206
+ title="Also readable through references"
207
+ description={`Secrets of ${project} that others read through references held elsewhere. Who reads a reference's environment reads its source, with no grant here.`}
208
+ >
209
+ <div className="dt-wrap">
210
+ <table className="dt stacks">
211
+ <thead>
212
+ <tr>
213
+ <th>Secret</th>
214
+ <th>Read through</th>
215
+ <th>Readers</th>
216
+ <th className="col-actions">
217
+ <span className="visually-hidden">Actions</span>
218
+ </th>
219
+ </tr>
220
+ </thead>
221
+ <tbody>
222
+ {into.map((reference) => (
223
+ <tr key={reference.id}>
224
+ <td className="mono" data-label="Secret">{reference.source}</td>
225
+ <td data-label="Read through">
226
+ <span className="cell-stack">
227
+ <span className="mono">{reference.holder}</span>
228
+ <small className="cell-muted">
229
+ Made by {reference.createdBy.replace(/^user:/, '')} <Timestamp iso={reference.createdAt} display="relative" />
230
+ </small>
231
+ </span>
232
+ </td>
233
+ <td data-label="Readers">
234
+ {reference.readers === null
235
+ ? '—'
236
+ : reference.readers.length === 0
237
+ ? <span className="cell-muted">No one, by a grant</span>
238
+ : reference.readers.map((reader) => reader.replace(/^user:/, '').replace(/^token:/, 'service:')).join(', ')}
239
+ </td>
240
+ <td className="col-actions">
241
+ {reference.canBreak && (
242
+ <button type="button" className="btn btn-sm btn-danger-outline" onClick={() => setBreaking(reference)}>
243
+ Break
244
+ </button>
245
+ )}
246
+ </td>
247
+ </tr>
248
+ ))}
249
+ </tbody>
250
+ </table>
251
+ </div>
252
+ {error !== null && <ErrorLine error={error} />}
253
+ <ConfirmDialog
254
+ open={breaking !== null}
255
+ onOpenChange={(open) => !open && setBreaking(null)}
256
+ title="Break this reference?"
257
+ body={breaking === null ? '' : `Whoever reads ${breaking.holder.split('/').slice(0, 2).join('/')} stops reading ${breaking.source} through it, and a run there refuses until ${breaking.holder.split('/')[2]} gets a value.`}
258
+ confirmLabel="Break"
259
+ onConfirm={() => {
260
+ const path = breaking!.holder;
261
+ void run(() => coffre.references.break(path), { affects: [['references']] });
262
+ }}
263
+ />
264
+ </Card>
265
+ );
266
+ }
267
+
268
+ /**
269
+ * The references that archiving `path` would stop, a project, an
270
+ * environment or a key: those reading a secret in it, held outside it in a
271
+ * place not archived itself (D58). Archiving is refused while any read
272
+ * (D41); the server decides, and this shows the dialog what it will say.
273
+ */
274
+ export function archiveBlockers(path: string, references: readonly ListedReference[]): ListedReference[] {
275
+ const within = (secret: string) => secret === path || secret.startsWith(`${path}/`);
276
+ return references.filter((reference) => reference.state === 'live' && !reference.holderArchived && within(reference.source) && !within(reference.holder));
277
+ }
278
+
279
+ /**
280
+ * What an archive dialog shows while references read what it would
281
+ * archive: each, and Break for those who may break it. Archive waits until
282
+ * none is left.
283
+ */
284
+ export function ArchiveBlocked({ references }: { references: readonly ListedReference[] }) {
285
+ const coffre = useCoffre();
286
+ const { run, error, pending } = useAction();
287
+ if (references.length === 0) return null;
288
+ const many = references.length > 1;
289
+ return (
290
+ <div className="archive-blocked">
291
+ <Notice tone="bad">
292
+ {many ? `${references.length} references read it` : 'A reference reads it'} from elsewhere. Break{' '}
293
+ {many ? 'them' : 'it'} first: archiving would stop {many ? 'those reads' : 'that read'}.
294
+ </Notice>
295
+ <ul className="archive-blockers" aria-label="References that read it">
296
+ {references.map((reference) => (
297
+ <li key={reference.id}>
298
+ <span className="cell-stack">
299
+ <span className="mono">{reference.holder}</span>
300
+ <small>
301
+ reads <span className="mono">{reference.source}</span>
302
+ </small>
303
+ </span>
304
+ {reference.canBreak ? (
305
+ <button
306
+ type="button"
307
+ className="btn btn-sm btn-danger-outline"
308
+ disabled={pending}
309
+ onClick={() => void run(() => coffre.references.break(reference.holder), { affects: [['references'], ['secrets']] })}
310
+ >
311
+ Break
312
+ </button>
313
+ ) : (
314
+ <small className="cell-muted">{`${reference.source.split('/')[0]}'s access managers, or whoever writes ${reference.holder.split('/').slice(0, 2).join('/')}, can break it`}</small>
315
+ )}
316
+ </li>
317
+ ))}
318
+ </ul>
319
+ <p className="hint">Once broken, a run where it is held refuses until that key gets a value of its own.</p>
320
+ {error !== null && <ErrorLine error={error} />}
321
+ </div>
322
+ );
323
+ }
@@ -13,7 +13,8 @@ import { Key, Plus, X } from './icons';
13
13
  const LIFETIMES = [30, 90, 180, 365] as const;
14
14
 
15
15
  /**
16
- * The bearer tokens a service presents to the API. A value exists in exactly
16
+ * The bearer tokens a service account presents to the API, for CI without
17
+ * OIDC. A value exists in exactly
17
18
  * one place, this dialog, for as long as it stays open: coffre keeps a hash.
18
19
  */
19
20
  export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens: ServiceTokenRow[] }) {
@@ -22,100 +23,118 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
22
23
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
23
24
 
24
25
  return (
25
- <Card
26
- labelledBy="service-tokens"
27
- title="Credentials"
28
- description="Bearer tokens this service presents to the API. Each is shown once, when it is issued; coffre keeps only a hash."
29
- actions={<IssueToken serviceId={serviceId} />}
30
- >
31
- {tokens.length === 0 ? (
32
- <EmptyState title="No live credentials">
33
- Nothing can act as this service until a token is issued.
34
- </EmptyState>
35
- ) : (
36
- <div className="dt-wrap">
37
- <table className="dt">
38
- <thead>
39
- <tr>
40
- <th>Token</th>
41
- <th className="col-shrink">Issued (UTC)</th>
42
- <th className="col-shrink">Last used</th>
43
- <th className="col-shrink">Expires</th>
44
- <th className="col-actions">
45
- <span className="visually-hidden">Actions</span>
46
- </th>
47
- </tr>
48
- </thead>
49
- <tbody>
50
- {tokens.map((token) => {
51
- const state = status(token.id);
52
- return (
53
- <Fragment key={token.id}>
54
- <tr className={rowClass(state)}>
55
- <td>
56
- <span className="cell-account">
57
- <Key size={15} />
58
- <span className="cell-stack">
59
- <span>{token.label ?? 'Unlabelled'}</span>
60
- <small className="mono">{token.hint}</small>
26
+ <>
27
+ <Card
28
+ labelledBy="service-tokens"
29
+ 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."
31
+ >
32
+ {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>
36
+ ) : (
37
+ <div className="dt-wrap">
38
+ <table className="dt">
39
+ <thead>
40
+ <tr>
41
+ <th>Token</th>
42
+ <th className="col-shrink">Issued (UTC)</th>
43
+ <th className="col-shrink">Last used</th>
44
+ <th className="col-shrink">Expires</th>
45
+ <th className="col-actions">
46
+ <span className="visually-hidden">Actions</span>
47
+ </th>
48
+ </tr>
49
+ </thead>
50
+ <tbody>
51
+ {tokens.map((token) => {
52
+ const state = status(token.id);
53
+ return (
54
+ <Fragment key={token.id}>
55
+ <tr className={rowClass(state)}>
56
+ <td>
57
+ <span className="cell-account">
58
+ <Key size={15} />
59
+ <span className="cell-stack">
60
+ <span>{token.label ?? 'Unlabelled'}</span>
61
+ <small className="mono">{token.hint}</small>
62
+ </span>
61
63
  </span>
62
- </span>
63
- </td>
64
- <td className="nowrap">
65
- <span className="cell-stack">
66
- <Timestamp iso={token.createdAt} />
67
- <small>by {token.createdBy}</small>
68
- </span>
69
- </td>
70
- <td className="nowrap cell-muted">
71
- {token.lastUsedAt === null ? (
72
- 'Never'
73
- ) : (
64
+ </td>
65
+ <td className="nowrap">
74
66
  <span className="cell-stack">
75
- <Timestamp iso={token.lastUsedAt} display="relative" />
76
- {token.lastUsedIp !== null && <small className="mono">{token.lastUsedIp}</small>}
67
+ <Timestamp iso={token.createdAt} />
68
+ <small>by {token.createdBy}</small>
77
69
  </span>
78
- )}
79
- </td>
80
- <td className="nowrap cell-muted">
81
- <Timestamp iso={token.expiresAt} display="relative" />
82
- </td>
83
- <td className="col-actions">
84
- {state.state === 'pending' ? (
85
- <RowPending status={state} />
86
- ) : (
87
- <ConfirmButton
88
- trigger={
89
- <button className="act">
90
- <X size={13} />
91
- Revoke
92
- </button>
93
- }
94
- title={
95
- <>
96
- Revoke <span className="mono">{token.hint}</span>?
97
- </>
98
- }
99
- body="Whatever uses it is refused from its next request. Issue a new token first if the service should keep working."
100
- confirmLabel="Revoke token"
101
- onConfirm={() => revoke(token)}
102
- />
103
- )}
104
- </td>
105
- </tr>
106
- <RowFailure
107
- status={state}
108
- columns={5}
109
- onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
110
- />
111
- </Fragment>
112
- );
113
- })}
114
- </tbody>
115
- </table>
116
- </div>
117
- )}
118
- </Card>
70
+ </td>
71
+ <td className="nowrap cell-muted">
72
+ {token.lastUsedAt === null ? (
73
+ 'Never'
74
+ ) : (
75
+ <span className="cell-stack">
76
+ <Timestamp iso={token.lastUsedAt} display="relative" />
77
+ {token.lastUsedIp !== null && <small className="mono">{token.lastUsedIp}</small>}
78
+ </span>
79
+ )}
80
+ </td>
81
+ <td className="nowrap cell-muted">
82
+ <Timestamp iso={token.expiresAt} display="relative" />
83
+ </td>
84
+ <td className="col-actions">
85
+ {state.state === 'pending' ? (
86
+ <RowPending status={state} />
87
+ ) : (
88
+ <ConfirmButton
89
+ trigger={
90
+ <button className="act">
91
+ <X size={13} />
92
+ Revoke
93
+ </button>
94
+ }
95
+ title={
96
+ <>
97
+ Revoke <span className="mono">{token.hint}</span>?
98
+ </>
99
+ }
100
+ body={
101
+ <>
102
+ {token.label ?? 'Unlabelled'},{' '}
103
+ {token.lastUsedAt === null ? (
104
+ 'never used'
105
+ ) : (
106
+ <>
107
+ last used <Timestamp iso={token.lastUsedAt} display="relative" />
108
+ </>
109
+ )}
110
+ .{' '}
111
+ Whatever uses it is refused from its next request. Issue a new token first if the
112
+ service account should keep working.
113
+ </>
114
+ }
115
+ confirmLabel="Revoke token"
116
+ onConfirm={() => revoke(token)}
117
+ />
118
+ )}
119
+ </td>
120
+ </tr>
121
+ <RowFailure
122
+ status={state}
123
+ columns={5}
124
+ onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
125
+ />
126
+ </Fragment>
127
+ );
128
+ })}
129
+ </tbody>
130
+ </table>
131
+ </div>
132
+ )}
133
+ </Card>
134
+ <div className="table-actions">
135
+ <IssueToken serviceId={serviceId} />
136
+ </div>
137
+ </>
119
138
  );
120
139
  }
121
140
 
@@ -136,7 +155,7 @@ function IssueToken({ serviceId }: { serviceId: string }) {
136
155
 
137
156
  return (
138
157
  <>
139
- <button className="btn btn-sm" onClick={() => setOpen(true)}>
158
+ <button className="btn" onClick={() => setOpen(true)}>
140
159
  <Plus size={14} />
141
160
  Issue token
142
161
  </button>
@@ -199,8 +218,9 @@ function IssueToken({ serviceId }: { serviceId: string }) {
199
218
  ) : (
200
219
  <div className="form">
201
220
  <Notice tone="info">
202
- This is the only time the value is shown. Store it where the service reads its
203
- configuration, as <span className="mono">COFFRE_TOKEN</span>.
221
+ This is the only time the value is shown. Store it where the service keeps its
222
+ secrets; a CI run signs the CLI in with it, piped to{' '}
223
+ <span className="mono">coffre login &lt;url&gt; --token</span>.
204
224
  </Notice>
205
225
  <div className="token-once">
206
226
  <code className="mono">{issued.token}</code>