@coffre/ui 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) 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/connected-apps-CUOyEZXR.js +146 -0
  4. package/dist/chunks/connected-apps-CUOyEZXR.js.map +1 -0
  5. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  6. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  7. package/dist/chunks/{directory-CSjWWUQ1.js → directory-CxxrnGUL.js} +177 -60
  8. package/dist/chunks/directory-CxxrnGUL.js.map +1 -0
  9. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  10. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  11. package/dist/chunks/grants-CXcmhujY.js +669 -0
  12. package/dist/chunks/grants-CXcmhujY.js.map +1 -0
  13. package/dist/chunks/offboarding-6eAduCsM.js +305 -0
  14. package/dist/chunks/offboarding-6eAduCsM.js.map +1 -0
  15. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  16. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  17. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  18. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  19. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  20. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  21. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-B9R2zPlp.js} +259 -251
  22. package/dist/chunks/principal-page-B9R2zPlp.js.map +1 -0
  23. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  24. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  25. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  26. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  27. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  28. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  29. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  30. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  31. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  32. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  33. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  34. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  35. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  36. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  37. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  38. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  39. package/dist/chunks/{use-change-c6CeLRin.js → use-change-CZdI2MJG.js} +75 -21
  40. package/dist/chunks/use-change-CZdI2MJG.js.map +1 -0
  41. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  42. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  43. package/dist/chunks/validation-D312_NLf.js +87 -0
  44. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  45. package/dist/index.d.ts +385 -31
  46. package/dist/index.js +188 -102
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.d.ts +2 -2
  49. package/dist/pages/account.js +174 -135
  50. package/dist/pages/account.js.map +1 -1
  51. package/dist/pages/approval.d.ts +9 -0
  52. package/dist/pages/approval.js +207 -0
  53. package/dist/pages/approval.js.map +1 -0
  54. package/dist/pages/audit.js +17 -542
  55. package/dist/pages/audit.js.map +1 -1
  56. package/dist/pages/device-login.js +2 -3
  57. package/dist/pages/device-login.js.map +1 -1
  58. package/dist/pages/environment.js +647 -257
  59. package/dist/pages/environment.js.map +1 -1
  60. package/dist/pages/login.js +18 -7
  61. package/dist/pages/login.js.map +1 -1
  62. package/dist/pages/oauth-authorize.d.ts +10 -0
  63. package/dist/pages/oauth-authorize.js +249 -0
  64. package/dist/pages/oauth-authorize.js.map +1 -0
  65. package/dist/pages/project-access.d.ts +6 -0
  66. package/dist/pages/project-access.js +370 -0
  67. package/dist/pages/project-access.js.map +1 -0
  68. package/dist/pages/project-environments.d.ts +4 -0
  69. package/dist/pages/project-environments.js +593 -0
  70. package/dist/pages/project-environments.js.map +1 -0
  71. package/dist/pages/project-settings.d.ts +4 -0
  72. package/dist/pages/project-settings.js +242 -0
  73. package/dist/pages/project-settings.js.map +1 -0
  74. package/dist/pages/project.d.ts +10 -2
  75. package/dist/pages/project.js +57 -934
  76. package/dist/pages/project.js.map +1 -1
  77. package/dist/pages/projects.js +53 -21
  78. package/dist/pages/projects.js.map +1 -1
  79. package/dist/pages/service-account.d.ts +10 -0
  80. package/dist/pages/{token.js → service-account.js} +112 -54
  81. package/dist/pages/service-account.js.map +1 -0
  82. package/dist/pages/service-accounts.d.ts +3 -0
  83. package/dist/pages/service-accounts.js +38 -0
  84. package/dist/pages/service-accounts.js.map +1 -0
  85. package/dist/pages/settings.d.ts +1 -0
  86. package/dist/pages/settings.js +104 -42
  87. package/dist/pages/settings.js.map +1 -1
  88. package/dist/pages/unregistered.js +2 -3
  89. package/dist/pages/unregistered.js.map +1 -1
  90. package/dist/pages/user.d.ts +6 -1
  91. package/dist/pages/user.js +18 -6
  92. package/dist/pages/user.js.map +1 -1
  93. package/dist/pages/users.js +6 -10
  94. package/dist/pages/users.js.map +1 -1
  95. package/package.json +3 -3
  96. package/src/components/actions-log.tsx +117 -0
  97. package/src/components/audit-sentence.tsx +55 -0
  98. package/src/components/command-palette.tsx +4 -4
  99. package/src/components/connected-apps.tsx +138 -0
  100. package/src/components/delete-place.tsx +180 -0
  101. package/src/components/directory.tsx +266 -110
  102. package/src/components/every-project.tsx +287 -0
  103. package/src/components/expiry-field.tsx +42 -0
  104. package/src/components/folders.tsx +219 -0
  105. package/src/components/grants.tsx +11 -4
  106. package/src/components/icons.tsx +2 -0
  107. package/src/components/missing.tsx +110 -0
  108. package/src/components/offboarding.tsx +62 -34
  109. package/src/components/page.tsx +4 -1
  110. package/src/components/principal-page.tsx +154 -108
  111. package/src/components/principal-picker.tsx +5 -5
  112. package/src/components/principal.tsx +4 -4
  113. package/src/components/references.tsx +323 -0
  114. package/src/components/service-tokens.tsx +112 -93
  115. package/src/components/shell.tsx +11 -32
  116. package/src/components/tabs.tsx +18 -0
  117. package/src/components/trusted-workloads.tsx +97 -79
  118. package/src/components/ui.tsx +8 -1
  119. package/src/index.ts +13 -3
  120. package/src/layout.tsx +2 -2
  121. package/src/lib/access-plan.ts +2 -2
  122. package/src/lib/audit-sentences.ts +161 -77
  123. package/src/lib/changes.ts +77 -5
  124. package/src/lib/coffre.ts +3 -2
  125. package/src/lib/one-time.ts +32 -0
  126. package/src/lib/project-access.ts +11 -23
  127. package/src/lib/project-page.ts +14 -0
  128. package/src/lib/queries.ts +126 -32
  129. package/src/lib/search.ts +25 -0
  130. package/src/lib/signin-errors.ts +45 -1
  131. package/src/lib/validation.ts +14 -0
  132. package/src/options.ts +187 -42
  133. package/src/pages/account.tsx +176 -133
  134. package/src/pages/approval.tsx +197 -0
  135. package/src/pages/audit.tsx +9 -61
  136. package/src/pages/environment.tsx +585 -286
  137. package/src/pages/login.tsx +8 -2
  138. package/src/pages/oauth-authorize.tsx +233 -0
  139. package/src/pages/project-access.tsx +219 -0
  140. package/src/pages/project-environments.tsx +582 -0
  141. package/src/pages/project-settings.tsx +259 -0
  142. package/src/pages/project.tsx +52 -879
  143. package/src/pages/projects.tsx +55 -18
  144. package/src/pages/service-account.tsx +50 -0
  145. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  146. package/src/pages/settings.tsx +62 -8
  147. package/src/pages/user.tsx +16 -4
  148. package/src/pages/users.tsx +2 -2
  149. package/src/parity.ts +160 -0
  150. package/src/register.ts +57 -10
  151. package/src/router.tsx +4 -0
  152. package/src/shared/models.ts +6 -2
  153. package/src/styles/globals.css +536 -31
  154. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  155. package/dist/chunks/grants-saMQagmG.js +0 -160
  156. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  157. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  158. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  159. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  160. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  161. package/dist/chunks/page-C5HcNqf2.js +0 -190
  162. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  163. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  164. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  165. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  166. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  167. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  168. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  169. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  170. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  171. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  172. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  173. package/dist/pages/token.d.ts +0 -3
  174. package/dist/pages/token.js.map +0 -1
  175. package/dist/pages/tokens.d.ts +0 -3
  176. package/dist/pages/tokens.js +0 -39
  177. package/dist/pages/tokens.js.map +0 -1
  178. package/dist/project-BqIy8gYR.d.ts +0 -5
  179. package/src/lib/instance.ts +0 -13
  180. package/src/pages/token.tsx +0 -34
