@coffre/ui 0.10.1 → 0.11.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 (74) hide show
  1. package/dist/chunks/{audit-sentence-DpYySuqg.js → audit-sentence-DmdhLsRR.js} +13 -2
  2. package/dist/chunks/audit-sentence-DmdhLsRR.js.map +1 -0
  3. package/dist/chunks/{connected-apps-D48SFJsG.js → connected-apps-IJdunsu8.js} +2 -2
  4. package/dist/chunks/{connected-apps-D48SFJsG.js.map → connected-apps-IJdunsu8.js.map} +1 -1
  5. package/dist/chunks/{delete-place-Cg_M6rAq.js → delete-place-dIVoK87I.js} +3 -3
  6. package/dist/chunks/{delete-place-Cg_M6rAq.js.map → delete-place-dIVoK87I.js.map} +1 -1
  7. package/dist/chunks/{directory-_LTgdiIM.js → directory-BM8yoiJN.js} +6 -6
  8. package/dist/chunks/{directory-_LTgdiIM.js.map → directory-BM8yoiJN.js.map} +1 -1
  9. package/dist/chunks/{grants-CNM913EY.js → grants-CjVmOgb2.js} +3 -3
  10. package/dist/chunks/{grants-CNM913EY.js.map → grants-CjVmOgb2.js.map} +1 -1
  11. package/dist/chunks/{offboarding-BeaNM3sf.js → offboarding-DbozhPym.js} +2 -2
  12. package/dist/chunks/{offboarding-BeaNM3sf.js.map → offboarding-DbozhPym.js.map} +1 -1
  13. package/dist/chunks/{personal-tokens-KsXajpx4.js → personal-tokens-zWZOzLIC.js} +2 -2
  14. package/dist/chunks/{personal-tokens-KsXajpx4.js.map → personal-tokens-zWZOzLIC.js.map} +1 -1
  15. package/dist/chunks/{principal-page-BaiZXh6D.js → principal-page-DA4Ua2C-.js} +25 -12
  16. package/dist/chunks/principal-page-DA4Ua2C-.js.map +1 -0
  17. package/dist/chunks/{project-page-CYZ_MkfX.js → project-page-BjwEoXfU.js} +2 -2
  18. package/dist/chunks/{project-page-CYZ_MkfX.js.map → project-page-BjwEoXfU.js.map} +1 -1
  19. package/dist/chunks/protected-y7KVhtHd.js +77 -0
  20. package/dist/chunks/protected-y7KVhtHd.js.map +1 -0
  21. package/dist/chunks/{queries-Danu0o75.js → queries-2jdgTwfZ.js} +27 -1
  22. package/dist/chunks/queries-2jdgTwfZ.js.map +1 -0
  23. package/dist/chunks/{references-BK2aPXae.js → references-CRT2BsOS.js} +3 -3
  24. package/dist/chunks/{references-BK2aPXae.js.map → references-CRT2BsOS.js.map} +1 -1
  25. package/dist/chunks/{role-field-DIJiRz9B.js → role-field-DswIpPqY.js} +3 -3
  26. package/dist/chunks/{role-field-DIJiRz9B.js.map → role-field-DswIpPqY.js.map} +1 -1
  27. package/dist/chunks/{use-action-BafZVwux.js → use-action-CXEFFjx5.js} +2 -2
  28. package/dist/chunks/{use-action-BafZVwux.js.map → use-action-CXEFFjx5.js.map} +1 -1
  29. package/dist/chunks/{use-change-DhV6i_Ge.js → use-change-BC4xo02c.js} +10 -7
  30. package/dist/chunks/use-change-BC4xo02c.js.map +1 -0
  31. package/dist/chunks/{use-roles-Daje0ikO.js → use-roles-DswiNxBk.js} +2 -2
  32. package/dist/chunks/{use-roles-Daje0ikO.js.map → use-roles-DswiNxBk.js.map} +1 -1
  33. package/dist/chunks/{use-shell-BX9mzfaL.js → use-shell-zpjE_MKh.js} +2 -2
  34. package/dist/chunks/{use-shell-BX9mzfaL.js.map → use-shell-zpjE_MKh.js.map} +1 -1
  35. package/dist/index.d.ts +4 -0
  36. package/dist/index.js +2 -2
  37. package/dist/pages/account.js +6 -6
  38. package/dist/pages/audit.js +2 -2
  39. package/dist/pages/environment.js +42 -13
  40. package/dist/pages/environment.js.map +1 -1
  41. package/dist/pages/login.js +1 -1
  42. package/dist/pages/project-access.js +8 -8
  43. package/dist/pages/project-environments.js +13 -46
  44. package/dist/pages/project-environments.js.map +1 -1
  45. package/dist/pages/project-settings.js +6 -6
  46. package/dist/pages/project.js +1 -1
  47. package/dist/pages/projects.js +4 -4
  48. package/dist/pages/service-account.js +30 -6
  49. package/dist/pages/service-account.js.map +1 -1
  50. package/dist/pages/service-accounts.js +4 -4
  51. package/dist/pages/settings.js +5 -5
  52. package/dist/pages/unregistered.js +1 -1
  53. package/dist/pages/user.js +5 -5
  54. package/dist/pages/users.js +4 -4
  55. package/package.json +3 -3
  56. package/src/components/protected.tsx +70 -6
  57. package/src/components/service-tokens.tsx +9 -1
  58. package/src/components/trusted-workloads.tsx +6 -0
  59. package/src/lib/audit-sentences.ts +18 -2
  60. package/src/lib/bindings.ts +2 -2
  61. package/src/lib/changes.ts +7 -4
  62. package/src/lib/queries.ts +20 -0
  63. package/src/lib/sensitivity.ts +2 -1
  64. package/src/lib/service-setup.ts +14 -0
  65. package/src/pages/environment.tsx +44 -11
  66. package/src/pages/project-environments.tsx +4 -46
  67. package/src/parity.ts +16 -2
  68. package/src/styles/globals.css +10 -0
  69. package/dist/chunks/audit-sentence-DpYySuqg.js.map +0 -1
  70. package/dist/chunks/principal-page-BaiZXh6D.js.map +0 -1
  71. package/dist/chunks/protected-BL_DsZO6.js +0 -22
  72. package/dist/chunks/protected-BL_DsZO6.js.map +0 -1
  73. package/dist/chunks/queries-Danu0o75.js.map +0 -1
  74. package/dist/chunks/use-change-DhV6i_Ge.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { x as queries } from "../chunks/queries-Danu0o75.js";
