@coffre/ui 0.9.0 → 0.10.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 (109) hide show
  1. package/dist/chunks/{audit-sentence-JrQIUq6j.js → audit-sentence-DpYySuqg.js} +74 -7
  2. package/dist/chunks/audit-sentence-DpYySuqg.js.map +1 -0
  3. package/dist/chunks/{connected-apps-Dr8UgjK7.js → connected-apps-D48SFJsG.js} +4 -4
  4. package/dist/chunks/{connected-apps-Dr8UgjK7.js.map → connected-apps-D48SFJsG.js.map} +1 -1
  5. package/dist/chunks/{delete-place-CQCDHkne.js → delete-place-Cg_M6rAq.js} +4 -4
  6. package/dist/chunks/{delete-place-CQCDHkne.js.map → delete-place-Cg_M6rAq.js.map} +1 -1
  7. package/dist/chunks/{directory-XcSbDRJv.js → directory-_LTgdiIM.js} +11 -9
  8. package/dist/chunks/directory-_LTgdiIM.js.map +1 -0
  9. package/dist/chunks/{folders-Dw240WMJ.js → folders-D3A1NGpt.js} +2 -2
  10. package/dist/chunks/{folders-Dw240WMJ.js.map → folders-D3A1NGpt.js.map} +1 -1
  11. package/dist/chunks/{grants-CmdZjKYU.js → grants-CNM913EY.js} +6 -6
  12. package/dist/chunks/{grants-CmdZjKYU.js.map → grants-CNM913EY.js.map} +1 -1
  13. package/dist/chunks/{multi-combobox-CsIXihuc.js → multi-combobox-B0JzP1QN.js} +2 -2
  14. package/dist/chunks/{multi-combobox-CsIXihuc.js.map → multi-combobox-B0JzP1QN.js.map} +1 -1
  15. package/dist/chunks/{offboarding-CrgwaetA.js → offboarding-BeaNM3sf.js} +3 -3
  16. package/dist/chunks/{offboarding-CrgwaetA.js.map → offboarding-BeaNM3sf.js.map} +1 -1
  17. package/dist/chunks/{personal-tokens-Dvl1FktE.js → personal-tokens-KsXajpx4.js} +4 -4
  18. package/dist/chunks/{personal-tokens-Dvl1FktE.js.map → personal-tokens-KsXajpx4.js.map} +1 -1
  19. package/dist/chunks/{principal-page-bOaEYWJB.js → principal-page-BaiZXh6D.js} +94 -78
  20. package/dist/chunks/principal-page-BaiZXh6D.js.map +1 -0
  21. package/dist/chunks/{project-page-BI--vjt3.js → project-page-CYZ_MkfX.js} +2 -2
  22. package/dist/chunks/{project-page-BI--vjt3.js.map → project-page-CYZ_MkfX.js.map} +1 -1
  23. package/dist/chunks/protected-BL_DsZO6.js +22 -0
  24. package/dist/chunks/protected-BL_DsZO6.js.map +1 -0
  25. package/dist/chunks/{queries-epz4MIuW.js → queries-Danu0o75.js} +99 -31
  26. package/dist/chunks/queries-Danu0o75.js.map +1 -0
  27. package/dist/chunks/{references-DImfw0cz.js → references-BK2aPXae.js} +4 -4
  28. package/dist/chunks/{references-DImfw0cz.js.map → references-BK2aPXae.js.map} +1 -1
  29. package/dist/chunks/{role-field-C1KhNaIR.js → role-field-DIJiRz9B.js} +8 -5
  30. package/dist/chunks/role-field-DIJiRz9B.js.map +1 -0
  31. package/dist/chunks/{row-state-BsIHspy4.js → row-state-xtRGFnDc.js} +2 -2
  32. package/dist/chunks/{row-state-BsIHspy4.js.map → row-state-xtRGFnDc.js.map} +1 -1
  33. package/dist/chunks/{theme-3b4DnCow.js → theme-Ck45wzWB.js} +2 -2
  34. package/dist/chunks/{theme-3b4DnCow.js.map → theme-Ck45wzWB.js.map} +1 -1
  35. package/dist/chunks/{ui-2kwXXfrX.js → ui-D-blFWfx.js} +29 -5
  36. package/dist/chunks/{ui-2kwXXfrX.js.map → ui-D-blFWfx.js.map} +1 -1
  37. package/dist/chunks/{use-action-BB-RcHo1.js → use-action-BafZVwux.js} +2 -2
  38. package/dist/chunks/{use-action-BB-RcHo1.js.map → use-action-BafZVwux.js.map} +1 -1
  39. package/dist/chunks/{use-change-BY6KPmnJ.js → use-change-DhV6i_Ge.js} +218 -101
  40. package/dist/chunks/use-change-DhV6i_Ge.js.map +1 -0
  41. package/dist/chunks/use-roles-Daje0ikO.js +224 -0
  42. package/dist/chunks/use-roles-Daje0ikO.js.map +1 -0
  43. package/dist/chunks/{use-shell-C_NmvCt_.js → use-shell-BX9mzfaL.js} +2 -2
  44. package/dist/chunks/{use-shell-C_NmvCt_.js.map → use-shell-BX9mzfaL.js.map} +1 -1
  45. package/dist/index.d.ts +8 -3
  46. package/dist/index.js +29 -15
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.js +9 -9
  49. package/dist/pages/approval.js +1 -1
  50. package/dist/pages/audit.js +96 -34
  51. package/dist/pages/audit.js.map +1 -1
  52. package/dist/pages/device-login.js +1 -1
  53. package/dist/pages/environment.js +255 -115
  54. package/dist/pages/environment.js.map +1 -1
  55. package/dist/pages/login.js +2 -2
  56. package/dist/pages/oauth-authorize.js +1 -1
  57. package/dist/pages/project-access.js +79 -46
  58. package/dist/pages/project-access.js.map +1 -1
  59. package/dist/pages/project-environments.js +79 -30
  60. package/dist/pages/project-environments.js.map +1 -1
  61. package/dist/pages/project-settings.js +7 -7
  62. package/dist/pages/project.js +2 -2
  63. package/dist/pages/projects.js +26 -14
  64. package/dist/pages/projects.js.map +1 -1
  65. package/dist/pages/service-account.js +22 -15
  66. package/dist/pages/service-account.js.map +1 -1
  67. package/dist/pages/service-accounts.js +4 -4
  68. package/dist/pages/settings.js +580 -8
  69. package/dist/pages/settings.js.map +1 -1
  70. package/dist/pages/unregistered.js +1 -1
  71. package/dist/pages/user.js +5 -5
  72. package/dist/pages/users.js +4 -4
  73. package/package.json +3 -3
  74. package/src/components/directory.tsx +5 -2
  75. package/src/components/grants.tsx +1 -1
  76. package/src/components/principal-page.tsx +38 -23
  77. package/src/components/protected.tsx +17 -0
  78. package/src/components/role-editor.tsx +582 -0
  79. package/src/components/role-field.tsx +7 -3
  80. package/src/components/scope-picker.tsx +19 -9
  81. package/src/components/shell.tsx +7 -1
  82. package/src/components/ui.tsx +25 -2
  83. package/src/lib/access-plan.ts +35 -36
  84. package/src/lib/audit-sentences.ts +75 -9
  85. package/src/lib/changes.ts +46 -8
  86. package/src/lib/project-access.ts +4 -78
  87. package/src/lib/queries.ts +97 -29
  88. package/src/lib/roles.ts +201 -0
  89. package/src/lib/row-reads.ts +12 -0
  90. package/src/lib/secret-edit-batch.ts +147 -56
  91. package/src/lib/sensitivity.ts +50 -0
  92. package/src/lib/service-setup.ts +20 -8
  93. package/src/lib/use-roles.ts +17 -0
  94. package/src/options.ts +2 -3
  95. package/src/pages/audit.tsx +99 -26
  96. package/src/pages/environment.tsx +264 -101
  97. package/src/pages/project-access.tsx +49 -19
  98. package/src/pages/project-environments.tsx +62 -3
  99. package/src/pages/projects.tsx +3 -1
  100. package/src/pages/settings.tsx +2 -0
  101. package/src/parity.ts +42 -5
  102. package/src/shared/models.ts +2 -9
  103. package/src/styles/globals.css +322 -25
  104. package/dist/chunks/audit-sentence-JrQIUq6j.js.map +0 -1
  105. package/dist/chunks/directory-XcSbDRJv.js.map +0 -1
  106. package/dist/chunks/principal-page-bOaEYWJB.js.map +0 -1
  107. package/dist/chunks/queries-epz4MIuW.js.map +0 -1
  108. package/dist/chunks/role-field-C1KhNaIR.js.map +0 -1
  109. package/dist/chunks/use-change-BY6KPmnJ.js.map +0 -1
