@coffre/ui 0.4.5 → 0.5.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.
- package/dist/chunks/{affordances-DAvsVz7u.js → affordances-Bqdevf7w.js} +10 -5
- package/dist/chunks/affordances-Bqdevf7w.js.map +1 -0
- package/dist/chunks/{audit-sentence-BhHmvQX_.js → audit-sentence-Cm5nby5k.js} +115 -8
- package/dist/chunks/audit-sentence-Cm5nby5k.js.map +1 -0
- package/dist/chunks/{connected-apps-AZsX9Zvv.js → connected-apps-DTNS7YmY.js} +2 -2
- package/dist/chunks/{connected-apps-AZsX9Zvv.js.map → connected-apps-DTNS7YmY.js.map} +1 -1
- package/dist/chunks/{delete-place-D6LIZkg9.js → delete-place-CIaOq0mt.js} +3 -3
- package/dist/chunks/{delete-place-D6LIZkg9.js.map → delete-place-CIaOq0mt.js.map} +1 -1
- package/dist/chunks/{directory-B6FuiCir.js → directory-DSVt5Tya.js} +54 -60
- package/dist/chunks/directory-DSVt5Tya.js.map +1 -0
- package/dist/chunks/{folders-DvSqBhuu.js → folders-CoGK9oqg.js} +2 -2
- package/dist/chunks/{folders-DvSqBhuu.js.map → folders-CoGK9oqg.js.map} +1 -1
- package/dist/chunks/grants-CRU7yZhL.js +164 -0
- package/dist/chunks/grants-CRU7yZhL.js.map +1 -0
- package/dist/chunks/{offboarding-CLJaNTcD.js → offboarding-DVBSiJRZ.js} +7 -3
- package/dist/chunks/offboarding-DVBSiJRZ.js.map +1 -0
- package/dist/chunks/{principal-page-UtNWKCf8.js → principal-page-BEBr_zW7.js} +350 -91
- package/dist/chunks/principal-page-BEBr_zW7.js.map +1 -0
- package/dist/chunks/{project-page-C4cEaRFa.js → project-page-B3TZ5_ig.js} +2 -2
- package/dist/chunks/{project-page-C4cEaRFa.js.map → project-page-B3TZ5_ig.js.map} +1 -1
- package/dist/chunks/{queries-Dew8mIeo.js → queries-DE5nK2y4.js} +132 -54
- package/dist/chunks/queries-DE5nK2y4.js.map +1 -0
- package/dist/chunks/{references-DWDnXNoW.js → references-uv4Mli9z.js} +4 -3
- package/dist/chunks/{references-DWDnXNoW.js.map → references-uv4Mli9z.js.map} +1 -1
- package/dist/chunks/role-field-DWhkRY6n.js +192 -0
- package/dist/chunks/role-field-DWhkRY6n.js.map +1 -0
- package/dist/chunks/use-action-BRgvbUWt.js +49 -0
- package/dist/chunks/use-action-BRgvbUWt.js.map +1 -0
- package/dist/chunks/{use-change-C4bGRhHY.js → use-change-BJ3dCFHb.js} +40 -14
- package/dist/chunks/use-change-BJ3dCFHb.js.map +1 -0
- package/dist/chunks/{use-shell-Dkv89nW1.js → use-shell-BO4ZTr1y.js} +2 -2
- package/dist/chunks/{use-shell-Dkv89nW1.js.map → use-shell-BO4ZTr1y.js.map} +1 -1
- package/dist/chunks/validation-DiHIwZRA.js +37 -0
- package/dist/chunks/validation-DiHIwZRA.js.map +1 -0
- package/dist/index.d.ts +116 -88
- package/dist/index.js +40 -21
- package/dist/index.js.map +1 -1
- package/dist/pages/account.js +8 -7
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.js +53 -21
- package/dist/pages/approval.js.map +1 -1
- package/dist/pages/audit.js +2 -2
- package/dist/pages/environment.js +8 -7
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +2 -2
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/project-access.js +7 -7
- package/dist/pages/project-environments.js +26 -21
- package/dist/pages/project-environments.js.map +1 -1
- package/dist/pages/project-settings.js +9 -8
- package/dist/pages/project-settings.js.map +1 -1
- package/dist/pages/project.js +1 -1
- package/dist/pages/projects.js +8 -13
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.js +294 -88
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +7 -7
- package/dist/pages/service-accounts.js.map +1 -1
- package/dist/pages/settings.js +91 -9
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.d.ts +1 -1
- package/dist/pages/unregistered.js +4 -4
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.d.ts +2 -0
- package/dist/pages/user.js +21 -3
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +4 -4
- package/package.json +3 -3
- package/src/components/affordances.ts +7 -3
- package/src/components/command-palette.tsx +2 -0
- package/src/components/directory.tsx +58 -63
- package/src/components/grants.tsx +9 -9
- package/src/components/offboarding.tsx +3 -1
- package/src/components/principal-page.tsx +124 -74
- package/src/components/role-field.tsx +183 -0
- package/src/components/scope-picker.tsx +73 -0
- package/src/components/service-tokens.tsx +20 -9
- package/src/components/shell.tsx +6 -10
- package/src/components/trusted-workloads.tsx +121 -42
- package/src/index.ts +1 -0
- package/src/lib/approval.ts +23 -0
- package/src/lib/audit-sentences.ts +109 -3
- package/src/lib/bindings.ts +33 -10
- package/src/lib/capabilities.ts +28 -8
- package/src/lib/changes.ts +22 -13
- package/src/lib/project-access.ts +21 -0
- package/src/lib/queries.ts +121 -44
- package/src/lib/service-setup.ts +41 -0
- package/src/lib/validation.ts +7 -0
- package/src/options.ts +31 -11
- package/src/pages/account.tsx +3 -2
- package/src/pages/approval.tsx +18 -17
- package/src/pages/login.tsx +1 -1
- package/src/pages/project-environments.tsx +12 -15
- package/src/pages/project-settings.tsx +3 -3
- package/src/pages/projects.tsx +1 -5
- package/src/pages/service-account.tsx +7 -5
- package/src/pages/service-accounts.tsx +8 -4
- package/src/pages/settings.tsx +80 -4
- package/src/pages/unregistered.tsx +3 -3
- package/src/pages/user.tsx +24 -1
- package/src/parity.ts +5 -1
- package/src/register.ts +3 -1
- package/src/shared/models.ts +8 -4
- package/src/styles/globals.css +111 -28
- package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
- package/dist/chunks/audit-sentence-BhHmvQX_.js.map +0 -1
- package/dist/chunks/directory-B6FuiCir.js.map +0 -1
- package/dist/chunks/grants-9kIV6uZ7.js +0 -669
- package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
- package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
- package/dist/chunks/principal-page-UtNWKCf8.js.map +0 -1
- package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
- package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
- package/dist/chunks/validation-DvPinn8V.js +0 -87
- package/dist/chunks/validation-DvPinn8V.js.map +0 -1
- package/src/components/every-project.tsx +0 -287
package/src/lib/queries.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AuthInfo, CoffreClient, Member } from '@coffre/client';
|
|
2
|
+
import { EVERYWHERE, INSTANCE_ROLES } from '@coffre/core/access';
|
|
2
3
|
import { QueryClient, queryOptions, type QueryKey } from '@tanstack/react-query';
|
|
3
4
|
|
|
4
5
|
import { deriveUiCapabilities } from './capabilities.ts';
|
|
@@ -51,6 +52,7 @@ export const keys = {
|
|
|
51
52
|
missing: ({ project, environment }: Place) => ['missing', project, environment],
|
|
52
53
|
directory: ['directory'],
|
|
53
54
|
report: (member: string) => ['report', member],
|
|
55
|
+
memberAccess: (member: string) => ['member-access', member],
|
|
54
56
|
credentials: (member: string) => ['credentials', member],
|
|
55
57
|
bindings: (member: string) => ['bindings', member],
|
|
56
58
|
identities: ['identities'],
|
|
@@ -58,35 +60,51 @@ export const keys = {
|
|
|
58
60
|
apps: ['apps'],
|
|
59
61
|
audit: ['audit'],
|
|
60
62
|
auditKeys: ['audit', 'keys'],
|
|
63
|
+
settings: ['settings'],
|
|
61
64
|
} satisfies Record<string, QueryKey | ((...args: never[]) => QueryKey)>;
|
|
62
65
|
|
|
63
|
-
/**
|
|
66
|
+
/** Members' grants, as rows, and a row for each one whose instance role reaches the place listed. */
|
|
64
67
|
function grantRows(members: Member[]): GrantRow[] {
|
|
65
|
-
return members.flatMap((member) =>
|
|
66
|
-
member.
|
|
68
|
+
return members.flatMap((member): GrantRow[] => [
|
|
69
|
+
...(member.reachesByRole && member.instanceRole !== 'root-admin'
|
|
70
|
+
? [{
|
|
71
|
+
id: `${member.member}/instance-role`,
|
|
72
|
+
principalType: member.principalType,
|
|
73
|
+
principalId: member.principalId,
|
|
74
|
+
role: member.instanceRole,
|
|
75
|
+
roleName: INSTANCE_ROLES[member.instanceRole].name,
|
|
76
|
+
permissions: [...INSTANCE_ROLES[member.instanceRole].permissions],
|
|
77
|
+
scope: 'instance-role' as const,
|
|
78
|
+
environmentSlug: null,
|
|
79
|
+
expiresAt: null,
|
|
80
|
+
}]
|
|
81
|
+
: []),
|
|
82
|
+
...member.grants.map((grant) => ({
|
|
67
83
|
id: grant.id,
|
|
68
84
|
principalType: member.principalType,
|
|
69
85
|
principalId: member.principalId,
|
|
70
86
|
role: grant.role,
|
|
71
87
|
roleName: grant.roleName,
|
|
72
88
|
permissions: grant.permissions,
|
|
73
|
-
scope: grant.
|
|
89
|
+
scope: grant.environment === null ? ('project' as const) : ('environment' as const),
|
|
74
90
|
environmentSlug: grant.environment,
|
|
75
91
|
expiresAt: grant.expiresAt,
|
|
76
92
|
})),
|
|
77
|
-
);
|
|
93
|
+
]);
|
|
78
94
|
}
|
|
79
95
|
|
|
80
96
|
function listDirectory(client: CoffreClient) {
|
|
81
97
|
return uiResult(async () => {
|
|
82
98
|
const { members, removed } = await client.members.list();
|
|
83
99
|
const principals: DirectoryPrincipal[] = members.map(
|
|
84
|
-
({ principalType, principalId, instanceRole, isRootAdmin, tampered, grants }) => ({
|
|
100
|
+
({ principalType, principalId, instanceRole, scope, isRootAdmin, tampered, managed, grants }) => ({
|
|
85
101
|
principalType,
|
|
86
102
|
principalId,
|
|
87
103
|
instanceRole,
|
|
104
|
+
scope,
|
|
88
105
|
isRootAdmin,
|
|
89
106
|
tampered,
|
|
107
|
+
managed,
|
|
90
108
|
grants: grants.map(({ project, environment }) => ({ project, environment })),
|
|
91
109
|
}),
|
|
92
110
|
);
|
|
@@ -154,8 +172,8 @@ export const queries = {
|
|
|
154
172
|
|
|
155
173
|
/**
|
|
156
174
|
* Everyone in the directory, and who was removed. The API shows grant
|
|
157
|
-
* managers the members of their projects; the directory pages
|
|
158
|
-
* owners'
|
|
175
|
+
* managers the members of their projects; the directory pages are admins'
|
|
176
|
+
* and owners', and asking for anyone else would only log a refusal, so
|
|
159
177
|
* nobody else is asked.
|
|
160
178
|
*/
|
|
161
179
|
directory: (client: CoffreClient, owner: boolean) =>
|
|
@@ -166,11 +184,22 @@ export const queries = {
|
|
|
166
184
|
? listDirectory(client)
|
|
167
185
|
: Promise.resolve({
|
|
168
186
|
ok: false as const,
|
|
169
|
-
error: 'Only owners
|
|
187
|
+
error: 'Only admins and owners manage users, and service accounts are set up by those who hold access where the instance lets them.',
|
|
170
188
|
signedOut: false,
|
|
171
189
|
}),
|
|
172
190
|
}),
|
|
173
191
|
|
|
192
|
+
/**
|
|
193
|
+
* One member's instance role and scope, and the grants you manage, in one
|
|
194
|
+
* read: their page's Access tab. Null for whoever may list nobody, which
|
|
195
|
+
* asking would only log as a refusal.
|
|
196
|
+
*/
|
|
197
|
+
memberAccess: (client: CoffreClient, member: string, allowed: boolean) =>
|
|
198
|
+
queryOptions({
|
|
199
|
+
queryKey: [...keys.memberAccess(member), { allowed }],
|
|
200
|
+
queryFn: () => (allowed ? uiResult(() => client.members.access(member)) : Promise.resolve(null)),
|
|
201
|
+
}),
|
|
202
|
+
|
|
174
203
|
/** What one member can reach and has seen; null for anyone but owners, who alone may ask. */
|
|
175
204
|
report: (client: CoffreClient, member: string, owner: boolean) =>
|
|
176
205
|
queryOptions({
|
|
@@ -232,6 +261,13 @@ export const queries = {
|
|
|
232
261
|
queryFn: () => (allowed ? uiResult(() => client.audit.keys()) : Promise.resolve(null)),
|
|
233
262
|
}),
|
|
234
263
|
|
|
264
|
+
/** The instance's settings: null for anyone but those who run it, who alone may ask. */
|
|
265
|
+
settings: (client: CoffreClient, allowed: boolean) =>
|
|
266
|
+
queryOptions({
|
|
267
|
+
queryKey: [...keys.settings, { allowed }],
|
|
268
|
+
queryFn: () => (allowed ? uiResult(() => client.settings.get()) : Promise.resolve(null)),
|
|
269
|
+
}),
|
|
270
|
+
|
|
235
271
|
/** A page of the log, as filtered: always read fresh. */
|
|
236
272
|
auditEntries: (client: CoffreClient, search: AuditSearch) =>
|
|
237
273
|
queryOptions({
|
|
@@ -273,8 +309,9 @@ export const queries = {
|
|
|
273
309
|
};
|
|
274
310
|
|
|
275
311
|
/**
|
|
276
|
-
* Whether the log holds, or why that is not known. Verifying is for
|
|
277
|
-
*
|
|
312
|
+
* Whether the log holds, or why that is not known. Verifying is for those
|
|
313
|
+
* who read the whole log (an Auditor, Admin or Owner whose scope narrows
|
|
314
|
+
* nothing, a root admin): anyone else reads their projects' part of it, and a part cannot be
|
|
278
315
|
* checked as a chain, so for them it is a fact about the page, not a fault.
|
|
279
316
|
*/
|
|
280
317
|
async function verifyChain(client: CoffreClient) {
|
|
@@ -324,6 +361,8 @@ export function shellOf(
|
|
|
324
361
|
auth,
|
|
325
362
|
principal: me === null ? null : me.principal,
|
|
326
363
|
instanceRole: member?.instanceRole ?? null,
|
|
364
|
+
/** Where their instance role applies, projects by slug. */
|
|
365
|
+
scope: member?.scope ?? EVERYWHERE,
|
|
327
366
|
projects: listed,
|
|
328
367
|
capabilities: deriveUiCapabilities(member, listed),
|
|
329
368
|
registrationRequired: me !== null && !me.registered,
|
|
@@ -331,6 +370,10 @@ export function shellOf(
|
|
|
331
370
|
accessTampered: me?.tampered === true,
|
|
332
371
|
/** What the deployment's configuration turns on: MCP clients, as their endpoint's URL, and CI runs signing in by their ID tokens. */
|
|
333
372
|
features: member?.features ?? { mcp: null, workloads: false },
|
|
373
|
+
/** Every environment you hold something in, and what: what you may give a service account there (`givable`). */
|
|
374
|
+
environments: member?.environments ?? [],
|
|
375
|
+
/** Where you set up service accounts yourself, the instance's setting, projects by slug. */
|
|
376
|
+
serviceSetup: member?.serviceSetup ?? null,
|
|
334
377
|
};
|
|
335
378
|
}
|
|
336
379
|
|
|
@@ -372,15 +415,31 @@ export async function loadDirectory(queryClient: QueryClient, client: CoffreClie
|
|
|
372
415
|
return queryClient.fetchQuery(queries.directory(client, shell.capabilities.canManageGrants));
|
|
373
416
|
}
|
|
374
417
|
|
|
375
|
-
/** The instance's settings: the directory's counts, and what its keys are checked against. */
|
|
418
|
+
/** The instance's settings: the directory's counts, where people set up service accounts, and what its keys are checked against. */
|
|
376
419
|
export async function loadSettings(queryClient: QueryClient, client: CoffreClient) {
|
|
377
420
|
const shell = await loadShell(queryClient, client);
|
|
378
421
|
await Promise.all([
|
|
379
422
|
loadDirectory(queryClient, client),
|
|
380
|
-
queryClient.fetchQuery(queries.
|
|
423
|
+
queryClient.fetchQuery(queries.settings(client, shell.capabilities.runsInstance)),
|
|
424
|
+
queryClient.fetchQuery(queries.auditKeys(client, shell.capabilities.runsInstance)),
|
|
381
425
|
]);
|
|
382
426
|
}
|
|
383
427
|
|
|
428
|
+
/** Whether the Service accounts page lists anyone: to admins and owners, and to whoever sets one up, those they manage. */
|
|
429
|
+
export function listsServices(shell: Shell): boolean {
|
|
430
|
+
return shell.capabilities.canManageGrants || shell.capabilities.setsUpServices;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* How the caller may have a service account sign in, from its list entry
|
|
435
|
+
* or its access: bearer tokens under coffre's own sign-in, trusted
|
|
436
|
+
* workloads where the deployment trusts them, each only for an account they
|
|
437
|
+
* manage.
|
|
438
|
+
*/
|
|
439
|
+
export function waysFor(shell: Shell, managed: boolean): { tokens: boolean; workloads: boolean } {
|
|
440
|
+
return { tokens: managed && shell.auth.signin !== null, workloads: managed && shell.features.workloads };
|
|
441
|
+
}
|
|
442
|
+
|
|
384
443
|
/**
|
|
385
444
|
* The service accounts page: the directory, and each account's bindings and
|
|
386
445
|
* tokens, read here as its own page reads them, so the list shows how each
|
|
@@ -389,56 +448,74 @@ export async function loadSettings(queryClient: QueryClient, client: CoffreClien
|
|
|
389
448
|
*/
|
|
390
449
|
export async function loadServiceDirectory(queryClient: QueryClient, client: CoffreClient) {
|
|
391
450
|
const shell = await loadShell(queryClient, client);
|
|
392
|
-
const directory = await
|
|
393
|
-
|
|
394
|
-
const trusts = shell.capabilities.canManageGrants && shell.features.workloads;
|
|
395
|
-
if (!directory.ok || !allowed) return directory;
|
|
451
|
+
const directory = await queryClient.fetchQuery(queries.directory(client, listsServices(shell)));
|
|
452
|
+
if (!directory.ok) return directory;
|
|
396
453
|
await Promise.all(
|
|
397
454
|
directory.principals
|
|
398
455
|
.filter((principal) => principal.principalType === 'service')
|
|
399
456
|
.flatMap((principal) => {
|
|
400
457
|
const member = memberRef('service', principal.principalId);
|
|
458
|
+
const ways = waysFor(shell, principal.managed === true);
|
|
401
459
|
return [
|
|
402
|
-
queryClient.fetchQuery(queries.credentials(client, member,
|
|
403
|
-
queryClient.fetchQuery(queries.bindings(client, member,
|
|
460
|
+
queryClient.fetchQuery(queries.credentials(client, member, ways.tokens)),
|
|
461
|
+
queryClient.fetchQuery(queries.bindings(client, member, ways.workloads)),
|
|
404
462
|
];
|
|
405
463
|
}),
|
|
406
464
|
);
|
|
407
465
|
return directory;
|
|
408
466
|
}
|
|
409
467
|
|
|
410
|
-
/** Who a user or service account is to the instance, its pages' header: null to anyone
|
|
468
|
+
/** Who a user or service account is to the instance, its pages' header: null to anyone who does not run it. */
|
|
411
469
|
export async function loadMember(queryClient: QueryClient, client: CoffreClient, member: string) {
|
|
412
470
|
const shell = await loadShell(queryClient, client);
|
|
413
|
-
return queryClient.fetchQuery(queries.report(client, member, shell.capabilities.
|
|
471
|
+
return queryClient.fetchQuery(queries.report(client, member, shell.capabilities.runsInstance));
|
|
414
472
|
}
|
|
415
473
|
|
|
416
474
|
export type MemberReport = Awaited<ReturnType<typeof loadMember>>;
|
|
417
475
|
|
|
418
476
|
/**
|
|
419
|
-
* What a user's or service account's Access tab reads:
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* keeps this member's. Projects where you do not hold grant.manage are
|
|
423
|
-
* skipped rather than asked: the refusal would land in the audit log as a
|
|
424
|
-
* denial in your name.
|
|
477
|
+
* What a user's or service account's Access tab reads: their role, scope
|
|
478
|
+
* and the grants you manage, in one request, which the server answers in
|
|
479
|
+
* one query, however many projects they hold grants in.
|
|
425
480
|
*/
|
|
426
|
-
export async function loadAccess(queryClient: QueryClient, client: CoffreClient) {
|
|
481
|
+
export async function loadAccess(queryClient: QueryClient, client: CoffreClient, member: string) {
|
|
427
482
|
const shell = await loadShell(queryClient, client);
|
|
428
|
-
|
|
483
|
+
return queryClient.fetchQuery(queries.memberAccess(client, member, listsAccess(shell)));
|
|
429
484
|
}
|
|
430
485
|
|
|
486
|
+
/**
|
|
487
|
+
* Whether the caller may ask what someone holds: admins and owners,
|
|
488
|
+
* whoever manages a project's access, and whoever sets up service accounts,
|
|
489
|
+
* of those they manage.
|
|
490
|
+
*/
|
|
491
|
+
export function listsAccess(shell: Shell): boolean {
|
|
492
|
+
return shell.capabilities.canManageGrants || shell.capabilities.setsUpServices || managedProjects(shell.projects).length > 0;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export type MemberAccessResult = Awaited<ReturnType<typeof loadAccess>>;
|
|
496
|
+
|
|
431
497
|
/**
|
|
432
498
|
* How a service account's page lets it sign in: bearer tokens under
|
|
433
499
|
* coffre's own sign-in, trusted workloads where the deployment trusts them.
|
|
434
|
-
* Null where it shows neither: to anyone
|
|
435
|
-
* that is not active, which can be
|
|
500
|
+
* Null where it shows neither: to anyone who does not manage it (its access
|
|
501
|
+
* says, `managed`), and for an account that is not active, which can be
|
|
502
|
+
* issued nothing.
|
|
503
|
+
*/
|
|
504
|
+
export function signInWays(shell: Shell, access: MemberAccessResult): { tokens: boolean; workloads: boolean } | null {
|
|
505
|
+
const managed = access?.ok === true && access.managed && access.status === 'active';
|
|
506
|
+
const ways = waysFor(shell, managed);
|
|
507
|
+
return ways.tokens || ways.workloads ? ways : null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Whether a user has a Connected apps tab: for an owner, where the
|
|
512
|
+
* deployment serves MCP, and while the user is registered and not removed,
|
|
513
|
+
* since removal disconnects every app. The tab, and the route under it,
|
|
514
|
+
* both ask.
|
|
436
515
|
*/
|
|
437
|
-
export function
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
const active = report?.ok === true && report.report?.status === 'active';
|
|
441
|
-
return active && (ways.tokens || ways.workloads) ? ways : null;
|
|
516
|
+
export function hasAppsTab(shell: Shell, report: MemberReport): boolean {
|
|
517
|
+
const found = report?.ok === true ? report.report : null;
|
|
518
|
+
return Boolean(shell.features.mcp) && shell.capabilities.runsInstance && found !== null && found.status !== 'removed';
|
|
442
519
|
}
|
|
443
520
|
|
|
444
521
|
export function managedProjects(projects: ProjectSummary[]): ProjectSummary[] {
|
|
@@ -460,25 +537,25 @@ export const affects = {
|
|
|
460
537
|
*/
|
|
461
538
|
access: (project: string, member: string): QueryKey[] => [
|
|
462
539
|
keys.grants(project),
|
|
540
|
+
keys.memberAccess(member),
|
|
463
541
|
keys.report(member),
|
|
464
542
|
keys.projects,
|
|
465
543
|
keys.me,
|
|
466
544
|
],
|
|
467
|
-
/**
|
|
468
|
-
* Someone's access on every project changed: every project's grants, which
|
|
469
|
-
* list it where it reaches, the list of them, their report, and what you
|
|
470
|
-
* can see, as it may be your own.
|
|
471
|
-
*/
|
|
472
|
-
everyProject: (member: string): QueryKey[] => [['grants'], keys.projects, keys.report(member), keys.me],
|
|
473
545
|
/** Someone let in: the directory. */
|
|
474
546
|
admission: (): QueryKey[] => [keys.directory],
|
|
475
547
|
/**
|
|
476
548
|
* An instance role changed: the directory, their report, and, as it may be
|
|
477
549
|
* your own, what you can see and do.
|
|
478
550
|
*/
|
|
479
|
-
role: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.me, keys.projects],
|
|
551
|
+
role: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.memberAccess(member), keys.me, keys.projects],
|
|
480
552
|
/** Someone removed: the directory, their report, and every grant, which removal ends, those on every project too. */
|
|
481
|
-
removal: (member: string): QueryKey[] => [keys.directory, keys.report(member), ['grants'], keys.projects],
|
|
553
|
+
removal: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.memberAccess(member), ['grants'], keys.projects],
|
|
554
|
+
/**
|
|
555
|
+
* Where people set up service accounts changed: the setting, and what you
|
|
556
|
+
* may do, which the directory and `/me` say.
|
|
557
|
+
*/
|
|
558
|
+
settings: (): QueryKey[] => [keys.settings, keys.me, keys.directory],
|
|
482
559
|
credentials: (member: string): QueryKey[] => [keys.credentials(member)],
|
|
483
560
|
bindings: (member: string): QueryKey[] => [keys.bindings(member)],
|
|
484
561
|
/** Unlinking an account also ends the sessions it signed in. */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { inScope, ROLE_NAMES, ROLES, type Permission, type Role, type Scope } from '@coffre/core/access';
|
|
2
|
+
|
|
3
|
+
import type { ProjectSummary } from '../shared/models';
|
|
4
|
+
|
|
5
|
+
/** What `givable` reads of the shell: the projects, what you hold in each environment, and the setting. */
|
|
6
|
+
type Holder = {
|
|
7
|
+
projects: readonly ProjectSummary[];
|
|
8
|
+
environments: readonly { project: string; environment: string; permissions: Permission[] }[];
|
|
9
|
+
/** The instance's setting as `/me` says it, projects by slug, those you see; null for a service account. */
|
|
10
|
+
serviceSetup: Scope | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The roles you may give a service account at a project, or one of its
|
|
15
|
+
* environments, as the server decides it (`givesService` in
|
|
16
|
+
* @coffre/core/access): any, where you manage access; otherwise, inside the
|
|
17
|
+
* instance's setting, those whose every permission you hold there.
|
|
18
|
+
*
|
|
19
|
+
* a Developer of every dev, at market/dev viewer, developer
|
|
20
|
+
* the same, at market none: a project takes holding all of it
|
|
21
|
+
*/
|
|
22
|
+
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];
|
|
27
|
+
const setting = holder.serviceSetup;
|
|
28
|
+
// The setting names projects by slug here, so a place is matched by its slugs.
|
|
29
|
+
const place = environment === null
|
|
30
|
+
? { projectId: project.slug }
|
|
31
|
+
: { projectId: project.slug, environmentId: environment, environmentSlug: environment };
|
|
32
|
+
if (setting === null || !inScope(setting, place)) return [];
|
|
33
|
+
return ROLE_NAMES.filter((role) => ROLES[role].permissions.every((permission) => held.includes(permission)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The projects where you may give a service account something: on the project, or on one of its environments. */
|
|
37
|
+
export function serviceProjects(holder: Holder): ProjectSummary[] {
|
|
38
|
+
return holder.projects.filter((project) =>
|
|
39
|
+
givable(holder, project, null).length > 0 ||
|
|
40
|
+
project.environments.some((environment) => givable(holder, project, environment.slug).length > 0));
|
|
41
|
+
}
|
package/src/lib/validation.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* bundle does not carry zod, and `test/validation.test.ts` holds the two in
|
|
8
8
|
* agreement.
|
|
9
9
|
*/
|
|
10
|
+
import type { Filter, InstanceRole, Scope } from '@coffre/core/access';
|
|
10
11
|
import { PROJECT_PAGES } from '@coffre/core/pages';
|
|
11
12
|
|
|
12
13
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
@@ -39,3 +40,9 @@ export function folderProblem(value: string): string | null {
|
|
|
39
40
|
if (/[/\p{Cc}]/u.test(value)) return 'No slash.';
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
/** Whether a role's scope can be saved: each Only or All except names something. A Member's has nothing to fill. */
|
|
45
|
+
export function scopeComplete({ role, scope }: { role: InstanceRole; scope: Scope }): boolean {
|
|
46
|
+
const named = (filter: Filter) => filter === 'all' || ('only' in filter ? filter.only : filter.except).length > 0;
|
|
47
|
+
return role === 'member' || (named(scope.projects) && named(scope.environments));
|
|
48
|
+
}
|
package/src/options.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { ShellLayout, SoloLayout } from './layout';
|
|
|
23
23
|
import { memberRef, uiResult } from './lib/coffre';
|
|
24
24
|
import { stringsOf } from './lib/search';
|
|
25
25
|
import {
|
|
26
|
+
hasAppsTab,
|
|
26
27
|
loadAccess,
|
|
27
28
|
loadDirectory,
|
|
28
29
|
loadMember,
|
|
@@ -204,9 +205,9 @@ export const user = {
|
|
|
204
205
|
|
|
205
206
|
/** `/users/$user/`, their access on every project where you manage it. */
|
|
206
207
|
export const userAccess = {
|
|
207
|
-
loader: ({ context }: Loader) => {
|
|
208
|
+
loader: ({ context, params }: Loader<{ user: string }>) => {
|
|
208
209
|
const { coffre, queryClient } = coffreOf(context);
|
|
209
|
-
return loadAccess(queryClient, coffre);
|
|
210
|
+
return loadAccess(queryClient, coffre, memberRef('user', params.user));
|
|
210
211
|
},
|
|
211
212
|
};
|
|
212
213
|
|
|
@@ -219,6 +220,21 @@ export const userActivity = {
|
|
|
219
220
|
},
|
|
220
221
|
};
|
|
221
222
|
|
|
223
|
+
/**
|
|
224
|
+
* `/users/$user/apps`, the MCP clients they connected, for an owner where the
|
|
225
|
+
* deployment serves MCP, and while they are not removed (removal disconnects
|
|
226
|
+
* every one); the others are sent to the first tab, which for someone removed
|
|
227
|
+
* is their offboarding.
|
|
228
|
+
*/
|
|
229
|
+
export const userApps = {
|
|
230
|
+
loader: async ({ context, params }: Loader<{ user: string }>) => {
|
|
231
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
232
|
+
const shell = await loadShell(queryClient, coffre);
|
|
233
|
+
const report = await loadMember(queryClient, coffre, memberRef('user', params.user));
|
|
234
|
+
if (!hasAppsTab(shell, report)) throw redirect({ to: '/users/$user', params });
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
|
|
222
238
|
/** `/service-accounts`. */
|
|
223
239
|
export const serviceAccounts = {
|
|
224
240
|
loader: ({ context }: Loader) => {
|
|
@@ -227,25 +243,29 @@ export const serviceAccounts = {
|
|
|
227
243
|
},
|
|
228
244
|
};
|
|
229
245
|
|
|
230
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* `/service-accounts/$account`, the layout of a service account's tabs: who
|
|
248
|
+
* it is to the instance, for owners, and what it holds, for whoever manages it.
|
|
249
|
+
*/
|
|
231
250
|
export const serviceAccount = {
|
|
232
|
-
loader: ({ context, params }: Loader<{ account: string }>) => {
|
|
251
|
+
loader: async ({ context, params }: Loader<{ account: string }>) => {
|
|
233
252
|
const { coffre, queryClient } = coffreOf(context);
|
|
234
|
-
|
|
253
|
+
const member = memberRef('service', params.account);
|
|
254
|
+
await Promise.all([loadMember(queryClient, coffre, member), loadAccess(queryClient, coffre, member)]);
|
|
235
255
|
},
|
|
236
256
|
};
|
|
237
257
|
|
|
238
258
|
/**
|
|
239
259
|
* `/service-accounts/$account/`, how it signs in: its trusted workloads and
|
|
240
|
-
* bearer tokens. Only
|
|
241
|
-
* anyone else is sent to its access.
|
|
260
|
+
* bearer tokens. Only whoever manages it sees them, and only while it is
|
|
261
|
+
* active; anyone else is sent to its access.
|
|
242
262
|
*/
|
|
243
263
|
export const serviceAccountSignIn = {
|
|
244
264
|
loader: async ({ context, params }: Loader<{ account: string }>) => {
|
|
245
265
|
const { coffre, queryClient } = coffreOf(context);
|
|
246
266
|
const member = memberRef('service', params.account);
|
|
247
|
-
const [shell,
|
|
248
|
-
const ways = signInWays(shell,
|
|
267
|
+
const [shell, access] = await Promise.all([loadShell(queryClient, coffre), loadAccess(queryClient, coffre, member)]);
|
|
268
|
+
const ways = signInWays(shell, access);
|
|
249
269
|
if (ways === null) throw redirect({ to: '/service-accounts/$account/access', params });
|
|
250
270
|
await Promise.all([
|
|
251
271
|
queryClient.fetchQuery(queries.credentials(coffre, member, ways.tokens)),
|
|
@@ -256,9 +276,9 @@ export const serviceAccountSignIn = {
|
|
|
256
276
|
|
|
257
277
|
/** `/service-accounts/$account/access`. */
|
|
258
278
|
export const serviceAccountAccess = {
|
|
259
|
-
loader: ({ context }: Loader) => {
|
|
279
|
+
loader: ({ context, params }: Loader<{ account: string }>) => {
|
|
260
280
|
const { coffre, queryClient } = coffreOf(context);
|
|
261
|
-
return loadAccess(queryClient, coffre);
|
|
281
|
+
return loadAccess(queryClient, coffre, memberRef('service', params.account));
|
|
262
282
|
},
|
|
263
283
|
};
|
|
264
284
|
|
package/src/pages/account.tsx
CHANGED
|
@@ -75,7 +75,7 @@ export function AccountPage() {
|
|
|
75
75
|
|
|
76
76
|
/** Its first tab: who you are to coffre, and the accounts you sign in with. */
|
|
77
77
|
export function AccountProfilePage() {
|
|
78
|
-
const { principal, instanceRole, auth } = useShell();
|
|
78
|
+
const { principal, instanceRole, scope, auth } = useShell();
|
|
79
79
|
if (principal === null) return null;
|
|
80
80
|
return (
|
|
81
81
|
<>
|
|
@@ -91,7 +91,8 @@ export function AccountProfilePage() {
|
|
|
91
91
|
principal={{
|
|
92
92
|
principalType: 'user',
|
|
93
93
|
principalId: principal.id,
|
|
94
|
-
instanceRole: instanceRole ?? '
|
|
94
|
+
instanceRole: instanceRole ?? 'member',
|
|
95
|
+
scope,
|
|
95
96
|
isRootAdmin: instanceRole === 'root-admin',
|
|
96
97
|
}}
|
|
97
98
|
/>
|
package/src/pages/approval.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import type { ApprovalView, Decision } from '@coffre/client';
|
|
3
3
|
|
|
4
|
+
import { settled } from '../lib/approval';
|
|
4
5
|
import { failureMessage, statusOf, useCoffre } from '../lib/coffre';
|
|
5
6
|
import { ClosedDoor } from '../components/page';
|
|
6
7
|
import { CopyButton, ErrorLine, Notice, Spinner, Timestamp } from '../components/ui';
|
|
@@ -33,25 +34,16 @@ export function ApprovalPage() {
|
|
|
33
34
|
return <Approve view={view} onDecided={setDecided} />;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const SETTLED: Record<Exclude<ApprovalView['status'], 'pending'>, string> = {
|
|
37
|
-
approved: 'You approved this',
|
|
38
|
-
denied: 'You denied this',
|
|
39
|
-
cancelled: 'The app cancelled this',
|
|
40
|
-
failed: 'This change failed',
|
|
41
|
-
expired: 'This approval expired',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
37
|
function Settled({ view }: { view: ApprovalView }) {
|
|
45
|
-
const
|
|
38
|
+
const { title, text } = settled(view);
|
|
46
39
|
return (
|
|
47
40
|
<ClosedDoor
|
|
48
|
-
icon={status === 'approved' ? <CheckCircle size={18} /> : <SlashCircle size={18} />}
|
|
41
|
+
icon={view.status === 'approved' ? <CheckCircle size={18} /> : <SlashCircle size={18} />}
|
|
49
42
|
label="Approve a change"
|
|
50
|
-
title={
|
|
43
|
+
title={title}
|
|
51
44
|
>
|
|
52
45
|
<p>
|
|
53
|
-
{view.client.name} asked to {view.summary}.{
|
|
54
|
-
{view.outcome?.text ?? (status === 'expired' ? 'Nothing changed. The app can ask again.' : 'Nothing changed.')}
|
|
46
|
+
{view.client.name} asked to {view.summary}. {text}
|
|
55
47
|
</p>
|
|
56
48
|
</ClosedDoor>
|
|
57
49
|
);
|
|
@@ -103,6 +95,7 @@ function Approve({ view, onDecided }: { view: ApprovalView; onDecided: (decision
|
|
|
103
95
|
await coffre.approvals.decide(view.id, {
|
|
104
96
|
approve,
|
|
105
97
|
digest: view.digest,
|
|
98
|
+
basis: view.basis,
|
|
106
99
|
...(approve && asksValue !== null ? { value } : {}),
|
|
107
100
|
}),
|
|
108
101
|
);
|
|
@@ -121,7 +114,9 @@ function Approve({ view, onDecided }: { view: ApprovalView; onDecided: (decision
|
|
|
121
114
|
<p className="signin-lede">
|
|
122
115
|
{client.name} asks to <strong>{view.summary}</strong>.{' '}
|
|
123
116
|
{reveal
|
|
124
|
-
?
|
|
117
|
+
? view.reveals
|
|
118
|
+
? 'Reveal shows it to you, here. The app holds Reveal values, so it can read it too.'
|
|
119
|
+
: 'Reveal shows it only to you, here. The app never gets it.'
|
|
125
120
|
: 'Nothing changes until you approve.'}
|
|
126
121
|
</p>
|
|
127
122
|
</div>
|
|
@@ -141,8 +136,11 @@ function Approve({ view, onDecided }: { view: ApprovalView; onDecided: (decision
|
|
|
141
136
|
{view.details.map((line) => (
|
|
142
137
|
<div className="fact" key={line.label}>
|
|
143
138
|
<dt>{line.label}</dt>
|
|
144
|
-
<dd
|
|
145
|
-
{line.kind === '
|
|
139
|
+
<dd>
|
|
140
|
+
<span className={line.kind === 'mono' ? 'mono' : undefined}>
|
|
141
|
+
{line.kind === 'time' ? <Timestamp iso={line.value} /> : line.value}
|
|
142
|
+
</span>
|
|
143
|
+
{line.note !== undefined && <small className={line.warn === true ? 'approval-note approval-warn' : 'approval-note'}>{line.note}</small>}
|
|
146
144
|
</dd>
|
|
147
145
|
</div>
|
|
148
146
|
))}
|
|
@@ -172,6 +170,9 @@ function Approve({ view, onDecided }: { view: ApprovalView; onDecided: (decision
|
|
|
172
170
|
)}
|
|
173
171
|
|
|
174
172
|
<div className="consent-notices">
|
|
173
|
+
{!view.ready && (
|
|
174
|
+
<Notice tone="warn">coffre couldn't read what this change replaces, so it can't be approved yet. Reload to try again.</Notice>
|
|
175
|
+
)}
|
|
175
176
|
{client.registration === 'dcr' && (
|
|
176
177
|
<Notice tone="warn">This app registered itself: its name is its own claim. Approve only what you asked it to do.</Notice>
|
|
177
178
|
)}
|
|
@@ -185,7 +186,7 @@ function Approve({ view, onDecided }: { view: ApprovalView; onDecided: (decision
|
|
|
185
186
|
</button>
|
|
186
187
|
<button
|
|
187
188
|
className="btn btn-primary"
|
|
188
|
-
disabled={pending !== null || (asksValue !== null && value === '')}
|
|
189
|
+
disabled={pending !== null || !view.ready || (asksValue !== null && value === '')}
|
|
189
190
|
onClick={() => void decide(true)}
|
|
190
191
|
>
|
|
191
192
|
{pending === 'approve' && <Spinner />}
|
package/src/pages/login.tsx
CHANGED
|
@@ -80,7 +80,7 @@ function ProviderLoginPage({
|
|
|
80
80
|
{title}
|
|
81
81
|
</h1>
|
|
82
82
|
<p className="signin-lede">
|
|
83
|
-
{note ?? 'Sign in with your organization’s account. Only people an
|
|
83
|
+
{note ?? 'Sign in with your organization’s account. Only people an admin has invited can get in.'}
|
|
84
84
|
</p>
|
|
85
85
|
</div>
|
|
86
86
|
|