@@ -0,0 +1,180 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { shownMember, type Deletion } from '@coffre/client';
4
+
5
+ import { useCoffre } from '../lib/coffre';
6
+ import { affects, queries } from '../lib/queries';
7
+ import { useAction } from '../lib/use-action';
8
+ import { Trash } from './icons';
9
+ import { ErrorLine, Modal, Notice, Spinner } from './ui';
10
+
11
+ /**
12
+ * Deleting an archived project or environment for good, `market` or
13
+ * `market/prod`. The dialog first asks the server what the deletion would
14
+ * take, then needs the place's path typed out before it deletes: nothing
15
+ * brings it back, so the one click a slip can make is never enough.
16
+ */
17
+ export function DeletePlaceDialog({
18
+ path,
19
+ open,
20
+ onOpenChange,
21
+ onDeleted,
22
+ }: {
23
+ path: string;
24
+ open: boolean;
25
+ onOpenChange: (open: boolean) => void;
26
+ onDeleted: (deletion: Deletion) => unknown;
27
+ }) {
28
+ const coffre = useCoffre();
29
+ const plan = useQuery({ ...queries.deletion(coffre, path), enabled: open });
30
+ const [typed, setTyped] = useState('');
31
+ const { pending, error, setError, run } = useAction();
32
+ const what = path.includes('/') ? 'environment' : 'project';
33
+
34
+ useEffect(() => {
35
+ if (!open) return;
36
+ setTyped('');
37
+ setError(null);
38
+ }, [open, setError]);
39
+
40
+ const deletion = plan.data?.ok === true ? plan.data.deletion : null;
41
+
42
+ return (
43
+ <Modal
44
+ open={open}
45
+ onOpenChange={onOpenChange}
46
+ title={
47
+ <>
48
+ Delete <span className="mono">{path}</span> for good?
49
+ </>
50
+ }
51
+ >
52
+ <div className="dialog-body">
53
+ {plan.data === undefined ? (
54
+ <Spinner />
55
+ ) : plan.data.ok ? (
56
+ <DeletionSummary deletion={plan.data.deletion} what={what} />
57
+ ) : (
58
+ <ErrorLine error={plan.data.error} />
59
+ )}
60
+ </div>
61
+ <div className="dialog-body">
62
+ <Notice tone="bad">
63
+ Nothing brings it back. Backups of the database taken before now still hold its
64
+ encrypted values; only they, with the vault key, could restore them.
65
+ </Notice>
66
+ </div>
67
+ <form
68
+ className="form"
69
+ onSubmit={(event) => {
70
+ event.preventDefault();
71
+ if (typed !== path || deletion === null) return;
72
+ run(
73
+ () => (what === 'project' ? coffre.projects.delete(path) : coffre.environments.delete(path)),
74
+ {
75
+ affects: affects.places(),
76
+ onSuccess: (result) => {
77
+ onOpenChange(false);
78
+ return onDeleted(result.deletion);
79
+ },
80
+ },
81
+ );
82
+ }}
83
+ >
84
+ <label className="field">
85
+ <span className="label">
86
+ Type <span className="mono">{path}</span> to confirm
87
+ </span>
88
+ <input
89
+ className="input input-mono"
90
+ autoFocus
91
+ spellCheck={false}
92
+ autoComplete="off"
93
+ value={typed}
94
+ onChange={(event) => setTyped(event.target.value)}
95
+ />
96
+ </label>
97
+ <ErrorLine error={error} />
98
+ <div className="dialog-actions">
99
+ <button className="btn" type="button" onClick={() => onOpenChange(false)}>
100
+ Cancel
101
+ </button>
102
+ <button
103
+ className="btn btn-danger"
104
+ type="submit"
105
+ disabled={typed !== path || deletion === null || pending}
106
+ >
107
+ {pending ? <Spinner /> : <Trash size={14} />}
108
+ Delete {what}
109
+ </button>
110
+ </div>
111
+ </form>
112
+ </Modal>
113
+ );
114
+ }
115
+
116
+ /** What the deletion takes and what it keeps, in the server's numbers. */
117
+ function DeletionSummary({ deletion, what }: { deletion: Deletion; what: 'project' | 'environment' }) {
118
+ const count = (n: number, one: string) => `${n} ${one}${n === 1 ? '' : 's'}`;
119
+ const environments = what === 'project' && deletion.environments.length > 0 ? (
120
+ <>
121
+ {' '}
122
+ in <span className="mono">{deletion.environments.join(', ')}</span>
123
+ </>
124
+ ) : null;
125
+ return (
126
+ <ul className="deletion-summary">
127
+ <li>
128
+ <strong>Erased:</strong> the values of {count(deletion.versions, 'secret version')}
129
+ {environments}, ciphertext and wrapped key both.
130
+ </li>
131
+ <li>
132
+ <strong>Revoked:</strong> {count(deletion.grants.length, 'grant')}
133
+ {deletion.grants.length > 0 && (
134
+ <>
135
+ {', '}
136
+ {deletion.grants.map((grant, index) => (
137
+ <span key={`${grant.member} ${grant.place}`}>
138
+ {index > 0 && ', '}
139
+ <span className="mono">{shownMember(grant.member)}</span> on{' '}
140
+ <span className="mono">{grant.place}</span>
141
+ </span>
142
+ ))}
143
+ </>
144
+ )}
145
+ .
146
+ </li>
147
+ {deletion.references.length > 0 && (
148
+ <li>
149
+ <strong>Ended:</strong> {count(deletion.references.length, 'reference')}, which read it from
150
+ elsewhere or which it reads:{' '}
151
+ {deletion.references.map((reference, index) => (
152
+ <span key={`${reference.holder} ${reference.source}`}>
153
+ {index > 0 && ', '}
154
+ <span className="mono">{reference.holder}</span> from{' '}
155
+ <span className="mono">{reference.source}</span>
156
+ </span>
157
+ ))}
158
+ .
159
+ </li>
160
+ )}
161
+ <li>
162
+ <strong>Kept, names only:</strong> the {what} and its {count(deletion.keys, 'key')}, as{' '}
163
+ <span className="mono">{deletion.tombstone}</span>, so the audit log still reads. Its
164
+ name is free to use again.
165
+ </li>
166
+ {deletion.stranded.length > 0 && (
167
+ <li>
168
+ <strong>Left with no access:</strong>{' '}
169
+ {deletion.stranded.map((member, index) => (
170
+ <span key={member}>
171
+ {index > 0 && ', '}
172
+ <span className="mono">{shownMember(member)}</span>
173
+ </span>
174
+ ))}
175
+ . Offboard them on the Users or Service accounts page if they are no longer needed.
176
+ </li>
177
+ )}
178
+ </ul>
179
+ );
180
+ }
@@ -1,16 +1,19 @@
1
1
  import { Fragment, useState } from 'react';