@@ -1,11 +1,15 @@
1
1
  import type { Generation } from '@coffre/core/recipe';
2
+ import type { Sensitivity } from '../shared/models.ts';
3
+ import { stricter } from './sensitivity.ts';
2
4
 
3
5
  /**
4
6
  * A second secret a row writes with its own value, in the same patch: a
5
7
  * generated key pair's public key, beside its private key. It is part of
6
- * the row's edit, so saving, undoing or retrying the row takes both.
8
+ * the row's edit, so saving, undoing or retrying the row takes both. It is
9
+ * written at its own level, not its row's (`companionLevel`): `sensitivity`
10
+ * where the user chose one.
7
11
  */
8
- export type Companion = { key: string; value: string };
12
+ export type Companion = { key: string; value: string; sensitivity?: 'secret' | 'sensitive' };
9
13
 
10
14
  export type SecretDraft = {
11
15
  id: number;
@@ -14,8 +18,8 @@ export type SecretDraft = {
14
18
  companion?: Companion;
15
19
  /** The recipe a generated value was made by, saved with it; typing over the value drops it. */
16
20
  recipe?: string;
17
- /** Written plain: no secret, shown to whoever lists the environment. */
18
- plain?: boolean;
21
+ /** Who sees it (`lib/sensitivity.ts`). */
22
+ sensitivity: Sensitivity;
19
23
  };
20
24
 
21
25
  export type SecretChange = {
@@ -26,39 +30,52 @@ export type SecretChange = {
26
30
  companion?: Companion;
27
31
  /** Only beside a generated value. */
28
32
  recipe?: string;
29
- /** Only beside a new value: whether it is written plain, no secret. A value is a secret unless it says so. */
30
- plain?: boolean;
31
33
  /**
32
- * The version the edit started from, by id (`valueEdit`): a plain write
33
- * replaces it, or is refused, so that making a stored secret plain never
34
- * publishes a value someone has written over since.
34
+ * Who sees the key's value once saved: beside a new value, that value's
35
+ * level; alone, a mark, the current value made stricter and kept (`valueEdit`).
35
36
  */
36
- replaces?: string;
37
+ sensitivity?: Sensitivity;
37
38
  };
38
39
 
39
40
  /**
40
- * What a value edit makes of a row's change: `value`, written `plain` or
41
- * not, from where the edit started (`from.start`, the row's plain value or
42
- * the secret it revealed, `from.plain`, whether the row is plain, and
43
- * `from.startedAt`, that version's id). Back where it started, it is no
44
- * change. The version it started from stays with the change from its first
45
- * edit on, so a remount of the row (a rename refused, then retried) never
46
- * loses it.
41
+ * What an edit of a row's value, and of who sees it, makes of its change,
42
+ * from where it started: `from.start`, the value the editor opened on (''
43
+ * when it could not be read), and `from.level`, who sees the row's value
44
+ * now (null for none of its own: a secret is written). A value left as it
45
+ * opened writes nothing; its level changed alone is then a mark. Looser
46
+ * than the row, the field opens empty, as that takes the value typed again:
47
+ * a stored value is never made more visible by a flip. Back where it
48
+ * started, it is no change.
49
+ *
50
+ * secret 'sk_1', opened on 'sk_1': Sensitive -> { value: null, sensitivity: 'sensitive' }, a mark
51
+ * secret 'sk_1', opened on 'sk_1': Plain -> { value: null, sensitivity: 'plain' }, waiting for a value
52
+ * then 'sk_2' typed -> { value: 'sk_2', sensitivity: 'plain' }
47
53
  */
48
- export function valueEdit(change: SecretChange, from: { start: string; plain: boolean; startedAt: string | undefined }, value: string, plain: boolean): Partial<SecretChange> {
49
- const replaces = change.replaces ?? from.startedAt;
50
- if (value === from.start && plain === from.plain) return { value: null, plain: undefined, replaces };
51
- return { value, plain, replaces, companion: undefined, recipe: undefined };
54
+ export function valueEdit(
55
+ from: { start: string; level: Sensitivity | null },
56
+ next: { value: string | null; sensitivity: Sensitivity },
57
+ ): Pick<SecretChange, 'value' | 'sensitivity'> {
58
+ const level = from.level ?? 'secret';
59
+ const opened = stricter(level, next.sensitivity) ? '' : from.start;
60
+ const value = next.value === opened ? null : next.value;
61
+ return { value, sensitivity: value === null && next.sensitivity === level ? undefined : next.sensitivity };
52
62
  }
53
63
 
54
- type ActiveSecret = { key: string };
64
+ /** A listed key, and who sees its value now (null for none of its own). */
65
+ type ActiveSecret = { key: string; sensitivity?: Sensitivity | null };
55
66
 
56
67
  /**
57
- * A merge patch: a string sets a key, adding it if it is new; a value with
58
- * how it was generated sets it with its recipe; a plain one, no secret,
59
- * says so; `null` archives it.
68
+ * A merge patch: a value sets a key with who sees it, adding it if it is
69
+ * new; a value with how it was generated sets it with its recipe; a level
70
+ * alone makes the key's value stricter, kept; `null` archives it.
60
71
  */
61
- export type SecretPatch = Record<string, string | { value: string; generated: Generation } | { value: string; plain: true; replaces?: string } | null>;
72
+ export type SecretPatch = Record<
73
+ string,
74
+ | { value: string; sensitivity: Sensitivity }
75
+ | { value: string; generated: Generation; sensitivity: 'secret' | 'sensitive' }
76
+ | { sensitivity: Sensitivity }
77
+ | null
78
+ >;
62
79
 
63
80
  /**
64
81
  * How a row's generated value was made, as its write says it: its recipe,
@@ -71,17 +88,101 @@ function generationOf(key: string, edit: { recipe?: string; companion?: Companio
71
88
  : { recipe: edit.recipe, pair: { private: key, public: edit.companion.key.trim() } };
72
89
  }
73
90
 
74
- /** What a row writes under each key: its value, and its companion's beside it. */
75
- function rowPatch(key: string, value: string, edit: { recipe?: string; companion?: Companion; plain?: boolean; replaces?: string }): SecretPatch {
91
+ type ValueEdit = { recipe?: string; companion?: Companion; sensitivity?: Sensitivity };
92
+
93
+ /** Who sees the value a row writes: a secret unless it says, and a generated one never plain. */
94
+ function levelOf(edit: ValueEdit): 'secret' | 'sensitive' | 'plain' {
95
+ return edit.sensitivity === 'sensitive' || (edit.sensitivity === 'plain' && edit.recipe === undefined) ? edit.sensitivity : 'secret';
96
+ }
97
+
98
+ /**
99
+ * Who sees each listed key's value now, by its name after the save: a
100
+ * renamed key keeps its level under its new name; an archived one is gone.
101
+ */
102
+ function levelsNow(
103
+ active: readonly ActiveSecret[],
104
+ changes: Readonly<Record<string, SecretChange>>,
105
+ ): Map<string, Sensitivity | null> {
106
+ const out = new Map<string, Sensitivity | null>();
107
+ for (const entry of active) {
108
+ const change = secretChangeFor(changes, entry.key);
109
+ if (change?.archived) continue;
110
+ out.set(change?.key.trim() ?? entry.key, entry.sensitivity ?? null);
111
+ }
112
+ return out;
113
+ }
114
+
115
+ /**
116
+ * Who sees the public key a pair writes: who the user chose, else who sees
117
+ * the key it writes over now, or a secret, as a generated value is never
118
+ * plain. A public key need not be hidden, so a sensitive private key does
119
+ * not make it sensitive.
120
+ *
121
+ * PRIVATE_KEY sensitive, PUBLIC_KEY secret -> PUBLIC_KEY written secret
122
+ * PRIVATE_KEY secret, PUBLIC_KEY sensitive -> PUBLIC_KEY written sensitive
123
+ * PUBLIC_KEY new -> secret
124
+ */
125
+ function companionLevel(companion: Companion, now: ReadonlyMap<string, Sensitivity | null>): 'secret' | 'sensitive' {
126
+ return companion.sensitivity ?? (now.get(companion.key.trim()) === 'sensitive' ? 'sensitive' : 'secret');
127
+ }
128
+
129
+ /**
130
+ * What a row writes under each key: its value, and its companion's beside
131
+ * it, each saying who sees it, as every write does: over a sensitive key,
132
+ * one that said nothing would stay sensitive.
133
+ */
134
+ function rowPatch(key: string, value: string, edit: ValueEdit, now: ReadonlyMap<string, Sensitivity | null>): SecretPatch {
76
135
  const generated = generationOf(key, edit);
77
- const plain = (each: string) => (edit.replaces === undefined ? { value: each, plain: true as const } : { value: each, plain: true as const, replaces: edit.replaces });
78
- const entry = (each: string) => (generated !== undefined ? { value: each, generated } : edit.plain === true ? plain(each) : each);
136
+ const entry = (each: string, sensitivity: Sensitivity) => (generated === undefined || sensitivity === 'plain'
137
+ ? { value: each, sensitivity }
138
+ : { value: each, generated, sensitivity });
139
+ const patch: SecretPatch = Object.create(null);
140
+ patch[key] = entry(value, levelOf(edit));
141
+ if (edit.companion !== undefined) patch[edit.companion.key.trim()] = entry(edit.companion.value, companionLevel(edit.companion, now));
142
+ return patch;
143
+ }
144
+
145
+ /**
146
+ * The one merge patch a save writes, by each key's name after its renames:
147
+ * every value with its companion, every mark and every archive. An edit
148
+ * whose key went from the list writes nothing.
149
+ */
150
+ function patchOf(
151
+ active: readonly ActiveSecret[],
152
+ drafts: readonly SecretDraft[],
153
+ changes: Readonly<Record<string, SecretChange>>,
154
+ ): SecretPatch {
155
+ const now = levelsNow(active, changes);
156
+ // A key named `__proto__` is a key like any other.
79
157
  const patch: SecretPatch = Object.create(null);
80
- patch[key] = entry(value);
81
- if (edit.companion !== undefined) patch[edit.companion.key.trim()] = entry(edit.companion.value);
158
+ for (const entry of active) {
159
+ const change = secretChangeFor(changes, entry.key);
160
+ if (change === undefined) continue;
161
+ const key = change.key.trim();
162
+ if (change.archived) patch[entry.key] = null;
163
+ else if (change.value !== null) Object.assign(patch, rowPatch(key, change.value, change, now));
164
+ else if (change.sensitivity !== undefined) patch[key] = { sensitivity: change.sensitivity };
165
+ }
166
+ for (const draft of drafts) Object.assign(patch, rowPatch(draft.key.trim(), draft.value, draft, now));
82
167
  return patch;
83
168
  }
84
169
 
170
+ /**
171
+ * The keys a save makes sensitive, by their names after it: each it writes
172
+ * sensitive, a companion included, that was not sensitive before. Nobody
173
+ * sees them again, so the save asks first.
174
+ */
175
+ export function madeSensitive(
176
+ active: readonly ActiveSecret[],
177
+ drafts: readonly SecretDraft[],
178
+ changes: Readonly<Record<string, SecretChange>>,
179
+ ): string[] {
180
+ const now = levelsNow(active, changes);
181
+ return Object.entries(patchOf(active, drafts, changes))
182
+ .filter(([key, write]) => write !== null && write.sensitivity === 'sensitive' && now.get(key) !== 'sensitive')
183
+ .map(([key]) => key);
184
+ }
185
+
85
186
  /**
86
187
  * The recipe each key a save writes will hold, by its name after the save:
87
188
  * what the list shows of it until it is read back.
@@ -107,19 +208,17 @@ export function generationsOf(
107
208
  }
108
209
 
109
210
  /**
110
- * The value each key a save writes plain will show, by its name after the
111
- * save: what the list shows of it until it is read back.
211
+ * Who sees each value a save writes, and a plain one's value, by its key's
212
+ * name after the save: what the list shows of it until it is read back.
112
213
  */
113
- export function plainValuesOf(
214
+ export function levelsOf(
114
215
  active: readonly ActiveSecret[],
115
216
  drafts: readonly SecretDraft[],
116
217
  changes: Readonly<Record<string, SecretChange>>,
117
- ): Map<string, string> {
118
- const out = new Map<string, string>();
119
- for (const draft of drafts) if (draft.plain === true && draft.recipe === undefined) out.set(draft.key.trim(), draft.value);
120
- for (const entry of active) {
121
- const change = secretChangeFor(changes, entry.key);
122
- if (change !== undefined && !change.archived && change.value !== null && change.plain === true && change.recipe === undefined) out.set(change.key.trim(), change.value);
218
+ ): Map<string, { sensitivity: Sensitivity; value: string | null }> {
219
+ const out = new Map<string, { sensitivity: Sensitivity; value: string | null }>();
220
+ for (const [key, write] of Object.entries(patchOf(active, drafts, changes))) {
221
+ if (write !== null && 'value' in write) out.set(key, { sensitivity: write.sensitivity, value: write.sensitivity === 'plain' ? write.value : null });
123
222
  }
124
223
  return out;
125
224
  }
@@ -185,7 +284,7 @@ export function hasSecretEditConflict(
185
284
  const valueEditTargets = new Set(
186
285
  active.flatMap((entry) => {
187
286
  const change = secretChangeFor(changes, entry.key);
188
- return change !== undefined && !change.archived && change.value !== null
287
+ return change !== undefined && !change.archived && (change.value !== null || change.sensitivity !== undefined)
189
288
  ? [change.key.trim()]
190
289
  : [];
191
290
  }),
@@ -228,24 +327,16 @@ export async function applySecretEditBatch({
228
327
  }
229
328
 
230
329
  let applied = 0;
231
- // A key named `__proto__` is a key like any other.
232
- const patch: SecretPatch = Object.create(null);
330
+ const patch = patchOf(active, drafts, changes);
233
331
  try {
234
332
  for (const { sourceKey, change } of plan) {
235
- if (change.archived) {
236
- patch[sourceKey] = null;
237
- continue;
238
- }
239
333
  const key = change.key.trim();
240
- if (key !== sourceKey) {
241
- await operations.rename(sourceKey, key);
242
- delete remainingChanges[sourceKey];
243
- applied += 1;
244
- if (change.value !== null) remainingChanges[key] = { ...change, key };
245
- }
246
- if (change.value !== null) Object.assign(patch, rowPatch(key, change.value, change));
334
+ if (change.archived || key === sourceKey) continue;
335
+ await operations.rename(sourceKey, key);
336
+ delete remainingChanges[sourceKey];
337
+ applied += 1;
338
+ if (change.value !== null || change.sensitivity !== undefined) remainingChanges[key] = { ...change, key };
247
339
  }
248
- for (const draft of drafts) Object.assign(patch, rowPatch(draft.key.trim(), draft.value, draft));
249
340
 
250
341
  const written = Object.keys(patch).length;
251
342
  if (written > 0) await operations.write({ ...patch });
@@ -0,0 +1,50 @@
1
+ import type { SecretKey, Sensitivity } from '../shared/models.ts';
2
+ import type { SecretChange } from './secret-edit-batch.ts';
3
+
4
+ /**
5
+ * Who sees a key's value, loosest first: `plain`, whoever lists its
6
+ * environment; `secret`, the default, people whose role reads secrets;
7
+ * `sensitive`, no person, Owners included, while their apps use it through
8
+ * the credential proxy and service accounts read it. A key is made
9
+ * stricter with its value kept; looser only with its value typed again, so
10
+ * nobody shows a value by flipping it.
11
+ */
12
+ export const SENSITIVITIES = ['plain', 'secret', 'sensitive'] as const satisfies readonly Sensitivity[];
13
+
14
+ /** Each level as the page names it, and who it lets see the value. */
15
+ export const LEVELS: Record<Sensitivity, { label: string; hint: string }> = {
16
+ plain: { label: 'Plain', hint: 'Visible to anyone who can see this environment' },
17
+ secret: { label: 'Secret', hint: 'Visible to people whose role can read secrets' },
18
+ sensitive: { label: 'Sensitive', hint: 'Never shown to anyone, Owners included. Used through the proxy or by services' },
19
+ };
20
+
21
+ /** The levels in your personal config, `dev@me`, whose values nobody else sees, whatever their level. */
22
+ const PERSONAL_LEVELS: Record<Sensitivity, { label: string; hint: string }> = {
23
+ plain: { label: 'Plain', hint: 'Visible to you alone, as it is' },
24
+ secret: { label: 'Secret', hint: 'Visible to you alone, when you reveal it' },
25
+ sensitive: { label: 'Sensitive', hint: 'Never shown, you included. Your app uses it through the proxy' },
26
+ };
27
+
28
+ /** Each level as a page names it, in your personal config or elsewhere. */
29
+ export function levelsIn(personal: boolean): Record<Sensitivity, { label: string; hint: string }> {
30
+ return personal ? PERSONAL_LEVELS : LEVELS;
31
+ }
32
+
33
+ /** Whether `a` lets fewer people see a value than `b`. */
34
+ export function stricter(a: Sensitivity, b: Sensitivity): boolean {
35
+ return SENSITIVITIES.indexOf(a) > SENSITIVITIES.indexOf(b);
36
+ }
37
+
38
+ /** A key's own value, which a mark makes stricter in place: not a reference's, nor one a fork inherits. */
39
+ export function markable(entry: SecretKey): boolean {
40
+ return entry.sensitivity !== null && entry.reference === null && (entry.parent === null || entry.parent.state === 'overridden');
41
+ }
42
+
43
+ /**
44
+ * Whether a change of who sees a key waits for its value typed: looser
45
+ * than the key is, or where it has no value of its own to mark.
46
+ */
47
+ export function waitsForValue(entry: SecretKey, change: SecretChange | undefined): boolean {
48
+ if (change === undefined || change.archived || change.value !== null || change.sensitivity === undefined) return false;
49
+ return !markable(entry) || stricter(entry.sensitivity!, change.sensitivity);
50
+ }
@@ -1,9 +1,12 @@
1
- import { inScope, ROLE_NAMES, ROLES, type Permission, type Role, type Scope } from '@coffre/core/access';
1
+ import { inScope, PROJECT_ONLY_PERMISSIONS, type Permission, type Role, type Scope } from '@coffre/core/access';
2
+ import type { RoleView } from '@coffre/client';
2
3
 
3
4
  import type { ProjectSummary } from '../shared/models';
4
5
 
5
6
  /** What `givable` reads of the shell: the projects, what you hold in each environment, and the setting. */
6
7
  type Holder = {
8
+ /** The instance's roles, as the policy defines them (`useRoles`). */
9
+ roles: readonly Pick<RoleView, 'id' | 'permissions' | 'assignableToEnvironment'>[];
7
10
  projects: readonly ProjectSummary[];
8
11
  environments: readonly { project: string; environment: string; permissions: Permission[] }[];
9
12
  /** The instance's setting as `/me` says it, projects by slug, those you see; null for a service account. */
@@ -14,23 +17,32 @@ type Holder = {
14
17
  * The roles you may give a service account at a project, or one of its
15
18
  * environments, as the server decides it (`givesService` in
16
19
  * @coffre/core/access): any, where you manage access; otherwise, inside the
17
- * instance's setting, those whose every permission you hold there.
20
+ * instance's setting, those whose every permission you hold there. An
21
+ * environment takes only the roles that hold nothing project-wide. A
22
+ * project's role reaches its protected environments too, where the service
23
+ * holds the role's normal column and you your protected one: you hold that
24
+ * normal column there as well, or give none.
18
25
  *
19
- * a Developer of every dev, at market/dev viewer, developer
26
+ * a Developer of every dev, at market/dev viewer, contributor, developer
20
27
  * the same, at market none: a project takes holding all of it
28
+ * a Developer of market, prod protected contributor: viewer and developer read prod, which you only use
21
29
  */
22
30
  export function givable(holder: Holder, project: ProjectSummary, environment: string | null): Role[] {
23
- const held = environment === null
24
- ? project.permissions
25
- : holder.environments.find((entry) => entry.project === project.slug && entry.environment === environment)?.permissions ?? [];
26
- if (held.includes('grant.manage')) return [...ROLE_NAMES];
31
+ const heldIn = (slug: string) => holder.environments.find((entry) => entry.project === project.slug && entry.environment === slug)?.permissions ?? [];
32
+ const held = environment === null ? project.permissions : heldIn(environment);
33
+ const roles = holder.roles.filter((role) => environment === null || role.assignableToEnvironment);
34
+ if (held.includes('grant.manage')) return roles.map((role) => role.id);
27
35
  const setting = holder.serviceSetup;
28
36
  // The setting names projects by slug here, so a place is matched by its slugs.
29
37
  const place = environment === null
30
38
  ? { projectId: project.slug }
31
39
  : { projectId: project.slug, environmentId: environment, environmentSlug: environment };
32
40
  if (setting === null || !inScope(setting, place)) return [];
33
- return ROLE_NAMES.filter((role) => ROLES[role].permissions.every((permission) => held.includes(permission)));
41
+ const reached = environment === null ? project.environments.filter((candidate) => candidate.protected && !candidate.personal).map((candidate) => heldIn(candidate.slug)) : [];
42
+ const gives = (permission: Permission) =>
43
+ held.includes(permission) && (PROJECT_ONLY_PERMISSIONS.includes(permission) || reached.every((there) => there.includes(permission)));
44
+ // A role that holds nothing is given where its giver manages access alone, as the server decides (`givesService`).
45
+ return roles.filter((role) => role.permissions.length > 0 && role.permissions.every(gives)).map((role) => role.id);
34
46
  }
35
47
 
36
48
  /** The projects where you may give a service account something: on the project, or on one of its environments. */
@@ -0,0 +1,17 @@
1
+ import type { RolesView } from '@coffre/client';
2
+ import { useQuery } from '@tanstack/react-query';
3
+
4
+ import { useCoffre } from './coffre';
5
+ import { queries } from './queries';
6
+ import { SHIPPED_ROLES } from './roles';
7
+
8
+ /**
9
+ * The instance's roles, for a picker or a name: as an Owner edited and made
10
+ * them once read, and as they ship until then, or where they cannot be read,
11
+ * so a picker never waits for them. The server decides every grant: a role
12
+ * shown here a moment stale is one it refuses, never one it gives.
13
+ */
14
+ export function useRoles(): RolesView {
15
+ const { data } = useQuery({ ...queries.roles(useCoffre()), placeholderData: { ok: true as const, ...SHIPPED_ROLES } });
16
+ return data?.ok === true ? data : SHIPPED_ROLES;
17
+ }
package/src/options.ts CHANGED
@@ -24,6 +24,7 @@ import { memberRef, uiResult } from './lib/coffre';
24
24
  import { stringsOf } from './lib/search';
25
25
  import {
26
26
  hasAppsTab,
27
+ loadAudit,
27
28
  loadDirectory,
28
29
  loadEnvironment,
29
30
  loadMember,
@@ -173,11 +174,9 @@ export const audit = {
173
174
  detail: search.detail === '1' || search.decision === 'deny' ? '1' : undefined,
174
175
  }),
175
176
  loaderDeps: ({ search }: { search: AuditSearch }) => search,
176
- // The entries only: the verification is asked for once the page is up
177
- // (`ChainStatus`), so the table never waits on it.
178
177
  loader: ({ context, deps }: Loader & { deps: AuditSearch }) => {
179
178
  const { coffre, queryClient } = coffreOf(context);
180
- return queryClient.fetchQuery(queries.auditEntries(coffre, deps));
179
+ return loadAudit(queryClient, coffre, deps);
181
180
  },
182
181
  };
183
182
 
@@ -1,9 +1,9 @@
1
1
  import { type AuditEntryView } from '@coffre/client';
2
2
  import { useState, type ReactNode } from 'react';
3
- import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
3
+ import { useSuspenseQuery } from '@tanstack/react-query';
4
4
  import { Link } from '@tanstack/react-router';
5
5
  import { useCoffre } from '../lib/coffre';
6
- import { queries, type AuditSearch, type ChainResult } from '../lib/queries';
6
+ import { chainResult, chainUnknown, queries, shownChain, type AuditSearch, type ChainResult } from '../lib/queries';
7
7
  import {
8
8
  decidedBy,
9
9
  describe,
@@ -37,9 +37,31 @@ export function AuditPage() {
37
37
  const search = Route.useSearch();
38
38
  const client = useCoffre();
39
39
  const { data: result } = useSuspenseQuery(queries.auditEntries(client, search));
40
- // Not suspended: the table shows while the log is verified.
41
- const verification = useQuery(queries.auditChain(client));
42
- const chain = verification.data;
40
+ // Loaded with the entries: the page arrives with its badge.
41
+ const verification = useSuspenseQuery(queries.auditChain(client));
42
+ // The walk from the first entry, once someone ran it, beside the check from the newest checkpoint, which
43
+ // the page reuses for `FRESH_MS` and asks again after that, after a change made here, or on Retry:
44
+ // `shownChain` says which the page shows, until the page is left.
45
+ const [whole, setWhole] = useState<ChainResult | null>(null);
46
+ const chain = shownChain(verification.data, whole);
47
+ // The walk from the first entry, when someone asks for it: how far it has got. Its verdict takes the badge's place.
48
+ const [walked, setWalked] = useState<{ through: number | null } | null>(null);
49
+ const [walkFailed, setWalkFailed] = useState<string | null>(null);
50
+ const walkWhole = async () => {
51
+ setWalked({ through: null });
52
+ setWalkFailed(null);
53
+ setWhole(null);
54
+ let verdict: ChainResult;
55
+ try {
56
+ verdict = chainResult(await client.audit.verifyWhole((stretch) => setWalked({ through: stretch.through })), true);
57
+ } catch (error) {
58
+ verdict = chainUnknown(error);
59
+ }
60
+ // A walk that could not run says nothing of the log: the verdict from the newest checkpoint stands.
61
+ if (verdict.integrity === 'unknown') setWalkFailed(verdict.problem);
62
+ else if (verdict.integrity !== 'owners-only') setWhole(verdict);
63
+ setWalked(null);
64
+ };
43
65
  const { decision, actorId } = search;
44
66
  const detail = search.detail === '1';
45
67
  const deniedOnly = decision === 'deny';
@@ -64,7 +86,14 @@ export function AuditPage() {
64
86
  actions={
65
87
  // One region for every state, so each change of it is announced.
66
88
  <div className="chain-live" aria-live="polite" aria-atomic="true">
67
- <ChainStatus chain={chain} onRetry={() => void verification.refetch()} />
89
+ <ChainStatus
90
+ chain={chain}
91
+ walked={walked}
92
+ walkFailed={walkFailed}
93
+ retrying={verification.isFetching}
94
+ onRetry={() => void verification.refetch()}
95
+ onWalk={() => void walkWhole()}
96
+ />
68
97
  </div>
69
98
  }
70
99
  />
@@ -368,16 +397,35 @@ function BreakMark() {
368
397
  * someone is already feeling confident, and not on the morning it would have
369
398
  * mattered. Recomputing on load makes the claim continuous.
370
399
  *
371
- * It is not waited for, though: verifying re-reads the whole log, so until
372
- * it answers the badge says it is verifying, and a check that could not run
373
- * says so and offers to run again, rather than passing for a broken log.
400
+ * On load it checks what was written since the newest checkpoint, which
401
+ * vouches for everything before, so it is quick however long the log. The
402
+ * walk from the first entry, which checks again what the checkpoints vouch
403
+ * for, is there to ask for, a stretch a request, with how far it has got.
404
+ * The check on load is rendered with the page, never a loading state; a
405
+ * check that could not run says so and offers to run again, rather than
406
+ * passing for a broken log.
374
407
  */
375
- function ChainStatus({ chain, onRetry }: { chain: ChainResult | undefined; onRetry: () => void }) {
376
- if (chain === undefined) {
408
+ function ChainStatus({
409
+ chain,
410
+ walked,
411
+ walkFailed,
412
+ retrying,
413
+ onRetry,
414
+ onWalk,
415
+ }: {
416
+ chain: ChainResult;
417
+ walked: { through: number | null } | null;
418
+ walkFailed: string | null;
419
+ /** The check on load is being asked again. */
420
+ retrying: boolean;
421
+ onRetry: () => void;
422
+ onWalk: () => void;
423
+ }) {
424
+ if (walked !== null) {
377
425
  return (
378
- <span className="chain-note">
426
+ <span className="chain-note" role="status">
379
427
  <Spinner size={14} />
380
- Verifying…
428
+ {walked.through === null ? 'Verifying from the first entry…' : `Verified through ${walked.through.toLocaleString('en')}…`}
381
429
  </span>
382
430
  );
383
431
  }
@@ -408,7 +456,7 @@ function ChainStatus({ chain, onRetry }: { chain: ChainResult | undefined; onRet
408
456
  Couldn’t verify
409
457
  </button>
410
458
  </Toggletip>
411
- <button type="button" className="btn btn-sm" onClick={onRetry}>
459
+ <button type="button" className="btn btn-sm" disabled={retrying} onClick={onRetry}>
412
460
  Retry
413
461
  </button>
414
462
  </div>
@@ -424,6 +472,12 @@ function ChainStatus({ chain, onRetry }: { chain: ChainResult | undefined; onRet
424
472
  );
425
473
  }
426
474
 
475
+ const signed = chain.checkpoint === null ? null : `${absolute(chain.checkpoint.signedAt, false)} UTC`;
476
+ const verified = chain.whole
477
+ ? `Audit log verified from its first entry by the app and vault keys${signed === null ? ', not signed yet' : `, last signature at ${signed}`}.`
478
+ : signed === null
479
+ ? 'Audit log verified by the app and vault keys, not signed yet.'
480
+ : `What was written since the last checkpoint verified by the app and vault keys; the checkpoint, signed at ${signed}, vouches for everything before it, as each was checked when it was written.`;
427
481
  return (
428
482
  <div className="chain">
429
483
  {chain.pending > 0 && (
@@ -436,19 +490,38 @@ function ChainStatus({ chain, onRetry }: { chain: ChainResult | undefined; onRet
436
490
  </button>
437
491
  </Toggletip>
438
492
  )}
439
- <Toggletip
440
- align="end"
441
- label={
442
- chain.checkpoint === null
443
- ? 'Audit log verified by the app and vault keys, not signed yet.'
444
- : `Audit log verified by the app and vault keys, last signature at ${absolute(chain.checkpoint.signedAt, false)} UTC.`
445
- }
446
- >
447
- <button type="button" className="chain-seal">
448
- <ShieldCheck size={14} />
449
- Verified
493
+ {chain.remaining > 0 && (
494
+ <Toggletip
495
+ align="end"
496
+ label={`Verified through entry ${chain.through?.toLocaleString('en') ?? 'none'}. The checkpoints are catching up with the log, a stretch every five minutes, and a check goes no further than they have.`}
497
+ >
498
+ <button type="button" className="chain-note" role="status">
499
+ {chain.remaining.toLocaleString('en')} newer {chain.remaining === 1 ? 'entry' : 'entries'} to verify
500
+ </button>
501
+ </Toggletip>
502
+ )}
503
+ {walkFailed !== null && (
504
+ <Toggletip align="end" label={`coffre could not walk the whole log: ${walkFailed}. The verdict beside it, from the newest checkpoint, stands.`}>
505
+ <button type="button" className="chain-flag chain-flag-warn">
506
+ <AlertTriangle size={14} />
507
+ Whole log not checked
508
+ </button>
509
+ </Toggletip>
510
+ )}
511
+ {!chain.whole && chain.remaining === 0 && (
512
+ <button type="button" className="btn btn-sm" onClick={onWalk}>
513
+ Verify whole log
450
514
  </button>
451
- </Toggletip>
515
+ )}
516
+ {/* No seal over a log verified only in part: what is left could be anything. */}
517
+ {chain.remaining === 0 && (
518
+ <Toggletip align="end" label={verified}>
519
+ <button type="button" className="chain-seal">
520
+ <ShieldCheck size={14} />
521
+ Verified
522
+ </button>
523
+ </Toggletip>
524
+ )}
452
525
  </div>
453
526
  );
454
527
  }