1
+ import { x as queries } from "../chunks/queries-2jdgTwfZ.js";
2
2
  import { i as PageHeader, n as ClosedDoor, ot as Users, u as useCoffre } from "../chunks/page-JTORvh-N.js";
3
- import { t as useShell } from "../chunks/use-shell-BX9mzfaL.js";
4
- import { t as DirectoryTable } from "../chunks/directory-_LTgdiIM.js";
5
- import { n as RemovedList } from "../chunks/offboarding-BeaNM3sf.js";
3
+ import { t as useShell } from "../chunks/use-shell-zpjE_MKh.js";
4
+ import { t as DirectoryTable } from "../chunks/directory-BM8yoiJN.js";
5
+ import { n as RemovedList } from "../chunks/offboarding-DbozhPym.js";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
7
  import { useSuspenseQuery } from "@tanstack/react-query";
8
8
  //#region src/pages/users.tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/ui",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "coffre's pages, for a deployment's own TanStack Start app: its router, and a Vite plugin for its build.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -44,8 +44,8 @@
44
44
  "@tanstack/router-core": "1.171.15",
45
45
  "lucide-react": "1.47.0",
46
46
  "sonner": "2.0.7",
47
- "@coffre/client": "0.10.1",
48
- "@coffre/core": "0.10.1"
47
+ "@coffre/client": "0.11.0",
48
+ "@coffre/core": "0.11.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@tanstack/react-query": "5.103.1",
@@ -1,17 +1,81 @@
1
+ import { environmentId, protectEnvironment } from '../lib/changes';
2
+ import { useCoffre } from '../lib/coffre';
3
+ import type { ProjectEnvironment } from '../lib/project-environments';
4
+ import { keys } from '../lib/queries';
5
+ import { protectionInWords } from '../lib/roles';
6
+ import { useChange, useChangeStatus } from '../lib/use-change';
7
+ import { useRoles } from '../lib/use-roles';
8
+ import { useShell } from '../lib/use-shell';
1
9
  import { Lock } from './icons';
2
- import { Toggletip } from './ui';
10
+ import { ConfirmButton, Toggletip } from './ui';
11
+
12
+ const MEANING = 'Protected: each person here holds their role’s protected column, which an Owner sets in Settings › Roles. Service accounts hold their role as anywhere else.';
13
+ const WHO_UNPROTECTS = 'Only an Owner of its project takes protection off.';
3
14
 
4
15
  /**
5
- * An environment's protection, by its name (docs/design/roles.md): a tag
6
- * whose note says what it means, on a tap too.
16
+ * An environment's protection (docs/design/roles.md), on its card and its
17
+ * page. Whoever manages the project's environments protects one, and only
18
+ * an Owner of its project, or of the whole instance, takes it off, as the
19
+ * server says (`unprotectable`): for them the tag is the button that does,
20
+ * behind a confirmation. Everyone else sees the tag, whose
21
+ * note says what it means and who changes it, and nothing while it is off.
22
+ * A personal config has none of its own: it is as its parent is.
7
23
  */