2
+ import { useQuery } from '@tanstack/react-query';
2
3
  import { Menu } from '@base-ui/react/menu';
3
4
  import { changeRole, directoryList, invite, removeMember, type InviteVars } from '../lib/changes';
4
5
  import { memberRef, useCoffre } from '../lib/coffre';
6
+ import { queries } from '../lib/queries';
7
+ import { useShell } from '../lib/use-shell';
5
8
  import { useChange, useChangeStatus } from '../lib/use-change';
6
9
  import type { DirectoryPrincipal } from '../shared/models';
7
10
  import { RowFailure, RowPending, rowClass } from './row-state';
8
- import { ConfirmDialog, EmptyState, MenuPopup, Modal, Spinner, Toggletip } from './ui';
11
+ import { ConfirmDialog, EmptyState, MenuPopup, Modal, Spinner, Timestamp, Toggletip } from './ui';
9
12
  import { PrincipalLink } from './principal';
10
- import { Key, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from './icons';
13
+ import { Clock, Folder, GitHub, Key, Link, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from './icons';
11
14
 
12
15
  /**
13
- * The instance directory, shared by the Users and Tokens pages.
16
+ * The instance directory, shared by the Users and Service accounts pages.
14
17
  *
15
18
  * Both are rows in the same table on the server (principals, typed user or
16
19
  * service); the pages split them because people and machines are looked after
@@ -19,7 +22,7 @@ import { Key, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from '.
19
22
 
20
23
  type PrincipalType = DirectoryPrincipal['principalType'];
21
24
 
22
- /** How the directory, and its changes, name someone: `user:…`, `token:…`. */
25
+ /** How the directory, and its changes, name someone to the API: `user:…`, `token:…` (shown `service:…`). */
23
26
  export const memberOf = (principal: Pick<DirectoryPrincipal, 'principalType' | 'principalId'>) =>
24
27
  memberRef(principal.principalType, principal.principalId);
25
28
 
@@ -32,7 +35,7 @@ export const ROLE_LABEL: Record<DirectoryPrincipal['instanceRole'], string> = {
32
35
  /** What each kind of principal is called in the interface. */
33
36
  export const KIND: Record<PrincipalType, string> = {
34
37
  user: 'user',
35
- service: 'token',
38
+ service: 'service account',
36
39
  };
37
40
 
38
41
  export function DirectoryTable({
@@ -46,109 +49,224 @@ export function DirectoryTable({
46
49
  hasRemoved?: boolean;
47
50
  }) {
48
51
  const users = principalType === 'user';
49
- const columns = users ? 4 : 3;
52
+ const columns = users ? 4 : 6;
50
53
  const { status, failedAdds, dismiss } = useChangeStatus(directoryList.queryKey);
51
54
  const refused = failedAdds<InviteVars>(principals.map(memberOf)).filter(
52
55
  ({ vars }) => vars.principalType === principalType,
53
56
  );
54
57
  return (
55
- <section className="card" aria-label={users ? 'Users' : 'Tokens'}>
56
- {principals.length === 0 && refused.length === 0 ? (
57
- <EmptyState
58
- title={
59
- hasRemoved
60
- ? `No active ${KIND[principalType]}s`
61
- : users
62
- ? 'Nobody is registered'
63
- : 'No tokens yet'
64
- }
65
- >
66
- {hasRemoved ? `Add a ${KIND[principalType]}` : `Add the first ${KIND[principalType]}`} to let
67
- it through the door. Project access is a separate step, granted from each project's page.
68
- </EmptyState>
69
- ) : (
70
- <div className="dt-wrap">
71
- <table className={`dt directory directory-${principalType} stacks`}>
72
- <thead>
73
- <tr>
74
- <th className="n">#</th>
75
- <th className="col-principal">
76
- <span className="th">
77
- {users ? <User size={14} /> : <Key size={14} />}
78
- {users ? 'Email' : 'Name'}
79
- </span>
80
- </th>
81
- {users && (
82
- <th className="col-role">
58
+ <>
59
+ <section className="card" aria-label={users ? 'Users' : 'Service accounts'}>
60
+ {principals.length === 0 && refused.length === 0 ? (
61
+ <EmptyState
62
+ title={
63
+ hasRemoved
64
+ ? `No active ${KIND[principalType]}s`
65
+ : users
66
+ ? 'Nobody is registered'
67
+ : 'No service accounts yet'
68
+ }
69
+ >
70
+ {hasRemoved ? `Add a ${KIND[principalType]}` : `Add the first ${KIND[principalType]}`} to let
71
+ it through the door. Project access is a separate step, granted from each project's page.
72
+ </EmptyState>
73
+ ) : (
74
+ <div className="dt-wrap">
75
+ <table className={`dt directory directory-${principalType} stacks${users ? '' : ' stacks-inline'}`}>
76
+ <thead>
77
+ <tr>
78
+ <th className="n">#</th>
79
+ <th className="col-principal">
83
80
  <span className="th">
84
- <ShieldCheck size={14} />
85
- Instance role
81
+ {users ? <User size={14} /> : <Key size={14} />}
82
+ {users ? 'Email' : 'Name'}
86
83
  </span>
87
84
  </th>
88
- )}
89
- <th className="col-actions">
90
- <span className="visually-hidden">Actions</span>
91
- </th>
92
- </tr>
93
- </thead>
94
- <tbody>
95
- {principals.map((principal, index) => {
96
- const state = status(memberOf(principal));
97
- return (
98
- <Fragment key={principal.principalId}>
99
- <tr className={`row-link ${rowClass(state)}`}>
100
- <td className="n">{index + 1}</td>
101
- <td
102
- className="col-lead"
103
- data-label={principal.principalType === 'user' ? 'Email' : 'Name'}
104
- >
105
- <PrincipalLink
106
- type={principal.principalType}
107
- id={principal.principalId}
108
- stretch
109
- />
110
- </td>
111
- {users && (
112
- <td className="col-role" data-label="Instance role">
113
- <InstanceRole principal={principal} />
85
+ {users ? (
86
+ <th className="col-role">
87
+ <span className="th">
88
+ <ShieldCheck size={14} />
89
+ Instance role
90
+ </span>
91
+ </th>
92
+ ) : (
93
+ <>
94
+ <th className="col-signin">
95
+ <span className="th">
96
+ <Link size={14} />
97
+ Signs in with
98
+ </span>
99
+ </th>
100
+ <th className="col-access">
101
+ <span className="th">
102
+ <Folder size={14} />
103
+ Access
104
+ </span>
105
+ </th>
106
+ <th className="col-used">
107
+ <span className="th">
108
+ <Clock size={14} />
109
+ Last used
110
+ </span>
111
+ </th>
112
+ </>
113
+ )}
114
+ <th className="col-actions">
115
+ <span className="visually-hidden">Actions</span>
116
+ </th>
117
+ </tr>
118
+ </thead>
119
+ <tbody>
120
+ {principals.map((principal, index) => {
121
+ const state = status(memberOf(principal));
122
+ return (
123
+ <Fragment key={principal.principalId}>
124
+ <tr className={`row-link ${rowClass(state)}`}>
125
+ <td className="n">{index + 1}</td>
126
+ <td
127
+ className="col-lead"
128
+ data-label={principal.principalType === 'user' ? 'Email' : 'Name'}
129
+ >
130
+ <PrincipalLink
131
+ type={principal.principalType}
132
+ id={principal.principalId}
133
+ stretch
134
+ />
114
135
  </td>
115
- )}
116
- <td className="col-actions">
117
- {state.state === 'pending' ? (
118
- <RowPending status={state} />
136
+ {users ? (
137
+ <td className="col-role" data-label="Instance role">
138
+ <InstanceRole principal={principal} />
139
+ </td>
119
140
  ) : (
120
- <PrincipalActions principal={principal} />
141
+ <ServiceCells principal={principal} />
121
142
  )}
122
- </td>
123
- </tr>
124
- <RowFailure
125
- status={state}
126
- columns={columns}
127
- onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
128
- />
129
- </Fragment>
130
- );
131
- })}
132
- {refused.map(({ mutationId, vars, status: failed }) => (
133
- <RowFailure
134
- key={mutationId}
135
- status={failed}
136
- columns={columns}
137
- onDismiss={() => dismiss(mutationId)}
138
- >
139
- {vars.principalId} was not added.
140
- </RowFailure>
141
- ))}
142
- </tbody>
143
- </table>
144
- </div>
145
- )}
146
- </section>
143
+ <td className="col-actions">
144
+ {state.state === 'pending' ? (
145
+ <RowPending status={state} />
146
+ ) : (
147
+ <PrincipalActions principal={principal} />
148
+ )}
149
+ </td>
150
+ </tr>
151
+ <RowFailure
152
+ status={state}
153
+ columns={columns}
154
+ onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
155
+ />
156
+ </Fragment>
157
+ );
158
+ })}
159
+ {refused.map(({ mutationId, vars, status: failed }) => (
160
+ <RowFailure
161
+ key={mutationId}
162
+ status={failed}
163
+ columns={columns}
164
+ onDismiss={() => dismiss(mutationId)}
165
+ >
166
+ {vars.principalId} was not added.
167
+ </RowFailure>
168
+ ))}
169
+ </tbody>
170
+ </table>
171
+ </div>
172
+ )}
173
+ </section>
174
+ <div className="table-actions">
175
+ <AddPrincipal principalType={principalType} />
176
+ </div>
177
+ </>
178
+ );
179
+ }
180
+
181
+ const PLATFORM: Record<string, string> = {
182
+ github: 'GitHub',
183
+ 'github-reusable': 'GitHub',
184
+ 'github-reusable-organization': 'GitHub',
185
+ gitlab: 'GitLab',
186
+ custom: 'OIDC',
187
+ };
188
+
189
+ /**
190
+ * What someone scanning service accounts wants of each: how it signs in, where
191
+ * it reaches, and whether it is still in use. Access comes with the list; the
192
+ * bindings and tokens are read per row, as its own page reads them.
193
+ */
194
+ function ServiceCells({ principal }: { principal: DirectoryPrincipal }) {
195
+ const client = useCoffre();
196
+ const { auth, capabilities, features } = useShell();
197
+ const member = memberOf(principal);
198
+ // As `loadServiceDirectory` read them, so these come from its cache.
199
+ const allowed = capabilities.canManageGrants && auth.signin !== null;
200
+ // Not suspended: an account added here is shown at once, its facts when they come.
201
+ const { data: bindings } = useQuery(queries.bindings(client, member, capabilities.canManageGrants && features.workloads));
202
+ const { data: credentials } = useQuery(queries.credentials(client, member, allowed));
203
+
204
+ const platforms = new Map<string, number>();
205
+ const bindingList = bindings?.ok === true ? bindings.bindings : [];
206
+ for (const binding of bindingList) {
207
+ const platform = PLATFORM[binding.profile] ?? 'OIDC';
208
+ platforms.set(platform, (platforms.get(platform) ?? 0) + 1);
209
+ }
210
+ const now = Date.now();
211
+ const tokenList = credentials?.ok === true ? credentials.tokens : [];
212
+ const activeTokens = tokenList.filter((token) => new Date(token.expiresAt).getTime() > now).length;
213
+ const lastUsed = [...bindingList, ...tokenList]
214
+ .map((credential) => credential.lastUsedAt)
215
+ .filter((at): at is string => at !== null)
216
+ .sort()
217
+ .at(-1);
218
+
219
+ const places = [
220
+ ...new Set(
221
+ (principal.grants ?? []).map(({ project, environment }) =>
222
+ environment === null ? project : `${project}/${environment}`,
223
+ ),
224
+ ),
225
+ ];
226
+ const projects = new Set((principal.grants ?? []).map((grant) => grant.project));
227
+ const loaded = bindings !== undefined && credentials !== undefined;
228
+
229
+ return (
230
+ <>
231
+ <td className="col-signin" data-label="Signs in with">
232
+ {!loaded ? null : platforms.size === 0 && activeTokens === 0 ? (
233
+ <span className="cell-muted">Nothing yet</span>
234
+ ) : (
235
+ <span className="signin-list">
236
+ {[...platforms].map(([platform, count]) => (
237
+ <span key={platform} className="signin-item">
238
+ {platform === 'GitHub' && <GitHub size={12} />}
239
+ {platform}
240
+ {count > 1 && ` ×${count}`}
241
+ </span>
242
+ ))}
243
+ {activeTokens > 0 && (
244
+ <span className="signin-item">
245
+ <Key size={12} />
246
+ {activeTokens} token{activeTokens === 1 ? '' : 's'}
247
+ </span>
248
+ )}
249
+ </span>
250
+ )}
251
+ </td>
252
+ <td className="col-access" data-label="Access" title={places.join(', ')}>
253
+ {places.length === 0 ? (
254
+ <span className="cell-muted">None</span>
255
+ ) : places.length <= 2 ? (
256
+ <span className="mono">{places.join(', ')}</span>
257
+ ) : (
258
+ `${projects.size} project${projects.size === 1 ? '' : 's'}`
259
+ )}
260
+ </td>
261
+ <td className="col-used cell-muted" data-label="Last used">
262
+ {!loaded ? null : lastUsed === undefined ? 'Never' : <Timestamp iso={lastUsed} display="relative" />}
263
+ </td>
264
+ </>
147
265
  );
148
266
  }
149
267
 
150
268
  /**
151
- * A user's instance role. Tokens have none worth showing: every one is a
269
+ * A user's instance role. Service accounts have none worth showing: every one is a
152
270
  * plain member. A root admin's role comes from the deployment, so its tag says
153
271
  * so on hover or tap instead of offering a menu that could not work.
154
272
  */
@@ -296,21 +414,7 @@ export function PrincipalActions({
296
414
  Remove <span className="mono">{principal.principalId}</span>?
297
415
  </>
298
416
  }
299
- body={
300
- principal.principalType === 'user' ? (
301
- <>
302
- They are signed out everywhere, and their CLI logins, linked sign-in accounts and
303
- project permissions are revoked at once. Their past actions stay in the audit log,
304
- and their page then lists the values they saw, to rotate.
305
- </>
306
- ) : (
307
- <>
308
- Every token issued to it stops working and its project permissions are revoked at
309
- once, including for anything running with it right now. Its past actions stay in
310
- the audit log, and its page then lists the values it read, to rotate.
311
- </>
312
- )
313
- }
417
+ body={<RemovalPreview principal={principal} open={confirming} />}
314
418
  confirmLabel={`Remove ${kind}`}
315
419
  onConfirm={() => remove(principal)}
316
420
  />
@@ -318,6 +422,58 @@ export function PrincipalActions({
318
422
  );
319
423
  }
320
424
 
425
+ const plural = (count: number, one: string) => `${count} ${one}${count === 1 ? '' : 's'}`;
426
+
427
+ /**
428
+ * What removing someone would do, read when its dialog opens, as `coffre
429
+ * offboard` previews it before `--apply`: every way in it revokes, and what
430
+ * they leave behind to rotate.
431
+ */
432
+ function RemovalPreview({ principal, open }: { principal: DirectoryPrincipal; open: boolean }) {
433
+ const { capabilities, features } = useShell();
434
+ const person = principal.principalType === 'user';
435
+ const { data, isPending } = useQuery({
436
+ ...queries.report(useCoffre(), memberOf(principal), capabilities.canManageGrants),
437
+ enabled: open,
438
+ });
439
+ const report = data?.ok === true ? data.report : null;
440
+ if (isPending) {
441
+ return (
442
+ <>
443
+ <Spinner size={13} /> Reading what {person ? 'they hold' : 'it holds'}…
444
+ </>
445
+ );
446
+ }
447
+ if (report === null) {
448
+ return person
449
+ ? 'They are signed out everywhere, and their sign-in accounts and project access are revoked at once.'
450
+ : 'Its bearer tokens and trust bindings stop working, and its project access is revoked at once.';
451
+ }
452
+ const { live } = report;
453
+ // Named, as an app's name is what its person knows it by: "2 connected apps (Claude, Cursor)".
454
+ const apps = `${plural(live.apps, 'connected app')}${report.apps.length > 0 ? ` (${report.apps.map((app) => app.name).join(', ')})` : ''}`;
455
+ const revokes = person
456
+ ? [
457
+ plural(live.grants, 'grant'),
458
+ plural(live.sessions, 'session'),
459
+ plural(live.identities, 'linked sign-in account'),
460
+ ...(features.mcp ? [apps] : []),
461
+ ]
462
+ : [plural(live.grants, 'grant'), plural(live.tokens, 'bearer token')];
463
+ return (
464
+ <>
465
+ Removing revokes {revokes.join(', ')} at once
466
+ {person ? '' : ', and its trust bindings, including for anything running as it now'}.{' '}
467
+ {report.exposed.length === 0
468
+ ? `No value ${person ? 'they' : 'it'} saw is still current.`
469
+ : `${plural(report.exposed.length, 'value')} ${person ? 'they' : 'it'} saw ${report.exposed.length === 1 ? 'is' : 'are'} still current: ${person ? 'their' : 'its'} page lists them, to rotate.`}
470
+ {report.issuedTokens.length > 0 &&
471
+ ` ${plural(report.issuedTokens.length, 'bearer token')} ${person ? 'they' : 'it'} issued still ${report.issuedTokens.length === 1 ? 'works' : 'work'}.`}{' '}
472
+ {person ? 'Their' : 'Its'} past actions stay in the audit log.
473
+ </>
474
+ );
475
+ }
476
+
321
477
  export function AddPrincipal({ principalType }: { principalType: PrincipalType }) {
322
478
  const [open, setOpen] = useState(false);
323
479
  const [principalId, setPrincipalId] = useState('');
@@ -355,7 +511,7 @@ export function AddPrincipal({ principalType }: { principalType: PrincipalType }
355
511
  >
356
512
  <label className="field">
357
513
  <span className="label">
358
- {principalType === 'user' ? 'Cloudflare Access email' : 'Service token common name'}
514
+ {principalType === 'user' ? 'Cloudflare Access email' : 'Service account name'}
359
515
  </span>
360
516
  <input
361
517
  className="input input-mono"
@@ -407,7 +563,7 @@ function RoleField({
407
563
  <option value="owner">Owner</option>
408
564
  </select>
409
565
  <span className="hint">
410
- Owners manage users and tokens, can create projects, and read the whole audit log.
566
+ Owners manage users and service accounts, can create projects, and read the whole audit log.
411
567
  Neither role reads a secret without a project grant.
412
568
  </span>
413
569
  </label>