@coffre/ui 0.5.1 → 0.6.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-Bqdevf7w.js → affordances-D0GyCT-I.js} +3 -3
- package/dist/chunks/affordances-D0GyCT-I.js.map +1 -0
- package/dist/chunks/{audit-sentence-Cm5nby5k.js → audit-sentence-CUUMshIp.js} +22 -6
- package/dist/chunks/audit-sentence-CUUMshIp.js.map +1 -0
- package/dist/chunks/{connected-apps-DTNS7YmY.js → connected-apps-IP0KfUjo.js} +5 -5
- package/dist/chunks/{connected-apps-DTNS7YmY.js.map → connected-apps-IP0KfUjo.js.map} +1 -1
- package/dist/chunks/{delete-place-CIaOq0mt.js → delete-place-CVv6CN5y.js} +5 -5
- package/dist/chunks/{delete-place-CIaOq0mt.js.map → delete-place-CVv6CN5y.js.map} +1 -1
- package/dist/chunks/{directory-DSVt5Tya.js → directory-pMVS1m-c.js} +62 -43
- package/dist/chunks/directory-pMVS1m-c.js.map +1 -0
- package/dist/chunks/{folders-CoGK9oqg.js → folders-hR2Lnk0k.js} +3 -3
- package/dist/chunks/{folders-CoGK9oqg.js.map → folders-hR2Lnk0k.js.map} +1 -1
- package/dist/chunks/{grants-CRU7yZhL.js → grants-CgC8Ybhu.js} +6 -6
- package/dist/chunks/{grants-CRU7yZhL.js.map → grants-CgC8Ybhu.js.map} +1 -1
- package/dist/chunks/{offboarding-DVBSiJRZ.js → offboarding-3fzRjKla.js} +5 -5
- package/dist/chunks/{offboarding-DVBSiJRZ.js.map → offboarding-3fzRjKla.js.map} +1 -1
- package/dist/chunks/{page-DvsgZ2Hd.js → page-JTORvh-N.js} +7 -3
- package/dist/chunks/page-JTORvh-N.js.map +1 -0
- package/dist/chunks/{principal-BIN-xwZw.js → principal-DFBswTBr.js} +2 -2
- package/dist/chunks/{principal-BIN-xwZw.js.map → principal-DFBswTBr.js.map} +1 -1
- package/dist/chunks/{principal-page-BEBr_zW7.js → principal-page-CYJIJAdp.js} +17 -19
- package/dist/chunks/principal-page-CYJIJAdp.js.map +1 -0
- package/dist/chunks/{project-page-B3TZ5_ig.js → project-page-lO5P6iCb.js} +3 -3
- package/dist/chunks/{project-page-B3TZ5_ig.js.map → project-page-lO5P6iCb.js.map} +1 -1
- package/dist/chunks/{queries-DE5nK2y4.js → queries-gigcQOO_.js} +26 -12
- package/dist/chunks/queries-gigcQOO_.js.map +1 -0
- package/dist/chunks/{references-uv4Mli9z.js → references-DZ179hTJ.js} +5 -5
- package/dist/chunks/{references-uv4Mli9z.js.map → references-DZ179hTJ.js.map} +1 -1
- package/dist/chunks/{role-field-DWhkRY6n.js → role-field-DiqiFwm_.js} +14 -7
- package/dist/chunks/role-field-DiqiFwm_.js.map +1 -0
- package/dist/chunks/{row-state-DOPUsjQK.js → row-state-Zf3kZVhd.js} +13 -5
- package/dist/chunks/row-state-Zf3kZVhd.js.map +1 -0
- package/dist/chunks/{signin-errors--ykMFuqN.js → signin-errors-TlQmQe0t.js} +2 -2
- package/dist/chunks/signin-errors-TlQmQe0t.js.map +1 -0
- package/dist/chunks/{theme-DJuz-xLM.js → theme-B6-V9JvY.js} +3 -3
- package/dist/chunks/{theme-DJuz-xLM.js.map → theme-B6-V9JvY.js.map} +1 -1
- package/dist/chunks/{ui-DJje3gST.js → ui-Br-dNUTc.js} +2 -2
- package/dist/chunks/{ui-DJje3gST.js.map → ui-Br-dNUTc.js.map} +1 -1
- package/dist/chunks/{use-action-BRgvbUWt.js → use-action-CQGGNqWb.js} +3 -3
- package/dist/chunks/{use-action-BRgvbUWt.js.map → use-action-CQGGNqWb.js.map} +1 -1
- package/dist/chunks/{use-change-BJ3dCFHb.js → use-change-BdS1gzyo.js} +31 -19
- package/dist/chunks/use-change-BdS1gzyo.js.map +1 -0
- package/dist/chunks/{use-shell-BO4ZTr1y.js → use-shell-BCU505bx.js} +3 -3
- package/dist/chunks/{use-shell-BO4ZTr1y.js.map → use-shell-BCU505bx.js.map} +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/dist/pages/account.js +12 -13
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.js +2 -2
- package/dist/pages/audit.js +5 -5
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -2
- package/dist/pages/environment.js +829 -155
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +4 -4
- package/dist/pages/oauth-authorize.js +2 -2
- package/dist/pages/project-access.js +160 -80
- package/dist/pages/project-access.js.map +1 -1
- package/dist/pages/project-environments.js +10 -10
- package/dist/pages/project-settings.js +8 -8
- package/dist/pages/project.js +3 -3
- package/dist/pages/projects.js +10 -10
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.js +537 -109
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +5 -5
- package/dist/pages/settings.js +8 -18
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +3 -3
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.js +6 -6
- package/dist/pages/users.js +5 -5
- package/package.json +3 -3
- package/src/components/affordances.ts +1 -1
- package/src/components/directory.tsx +40 -34
- package/src/components/generate-value.tsx +362 -0
- package/src/components/github-picker.tsx +83 -0
- package/src/components/icons.tsx +4 -0
- package/src/components/masked.tsx +60 -0
- package/src/components/missing.tsx +3 -3
- package/src/components/multi-combobox.tsx +94 -0
- package/src/components/principal-page.tsx +8 -12
- package/src/components/principal-picker.tsx +68 -18
- package/src/components/role-field.tsx +7 -5
- package/src/components/row-state.tsx +7 -3
- package/src/components/shell.tsx +0 -1
- package/src/components/trusted-workloads.tsx +157 -62
- package/src/lib/audit-sentences.ts +25 -3
- package/src/lib/bindings.ts +125 -14
- package/src/lib/capabilities.ts +15 -9
- package/src/lib/changes.ts +15 -9
- package/src/lib/coffre.ts +2 -0
- package/src/lib/generate.ts +160 -0
- package/src/lib/queries.ts +18 -5
- package/src/lib/secret-edit-batch.ts +38 -5
- package/src/lib/secret-order.ts +23 -0
- package/src/lib/shortcuts.ts +9 -0
- package/src/lib/signin-errors.ts +1 -1
- package/src/lib/use-github-lookup.ts +70 -0
- package/src/pages/account.tsx +1 -2
- package/src/pages/audit.tsx +1 -1
- package/src/pages/environment.tsx +228 -119
- package/src/pages/project-access.tsx +19 -8
- package/src/pages/projects.tsx +3 -3
- package/src/pages/settings.tsx +0 -10
- package/src/pages/unregistered.tsx +1 -1
- package/src/parity.ts +3 -1
- package/src/shared/models.ts +2 -2
- package/src/styles/globals.css +303 -19
- package/dist/chunks/affordances-Bqdevf7w.js.map +0 -1
- package/dist/chunks/audit-sentence-Cm5nby5k.js.map +0 -1
- package/dist/chunks/directory-DSVt5Tya.js.map +0 -1
- package/dist/chunks/page-DvsgZ2Hd.js.map +0 -1
- package/dist/chunks/principal-page-BEBr_zW7.js.map +0 -1
- package/dist/chunks/queries-DE5nK2y4.js.map +0 -1
- package/dist/chunks/role-field-DWhkRY6n.js.map +0 -1
- package/dist/chunks/row-state-DOPUsjQK.js.map +0 -1
- package/dist/chunks/signin-errors--ykMFuqN.js.map +0 -1
- package/dist/chunks/use-change-BJ3dCFHb.js.map +0 -1
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import type { BindingPlan, BindingView } from '@coffre/client';
|
|
1
|
+
import type { BindingPlan, BindingView, CoffreClient } from '@coffre/client';
|
|
2
2
|
import { credentialScopeInWords } from '@coffre/core/access';
|
|
3
3
|
import { claimValues, EVENT_EXPOSURE, githubEventsAt, GITLAB_PIPELINE_SOURCES } from '@coffre/core/workloads';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useQuery } from '@tanstack/react-query';
|
|
5
|
+
import { Fragment, useEffect, useState } from 'react';
|
|
6
|
+
import { askedScope, bindingOf, EMPTY_FORM, githubTarget, listedIds, listingGap, planned, summary, type Form, type GitHubLookup, type RefKind, type ScopeChoice } from '../lib/bindings';
|
|
6
7
|
import { removeBinding } from '../lib/changes';
|
|
7
|
-
import { memberRef, useCoffre } from '../lib/coffre';
|
|
8
|
-
import { affects } from '../lib/queries';
|
|
8
|
+
import { memberRef, statusOf, useCoffre } from '../lib/coffre';
|
|
9
|
+
import { affects, queries } from '../lib/queries';
|
|
9
10
|
import { useAction } from '../lib/use-action';
|
|
10
11
|
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
12
|
+
import { useGitHubLookup } from '../lib/use-github-lookup';
|
|
13
|
+
import { GitHubPicker, type Listed } from './github-picker';
|
|
14
|
+
import { MultiCombobox } from './multi-combobox';
|
|
11
15
|
import { RowFailure, RowPending, rowClass } from './row-state';
|
|
12
16
|
import { Card } from './page';
|
|
13
17
|
import { ScopePicker, wholeScope, type HeldGrant } from './scope-picker';
|
|
14
18
|
import { ConfirmButton, EmptyState, ErrorLine, Modal, Notice, Spinner, Timestamp } from './ui';
|
|
15
|
-
import { GitHub, Link, Plus, X } from './icons';
|
|
19
|
+
import { CheckCircle, GitHub, Link, Plus, X } from './icons';
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* The CI runs that may sign in as a service, by the ID token their platform
|
|
@@ -155,28 +159,72 @@ function Claims({ binding }: { binding: Pick<BindingPlan, 'issuer' | 'jwksUri' |
|
|
|
155
159
|
);
|
|
156
160
|
}
|
|
157
161
|
|
|
158
|
-
/**
|
|
159
|
-
function
|
|
160
|
-
|
|
162
|
+
/** Beside `pull_request` and `workflow_run` in the events' list: they run code nobody reviewed, said in full once chosen. */
|
|
163
|
+
function exposureNote(event: string) {
|
|
164
|
+
return EVENT_EXPOSURE[event] === undefined ? null : <span className="tag tag-amber">unreviewed code</span>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* What GitHub said of the repository or owner the form names: who it is,
|
|
169
|
+
* as confirmation, or why it could not say, with the way to type its IDs.
|
|
170
|
+
*/
|
|
171
|
+
function GitHubFound({ lookup, kind }: { lookup: GitHubLookup | null; kind: 'repository' | 'owner' }) {
|
|
172
|
+
if (lookup === null) return null;
|
|
173
|
+
if (lookup.state === 'looking') {
|
|
174
|
+
return (
|
|
175
|
+
<p className="lookup" role="status">
|
|
176
|
+
<Spinner size={13} />
|
|
177
|
+
Looking it up on GitHub…
|
|
178
|
+
</p>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (lookup.state === 'found') {
|
|
182
|
+
const { github, repositoryId, ownerId } = lookup.ids;
|
|
183
|
+
return (
|
|
184
|
+
<p className="lookup lookup-found" role="status">
|
|
185
|
+
<CheckCircle size={14} />
|
|
186
|
+
<span>
|
|
187
|
+
<span className="mono lookup-name">{github}</span>
|
|
188
|
+
{kind === 'repository' ? ` · ID ${repositoryId}, owned by ${github.split('/')[0]} (ID ${ownerId})` : ` · ID ${ownerId}`}
|
|
189
|
+
</span>
|
|
190
|
+
</p>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
161
193
|
return (
|
|
162
|
-
<
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
194
|
+
<p className="lookup lookup-failed" role="status">
|
|
195
|
+
{lookup.message}
|
|
196
|
+
</p>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* What the deployment's GitHub App could not list, said under the field (`listingGap`): it
|
|
202
|
+
* is installed nowhere yet, or reaches no repository, with where to change
|
|
203
|
+
* that, or GitHub did not answer. Nothing without an app, or while it lists.
|
|
204
|
+
*/
|
|
205
|
+
function Listing({ listing, owner }: { listing: { data?: Awaited<ReturnType<CoffreClient['bindings']['repositories']>>; error: unknown }; owner: boolean }) {
|
|
206
|
+
if (listing.error !== null && listing.error !== undefined) {
|
|
207
|
+
// A 503 says what GitHub answered, for the person; anything else is no more use to them than that it failed.
|
|
208
|
+
const why = statusOf(listing.error) === 503 ? `: ${(listing.error as Error).message}` : '. Type the name: it is still looked up.';
|
|
209
|
+
return <p className="hint">The GitHub App's repositories could not be listed{why}</p>;
|
|
210
|
+
}
|
|
211
|
+
const listed = listing.data;
|
|
212
|
+
if (listed === undefined || !('repositories' in listed)) return null;
|
|
213
|
+
const install = (words: string) => (
|
|
214
|
+
<a href={listed.app.installUrl} target="_blank" rel="noreferrer">
|
|
215
|
+
{words}
|
|
216
|
+
</a>
|
|
179
217
|
);
|
|
218
|
+
switch (listingGap(listed, owner)) {
|
|
219
|
+
case 'partial':
|
|
220
|
+
return <p className="hint">Only some of {listed.app.name}'s repositories are listed: type any other by name.</p>;
|
|
221
|
+
case 'not_installed':
|
|
222
|
+
return <p className="hint">{listed.app.name} is installed on no account yet: {install('install it')} on yours to pick its repositories here.</p>;
|
|
223
|
+
case 'no_repositories':
|
|
224
|
+
return <p className="hint">{listed.app.name} reaches no repository yet: {install('choose some')} to pick them here.</p>;
|
|
225
|
+
case null:
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
180
228
|
}
|
|
181
229
|
|
|
182
230
|
/** What trusting `pull_request` or `workflow_run` exposes, said where the owner chooses it and again before saving. */
|
|
@@ -215,11 +263,22 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
|
|
|
215
263
|
const member = memberRef('service', serviceId);
|
|
216
264
|
const { pending, error, setError, run } = useAction();
|
|
217
265
|
const lookup = useAction();
|
|
266
|
+
const target = githubTarget(form);
|
|
267
|
+
// Not asked while IDs are typed in: the name is then a private repository's, which GitHub would not show.
|
|
268
|
+
const github = useGitHubLookup(form.typedIds ? { ...target, name: '' } : target);
|
|
269
|
+
const found = github.lookup?.state === 'found' ? github.lookup.ids : null;
|
|
270
|
+
// What the deployment's GitHub App is installed on, asked once the dialog shows a GitHub binding: names the field offers, their IDs known.
|
|
271
|
+
const listing = useQuery({ ...queries.githubRepositories(coffre), enabled: open && form.platform === 'github' });
|
|
272
|
+
const listed = listing.data !== undefined && 'repositories' in listing.data ? listing.data : null;
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (listed !== null) github.remember(...listedIds(listed.repositories));
|
|
275
|
+
// Once per listing: `remember` is new each render.
|
|
276
|
+
}, [listed]);
|
|
218
277
|
const set = (changes: Partial<Form>) => {
|
|
219
278
|
setForm((current) => ({ ...current, ...changes }));
|
|
220
279
|
setPlan(null);
|
|
221
280
|
};
|
|
222
|
-
const input = () => ({ ...bindingOf(form), ...askedScope(choice), label: form.label.trim() === '' ? null : form.label.trim(), replaces: [] });
|
|
281
|
+
const input = () => ({ ...bindingOf(form, found), ...askedScope(choice), label: form.label.trim() === '' ? null : form.label.trim(), replaces: [] });
|
|
223
282
|
|
|
224
283
|
function close() {
|
|
225
284
|
setOpen(false);
|
|
@@ -248,19 +307,68 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
|
|
|
248
307
|
});
|
|
249
308
|
}
|
|
250
309
|
|
|
251
|
-
const field = (label: string, key: keyof Form, props: { placeholder?: string; mono?: boolean; hint?: string } = {}) => (
|
|
310
|
+
const field = (label: string, key: keyof Form, props: { placeholder?: string; mono?: boolean; hint?: string; onBlur?: () => void } = {}) => (
|
|
252
311
|
<label className="field">
|
|
253
312
|
<span className="label">{label}</span>
|
|
254
313
|
<input
|
|
255
314
|
className={`input${props.mono ? ' mono' : ''}`}
|
|
256
315
|
value={form[key] as string}
|
|
257
316
|
placeholder={props.placeholder}
|
|
317
|
+
spellCheck={props.mono ? false : undefined}
|
|
258
318
|
onChange={(event) => set({ [key]: event.target.value } as Partial<Form>)}
|
|
319
|
+
onBlur={props.onBlur}
|
|
259
320
|
/>
|
|
260
321
|
{props.hint !== undefined && <span className="hint">{props.hint}</span>}
|
|
261
322
|
</label>
|
|
262
323
|
);
|
|
263
324
|
|
|
325
|
+
// The repository, or the organization, its IDs looked up as it settles; typed in only where GitHub shows nothing.
|
|
326
|
+
const owner = target.kind === 'owner';
|
|
327
|
+
const lookedUp = github.lookup;
|
|
328
|
+
const named = owner
|
|
329
|
+
? { label: 'Organization', key: 'owner' as const, placeholder: 'acme' }
|
|
330
|
+
: { label: 'Repository', key: 'repository' as const, placeholder: 'acme/api' };
|
|
331
|
+
const githubIds = (
|
|
332
|
+
<div className="lookup-group">
|
|
333
|
+
<GitHubPicker
|
|
334
|
+
label={named.label}
|
|
335
|
+
value={form[named.key]}
|
|
336
|
+
onChange={(name) => set({ [named.key]: name })}
|
|
337
|
+
// Its IDs are the list's, never IDs typed for another name.
|
|
338
|
+
onPick={(name) => set({ [named.key]: name, typedIds: false, repositoryId: '', ownerId: '' })}
|
|
339
|
+
onBlur={github.settle}
|
|
340
|
+
options={
|
|
341
|
+
listed === null
|
|
342
|
+
? null
|
|
343
|
+
: owner
|
|
344
|
+
? listed.installations.map((name): Listed => ({ name }))
|
|
345
|
+
: listed.repositories.map((each): Listed => ({ name: each.github, private: each.private }))
|
|
346
|
+
}
|
|
347
|
+
placeholder={named.placeholder}
|
|
348
|
+
empty={listed === null ? '' : `None of ${listed.app.name}'s ${owner ? 'accounts' : 'repositories'} match: type the whole name.`}
|
|
349
|
+
/>
|
|
350
|
+
<Listing listing={listing} owner={owner} />
|
|
351
|
+
{!form.typedIds && <GitHubFound lookup={lookedUp} kind={target.kind} />}
|
|
352
|
+
{(form.typedIds || lookedUp?.state === 'missing' || lookedUp?.state === 'failed') && (
|
|
353
|
+
<details className="disclosure" open={form.typedIds} onToggle={(event) => set({ typedIds: event.currentTarget.open })}>
|
|
354
|
+
<summary>{owner ? 'Enter its ID' : 'Private repository? Enter IDs'}</summary>
|
|
355
|
+
<div className="disclosure-body">
|
|
356
|
+
<div className="form-row">
|
|
357
|
+
{!owner && field('Repository ID', 'repositoryId', { mono: true })}
|
|
358
|
+
{field('Owner ID', 'ownerId', { mono: true })}
|
|
359
|
+
</div>
|
|
360
|
+
<p className="hint">
|
|
361
|
+
Bindings use IDs, since a name can pass to someone else. Get them with{' '}
|
|
362
|
+
<span className="mono">
|
|
363
|
+
{owner ? `gh api users/${target.name || 'acme'} --jq .id` : `gh api repos/${target.name || 'acme/api'} --jq '.id, .owner.id'`}
|
|
364
|
+
</span>
|
|
365
|
+
</p>
|
|
366
|
+
</div>
|
|
367
|
+
</details>
|
|
368
|
+
)}
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
|
|
264
372
|
const ref = (
|
|
265
373
|
<div className="form-row">
|
|
266
374
|
<label className="field" style={{ flex: '0 0 8rem' }}>
|
|
@@ -315,55 +423,40 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
|
|
|
315
423
|
A reusable workflow
|
|
316
424
|
</button>
|
|
317
425
|
</nav>
|
|
318
|
-
<div className="form-row">
|
|
319
|
-
{field('Repository', 'repository', { placeholder: 'acme/api', mono: true })}
|
|
320
|
-
<div className="field" style={{ flex: '0 0 auto', alignSelf: 'end' }}>
|
|
321
|
-
<button
|
|
322
|
-
className="btn"
|
|
323
|
-
type="button"
|
|
324
|
-
disabled={lookup.pending || form.repository.trim() === ''}
|
|
325
|
-
onClick={() =>
|
|
326
|
-
void lookup.run(() => coffre.bindings.lookup({ github: form.repository.trim() }), {
|
|
327
|
-
affects: [],
|
|
328
|
-
onSuccess: (ids) => 'repositoryId' in ids && set({ repositoryId: ids.repositoryId, ownerId: ids.ownerId }),
|
|
329
|
-
})
|
|
330
|
-
}
|
|
331
|
-
>
|
|
332
|
-
{lookup.pending && <Spinner />}
|
|
333
|
-
Look up IDs
|
|
334
|
-
</button>
|
|
335
|
-
</div>
|
|
336
|
-
</div>
|
|
337
|
-
<div className="form-row">
|
|
338
|
-
{!(form.reusable && form.anyRepository) && field('Repository ID', 'repositoryId', { mono: true })}
|
|
339
|
-
{field('Owner ID', 'ownerId', { mono: true })}
|
|
340
|
-
</div>
|
|
341
|
-
<p className="hint">
|
|
342
|
-
Bindings use IDs, since a name can pass to someone else. For a private repository:{' '}
|
|
343
|
-
<span className="mono">gh api repos/{form.repository.trim() || 'acme/api'} --jq '.id, .owner.id'</span>
|
|
344
|
-
</p>
|
|
345
|
-
<ErrorLine error={lookup.error} />
|
|
346
426
|
{form.reusable ? (
|
|
347
427
|
<>
|
|
348
428
|
{field('Called workflow', 'called', { placeholder: 'acme/deploy/.github/workflows/release.yml@refs/heads/main', mono: true })}
|
|
349
429
|
{field("Its commit", 'sha', { placeholder: 'the full SHA it is trusted at', mono: true, hint: 'A new version of the workflow needs a new binding.' })}
|
|
350
|
-
{field('Calling workflow (optional)', 'workflow', { placeholder: 'deploy.yml', mono: true, hint: 'Left out, every workflow of the repository at the ref below may call it.' })}
|
|
351
430
|
<label className="check">
|
|
352
431
|
<input type="checkbox" checked={form.anyRepository} onChange={(event) => set({ anyRepository: event.target.checked })} />
|
|
353
432
|
Called from any repository of the organization
|
|
354
433
|
</label>
|
|
434
|
+
{githubIds}
|
|
435
|
+
{!form.anyRepository &&
|
|
436
|
+
field('Calling workflow (optional)', 'workflow', { placeholder: 'deploy.yml', mono: true, hint: 'Left out, every workflow of the repository at the ref below may call it.' })}
|
|
355
437
|
</>
|
|
356
438
|
) : (
|
|
357
|
-
|
|
439
|
+
<>
|
|
440
|
+
{githubIds}
|
|
441
|
+
{field('Workflow file', 'workflow', { placeholder: 'deploy.yml', mono: true })}
|
|
442
|
+
</>
|
|
358
443
|
)}
|
|
359
444
|
{ref}
|
|
360
|
-
<
|
|
445
|
+
<MultiCombobox
|
|
361
446
|
label="Events"
|
|
362
447
|
options={githubEventsAt(form.refKind)}
|
|
363
|
-
|
|
448
|
+
value={form.events}
|
|
364
449
|
onChange={(events) => set({ events })}
|
|
450
|
+
placeholder="push, workflow_dispatch…"
|
|
451
|
+
note={exposureNote}
|
|
452
|
+
mono
|
|
365
453
|
hint={form.events.includes('pull_request') ? `A pull request matches by the branch it merges into: ${form.refName.trim() || 'main'}.` : undefined}
|
|
366
454
|
/>
|
|
455
|
+
{field('GitHub environment (optional)', 'environment', {
|
|
456
|
+
placeholder: 'production',
|
|
457
|
+
mono: true,
|
|
458
|
+
hint: 'Only jobs that run in this environment sign in, once its protection rules, such as required reviewers, let them.',
|
|
459
|
+
})}
|
|
367
460
|
<Exposure events={form.events} />
|
|
368
461
|
</>
|
|
369
462
|
)}
|
|
@@ -396,11 +489,13 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
|
|
|
396
489
|
</div>
|
|
397
490
|
<ErrorLine error={lookup.error} />
|
|
398
491
|
{ref}
|
|
399
|
-
<
|
|
492
|
+
<MultiCombobox
|
|
400
493
|
label="Pipeline sources"
|
|
401
494
|
options={GITLAB_PIPELINE_SOURCES}
|
|
402
|
-
|
|
495
|
+
value={form.sources}
|
|
403
496
|
onChange={(sources) => set({ sources })}
|
|
497
|
+
placeholder="push, web, schedule"
|
|
498
|
+
mono
|
|
404
499
|
hint="Merge-request pipelines are never trusted: they name another project."
|
|
405
500
|
/>
|
|
406
501
|
</>
|
|
@@ -83,6 +83,11 @@ function subject(entry: AuditEntry): Part[] {
|
|
|
83
83
|
return [{ member: `${entry.metadata.principalType === 'service' ? 'token' : 'user'}:${id}` }];
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** Why the vault made someone an Owner itself, said after it. */
|
|
87
|
+
function owned(entry: AuditEntry): Part[] {
|
|
88
|
+
return entry.metadata.reason === 'owners' ? [': the deployment names them one'] : [];
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
/** An MCP client, by the name it connected under. */
|
|
87
92
|
function app(entry: AuditEntry): Part[] {
|
|
88
93
|
return [text(entry.metadata.clientName) ?? 'an app'];
|
|
@@ -289,6 +294,7 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
289
294
|
...subject(entry),
|
|
290
295
|
...(entry.metadata.rootAdmin === true ? [' as a root admin'] : entry.metadata.owner === true ? [' as an owner'] : asRole(entry)),
|
|
291
296
|
],
|
|
297
|
+
then: ({ entry }) => owned(entry),
|
|
292
298
|
},
|
|
293
299
|
'member.remove': {
|
|
294
300
|
did: 'removed',
|
|
@@ -296,14 +302,23 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
296
302
|
what: (facts) => subject(facts.entry),
|
|
297
303
|
then: ({ entry }) => (number(entry.metadata.revoked) === null ? [] : [`, who held ${plural(number(entry.metadata.revoked)!, 'grant')}`]),
|
|
298
304
|
},
|
|
299
|
-
'member.restore': {
|
|
305
|
+
'member.restore': {
|
|
306
|
+
did: 'brought back',
|
|
307
|
+
tried: 'bring back',
|
|
308
|
+
what: ({ entry }) => [...subject(entry), ...asRole(entry)],
|
|
309
|
+
then: ({ entry }) => owned(entry),
|
|
310
|
+
},
|
|
300
311
|
'member.role': {
|
|
301
312
|
did: 'made',
|
|
302
313
|
tried: 'make',
|
|
303
314
|
what: ({ entry }) => [...subject(entry), ` ${article(roleName(text(entry.metadata.role) ?? 'member') ?? 'Member')}`, ...scoped(entry)],
|
|
304
315
|
then: ({ entry }) => {
|
|
305
316
|
const before = roleName(text(entry.metadata.previousRole) ?? '');
|
|
306
|
-
return [
|
|
317
|
+
return [
|
|
318
|
+
...(before === null ? [] : [`, was ${before}`]),
|
|
319
|
+
...(entry.metadata.reason === 'every-project' ? [', for their grants on every project'] : []),
|
|
320
|
+
...owned(entry),
|
|
321
|
+
];
|
|
307
322
|
},
|
|
308
323
|
},
|
|
309
324
|
'member.owner': {
|
|
@@ -326,7 +341,7 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
326
341
|
did: 'trusted CI runs to sign in as',
|
|
327
342
|
tried: 'trust CI runs to sign in as',
|
|
328
343
|
what: (facts) => subject(facts.entry),
|
|
329
|
-
then: ({ entry }) => reaching(entry),
|
|
344
|
+
then: ({ entry }) => [...inGitHubEnvironment(entry), ...reaching(entry)],
|
|
330
345
|
},
|
|
331
346
|
// The tokens and bindings 0.4 made, given their own scope when 0.5 first checked a credential: what their account held then.
|
|
332
347
|
'token.seal': {
|
|
@@ -451,6 +466,12 @@ function reaching(entry: AuditEntry, none = ''): Part[] {
|
|
|
451
466
|
return [`, reaching ${[...byRole].map(([role, count]) => `${role} on ${plural(count, 'place')}`).join(', ')}`];
|
|
452
467
|
}
|
|
453
468
|
|
|
469
|
+
/** The GitHub environment a binding takes its runs from, when it names one. */
|
|
470
|
+
function inGitHubEnvironment(entry: AuditEntry): Part[] {
|
|
471
|
+
const environment = text((entry.metadata.claims as Record<string, unknown> | undefined)?.environment);
|
|
472
|
+
return environment === null || !String(entry.metadata.profile).startsWith('github') ? [] : [`, in GitHub environment ${environment}`];
|
|
473
|
+
}
|
|
474
|
+
|
|
454
475
|
/** The tokens and trust bindings a `token.seal` names, counted: `2 tokens and a trust binding`. */
|
|
455
476
|
function sealedOf(entry: AuditEntry): string {
|
|
456
477
|
const count = (key: string) => (Array.isArray(entry.metadata[key]) ? (entry.metadata[key] as unknown[]).length : 0);
|
|
@@ -509,6 +530,7 @@ const REASONS: Record<string, string> = {
|
|
|
509
530
|
deleted: 'the place was deleted',
|
|
510
531
|
not_allowed: 'not allowed',
|
|
511
532
|
root_admin: 'root admins are set by the deployment',
|
|
533
|
+
last_owner: 'they are the last Owner of the whole instance',
|
|
512
534
|
requires_instance_admin: 'requires an admin or owner of the whole instance',
|
|
513
535
|
requires_instance_owner: 'requires an instance owner',
|
|
514
536
|
own_role: 'nobody changes their own role',
|
package/src/lib/bindings.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { CoffreError, type BindingPlan, type BindingView } from '@coffre/client';
|
|
2
2
|
import { claimValues, fullRef, githubReusable, githubWorkflow, gitlabProject, type BindingClaims } from '@coffre/core/workloads';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -14,14 +14,15 @@ export function summary(binding: Pick<BindingView, 'profile' | 'issuer' | 'claim
|
|
|
14
14
|
const events = claimValues(binding.claims.event_name).join(', ');
|
|
15
15
|
const short = (ref: string | undefined) => ref?.replace(/^refs\/(heads|tags)\//, '') ?? '';
|
|
16
16
|
const [workflow, at] = (claims.workflow_ref ?? '').split('@');
|
|
17
|
+
const environment = claims.environment === undefined ? '' : `, in environment ${claims.environment}`;
|
|
17
18
|
if (binding.profile === 'github') {
|
|
18
19
|
const [owner, repository, , , file] = (workflow ?? '').split('/');
|
|
19
|
-
return { title: `${owner}/${repository} · ${file}`, detail: `${events} at ${short(at)}` };
|
|
20
|
+
return { title: `${owner}/${repository} · ${file}`, detail: `${events} at ${short(at)}${environment}` };
|
|
20
21
|
}
|
|
21
22
|
if (binding.profile.startsWith('github-reusable')) {
|
|
22
23
|
const called = (claims.job_workflow_ref ?? '').split('@')[0]!.replace('/.github/workflows/', ' · ');
|
|
23
24
|
const from = binding.profile === 'github-reusable-organization' ? 'any repository of the organization' : `repository ${claims.repository_id}`;
|
|
24
|
-
return { title: `${called} @ ${claims.job_workflow_sha?.slice(0, 7)}`, detail: `${events} at ${short(claims.ref)}, from ${from}` };
|
|
25
|
+
return { title: `${called} @ ${claims.job_workflow_sha?.slice(0, 7)}`, detail: `${events} at ${short(claims.ref)}, from ${from}${environment}` };
|
|
25
26
|
}
|
|
26
27
|
if (binding.profile === 'gitlab') {
|
|
27
28
|
return { title: `GitLab project ${claims.project_id}`, detail: `${claimValues(binding.claims.pipeline_source).join(', ')} at ${claims.ref_type} ${claims.ref}` };
|
|
@@ -53,12 +54,16 @@ export type RefKind = 'branch' | 'tag';
|
|
|
53
54
|
export const EMPTY_FORM = {
|
|
54
55
|
platform: 'github' as Platform,
|
|
55
56
|
label: '',
|
|
56
|
-
// GitHub
|
|
57
|
+
// GitHub: the repository, or for a reusable workflow called from any of its repositories, the owner.
|
|
57
58
|
reusable: false,
|
|
58
59
|
repository: '',
|
|
60
|
+
owner: '',
|
|
61
|
+
// IDs typed in, for a repository GitHub does not show: the lookup's otherwise.
|
|
62
|
+
typedIds: false,
|
|
59
63
|
repositoryId: '',
|
|
60
64
|
ownerId: '',
|
|
61
65
|
workflow: '',
|
|
66
|
+
environment: '',
|
|
62
67
|
events: ['push'] as string[],
|
|
63
68
|
refKind: 'branch' as RefKind,
|
|
64
69
|
refName: 'main',
|
|
@@ -79,8 +84,99 @@ export const EMPTY_FORM = {
|
|
|
79
84
|
|
|
80
85
|
export type Form = typeof EMPTY_FORM;
|
|
81
86
|
|
|
82
|
-
/**
|
|
83
|
-
|
|
87
|
+
/**
|
|
88
|
+
* A GitHub repository or owner by its IDs, under the name GitHub gives it
|
|
89
|
+
* (`acme/api` for `Acme/API`), as its tokens spell it: what the lookup
|
|
90
|
+
* found, or what a picker knows. An owner has no repository ID.
|
|
91
|
+
*/
|
|
92
|
+
export type GitHubIds = { github: string; repositoryId?: string; ownerId: string };
|
|
93
|
+
|
|
94
|
+
/** What a GitHub App's listing tells of names' IDs: each repository's, and its owner's, once each. */
|
|
95
|
+
export function listedIds(repositories: readonly { github: string; repositoryId: string; ownerId: string }[]): GitHubIds[] {
|
|
96
|
+
const owners = new Map(repositories.map(({ github, ownerId }) => [github.split('/')[0]!, ownerId]));
|
|
97
|
+
return [
|
|
98
|
+
...repositories.map(({ github, repositoryId, ownerId }) => ({ github, repositoryId, ownerId })),
|
|
99
|
+
...[...owners].map(([github, ownerId]) => ({ github, ownerId })),
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* What a GitHub App's listing lacks, as the dialog says it under the field:
|
|
105
|
+
* it stopped short (`partial`), which comes first since an empty partial
|
|
106
|
+
* list may only lack what it did not reach; or, whole, the app is installed
|
|
107
|
+
* on no account, or, for a repository, reaches none of theirs.
|
|
108
|
+
*/
|
|
109
|
+
export function listingGap(
|
|
110
|
+
listed: { installations: readonly string[]; repositories: readonly unknown[]; truncated: boolean },
|
|
111
|
+
owner: boolean,
|
|
112
|
+
): 'partial' | 'not_installed' | 'no_repositories' | null {
|
|
113
|
+
if (listed.truncated) return 'partial';
|
|
114
|
+
if (listed.installations.length === 0) return 'not_installed';
|
|
115
|
+
return !owner && listed.repositories.length === 0 ? 'no_repositories' : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Who the GitHub form names: a repository, or for a reusable workflow called from any of its repositories, an owner. */
|
|
119
|
+
export function githubTarget(form: Form): { kind: 'repository' | 'owner'; name: string } {
|
|
120
|
+
return form.reusable && form.anyRepository ? { kind: 'owner', name: form.owner.trim() } : { kind: 'repository', name: form.repository.trim() };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const GITHUB_NAME = { repository: /^[A-Za-z0-9-]{1,39}\/[A-Za-z0-9._-]{1,100}$/, owner: /^[A-Za-z0-9-]{1,39}$/ };
|
|
124
|
+
|
|
125
|
+
/** Whether a name is one GitHub could know: `acme/api` for a repository, `acme` for an owner; not `acme/` while it is typed. */
|
|
126
|
+
export function lookupable(target: { kind: 'repository' | 'owner'; name: string }): boolean {
|
|
127
|
+
return GITHUB_NAME[target.kind].test(target.name);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** How the dialog remembers a lookup, by name in any case: GitHub's names are case-insensitive. */
|
|
131
|
+
export const lookupKey = (name: string) => name.trim().toLowerCase();
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* What GitHub said of a name: still asking; its IDs; nothing public there
|
|
135
|
+
* (private, or not there), which is final; or no answer, such as when the
|
|
136
|
+
* hour's lookups are spent, which asking again may change.
|
|
137
|
+
*/
|
|
138
|
+
export type GitHubLookup =
|
|
139
|
+
| { state: 'looking' }
|
|
140
|
+
| { state: 'found'; ids: GitHubIds }
|
|
141
|
+
| { state: 'missing' | 'failed'; message: string };
|
|
142
|
+
|
|
143
|
+
/** The lookups a page made, by `lookupKey`: a Map, since `constructor` is an owner's name, not a lookup made. */
|
|
144
|
+
export type GitHubLookups = ReadonlyMap<string, GitHubLookup>;
|
|
145
|
+
|
|
146
|
+
/** What the page knows of the name the form names: nothing yet, or nothing to ask while it reads as no name. */
|
|
147
|
+
export function lookupOf(known: GitHubLookups, target: { kind: 'repository' | 'owner'; name: string }): GitHubLookup | null {
|
|
148
|
+
return lookupable(target) ? (known.get(lookupKey(target.name)) ?? null) : null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The lookups with one more answer. IDs found always stand. Anything else
|
|
153
|
+
* replaces only the lookup under way for that name: a failure arriving after
|
|
154
|
+
* the name was found otherwise, as a repository's owner, changes nothing.
|
|
155
|
+
*/
|
|
156
|
+
export function answered(known: GitHubLookups, name: string, answer: GitHubLookup): GitHubLookups {
|
|
157
|
+
const key = lookupKey(name);
|
|
158
|
+
if (answer.state !== 'found' && answer.state !== 'looking' && known.get(key)?.state !== 'looking') return known;
|
|
159
|
+
return new Map(known).set(key, answer);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A lookup that failed, as the dialog says it. */
|
|
163
|
+
export function lookupFailure(name: string, failure: unknown): GitHubLookup {
|
|
164
|
+
if (failure instanceof CoffreError && failure.status === 404) {
|
|
165
|
+
// With the deployment's GitHub App, the server says where to install it.
|
|
166
|
+
return { state: 'missing', message: failure.reason === 'not_installed' ? failure.message : `GitHub shows nothing public at ${name}.` };
|
|
167
|
+
}
|
|
168
|
+
if (failure instanceof CoffreError && failure.status === 429) {
|
|
169
|
+
return { state: 'failed', message: "GitHub's hourly limit on lookups without signing in is spent. Enter the IDs, or try again later." };
|
|
170
|
+
}
|
|
171
|
+
return { state: 'failed', message: failure instanceof Error ? failure.message : 'GitHub could not be asked.' };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The binding the form describes, or why it does not describe one yet. The
|
|
176
|
+
* server checks the rest. A GitHub binding takes its IDs, and its
|
|
177
|
+
* repository's name as GitHub spells it, from `found`, unless typed in.
|
|
178
|
+
*/
|
|
179
|
+
export function bindingOf(form: Form, found: GitHubIds | null = null): { profile: BindingPlan['profile']; issuer: string | null; claims: BindingClaims } {
|
|
84
180
|
const needed = (value: string, what: string) => {
|
|
85
181
|
if (value.trim() === '') throw new Error(`${what} is needed`);
|
|
86
182
|
return value.trim();
|
|
@@ -90,23 +186,38 @@ export function bindingOf(form: Form): { profile: BindingPlan['profile']; issuer
|
|
|
90
186
|
return values;
|
|
91
187
|
};
|
|
92
188
|
if (form.platform === 'github') {
|
|
189
|
+
const target = githubTarget(form);
|
|
190
|
+
const what = target.kind === 'owner' ? 'The organization' : 'The repository';
|
|
191
|
+
needed(target.name, what);
|
|
192
|
+
// Typed in, or found under the name now in the field: never IDs found for a name since changed.
|
|
193
|
+
const ids: GitHubIds | null = form.typedIds
|
|
194
|
+
? {
|
|
195
|
+
github: target.name,
|
|
196
|
+
...(target.kind === 'repository' ? { repositoryId: needed(form.repositoryId, "The repository's ID") } : {}),
|
|
197
|
+
ownerId: needed(form.ownerId, "The owner's ID"),
|
|
198
|
+
}
|
|
199
|
+
: found !== null && lookupKey(found.github) === lookupKey(target.name) ? found : null;
|
|
200
|
+
if (ids === null) throw new Error(`${what}'s IDs are needed: wait for GitHub to find ${target.name}, or enter them`);
|
|
93
201
|
const ref = fullRef(form.refKind, needed(form.refName, form.refKind === 'branch' ? 'The branch' : 'The tag'));
|
|
202
|
+
const environment = form.environment.trim() === '' ? undefined : form.environment.trim();
|
|
203
|
+
const events = some(form.events, 'event');
|
|
94
204
|
if (form.reusable) {
|
|
95
205
|
const called = needed(form.called, 'The called workflow');
|
|
96
206
|
const sha = needed(form.sha, "The called workflow's commit");
|
|
97
|
-
|
|
98
|
-
const caller = form.workflow.trim() === '' ? undefined : { repository:
|
|
99
|
-
const repositoryId =
|
|
100
|
-
return { ...githubReusable({ repositoryId, ownerId, ref, events
|
|
207
|
+
if (form.anyRepository) return { ...githubReusable({ repositoryId: null, ownerId: ids.ownerId, ref, events, called, sha, environment }), issuer: null };
|
|
208
|
+
const caller = form.workflow.trim() === '' ? undefined : { repository: ids.github, workflow: form.workflow.trim() };
|
|
209
|
+
const repositoryId = needed(ids.repositoryId ?? '', "The repository's ID");
|
|
210
|
+
return { ...githubReusable({ repositoryId, ownerId: ids.ownerId, ref, events, called, sha, caller, environment }), issuer: null };
|
|
101
211
|
}
|
|
102
212
|
return {
|
|
103
213
|
...githubWorkflow({
|
|
104
|
-
repository:
|
|
105
|
-
repositoryId: needed(
|
|
106
|
-
ownerId:
|
|
214
|
+
repository: ids.github,
|
|
215
|
+
repositoryId: needed(ids.repositoryId ?? '', "The repository's ID"),
|
|
216
|
+
ownerId: ids.ownerId,
|
|
107
217
|
workflow: needed(form.workflow, 'The workflow file'),
|
|
108
218
|
ref,
|
|
109
|
-
events
|
|
219
|
+
events,
|
|
220
|
+
environment,
|
|
110
221
|
}),
|
|
111
222
|
issuer: null,
|
|
112
223
|
};
|
package/src/lib/capabilities.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { administers, makesProjects,
|
|
1
|
+
import { administers, makesProjects, ownsInstance } from '@coffre/core/access';
|
|
2
2
|
|
|
3
3
|
import type { Me, Permission, ProjectSummary } from '../shared/models';
|
|
4
4
|
|
|
@@ -10,14 +10,19 @@ import type { Me, Permission, ProjectSummary } from '../shared/models';
|
|
|
10
10
|
* live outside one resource page.
|
|
11
11
|
*/
|
|
12
12
|
export type UiCapabilities = {
|
|
13
|
-
/** Admins and owners, scoped or not
|
|
13
|
+
/** Admins and owners, scoped or not: the Users and Service accounts pages. */
|
|
14
14
|
canManageGrants: boolean;
|
|
15
15
|
/**
|
|
16
|
-
* Admins and owners whose scope narrows nothing
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Admins and owners whose scope narrows nothing: adding and removing
|
|
17
|
+
* people and service accounts, instance roles, tokens and trust bindings,
|
|
18
|
+
* offboarding reports, the instance's keys.
|
|
19
19
|
*/
|
|
20
20
|
runsInstance: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Owners whose scope narrows nothing: they alone make someone an Owner,
|
|
23
|
+
* and change or remove one, their own role included.
|
|
24
|
+
*/
|
|
25
|
+
ownsInstance: boolean;
|
|
21
26
|
/**
|
|
22
27
|
* Who sets up service accounts: those who run the instance, and a person
|
|
23
28
|
* who holds access somewhere the instance's setting takes in. The Service
|
|
@@ -31,6 +36,7 @@ export type UiCapabilities = {
|
|
|
31
36
|
const NONE: UiCapabilities = {
|
|
32
37
|
canManageGrants: false,
|
|
33
38
|
runsInstance: false,
|
|
39
|
+
ownsInstance: false,
|
|
34
40
|
setsUpServices: false,
|
|
35
41
|
canReadAudit: false,
|
|
36
42
|
canCreateProject: false,
|
|
@@ -42,20 +48,20 @@ export function deriveUiCapabilities(
|
|
|
42
48
|
): UiCapabilities {
|
|
43
49
|
if (me === null) return NONE;
|
|
44
50
|
|
|
45
|
-
const
|
|
46
|
-
const role: InstanceRole = me.instanceRole === 'root-admin' ? 'owner' : me.instanceRole;
|
|
51
|
+
const role = me.instanceRole;
|
|
47
52
|
|
|
48
53
|
return {
|
|
49
54
|
// Users and Service accounts list the instance's directory, for those
|
|
50
55
|
// who manage access across projects. Project access managers keep their
|
|
51
56
|
// grant controls on each project page.
|
|
52
|
-
canManageGrants:
|
|
57
|
+
canManageGrants: administers(role),
|
|
53
58
|
runsInstance: me.runsInstance,
|
|
59
|
+
ownsInstance: ownsInstance({ role, scope: me.scope }),
|
|
54
60
|
setsUpServices: me.setsUpServices,
|
|
55
61
|
canReadAudit: me.canReadAudit,
|
|
56
62
|
// A new project is one no `only` list names: as the server decides,
|
|
57
63
|
// from the role and the scope, projects by slug.
|
|
58
|
-
canCreateProject: makesProjects({
|
|
64
|
+
canCreateProject: makesProjects({ role, scope: me.scope, grants: [] }),
|
|
59
65
|
};
|
|
60
66
|
}
|
|
61
67
|
|