8
- export function ProtectedTag() {
24
+ export function Protection({ project, environment }: { project: string; environment: ProjectEnvironment }) {
25
+ const { projects } = useShell();
26
+ const manages = projects.find((entry) => entry.slug === project)?.permissions.includes('environment.manage') === true;
27
+ const unprotects = environment.unprotectable === true;
28
+ const guarded = environment.protected;
29
+ if (manages && environment.details !== null && environment.personal !== true && (!guarded || unprotects)) {
30
+ return <ChangeProtection project={project} slug={environment.slug} guarded={guarded} unprotects={unprotects} />;
31
+ }
32
+ if (!guarded) return null;
9
33
  return (
10
- <Toggletip label="Protected: each person here holds their role’s protected column, which an Owner sets in Settings › Roles. Service accounts hold their role as anywhere else.">
11
- <button type="button" className="tag tag-button">
34
+ <Toggletip label={`${MEANING} ${WHO_UNPROTECTS}`}>
35
+ <button type="button" className="tag tag-amber tag-button">
12
36
  <Lock size={11} />
13
37
  Protected
14
38
  </button>
15
39
  </Toggletip>
16
40
  );
17
41
  }
42
+
43
+ /** The tag as the button that protects the environment, or takes it off, once confirmed. */
44
+ function ChangeProtection({ project, slug, guarded, unprotects }: { project: string; slug: string; guarded: boolean; unprotects: boolean }) {
45
+ const { roles } = useRoles();
46
+ const protect = useChange(protectEnvironment(useCoffre(), project));
47
+ const { status } = useChangeStatus(keys.projects);
48
+ const protection = protectionInWords(roles);
49
+ const place = `${project}/${slug}`;
50
+ return (
51
+ <ConfirmButton
52
+ trigger={
53
+ <button
54
+ type="button"
55
+ className={`tag tag-button tag-control ${guarded ? 'tag-amber' : 'tag-outline'}`}
56
+ aria-label={guarded ? `Protected: unprotect ${place}…` : `Protect ${place}…`}
57
+ >
58
+ <Lock size={11} />
59
+ {guarded ? 'Protected' : 'Protect…'}
60
+ </button>
61
+ }
62
+ // Once a change is on its way, the tag shows it already; another waits for its answer.
63
+ disabled={status(environmentId(project, slug)).state === 'pending'}
64
+ title={
65
+ <>
66
+ {guarded ? 'Unprotect' : 'Protect'} <span className="mono">{place}</span>?
67
+ </>
68
+ }
69
+ body={
70
+ guarded
71
+ ? 'People holding a role here get its full column again, as in any other environment. Service accounts are unaffected.'
72
+ : `People holding a role here get its protected column${protection === null ? ', which for now holds what the other does' : `: ${protection}`}. Service accounts are unaffected.${
73
+ unprotects ? '' : ` ${WHO_UNPROTECTS}`
74
+ }`
75
+ }
76
+ confirmLabel={guarded ? 'Unprotect' : 'Protect'}
77
+ destructive={guarded}
78
+ onConfirm={() => protect({ slug, protected: !guarded })}
79
+ />
80
+ );
81
+ }
@@ -1,9 +1,11 @@
1
1
  import type { TokenRow } from '@coffre/client';
2
2
  import { credentialScopeInWords } from '@coffre/core/access';
3
+ import { useQuery } from '@tanstack/react-query';
3
4
  import { Fragment, useState } from 'react';
4
5
  import { revokeCredential } from '../lib/changes';
5
6
  import { memberRef, useCoffre } from '../lib/coffre';
6
- import { affects } from '../lib/queries';
7
+ import { affects, queries } from '../lib/queries';
8
+ import { withheldInWords } from '../lib/service-setup';
7
9
  import { useAction } from '../lib/use-action';
8
10
  import { useChange, useChangeStatus } from '../lib/use-change';
9
11
  import { RowFailure, RowPending, rowClass } from './row-state';
@@ -144,6 +146,10 @@ function IssueToken({ serviceId, grants }: { serviceId: string; grants: HeldGran
144
146
  const [issued, setIssued] = useState<{ token: string; expiresAt: string } | null>(null);
145
147
  const coffre = useCoffre();
146
148
  const { pending, error, setError, run } = useAction();
149
+ const member = memberRef('service', serviceId);
150
+ // Told before it is issued: the sensitive values it would not read, as the server decides (R32).
151
+ const plan = useQuery({ ...queries.tokenPlan(coffre, member, scope), enabled: open && issued === null && Object.keys(scope).length > 0 });
152
+ const unread = withheldInWords(plan.data?.withheld, 'token');
147
153
 
148
154
  function close() {
149
155
  setOpen(false);
@@ -206,6 +212,8 @@ function IssueToken({ serviceId, grants }: { serviceId: string; grants: HeldGran
206
212
  </label>
207
213
  </div>
208
214
  <ScopePicker grants={grants} value={scope} onChange={setScope} />
215
+ {unread !== null && <Notice tone="warn">{unread}</Notice>}
216
+ {plan.isError && <Notice tone="warn">Coffre could not check which sensitive values this token would read.</Notice>}
209
217
  <ErrorLine error={error} />
210
218
  <div className="dialog-actions">
211
219
  <button className="btn" type="button" onClick={close}>
@@ -23,6 +23,7 @@ import {
23
23
  import { removeBinding } from '../lib/changes';
24
24
  import { memberRef, statusOf, useCoffre } from '../lib/coffre';
25
25
  import { affects, queries } from '../lib/queries';
26
+ import { withheldInWords } from '../lib/service-setup';
26
27
  import { useAction } from '../lib/use-action';
27
28
  import { useChange, useChangeStatus } from '../lib/use-change';
28
29
  import { useGitHubLookup } from '../lib/use-github-lookup';
@@ -178,6 +179,7 @@ function ReplaceKeys({ serviceId, issuer, bindings }: { serviceId: string; issue
178
179
  // The plan, with the keys it was made for: Save sends those, whatever the field says by then.
179
180
  const [preview, setPreview] = useState<{ plan: KeysPlan; jwks: KeySet } | null>(null);
180
181
  const plan = preview?.plan ?? null;
182
+ const unread = withheldInWords(plan?.withheld, 'binding');
181
183
  const coffre = useCoffre();
182
184
  const member = memberRef('service', serviceId);
183
185
  const { pending, error, setError, run } = useAction();
@@ -268,6 +270,7 @@ function ReplaceKeys({ serviceId, issuer, bindings }: { serviceId: string; issue
268
270
  ))}
269
271
  </tbody>
270
272
  </table>
273
+ {unread !== null && <Notice tone="warn">{unread}</Notice>}
271
274
  <ErrorLine error={error} />
272
275
  <div className="dialog-actions">
273
276
  <button className="btn" type="button" onClick={() => setPreview(null)}>
@@ -390,6 +393,8 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
390
393
  const whole = (): ScopeChoice => ({ scope: wholeScope(grants), chosen: false });
391
394
  const [choice, setChoice] = useState(whole);
392
395
  const [plan, setPlan] = useState<BindingPlan | null>(null);
396
+ // The sensitive values its credentials would not read, as the server planned it (R32).
397
+ const unread = withheldInWords(plan?.withheld, 'binding');
393
398
  // What the plan was made from: Save sends it, whatever the form says by then.
394
399
  const [reviewed, setReviewed] = useState<ReturnType<typeof input> | null>(null);
395
400
  const coffre = useCoffre();
@@ -700,6 +705,7 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
700
705
  </p>
701
706
  <Claims binding={plan} />
702
707
  <Exposure events={claimValues(plan.claims.event_name)} />
708
+ {unread !== null && <Notice tone="warn">{unread}</Notice>}
703
709
  {plan.replaces.length > 0 && (
704
710
  <Notice tone="info">
705
711
  This replaces {plan.replaces.length === 1 ? 'a binding' : `${plan.replaces.length} bindings`}
@@ -262,11 +262,15 @@ const TEMPLATES: Record<string, Template> = {
262
262
  return [...version, ...(level === 'plain' ? [', as a plain value, no secret'] : level === 'sensitive' ? [', as a sensitive value, shown to nobody'] : [])];
263
263
  },
264
264
  },
265
- // The credential proxy's own entry beside the vault's read: which credential the keys went into, and where.
265
+ // The credential proxy's own entry beside the vault's read: which credential the keys went into, where, and by which road.
266
266
  'credential.use': {
267
267
  did: ({ entry }) => (entry.metadata.purpose === 'expose' ? 'was given the values of' : 'used the credential'),
268
268
  tried: ({ entry }) => (entry.metadata.purpose === 'expose' ? 'be given the values of' : 'use the credential'),
269
- what: ({ entry }) => [text(entry.metadata.credential) ?? '', ...(text(entry.metadata.host) === null ? [] : [` on ${text(entry.metadata.host)}`])],
269
+ what: ({ entry }) => [
270
+ text(entry.metadata.credential) ?? '',
271
+ ...(text(entry.metadata.host) === null ? [] : [` on ${text(entry.metadata.host)}`]),
272
+ ...(entry.metadata.egress === true ? [", through the deployment's egress"] : []),
273
+ ],
270
274
  },
271
275
  'secret.restore': {
272
276
  did: 'restored',
@@ -274,6 +278,16 @@ const TEMPLATES: Record<string, Template> = {
274
278
  what: ({ entry }) => [...place(entry), ...(number(entry.metadata.from) === null ? [] : [` to version ${number(entry.metadata.from)}`])],
275
279
  then: ({ entry }) => (entry.version === null ? [] : [`, now ${entry.version}`]),
276
280
  },
281
+ // A sensitive value made a secret in place, by an Owner of its project: its value kept, shown to its readers from then on.
282
+ 'secret.loosen': {
283
+ did: 'made',
284
+ tried: 'make',
285
+ what: ({ entry }) => place(entry),
286
+ then: ({ entry }) => [
287
+ ` ${text(entry.metadata.to) ?? 'secret'}, from ${text(entry.metadata.from) ?? 'sensitive'}, its value kept`,
288
+ ...(entry.version === null ? [] : [`, now version ${entry.version}`]),
289
+ ],
290
+ },
277
291
  'secret.rename': {
278
292
  did: 'renamed',
279
293
  tried: 'rename',
@@ -662,6 +676,8 @@ const REASONS: Record<string, string> = {
662
676
  stand_ins: 'people get placeholders',
663
677
  sensitive: 'the value is sensitive',
664
678
  looser: 'making it visible takes a new value',
679
+ // A sensitive value made a secret in place by anyone but an Owner of its project.
680
+ not_owner: 'only an Owner of the project does it in place',
665
681
  inherited: 'it is inherited',
666
682
  expired: 'grant expired',
667
683
  removed: 'removed from coffre',
@@ -1,5 +1,5 @@
1
1
  import { CoffreError, type BindingPlan, type BindingView } from '@coffre/client';
2
- import { claimValues, fullRef, githubReusable, githubWorkflow, gitlabProject, type BindingClaims } from '@coffre/core/workloads';
2
+ import { claimValues, fullRef, githubReusable, githubWorkflow, gitlabProject, type BearerProfile, type BindingClaims } from '@coffre/core/workloads';
3
3
 
4
4
  /**
5
5
  * Trust bindings as the pages show and make them. A binding is its claims;
@@ -190,7 +190,7 @@ export function lookupFailure(name: string, failure: unknown): GitHubLookup {
190
190
  export function bindingOf(
191
191
  form: Form,
192
192
  found: GitHubIds | null = null,
193
- ): { profile: BindingPlan['profile']; issuer: string | null; claims: BindingClaims; jwks?: KeySet } {
193
+ ): { profile: BearerProfile; issuer: string | null; claims: BindingClaims; jwks?: KeySet } {
194
194
  const needed = (value: string, what: string) => {
195
195
  if (value.trim() === '') throw new Error(`${what} is needed`);
196
196
  return value.trim();
@@ -393,6 +393,8 @@ export function createEnvironment(client: CoffreClient, project: string): Change
393
393
  parent: vars.inherit === true ? (vars.from ?? null) : null,
394
394
  // A fork of a protected environment, however made, is protected from its first moment.
395
395
  protected: vars.from !== undefined && environments.some((environment) => environment.slug === vars.from && environment.protected),
396
+ // Who unprotects it is who unprotects any of the project's, as its siblings say, until the server answers.
397
+ unprotectable: environments.some((environment) => environment.unprotectable),
396
398
  personal: false,
397
399
  details: { archivedAt: null, secretCount: 0 },
398
400
  },
@@ -430,10 +432,11 @@ export function renameEnvironment(client: CoffreClient, project: string): Change
430
432
 
431
433
  /**
432
434
  * Protect an environment, or take its protection off (docs/design/roles.md):
433
- * shown on its card at once, and the card says if the server refuses. Only
434
- * an Owner of the whole instance unprotects one, which the page offers to
435
- * them alone. What everyone holds there changes, so the roles' readers are
436
- * refetched too.
435
+ * shown at once, on its card and its page, which say if the server
436
+ * refuses. Only an Owner of its project, or of the whole instance,
437
+ * unprotects one, which the page offers to them alone (`unprotectable`).
438
+ * What everyone holds there changes, so the
439
+ * roles' readers are refetched too.
437
440
  */
438
441
  export function protectEnvironment(client: CoffreClient, project: string): Change<Projects, Environment, { slug: string; protected: boolean }, unknown> {
439
442
  return {
@@ -59,6 +59,7 @@ export const keys = {
59
59
  credentials: (member: string) => ['credentials', member],
60
60
  bindings: (member: string) => ['bindings', member],
61
61
  githubRepositories: ['github-repositories'],
62
+ tokenPlan: (member: string, scope: Record<string, string>) => ['token-plan', member, scope],
62
63
  identities: ['identities'],
63
64
  sessions: ['sessions'],
64
65
  apps: ['apps'],
@@ -161,6 +162,25 @@ export const queries = {
161
162
  refetchOnWindowFocus: false,
162
163
  }),
163
164
 
165
+ /**
166
+ * What a service's token would reach, as the server would issue it now,
167
+ * and the sensitive values it would not read (`withheld`); issues
168
+ * nothing. A scope the server refuses plans nothing: issuing says why.
169
+ * Any other failure is one, asked once.
170
+ */
171
+ tokenPlan: (client: CoffreClient, member: string, scope: Record<string, string>) =>
172
+ queryOptions({
173
+ queryKey: keys.tokenPlan(member, scope),
174
+ queryFn: () => client.tokens.preview(member, { label: null, expiresInDays: 1, scope }).catch((failure: unknown) => {
175
+ const status = statusOf(failure);
176
+ if (status !== undefined && status >= 400 && status < 500) return null;
177
+ throw failure;
178
+ }),
179
+ staleTime: 60_000,
180
+ refetchOnWindowFocus: false,
181
+ retry: false,
182
+ }),
183
+
164
184
  /** Who holds what in a project, for those who manage its access. */
165
185
  grants: (client: CoffreClient, project: string) =>
166
186
  queryOptions({
@@ -7,7 +7,8 @@ import type { SecretChange } from './secret-edit-batch.ts';
7
7
  * `sensitive`, no person, Owners included, while their apps use it through
8
8
  * the credential proxy and service accounts read it. A key is made
9
9
  * stricter with its value kept; looser only with its value typed again, so
10
- * nobody shows a value by flipping it.
10
+ * nobody shows a value by flipping it, but for a sensitive value an Owner
11
+ * of the project makes a secret, from its row's menu (`loosenable`).
11
12
  */
12
13
  export const SENSITIVITIES = ['plain', 'secret', 'sensitive'] as const satisfies readonly Sensitivity[];
13
14
 
@@ -51,3 +51,17 @@ export function serviceProjects(holder: Holder): ProjectSummary[] {
51
51
  givable(holder, project, null).length > 0 ||
52
52
  project.environments.some((environment) => givable(holder, project, environment.slug).length > 0));
53
53
  }
54
+
55
+ /**
56
+ * What a service's new token or binding will not read, as the server said
57
+ * (`withheld`), in a sentence: the sensitive values of these places, which
58
+ * only one an Owner of their project issues reads (R32). Null for none.
59
+ *
60
+ * ['backend/dev'] It will not read the sensitive values of backend/dev: only one an Owner of backend issues does.
61
+ */
62
+ export function withheldInWords(withheld: readonly string[] | undefined, what: 'token' | 'binding'): string | null {
63
+ if (withheld === undefined || withheld.length === 0) return null;
64
+ const projects = [...new Set(withheld.map((path) => path.split('/')[0]!))];
65
+ const by = projects.length === 1 ? `an Owner of ${projects[0]}` : 'an Owner of their project';
66
+ return `This ${what} will not read the sensitive values of ${withheld.join(', ')}: only one ${by} ${what === 'token' ? 'issues' : 'saves'} does.`;
67
+ }
@@ -8,11 +8,11 @@ import { useShell } from '../lib/use-shell';
8
8
  import { Menu } from '@base-ui/react/menu';
9
9
  import { toast } from 'sonner';
10
10
  import { failureMessage, useCoffre } from '../lib/coffre';
11
- import { archiveSecret, forkKey, moveSecret, regenerateSecret, restoreSecret, saveSecrets, UnsavedEdits, type ForkAction, type SaveSecretsVars } from '../lib/changes';
11
+ import { archiveSecret, environmentId, forkKey, moveSecret, regenerateSecret, restoreSecret, saveSecrets, UnsavedEdits, type ForkAction, type SaveSecretsVars } from '../lib/changes';
12
12
  import { changeKey, type ItemStatus } from '../lib/optimistic';
13
13
  import { affects, keys as queryKeys, queries } from '../lib/queries';
14
14
  import { useChange, useChangeStatus } from '../lib/use-change';
15
- import { RowFailure, RowPending, rowClass } from '../components/row-state';
15
+ import { ItemFailure, RowFailure, RowPending, rowClass } from '../components/row-state';
16
16
  import { useAction } from '../lib/use-action';
17
17
  import type {
18
18
  ImportPlanEntry,
@@ -55,7 +55,7 @@ import {
55
55
  Tip,
56
56
  } from '../components/ui';
57
57
  import { Card, ClosedDoor, PageHeader } from '../components/page';
58
- import { ProtectedTag } from '../components/protected';
58
+ import { Protection } from '../components/protected';
59
59
  import { SecretReadOnly } from '../components/affordances';
60
60
  import { GenerateValue, type GeneratedUse } from '../components/generate-value';
61
61
  import { RecipeMark, RegenerateSecret } from '../components/regenerate';
@@ -154,7 +154,7 @@ export function EnvironmentPage() {
154
154
  keys={result.keys}
155
155
  parents={result.parents ?? []}
156
156
  personal={result.personal != null}
157
- guarded={result.protected}
157
+ loosenable={result.loosenable === true}
158
158
  rotateAfterDays={result.rotateAfterDays}
159
159
  />
160
160
  );
@@ -169,7 +169,7 @@ function EnvironmentLedger({
169
169
  keys,
170
170
  parents,
171
171
  personal,
172
- guarded,
172
+ loosenable,
173
173
  rotateAfterDays,
174
174
  }: {
175
175
  project: string;
@@ -180,14 +180,18 @@ function EnvironmentLedger({
180
180
  parents: string[];
181
181
  /** Your personal config, `dev@me`: its values yours alone. */
182
182
  personal: boolean;
183
- /** Protected (docs/design/roles.md): you hold your role's protected column here, a personal config as its parent. */
184
- guarded: boolean;
183
+ /** Whether you make a sensitive value of its own a secret in place, as an Owner of its project does, as the server says. */
184
+ loosenable: boolean;
185
185
  /** Days a value may go unchanged before it is flagged for rotation; null for no flag. */
186
186
  rotateAfterDays: number | null;
187
187
  }) {
188
188
  const coffre = useCoffre();
189
189
  const queryClient = useQueryClient();
190
- const { principal } = useShell();
190
+ const { principal, projects } = useShell();
191
+ // It as the project tree has it, where its protection changes at once: said while on its way, or why it did not.
192
+ const inProject = projects.find((entry) => entry.slug === project)?.environments.find((entry) => entry.slug === environment);
193
+ const { status: projectStatus, dismiss: dismissProject } = useChangeStatus(queryKeys.projects);
194
+ const protecting = projectStatus(environmentId(project, environment));
191
195
  const save = useChange(saveSecrets(coffre, { project, environment }, principal?.id ?? null));
192
196
  const restore = useChange(restoreSecret(coffre, { project, environment }));
193
197
  const archive = useChange(archiveSecret(coffre, { project, environment }));
@@ -540,7 +544,7 @@ function EnvironmentLedger({
540
544
  <PageHeader
541
545
  tile={project}
542
546
  title={environment}
543
- aside={guarded && <ProtectedTag />}
547
+ aside={inProject !== undefined && <Protection project={project} environment={inProject} />}
544
548
  actions={personal ? (
545
549
  <DeletePersonal project={project} environment={environment} of={parents[0]!} />
546
550
  ) : principal?.type === 'user' && canList && (
@@ -549,6 +553,11 @@ function EnvironmentLedger({
549
553
  My own {environment}
550
554
  </Link>
551
555
  )}
556
+ meta={protecting.state === 'pending' ? (
557
+ <RowPending status={protecting} />
558
+ ) : protecting.state === 'failed' ? (
559
+ <ItemFailure status={protecting} onDismiss={() => dismissProject(protecting.mutationId)} />
560
+ ) : undefined}
552
561
  description={personal ? (
553
562
  <span className="inherits">
554
563
  Your own{' '}
@@ -686,6 +695,7 @@ function EnvironmentLedger({
686
695
  canArchive={canArchive}
687
696
  canReveal={canReveal}
688
697
  canList={canList}
698
+ canLoosen={loosenable}
689
699
  folders={folders}
690
700
  onMove={(folder) => move({ key: entry.key, folder })}
691
701
  lent={lentBy.get(entry.key) ?? []}
@@ -1225,6 +1235,7 @@ function SecretRow({
1225
1235
  canArchive,
1226
1236
  canReveal,
1227
1237
  canList,
1238
+ canLoosen,
1228
1239
  folders,
1229
1240
  onMove,
1230
1241
  lent,
@@ -1261,6 +1272,8 @@ function SecretRow({
1261
1272
  canReveal: boolean;
1262
1273
  /** Whether the caller lists the environment: reads it, or uses it as a Contributor does. */
1263
1274
  canList: boolean;
1275
+ /** Whether the caller makes a sensitive value a secret in place, its value kept: an Owner of the project. */
1276
+ canLoosen: boolean;
1264
1277
  /** The folders in use in this environment, offered when moving it. */
1265
1278
  folders: readonly string[];
1266
1279
  onMove: (folder: string | null) => void;
@@ -1305,6 +1318,8 @@ function SecretRow({
1305
1318
  const { run: act, error: actError } = useAction();
1306
1319
  // Made sensitive from the menu, once confirmed: nobody sees its value after.
1307
1320
  const [hiding, setHiding] = useState(false);
1321
+ // Made a secret from the menu, by an Owner, once confirmed: its readers see its value after.
1322
+ const [showing, setShowing] = useState(false);
1308
1323
  const { reference, parent } = entry;
1309
1324
  // In a fork (docs/design/forking.md): a key it inherits has no row of its
1310
1325
  // own, one it overrides has, and one it removed is not served.
@@ -1437,10 +1452,12 @@ function SecretRow({
1437
1452
  }
1438
1453
 
1439
1454
  // Who sees it, chosen from its menu: stricter at once, its value kept; more
1440
- // visible in the editor, which asks for the value typed again.
1455
+ // visible in the editor, which asks for the value typed again. But a
1456
+ // sensitive value an Owner makes a secret keeps its value too, once confirmed.
1441
1457
  function chooseLevel(next: Sensitivity) {
1442
1458
  if (entry.sensitivity === null || next === entry.sensitivity) return;
1443
- if (stricter(entry.sensitivity, next)) {
1459
+ if (canLoosen && entry.sensitivity === 'sensitive' && next === 'secret') setShowing(true);
1460
+ else if (stricter(entry.sensitivity, next)) {
1444
1461
  setFocusName(false);
1445
1462
  setReveal(null);
1446
1463
  onEdit();
@@ -1899,6 +1916,22 @@ function SecretRow({
1899
1916
  onConfirm={() => mark('sensitive')}
1900
1917
  />
1901
1918
 
1919
+ <ConfirmDialog
1920
+ open={showing}
1921
+ onOpenChange={setShowing}
1922
+ title={
1923
+ <>
1924
+ Make <span className="mono">{entry.key}</span> a secret?
1925
+ </>
1926
+ }
1927
+ body={personal
1928
+ ? 'Its value is kept, and you will see it. Its earlier versions stay sensitive.'
1929
+ : `Its value is kept, and shown from now on to people whose role reads secrets in ${project}/${environment}, you included, and wherever a reference or a fork reads it. Its earlier versions stay sensitive.`}
1930
+ confirmLabel="Make secret"
1931
+ destructive={false}
1932
+ onConfirm={() => mark('secret')}
1933
+ />
1934
+
1902
1935
  <ConfirmDialog
1903
1936
  open={breaking !== null}
1904
1937
  onOpenChange={(open) => !open && setBreaking(null)}
@@ -6,7 +6,7 @@ import { useShell } from '../lib/use-shell';
6
6
  import { Menu } from '@base-ui/react/menu';
7
7
  import { toast } from 'sonner';
8
8
  import { useCoffre } from '../lib/coffre';
9
- import { archiveEnvironment, createEnvironment, environmentId, protectEnvironment, renameEnvironment } from '../lib/changes';
9
+ import { archiveEnvironment, createEnvironment, environmentId, renameEnvironment } from '../lib/changes';
10
10
  import { affects, keys, queries } from '../lib/queries';
11
11
  import { useChange, useChangeStatus } from '../lib/use-change';
12
12
  import { ItemFailure, RowPending, rowClass } from '../components/row-state';
@@ -19,10 +19,8 @@ import { Card } from '../components/page';
19
19
  import { useAction } from '../lib/use-action';
20
20
  import { DeletePlaceDialog } from '../components/delete-place';
21
21
  import { PrincipalAvatar } from '../components/principal';
22
- import { Archive, ChevronRight, Lock, MoreHorizontal, Pencil, Plus, RotateBack, Trash } from '../components/icons';
23
- import { ProtectedTag } from '../components/protected';
24
- import { protectionInWords } from '../lib/roles';
25
- import { useRoles } from '../lib/use-roles';
22
+ import { Archive, ChevronRight, MoreHorizontal, Pencil, Plus, RotateBack, Trash } from '../components/icons';
23
+ import { Protection } from '../components/protected';
26
24
  import { pageRoute } from '../lib/page-route';
27
25
  import { useProject } from '../lib/project-page';
28
26
  import type { projectEnvironments } from '../options';
@@ -187,15 +185,11 @@ function EnvironmentCard({
187
185
  const [renaming, setRenaming] = useState(false);
188
186
  const [confirming, setConfirming] = useState(false);
189
187
  const [deleting, setDeleting] = useState(false);
190
- // Protecting, or taking it off, waiting for its confirmation.
191
- const [guarding, setGuarding] = useState(false);
192
188
  const { capabilities } = useShell();
193
- const { roles } = useRoles();
194
189
  const [slug, setSlug] = useState(environment.slug);
195
190
  const coffre = useCoffre();
196
191
  const rename = useChange(renameEnvironment(coffre, project));
197
192
  const archive = useChange(archiveEnvironment(coffre, project));
198
- const protect = useChange(protectEnvironment(coffre, project));
199
193
  // What archiving it would stop, asked once the dialog opens (D41); Archive waits for the answer.
200
194
  const place = `${project}/${environment.slug}`;
201
195
  const archiving = confirming && environment.details?.archivedAt == null;
@@ -212,10 +206,6 @@ function EnvironmentCard({
212
206
  const manageable = isAdmin && details !== null;
213
207
  // Deleting is for those who run the instance, and only once the environment is archived.
214
208
  const deletable = manageable && isArchived && capabilities.runsInstance;
215
- // Whoever manages environments protects one; only an Owner of the whole instance takes it off.
216
- const guarded = environment.protected;
217
- const guardable = manageable && environment.personal !== true && (!guarded || capabilities.ownsInstance);
218
- const protection = protectionInWords(roles);
219
209
  const slugError = slug === '' ? null : environmentSlugProblem(slug);
220
210
  const lastChange = useLastChange(project, environment.slug, opens);
221
211
  // A personal config is its owner's alone: no grant reaches it, so none is shown on its card.
@@ -240,7 +230,7 @@ function EnvironmentCard({
240
230
  ) : (
241
231
  <span className="env-card-name">{environment.slug}</span>
242
232
  )}
243
- {guarded && <ProtectedTag />}
233
+ <Protection project={project} environment={environment} />
244
234
  {/* A fork: its keys are its parent's, but for those it sets or removes. An instance before 0.7 says nothing. */}
245
235
  {environment.personal === true
246
236
  ? <span className="tag tag-blue">yours alone</span>
@@ -314,12 +304,6 @@ function EnvironmentCard({
314
304
  <Pencil size={14} />
315
305
  Rename
316
306
  </Menu.Item>
317
- {guardable && (
318
- <Menu.Item className="menu-item" onClick={() => setGuarding(true)}>
319
- <Lock size={14} />
320
- {guarded ? 'Unprotect…' : 'Protect…'}
321
- </Menu.Item>
322
- )}
323
307
  <Menu.Separator className="menu-sep" />
324
308
  <Menu.Item
325
309
  className={`menu-item${isArchived ? '' : ' menu-item-danger'}`}
@@ -442,32 +426,6 @@ function EnvironmentCard({
442
426
  </>
443
427
  )}
444
428
 
445
- {guardable && (
446
- <ConfirmDialog
447
- open={guarding}
448
- onOpenChange={setGuarding}
449
- title={
450
- <>
451
- {guarded ? 'Unprotect' : 'Protect'}{' '}
452
- <span className="mono">
453
- {project}/{environment.slug}
454
- </span>
455
- ?
456
- </>
457
- }
458
- body={
459
- guarded
460
- ? 'People holding a role here get its full column again, as in any other environment. Service accounts are unaffected.'
461
- : `People holding a role here get its protected column${protection === null ? ', which for now holds what the other does' : `: ${protection}`}. Service accounts are unaffected.${
462
- capabilities.ownsInstance ? '' : ' Only an Owner of the whole instance takes protection off.'
463
- }`
464
- }
465
- confirmLabel={guarded ? 'Unprotect' : 'Protect'}
466
- destructive={guarded}
467
- onConfirm={() => protect({ slug: environment.slug, protected: !guarded })}
468
- />
469
- )}
470
-
471
429
  {deletable && (
472
430
  <DeletePlaceDialog
473
431
  path={`${project}/${environment.slug}`}