@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.
- package/dist/chunks/{audit-sentence-JrQIUq6j.js → audit-sentence-DpYySuqg.js} +74 -7
- package/dist/chunks/audit-sentence-DpYySuqg.js.map +1 -0
- package/dist/chunks/{connected-apps-Dr8UgjK7.js → connected-apps-D48SFJsG.js} +4 -4
- package/dist/chunks/{connected-apps-Dr8UgjK7.js.map → connected-apps-D48SFJsG.js.map} +1 -1
- package/dist/chunks/{delete-place-CQCDHkne.js → delete-place-Cg_M6rAq.js} +4 -4
- package/dist/chunks/{delete-place-CQCDHkne.js.map → delete-place-Cg_M6rAq.js.map} +1 -1
- package/dist/chunks/{directory-XcSbDRJv.js → directory-_LTgdiIM.js} +11 -9
- package/dist/chunks/directory-_LTgdiIM.js.map +1 -0
- package/dist/chunks/{folders-Dw240WMJ.js → folders-D3A1NGpt.js} +2 -2
- package/dist/chunks/{folders-Dw240WMJ.js.map → folders-D3A1NGpt.js.map} +1 -1
- package/dist/chunks/{grants-CmdZjKYU.js → grants-CNM913EY.js} +6 -6
- package/dist/chunks/{grants-CmdZjKYU.js.map → grants-CNM913EY.js.map} +1 -1
- package/dist/chunks/{multi-combobox-CsIXihuc.js → multi-combobox-B0JzP1QN.js} +2 -2
- package/dist/chunks/{multi-combobox-CsIXihuc.js.map → multi-combobox-B0JzP1QN.js.map} +1 -1
- package/dist/chunks/{offboarding-CrgwaetA.js → offboarding-BeaNM3sf.js} +3 -3
- package/dist/chunks/{offboarding-CrgwaetA.js.map → offboarding-BeaNM3sf.js.map} +1 -1
- package/dist/chunks/{personal-tokens-Dvl1FktE.js → personal-tokens-KsXajpx4.js} +4 -4
- package/dist/chunks/{personal-tokens-Dvl1FktE.js.map → personal-tokens-KsXajpx4.js.map} +1 -1
- package/dist/chunks/{principal-page-bOaEYWJB.js → principal-page-BaiZXh6D.js} +94 -78
- package/dist/chunks/principal-page-BaiZXh6D.js.map +1 -0
- package/dist/chunks/{project-page-BI--vjt3.js → project-page-CYZ_MkfX.js} +2 -2
- package/dist/chunks/{project-page-BI--vjt3.js.map → project-page-CYZ_MkfX.js.map} +1 -1
- package/dist/chunks/protected-BL_DsZO6.js +22 -0
- package/dist/chunks/protected-BL_DsZO6.js.map +1 -0
- package/dist/chunks/{queries-epz4MIuW.js → queries-Danu0o75.js} +99 -31
- package/dist/chunks/queries-Danu0o75.js.map +1 -0
- package/dist/chunks/{references-DImfw0cz.js → references-BK2aPXae.js} +4 -4
- package/dist/chunks/{references-DImfw0cz.js.map → references-BK2aPXae.js.map} +1 -1
- package/dist/chunks/{role-field-C1KhNaIR.js → role-field-DIJiRz9B.js} +8 -5
- package/dist/chunks/role-field-DIJiRz9B.js.map +1 -0
- package/dist/chunks/{row-state-BsIHspy4.js → row-state-xtRGFnDc.js} +2 -2
- package/dist/chunks/{row-state-BsIHspy4.js.map → row-state-xtRGFnDc.js.map} +1 -1
- package/dist/chunks/{theme-3b4DnCow.js → theme-Ck45wzWB.js} +2 -2
- package/dist/chunks/{theme-3b4DnCow.js.map → theme-Ck45wzWB.js.map} +1 -1
- package/dist/chunks/{ui-2kwXXfrX.js → ui-D-blFWfx.js} +29 -5
- package/dist/chunks/{ui-2kwXXfrX.js.map → ui-D-blFWfx.js.map} +1 -1
- package/dist/chunks/{use-action-BB-RcHo1.js → use-action-BafZVwux.js} +2 -2
- package/dist/chunks/{use-action-BB-RcHo1.js.map → use-action-BafZVwux.js.map} +1 -1
- package/dist/chunks/{use-change-BY6KPmnJ.js → use-change-DhV6i_Ge.js} +218 -101
- package/dist/chunks/use-change-DhV6i_Ge.js.map +1 -0
- package/dist/chunks/use-roles-Daje0ikO.js +224 -0
- package/dist/chunks/use-roles-Daje0ikO.js.map +1 -0
- package/dist/chunks/{use-shell-C_NmvCt_.js → use-shell-BX9mzfaL.js} +2 -2
- package/dist/chunks/{use-shell-C_NmvCt_.js.map → use-shell-BX9mzfaL.js.map} +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +29 -15
- package/dist/index.js.map +1 -1
- package/dist/pages/account.js +9 -9
- package/dist/pages/approval.js +1 -1
- package/dist/pages/audit.js +96 -34
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +1 -1
- package/dist/pages/environment.js +255 -115
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +2 -2
- package/dist/pages/oauth-authorize.js +1 -1
- package/dist/pages/project-access.js +79 -46
- package/dist/pages/project-access.js.map +1 -1
- package/dist/pages/project-environments.js +79 -30
- package/dist/pages/project-environments.js.map +1 -1
- package/dist/pages/project-settings.js +7 -7
- package/dist/pages/project.js +2 -2
- package/dist/pages/projects.js +26 -14
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.js +22 -15
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +4 -4
- package/dist/pages/settings.js +580 -8
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +1 -1
- package/dist/pages/user.js +5 -5
- package/dist/pages/users.js +4 -4
- package/package.json +3 -3
- package/src/components/directory.tsx +5 -2
- package/src/components/grants.tsx +1 -1
- package/src/components/principal-page.tsx +38 -23
- package/src/components/protected.tsx +17 -0
- package/src/components/role-editor.tsx +582 -0
- package/src/components/role-field.tsx +7 -3
- package/src/components/scope-picker.tsx +19 -9
- package/src/components/shell.tsx +7 -1
- package/src/components/ui.tsx +25 -2
- package/src/lib/access-plan.ts +35 -36
- package/src/lib/audit-sentences.ts +75 -9
- package/src/lib/changes.ts +46 -8
- package/src/lib/project-access.ts +4 -78
- package/src/lib/queries.ts +97 -29
- package/src/lib/roles.ts +201 -0
- package/src/lib/row-reads.ts +12 -0
- package/src/lib/secret-edit-batch.ts +147 -56
- package/src/lib/sensitivity.ts +50 -0
- package/src/lib/service-setup.ts +20 -8
- package/src/lib/use-roles.ts +17 -0
- package/src/options.ts +2 -3
- package/src/pages/audit.tsx +99 -26
- package/src/pages/environment.tsx +264 -101
- package/src/pages/project-access.tsx +49 -19
- package/src/pages/project-environments.tsx +62 -3
- package/src/pages/projects.tsx +3 -1
- package/src/pages/settings.tsx +2 -0
- package/src/parity.ts +42 -5
- package/src/shared/models.ts +2 -9
- package/src/styles/globals.css +322 -25
- package/dist/chunks/audit-sentence-JrQIUq6j.js.map +0 -1
- package/dist/chunks/directory-XcSbDRJv.js.map +0 -1
- package/dist/chunks/principal-page-bOaEYWJB.js.map +0 -1
- package/dist/chunks/queries-epz4MIuW.js.map +0 -1
- package/dist/chunks/role-field-C1KhNaIR.js.map +0 -1
- package/dist/chunks/use-change-BY6KPmnJ.js.map +0 -1
package/src/components/shell.tsx
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
GitHub,
|
|
28
28
|
Key,
|
|
29
29
|
Ledger,
|
|
30
|
+
Lock,
|
|
30
31
|
Mark,
|
|
31
32
|
Menu as MenuIcon,
|
|
32
33
|
PanelLeft,
|
|
@@ -506,6 +507,9 @@ function EnvironmentCrumb({
|
|
|
506
507
|
slug: string;
|
|
507
508
|
environments: ProjectSummary['environments'];
|
|
508
509
|
}) {
|
|
510
|
+
// Protected, it says so where you are and in the list.
|
|
511
|
+
const guarded = environments.some((environment) => environment.slug === slug && environment.protected);
|
|
512
|
+
const lock = <Lock size={12} className="crumb-lock" label="protected" />;
|
|
509
513
|
if (environments.length === 0) {
|
|
510
514
|
return (
|
|
511
515
|
<span className="crumb-link" aria-current="page">
|
|
@@ -517,10 +521,11 @@ function EnvironmentCrumb({
|
|
|
517
521
|
<Menu.Root>
|
|
518
522
|
<Menu.Trigger
|
|
519
523
|
className="crumb-link crumb-switch"
|
|
520
|
-
aria-label={`${slug}, switch environment`}
|
|
524
|
+
aria-label={`${slug}${guarded ? ', protected' : ''}, switch environment`}
|
|
521
525
|
aria-current="page"
|
|
522
526
|
>
|
|
523
527
|
<span className="crumb-name">{slug}</span>
|
|
528
|
+
{guarded && <Lock size={12} className="crumb-lock" />}
|
|
524
529
|
<ChevronsUpDown size={14} className="crumb-chevron" />
|
|
525
530
|
</Menu.Trigger>
|
|
526
531
|
<MenuPopup align="start">
|
|
@@ -541,6 +546,7 @@ function EnvironmentCrumb({
|
|
|
541
546
|
}
|
|
542
547
|
>
|
|
543
548
|
<span className="mono">{environment.slug}</span>
|
|
549
|
+
{environment.protected && lock}
|
|
544
550
|
<span className="menu-hint">
|
|
545
551
|
{environment.details?.secretCount ?? 0} secret
|
|
546
552
|
{environment.details?.secretCount === 1 ? '' : 's'}
|
package/src/components/ui.tsx
CHANGED
|
@@ -356,6 +356,22 @@ export function ConfirmButton({
|
|
|
356
356
|
);
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
const hydrated = () => true;
|
|
360
|
+
const serverRender = () => false;
|
|
361
|
+
const unchanging = () => () => {};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Whether a dialog's root is drawn: always once the page is the browser's,
|
|
365
|
+
* which closes it with its animation; on the server and while hydrating,
|
|
366
|
+
* only when it is open. Closed, a dialog draws nothing, so the page's HTML
|
|
367
|
+
* is the same either way, and the server skips a root per dialog: four in
|
|
368
|
+
* each row of an environment's table. Its trigger is elsewhere, so mounting
|
|
369
|
+
* it after hydration remounts nothing else.
|
|
370
|
+
*/
|
|
371
|
+
function useHydrated(open: boolean): boolean {
|
|
372
|
+
return useSyncExternalStore(unchanging, hydrated, serverRender) || open;
|
|
373
|
+
}
|
|
374
|
+
|
|
359
375
|
/**
|
|
360
376
|
* The same confirmation, opened from something that is not a trigger.
|
|
361
377
|
*
|
|
@@ -368,6 +384,7 @@ export function ConfirmDialog({
|
|
|
368
384
|
onOpenChange,
|
|
369
385
|
...confirm
|
|
370
386
|
}: ConfirmProps & { open: boolean; onOpenChange: (open: boolean) => void }) {
|
|
387
|
+
if (!useHydrated(open)) return null;
|
|
371
388
|
return (
|
|
372
389
|
<AlertDialog.Root open={open} onOpenChange={onOpenChange}>
|
|
373
390
|
<ConfirmContent {...confirm} />
|
|
@@ -397,6 +414,7 @@ export function Modal({
|
|
|
397
414
|
children: ReactNode;
|
|
398
415
|
}) {
|
|
399
416
|
const { portal } = usePreferences();
|
|
417
|
+
if (!useHydrated(open)) return null;
|
|
400
418
|
return (
|
|
401
419
|
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
402
420
|
<Dialog.Portal container={portal}>
|
|
@@ -431,12 +449,17 @@ const RELATIVE_STEPS: [limit: number, divisor: number, unit: Intl.RelativeTimeFo
|
|
|
431
449
|
[Infinity, 31536000, 'year'],
|
|
432
450
|
];
|
|
433
451
|
|
|
452
|
+
/** One formatter per style, made once: making one costs more than a row of a page renders around it. */
|
|
453
|
+
const RELATIVE = {
|
|
454
|
+
long: new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'long' }),
|
|
455
|
+
narrow: new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'narrow' }),
|
|
456
|
+
};
|
|
457
|
+
|
|
434
458
|
function relative(iso: string, now: number, style: 'long' | 'narrow' = 'long'): string {
|
|
435
459
|
const delta = (new Date(iso).getTime() - now) / 1000;
|
|
436
460
|
const magnitude = Math.abs(delta);
|
|
437
461
|
const [, divisor, unit] = RELATIVE_STEPS.find(([limit]) => magnitude < limit)!;
|
|
438
|
-
|
|
439
|
-
return formatter.format(Math.round(delta / divisor), unit);
|
|
462
|
+
return RELATIVE[style].format(Math.round(delta / divisor), unit);
|
|
440
463
|
}
|
|
441
464
|
|
|
442
465
|
/** A UTC time as the log writes it: `2026-10-17 08:45:13`, to the millisecond when `precise`. */
|
package/src/lib/access-plan.ts
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import type { AccessValue } from '@coffre/client';
|
|
2
|
-
import type
|
|
2
|
+
import { assignableToEnvironment, type Role } from '@coffre/core/access';
|
|
3
3
|
|
|
4
4
|
import type { GrantRow } from '../shared/models';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
export type EnvironmentAccess = { role:
|
|
6
|
+
/** A role on one environment, and when it ends: an ISO instant, or null for never. */
|
|
7
|
+
export type EnvironmentAccess = { role: Role; expiresAt: string | null };
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* What one project is set to in a principal's access editor: nothing,
|
|
11
|
-
*
|
|
10
|
+
* What one project is set to in a principal's access editor: nothing, one
|
|
11
|
+
* role on the whole project, or a role per environment. Every grant the
|
|
12
12
|
* plan asks for carries its own expiry.
|
|
13
13
|
*
|
|
14
|
-
* `custom` is for grants that do not fit that shape --
|
|
15
|
-
*
|
|
16
|
-
* leaves them alone unless another setting
|
|
14
|
+
* `custom` is for grants that do not fit that shape -- read everywhere plus
|
|
15
|
+
* write on one environment, or a grant on an environment the editor does not
|
|
16
|
+
* list. The editor shows them and leaves them alone unless another setting
|
|
17
|
+
* is picked.
|
|
17
18
|
*/
|
|
18
19
|
export type AccessPlan = {
|
|
19
|
-
level: 'none' |
|
|
20
|
-
/**
|
|
20
|
+
level: 'none' | 'project' | 'env' | 'custom';
|
|
21
|
+
/** The role on the whole project, at level `project`. */
|
|
22
|
+
role: Role | null;
|
|
23
|
+
/** When the project-wide role ends. */
|
|
21
24
|
expiresAt: string | null;
|
|
22
25
|
/** Environments without an entry get no access. */
|
|
23
26
|
environments: Record<string, EnvironmentAccess>;
|
|
@@ -38,6 +41,8 @@ export function environmentAccess(plan: AccessPlan, slug: string): EnvironmentAc
|
|
|
38
41
|
return Object.hasOwn(plan.environments, slug) ? plan.environments[slug] : null;
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
const NONE: AccessPlan = { level: 'none', role: null, expiresAt: null, environments: {} };
|
|
45
|
+
|
|
41
46
|
/**
|
|
42
47
|
* Read what a principal holds on a project back into the editor's terms.
|
|
43
48
|
* `environments` are the ones the editor can set: live, and not archived.
|
|
@@ -46,56 +51,52 @@ export function planFromGrants(
|
|
|
46
51
|
grants: readonly HeldGrant[],
|
|
47
52
|
environments: readonly string[],
|
|
48
53
|
): AccessPlan {
|
|
49
|
-
if (grants.length === 0) return
|
|
54
|
+
if (grants.length === 0) return NONE;
|
|
50
55
|
|
|
51
56
|
const [only] = grants;
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
only.environmentSlug === null &&
|
|
55
|
-
(only.role === 'owner' || only.role === 'viewer' || only.role === 'developer')
|
|
56
|
-
) {
|
|
57
|
-
return { level: only.role, expiresAt: only.expiresAt, environments: {} };
|
|
57
|
+
if (grants.length === 1 && only.environmentSlug === null) {
|
|
58
|
+
return { level: 'project', role: only.role, expiresAt: only.expiresAt, environments: {} };
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
const perEnvironment: Record<string, EnvironmentAccess> = {};
|
|
61
62
|
for (const grant of grants) {
|
|
62
63
|
const slug = grant.environmentSlug;
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
!environments.includes(slug) ||
|
|
66
|
-
Object.hasOwn(perEnvironment, slug) ||
|
|
67
|
-
(grant.role !== 'viewer' && grant.role !== 'developer')
|
|
68
|
-
) {
|
|
69
|
-
return { level: 'custom', expiresAt: null, environments: {} };
|
|
64
|
+
if (slug === null || !environments.includes(slug) || Object.hasOwn(perEnvironment, slug)) {
|
|
65
|
+
return { ...NONE, level: 'custom' };
|
|
70
66
|
}
|
|
71
67
|
perEnvironment[slug] = { role: grant.role, expiresAt: grant.expiresAt };
|
|
72
68
|
}
|
|
73
|
-
return { level: 'env', expiresAt: null, environments: perEnvironment };
|
|
69
|
+
return { level: 'env', role: null, expiresAt: null, environments: perEnvironment };
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
/**
|
|
77
|
-
* Switch a plan's level
|
|
78
|
-
* environment starts every environment at that
|
|
79
|
-
*
|
|
73
|
+
* Switch a plan's level, with its role for `project`. Going from one role
|
|
74
|
+
* on the whole project to per environment starts every environment at that
|
|
75
|
+
* role and expiry, where an environment takes it, so the switch alone keeps
|
|
76
|
+
* the same reach.
|
|
80
77
|
*/
|
|
81
78
|
export function withLevel(
|
|
82
79
|
plan: AccessPlan,
|
|
83
80
|
level: AccessPlan['level'],
|
|
84
81
|
environments: readonly string[],
|
|
82
|
+
{ role = null, assignable = (each) => assignableToEnvironment(each) }: { role?: Role | null; assignable?: (role: Role) => boolean } = {},
|
|
85
83
|
): AccessPlan {
|
|
86
84
|
if (
|
|
87
85
|
level === 'env' &&
|
|
88
|
-
|
|
86
|
+
plan.level === 'project' &&
|
|
87
|
+
plan.role !== null &&
|
|
88
|
+
assignable(plan.role) &&
|
|
89
89
|
Object.keys(plan.environments).length === 0
|
|
90
90
|
) {
|
|
91
|
-
const access = { role: plan.
|
|
91
|
+
const access = { role: plan.role, expiresAt: plan.expiresAt };
|
|
92
92
|
return {
|
|
93
93
|
...plan,
|
|
94
94
|
level,
|
|
95
|
+
role: null,
|
|
95
96
|
environments: Object.fromEntries(environments.map((slug) => [slug, access])),
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
|
-
return { ...plan, level };
|
|
99
|
+
return { ...plan, level, role: level === 'project' ? role : null };
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
/** Set one environment's access, or take it away with `null`. */
|
|
@@ -117,10 +118,8 @@ function grantsFor(
|
|
|
117
118
|
case 'none':
|
|
118
119
|
case 'custom':
|
|
119
120
|
return [];
|
|
120
|
-
case '
|
|
121
|
-
|
|
122
|
-
case 'developer':
|
|
123
|
-
return [{ role: plan.level, environmentSlug: null, expiresAt: plan.expiresAt }];
|
|
121
|
+
case 'project':
|
|
122
|
+
return plan.role === null ? [] : [{ role: plan.role, environmentSlug: null, expiresAt: plan.expiresAt }];
|
|
124
123
|
case 'env':
|
|
125
124
|
return Object.entries(plan.environments).map(([environmentSlug, access]) => ({
|
|
126
125
|
environmentSlug,
|
|
@@ -177,7 +176,7 @@ export function accessPatch(project: string, changes: readonly AccessChange[]):
|
|
|
177
176
|
const place = (environmentSlug: string | null) =>
|
|
178
177
|
environmentSlug === null ? project : `${project}/${environmentSlug}`;
|
|
179
178
|
const holding = (role: string, expiresAt: string | null): AccessValue =>
|
|
180
|
-
expiresAt === null ?
|
|
179
|
+
expiresAt === null ? role : { role, until: expiresAt };
|
|
181
180
|
|
|
182
181
|
const patch: Record<string, AccessValue> = {};
|
|
183
182
|
for (const change of changes) {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* and places in it links. `plain` flattens it, for tests and titles.
|
|
9
9
|
*/
|
|
10
10
|
import { shownMember, type AuditEntryView } from '@coffre/client';
|
|
11
|
-
import { INSTANCE_ROLES, isInstanceRole, isScope, scopeInWords, type Scope } from '@coffre/core/access';
|
|
11
|
+
import { INSTANCE_ROLES, isBuiltinRole, isInstanceRole, isScope, ROLES, scopeInWords, type Scope } from '@coffre/core/access';
|
|
12
12
|
|
|
13
13
|
/** What a sentence is made from: an entry of the log, as `GET /api/audit` gives it. */
|
|
14
14
|
export type AuditEntry = Pick<
|
|
@@ -245,18 +245,22 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
245
245
|
what: secrets,
|
|
246
246
|
},
|
|
247
247
|
'secret.write': {
|
|
248
|
-
// New secrets are added, others changed; a batch of both is written.
|
|
249
|
-
did: ({ batch }) => {
|
|
248
|
+
// New secrets are added, others changed; a batch of both is written. One whose level changed is made that.
|
|
249
|
+
did: ({ entry, batch }) => {
|
|
250
|
+
if (batch.length === 1 && text(entry.metadata.was) !== null) return 'made';
|
|
250
251
|
const firsts = batch.filter((entry) => entry.version === 1).length;
|
|
251
252
|
return firsts === batch.length ? 'added' : firsts === 0 ? 'changed' : 'wrote';
|
|
252
253
|
},
|
|
253
254
|
tried: 'change',
|
|
254
255
|
what: secrets,
|
|
255
|
-
//
|
|
256
|
-
then: ({ entry, batch }) =>
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
// Who sees the value, where it is not a secret's or it changed: a mark keeps the value, a write gives a new one.
|
|
257
|
+
then: ({ entry, batch }) => {
|
|
258
|
+
const version = batch.length > 1 || entry.version === null || entry.version === 1 ? [] : [`, now version ${entry.version}`];
|
|
259
|
+
if (batch.length > 1) return version;
|
|
260
|
+
const level = entry.metadata.sensitive === true ? 'sensitive' : entry.metadata.plain === true ? 'plain' : 'secret';
|
|
261
|
+
if (text(entry.metadata.was) !== null) return [` ${level}`, ...(number(entry.metadata.kept) === null ? [' with a new value'] : []), ...version];
|
|
262
|
+
return [...version, ...(level === 'plain' ? [', as a plain value, no secret'] : level === 'sensitive' ? [', as a sensitive value, shown to nobody'] : [])];
|
|
263
|
+
},
|
|
260
264
|
},
|
|
261
265
|
// The credential proxy's own entry beside the vault's read: which credential the keys went into, and where.
|
|
262
266
|
'credential.use': {
|
|
@@ -396,6 +400,12 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
396
400
|
return setting(previous).map((words) => `, was ${words}`);
|
|
397
401
|
},
|
|
398
402
|
},
|
|
403
|
+
// The roles an Owner edits and which environments are protected (docs/design/roles.md), the vault's to change.
|
|
404
|
+
'policy.change': {
|
|
405
|
+
did: ({ entry }) => POLICY_VERBS[policyOf(entry).verb][0],
|
|
406
|
+
tried: ({ entry }) => POLICY_VERBS[policyOf(entry).verb][1],
|
|
407
|
+
what: ({ entry }) => policyOf(entry).what,
|
|
408
|
+
},
|
|
399
409
|
// A binding trusts CI runs to sign in as a service; removing one is its tombstone.
|
|
400
410
|
'token.bind': {
|
|
401
411
|
did: 'trusted CI runs to sign in as',
|
|
@@ -516,6 +526,57 @@ function roleName(role: string): string | null {
|
|
|
516
526
|
return isInstanceRole(role) ? INSTANCE_ROLES[role].name : null;
|
|
517
527
|
}
|
|
518
528
|
|
|
529
|
+
/** What a policy change did, and what it did it to, as `did` and `tried` say it. */
|
|
530
|
+
const POLICY_VERBS = {
|
|
531
|
+
protect: ['protected', 'protect'],
|
|
532
|
+
unprotect: ['unprotected', 'unprotect'],
|
|
533
|
+
edit: ['edited', 'edit'],
|
|
534
|
+
reset: ['reset', 'reset'],
|
|
535
|
+
make: ['made', 'make'],
|
|
536
|
+
delete: ['deleted', 'delete'],
|
|
537
|
+
} as const;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* A `policy.change` entry, from what it names: its `change`, an
|
|
541
|
+
* environment's protection or a role's definition, and the role `before`
|
|
542
|
+
* it. A built-in role's definition dropped is a reset; one an Owner made, a
|
|
543
|
+
* deletion; one that was not there, made. A refusal the app wrote names the
|
|
544
|
+
* role alone.
|
|
545
|
+
*
|
|
546
|
+
* protected market/prod edited the Developer role
|
|
547
|
+
* made the Release manager role reset the Auditor instance role
|
|
548
|
+
*/
|
|
549
|
+
function policyOf(entry: AuditEntry): { verb: keyof typeof POLICY_VERBS; what: Part[] } {
|
|
550
|
+
const change = record(entry.metadata.change);
|
|
551
|
+
if (change.kind === 'protect') {
|
|
552
|
+
const count = Array.isArray(change.environmentIds) ? change.environmentIds.length : 1;
|
|
553
|
+
// A fork's, protected before its row is written, names its project alone.
|
|
554
|
+
const what: Part[] = entry.environment !== null
|
|
555
|
+
? place({ ...entry, key: null })
|
|
556
|
+
: entry.project === null
|
|
557
|
+
? [count === 1 ? 'an environment' : plural(count, 'environment')]
|
|
558
|
+
: [count === 1 ? 'a new environment of ' : `${plural(count, 'environment')} of `, { place: entry.project }];
|
|
559
|
+
return { verb: change.protected === false ? 'unprotect' : 'protect', what };
|
|
560
|
+
}
|
|
561
|
+
const instance = (change.kind ?? entry.metadata.kind) === 'instance-role';
|
|
562
|
+
const id = text(change.role) ?? text(entry.metadata.role);
|
|
563
|
+
const shipped = id !== null && (instance ? isInstanceRole(id) : isBuiltinRole(id));
|
|
564
|
+
const definition = change.definition === null ? null : record(change.definition);
|
|
565
|
+
const before = record(entry.metadata.before);
|
|
566
|
+
const name = text(definition?.name) ?? text(record(before.definition).name)
|
|
567
|
+
?? (id === null ? null : shipped ? (instance ? INSTANCE_ROLES[id as keyof typeof INSTANCE_ROLES] : ROLES[id as keyof typeof ROLES]).name : id);
|
|
568
|
+
// A reset or deletion: the vault's entry says so in its change, a refusal of the app's in its own metadata.
|
|
569
|
+
const verb = change.definition === null || entry.metadata.definition === null || entry.reason === 'role_granted'
|
|
570
|
+
? (shipped ? 'reset' : 'delete')
|
|
571
|
+
: before.definition === null ? 'make' : 'edit';
|
|
572
|
+
return { verb, what: [name === null ? 'a role' : `the ${name} ${instance ? 'instance role' : 'role'}`] };
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/** An object of the metadata's, or an empty one for anything else. */
|
|
576
|
+
function record(value: unknown): Record<string, unknown> {
|
|
577
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
|
|
578
|
+
}
|
|
579
|
+
|
|
519
580
|
function article(name: string): string {
|
|
520
581
|
return `${/^[AEIOU]/.test(name) ? 'an' : 'a'} ${name}`;
|
|
521
582
|
}
|
|
@@ -597,7 +658,11 @@ const TAMPERING: Record<string, string> = {
|
|
|
597
658
|
const REASONS: Record<string, string> = {
|
|
598
659
|
no_grant: 'no grant',
|
|
599
660
|
bulk_limit: 'bulk limit',
|
|
600
|
-
|
|
661
|
+
// 0.9's `people: 'stand-ins'`, in entries written before 0.10.
|
|
662
|
+
stand_ins: 'people get placeholders',
|
|
663
|
+
sensitive: 'the value is sensitive',
|
|
664
|
+
looser: 'making it visible takes a new value',
|
|
665
|
+
inherited: 'it is inherited',
|
|
601
666
|
expired: 'grant expired',
|
|
602
667
|
removed: 'removed from coffre',
|
|
603
668
|
not_a_member: 'not a member',
|
|
@@ -634,6 +699,7 @@ const REASONS: Record<string, string> = {
|
|
|
634
699
|
disconnected: 'the app was disconnected',
|
|
635
700
|
personal_token: 'only its person can, signed in as themselves',
|
|
636
701
|
beyond_holder: 'more than they hold',
|
|
702
|
+
role_granted: 'grants still name it',
|
|
637
703
|
};
|
|
638
704
|
|
|
639
705
|
/** What a missing permission meant, from the app's `missing_<permission>`. */
|
package/src/lib/changes.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { Change, ListShape, Target, Words } from './optimistic.ts';
|
|
|
8
8
|
import { affects, keys } from './queries.ts';
|
|
9
9
|
import { regenerateWrite, type Generation } from '@coffre/core/recipe';
|
|
10
10
|
import { regeneratedKeys, renamePairs } from './recipes.ts';
|
|
11
|
-
import { applySecretEditBatch, companionsOf, generationsOf,
|
|
11
|
+
import { applySecretEditBatch, companionsOf, generationsOf, levelsOf, type SecretChange, type SecretDraft, type SecretEditBatchResult } from './secret-edit-batch.ts';
|
|
12
12
|
import type { DirectoryPrincipal, GrantRow, ProjectSummary } from '../shared/models.ts';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -81,7 +81,7 @@ export function grantAccess(client: CoffreClient, project: string): Change<Grant
|
|
|
81
81
|
const list = grantsList(project);
|
|
82
82
|
return {
|
|
83
83
|
list,
|
|
84
|
-
label: (vars) => `${vars
|
|
84
|
+
label: (vars) => `${projectAccessLabel(vars)} for ${vars.principalId}`,
|
|
85
85
|
targets: (vars) => [saving(grantId(vars))],
|
|
86
86
|
apply: (grants, vars) => {
|
|
87
87
|
const row: GrantRow = {
|
|
@@ -106,7 +106,7 @@ export function grantAccess(client: CoffreClient, project: string): Change<Grant
|
|
|
106
106
|
],
|
|
107
107
|
run: async (vars) => {
|
|
108
108
|
const place = grantPlace(project, vars.environmentSlug);
|
|
109
|
-
const role = vars.role
|
|
109
|
+
const role = vars.role;
|
|
110
110
|
const member = memberRef(vars.principalType, vars.principalId);
|
|
111
111
|
const access = { [place]: vars.expiresAt === null ? role : { role, until: vars.expiresAt } };
|
|
112
112
|
const { changes } = vars.admit === true ? await client.members.add(member, { access }) : await client.access.set(member, access);
|
|
@@ -386,7 +386,16 @@ export function createEnvironment(client: CoffreClient, project: string): Change
|
|
|
386
386
|
targets: (vars) => [saving(environmentId(project, vars.slug))],
|
|
387
387
|
apply: (environments, vars) => [
|
|
388
388
|
...environments,
|
|
389
|
-
{
|
|
389
|
+
{
|
|
390
|
+
slug: vars.slug,
|
|
391
|
+
name: vars.slug,
|
|
392
|
+
accessible: false,
|
|
393
|
+
parent: vars.inherit === true ? (vars.from ?? null) : null,
|
|
394
|
+
// A fork of a protected environment, however made, is protected from its first moment.
|
|
395
|
+
protected: vars.from !== undefined && environments.some((environment) => environment.slug === vars.from && environment.protected),
|
|
396
|
+
personal: false,
|
|
397
|
+
details: { archivedAt: null, secretCount: 0 },
|
|
398
|
+
},
|
|
390
399
|
],
|
|
391
400
|
affects: () => affects.places(),
|
|
392
401
|
run: async (vars) => {
|
|
@@ -419,6 +428,25 @@ export function renameEnvironment(client: CoffreClient, project: string): Change
|
|
|
419
428
|
};
|
|
420
429
|
}
|
|
421
430
|
|
|
431
|
+
/**
|
|
432
|
+
* 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.
|
|
437
|
+
*/
|
|
438
|
+
export function protectEnvironment(client: CoffreClient, project: string): Change<Projects, Environment, { slug: string; protected: boolean }, unknown> {
|
|
439
|
+
return {
|
|
440
|
+
list: environmentsList(project),
|
|
441
|
+
label: (vars) => `environment ${vars.slug}`,
|
|
442
|
+
targets: (vars) => [saving(environmentId(project, vars.slug))],
|
|
443
|
+
apply: (environments, vars) =>
|
|
444
|
+
environments.map((environment) => (environment.slug === vars.slug ? { ...environment, protected: vars.protected } : environment)),
|
|
445
|
+
affects: () => [...affects.places(), ...affects.roles()],
|
|
446
|
+
run: (vars) => client.environments.protect(`${project}/${vars.slug}`, vars.protected),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
422
450
|
/**
|
|
423
451
|
* Archive an environment or bring it back. Archiving ends every read of it,
|
|
424
452
|
* so it waits for the server, as a removal does; restoring shows at once.
|
|
@@ -520,10 +548,11 @@ export function saveSecrets(
|
|
|
520
548
|
const now = new Date().toISOString();
|
|
521
549
|
// A value typed by hand has no recipe; a generated one has the one it was made by. A plain one shows as it is.
|
|
522
550
|
const generations = generationsOf(vars.active, vars.drafts, vars.changes);
|
|
523
|
-
const
|
|
551
|
+
const levels = levelsOf(vars.active, vars.drafts, vars.changes);
|
|
524
552
|
const bumped = (entry: SecretKey | undefined, key: string): SecretKey => {
|
|
525
553
|
// In a fork, a value written over the parent's is an override, whose own version the list read back says.
|
|
526
554
|
const inherited = entry?.parent != null && entry.parent.state !== 'overridden' && entry.key === key;
|
|
555
|
+
const level = levels.get(key);
|
|
527
556
|
return {
|
|
528
557
|
key,
|
|
529
558
|
// A rename keeps its folder; a new secret is in none.
|
|
@@ -537,7 +566,11 @@ export function saveSecrets(
|
|
|
537
566
|
updatedAt: now,
|
|
538
567
|
updatedBy: author,
|
|
539
568
|
generated: generations.get(key) ?? null,
|
|
540
|
-
value:
|
|
569
|
+
value: level?.value ?? null,
|
|
570
|
+
sensitivity: level?.sensitivity ?? 'secret',
|
|
571
|
+
// Until the list is read back: a plain value as it is listed, a secret over one its writer read here, and nothing else.
|
|
572
|
+
readable: level?.value != null
|
|
573
|
+
|| ((level?.sensitivity ?? 'secret') === 'secret' && !inherited && entry?.sensitivity === 'secret' && entry.readable),
|
|
541
574
|
parent: entry?.parent == null || entry.key !== key ? null : { ...entry.parent, state: 'overridden', changed: false, reset: false },
|
|
542
575
|
};
|
|
543
576
|
};
|
|
@@ -547,7 +580,11 @@ export function saveSecrets(
|
|
|
547
580
|
if (change === undefined || change.archived) return entry;
|
|
548
581
|
const key = change.key.trim();
|
|
549
582
|
if (key !== entry.key) renames.set(entry.key, key);
|
|
550
|
-
|
|
583
|
+
if (change.value !== null) return bumped(entry, key);
|
|
584
|
+
// A mark: the same value, as a new version, stricter, so a plain one no longer listed, nor read until the list says so.
|
|
585
|
+
return change.sensitivity === undefined
|
|
586
|
+
? { ...entry, key }
|
|
587
|
+
: { ...entry, key, version: (entry.version ?? 0) + 1, versionId: null, updatedAt: now, updatedBy: author, value: null, sensitivity: change.sensitivity, readable: false };
|
|
551
588
|
});
|
|
552
589
|
// A rename moves no value: a pair it touches names the new key, in both halves.
|
|
553
590
|
next = renamePairs(next, renames);
|
|
@@ -644,8 +681,9 @@ export function regenerateSecret(
|
|
|
644
681
|
updatedAt: now,
|
|
645
682
|
updatedBy: author,
|
|
646
683
|
generated: vars.generated,
|
|
647
|
-
// A generated value is a secret.
|
|
684
|
+
// A generated value is a secret, and sensitive where the key is.
|
|
648
685
|
value: null,
|
|
686
|
+
sensitivity: entry.sensitivity === 'sensitive' ? 'sensitive' : 'secret',
|
|
649
687
|
parent: entry.parent == null ? null : { ...entry.parent, state: 'overridden', changed: false, reset: false },
|
|
650
688
|
};
|
|
651
689
|
});
|
|
@@ -1,85 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { GrantRow, ProjectSummary } from '../shared/models';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** The roles the project's access picker offers, a product choice; others show by their names. */
|
|
6
|
-
export type ProjectAccessRole = Extract<Role, 'owner' | 'viewer' | 'developer'>;
|
|
7
|
-
|
|
8
|
-
export type ProjectAccessOption = {
|
|
9
|
-
value: string;
|
|
10
|
-
role: ProjectAccessRole;
|
|
11
|
-
environmentSlug: string | null;
|
|
12
|
-
label: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export function projectAccessOptions(
|
|
16
|
-
environments: ProjectSummary['environments'],
|
|
17
|
-
): ProjectAccessOption[] {
|
|
18
|
-
const options: ProjectAccessOption[] = [
|
|
19
|
-
{
|
|
20
|
-
value: 'owner:',
|
|
21
|
-
role: 'owner',
|
|
22
|
-
environmentSlug: null,
|
|
23
|
-
label: ROLES.owner.name,
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
for (const role of ['viewer', 'developer'] as const) {
|
|
28
|
-
options.push({
|
|
29
|
-
value: `${role}:`,
|
|
30
|
-
role,
|
|
31
|
-
environmentSlug: null,
|
|
32
|
-
label: `${ROLES[role].name}: all`,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
for (const environment of environments) {
|
|
37
|
-
if (environment.details === null || environment.details.archivedAt !== null) continue;
|
|
38
|
-
for (const role of ['viewer', 'developer'] as const) {
|
|
39
|
-
options.push({
|
|
40
|
-
value: `${role}:${environment.slug}`,
|
|
41
|
-
role,
|
|
42
|
-
environmentSlug: environment.slug,
|
|
43
|
-
label: `${ROLES[role].name}: ${environment.slug}`,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return options;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function parseProjectAccess(value: string): {
|
|
52
|
-
role: ProjectAccessRole;
|
|
53
|
-
environmentSlug: string | null;
|
|
54
|
-
} {
|
|
55
|
-
const [role, environmentSlug = ''] = value.split(':', 2);
|
|
56
|
-
if (role !== 'owner' && role !== 'viewer' && role !== 'developer') {
|
|
57
|
-
throw new Error('unknown project access level');
|
|
58
|
-
}
|
|
59
|
-
return { role, environmentSlug: environmentSlug || null };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** "Owner", "Viewer: all" or "Developer: prod": a grant by its role's name, and where. */
|
|
3
|
+
/** "Owner", "Viewer: all" or "Developer: prod": a grant by its role's name, as the instance names it, and where. */
|
|
63
4
|
export function projectAccessLabel(
|
|
64
5
|
grant: Pick<GrantRow, 'role' | 'roleName' | 'environmentSlug'>,
|
|
65
6
|
): string {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return `${name}: ${grant.environmentSlug ?? 'all'}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function projectAccessRoles(
|
|
72
|
-
roles: RoleRow[],
|
|
73
|
-
environmentSlug: string | null,
|
|
74
|
-
currentRole?: string,
|
|
75
|
-
): RoleRow[] {
|
|
76
|
-
const allowed = new Set(
|
|
77
|
-
environmentSlug === null
|
|
78
|
-
? ['owner', 'viewer', 'developer']
|
|
79
|
-
: ['viewer', 'developer'],
|
|
80
|
-
);
|
|
81
|
-
if (currentRole) allowed.add(currentRole);
|
|
82
|
-
return roles.filter((role) => allowed.has(role.slug));
|
|
7
|
+
if (grant.role === 'owner') return grant.roleName;
|
|
8
|
+
return `${grant.roleName}: ${grant.environmentSlug ?? 'all'}`;
|
|
83
9
|
}
|
|
84
10
|
|
|
85
11
|
/** A project on someone's Access tab: their grants there, or why those could not be read. */
|