@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
package/src/lib/changes.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { failureMessage, memberRef, Refusal } from './coffre.ts';
|
|
|
6
6
|
import { projectAccessLabel } from './project-access.ts';
|
|
7
7
|
import type { Change, ListShape, Target, Words } from './optimistic.ts';
|
|
8
8
|
import { affects, keys } from './queries.ts';
|
|
9
|
-
import { applySecretEditBatch, type SecretChange, type SecretDraft, type SecretEditBatchResult } from './secret-edit-batch.ts';
|
|
9
|
+
import { applySecretEditBatch, companionsOf, type SecretChange, type SecretDraft, type SecretEditBatchResult } from './secret-edit-batch.ts';
|
|
10
10
|
import type { DirectoryPrincipal, GrantRow, ProjectSummary } from '../shared/models.ts';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -65,6 +65,8 @@ export type GrantVars = {
|
|
|
65
65
|
roleName: string;
|
|
66
66
|
environmentSlug: string | null;
|
|
67
67
|
expiresAt: string | null;
|
|
68
|
+
/** A new service account, which the grant makes in the same call: refused, neither is made. */
|
|
69
|
+
admit?: boolean;
|
|
68
70
|
};
|
|
69
71
|
|
|
70
72
|
/**
|
|
@@ -94,14 +96,17 @@ export function grantAccess(client: CoffreClient, project: string): Change<Grant
|
|
|
94
96
|
? grants.map((grant) => (grantId(grant) === id ? { ...row, id: grant.id } : grant))
|
|
95
97
|
: [...grants, row];
|
|
96
98
|
},
|
|
97
|
-
affects: (vars) =>
|
|
99
|
+
affects: (vars) => [
|
|
100
|
+
...affects.access(project, memberRef(vars.principalType, vars.principalId)),
|
|
101
|
+
...(vars.admit === true ? affects.admission() : []),
|
|
102
|
+
],
|
|
98
103
|
run: async (vars) => {
|
|
99
104
|
const place = grantPlace(project, vars.environmentSlug);
|
|
100
105
|
const role = vars.role as Role;
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
return { existed: changes[place] === 'unchanged' };
|
|
106
|
+
const member = memberRef(vars.principalType, vars.principalId);
|
|
107
|
+
const access = { [place]: vars.expiresAt === null ? role : { role, until: vars.expiresAt } };
|
|
108
|
+
const { changes } = vars.admit === true ? await client.members.add(member, { access }) : await client.access.set(member, access);
|
|
109
|
+
return { existed: changes?.[place] === 'unchanged' };
|
|
105
110
|
},
|
|
106
111
|
};
|
|
107
112
|
}
|
|
@@ -154,7 +159,6 @@ export function invite(client: CoffreClient): Change<Directory, DirectoryPrincip
|
|
|
154
159
|
principalId: vars.principalId,
|
|
155
160
|
instanceRole: vars.principalType === 'user' ? vars.role : 'member',
|
|
156
161
|
scope: vars.principalType === 'user' ? vars.scope : EVERYWHERE,
|
|
157
|
-
isRootAdmin: false,
|
|
158
162
|
},
|
|
159
163
|
],
|
|
160
164
|
affects: () => affects.admission(),
|
|
@@ -472,6 +476,8 @@ export function saveSecrets(
|
|
|
472
476
|
const change = vars.changes[entry.key];
|
|
473
477
|
return change === undefined ? [] : [{ entry, change }];
|
|
474
478
|
});
|
|
479
|
+
// A key pair's public key lands as a new row would, beside its private key.
|
|
480
|
+
const written = (vars: SaveSecretsVars) => [...vars.drafts, ...companionsOf(vars.active, vars.drafts, vars.changes)];
|
|
475
481
|
return {
|
|
476
482
|
list: secretsList(place),
|
|
477
483
|
label: (vars) => {
|
|
@@ -479,7 +485,7 @@ export function saveSecrets(
|
|
|
479
485
|
return named.length === 1 ? named[0]! : `${named.length} changes`;
|
|
480
486
|
},
|
|
481
487
|
targets: (vars) => [
|
|
482
|
-
...vars.
|
|
488
|
+
...written(vars).map((draft) => saving(draft.key.trim())),
|
|
483
489
|
...edits(vars).flatMap(({ entry, change }) =>
|
|
484
490
|
change.archived
|
|
485
491
|
? [removing(entry.key)]
|
|
@@ -508,7 +514,7 @@ export function saveSecrets(
|
|
|
508
514
|
const key = change.key.trim();
|
|
509
515
|
return change.value === null ? { ...entry, key } : bumped(entry, key);
|
|
510
516
|
});
|
|
511
|
-
for (const draft of vars
|
|
517
|
+
for (const draft of written(vars)) {
|
|
512
518
|
const key = draft.key.trim();
|
|
513
519
|
const existing = next.find((entry) => entry.key === key);
|
|
514
520
|
next = existing === undefined ? [bumped(undefined, key), ...next] : next.map((entry) => (entry.key === key ? bumped(entry, key) : entry));
|
package/src/lib/coffre.ts
CHANGED
|
@@ -31,6 +31,8 @@ export function failureMessage(error: unknown): string {
|
|
|
31
31
|
if (!(error instanceof CoffreError)) return 'The request could not be sent. Nothing was changed.';
|
|
32
32
|
if (error.status === 401) return 'Your session has ended. Sign in again, then retry.';
|
|
33
33
|
if (error.code === 'cross_origin') return 'coffre refused a change that did not come from this page. Reload, then retry.';
|
|
34
|
+
// The vault's own rule, which the app could not foresee (one removed by someone else, say), in its words.
|
|
35
|
+
if (error.code === 'vault_refused' && error.reason === 'not_allowed') return error.message.replace(/^the vault refused: /, '');
|
|
34
36
|
if (error.status === 403) {
|
|
35
37
|
return 'You hold no grant that covers this. Someone with grant.manage on the project can add one.';
|
|
36
38
|
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values the browser makes for a secret: random strings, AES keys and EC key
|
|
3
|
+
* pairs, from Web Crypto alone.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here talks to the server. A value made here goes into the row's
|
|
6
|
+
* field like a typed one, and leaves the page only when that row is saved.
|
|
7
|
+
*/
|
|
8
|
+
import { secretKeyProblem } from './validation.ts';
|
|
9
|
+
|
|
10
|
+
export type Encoding = 'base62' | 'hex' | 'base64' | 'base64url';
|
|
11
|
+
export type AesSize = 128 | 256;
|
|
12
|
+
export type Curve = 'P-256' | 'P-384' | 'P-521';
|
|
13
|
+
export type PairAlgorithm = 'ECDSA' | 'ECDH';
|
|
14
|
+
|
|
15
|
+
export type Recipe =
|
|
16
|
+
| { kind: 'random'; encoding: Encoding; bytes: number }
|
|
17
|
+
| { kind: 'aes'; size: AesSize }
|
|
18
|
+
| { kind: 'pair'; algorithm: PairAlgorithm; curve: Curve };
|
|
19
|
+
|
|
20
|
+
/** A value for the row, and for a key pair the public key, which takes a row of its own. */
|
|
21
|
+
export type Generated = { value: string; publicKey?: string };
|
|
22
|
+
|
|
23
|
+
export const MIN_BYTES = 1;
|
|
24
|
+
export const MAX_BYTES = 256;
|
|
25
|
+
export const DEFAULT_RECIPE: Recipe = { kind: 'random', encoding: 'base62', bytes: 32 };
|
|
26
|
+
|
|
27
|
+
export const ENCODINGS: { id: Encoding; name: string }[] = [
|
|
28
|
+
{ id: 'base62', name: 'Letters and digits' },
|
|
29
|
+
{ id: 'hex', name: 'Hex' },
|
|
30
|
+
{ id: 'base64', name: 'Base64' },
|
|
31
|
+
{ id: 'base64url', name: 'Base64 URL' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** Strongest first, as a new key should be. */
|
|
35
|
+
export const PAIRS: { algorithm: PairAlgorithm; curve: Curve }[] = [
|
|
36
|
+
{ algorithm: 'ECDSA', curve: 'P-521' },
|
|
37
|
+
{ algorithm: 'ECDSA', curve: 'P-384' },
|
|
38
|
+
{ algorithm: 'ECDSA', curve: 'P-256' },
|
|
39
|
+
{ algorithm: 'ECDH', curve: 'P-521' },
|
|
40
|
+
{ algorithm: 'ECDH', curve: 'P-384' },
|
|
41
|
+
{ algorithm: 'ECDH', curve: 'P-256' },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const BASE62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
45
|
+
/**
|
|
46
|
+
* The largest multiple of 62 a byte reaches: 248. A byte below it is taken
|
|
47
|
+
* modulo 62, and each of the 62 characters has four bytes that make it. The
|
|
48
|
+
* eight bytes from 248 up are thrown away, as taking them would make the
|
|
49
|
+
* first eight characters a little likelier than the rest.
|
|
50
|
+
*/
|
|
51
|
+
const BASE62_LIMIT = 256 - (256 % 62);
|
|
52
|
+
|
|
53
|
+
type RandomBytes = (bytes: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
|
|
54
|
+
const randomBytes: RandomBytes = (bytes) => crypto.getRandomValues(bytes);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* How many characters carry `bytes` of entropy. Hex and base64 encode the
|
|
58
|
+
* bytes themselves; base62 draws whole characters, each worth log2(62) bits,
|
|
59
|
+
* so it takes as many as reach the same number of bits: 43 for 32 bytes.
|
|
60
|
+
* Base64 pads to a multiple of four; base64 URL leaves the padding off.
|
|
61
|
+
*/
|
|
62
|
+
export function encodedLength(encoding: Encoding, bytes: number): number {
|
|
63
|
+
switch (encoding) {
|
|
64
|
+
case 'hex':
|
|
65
|
+
return bytes * 2;
|
|
66
|
+
case 'base64':
|
|
67
|
+
return Math.ceil(bytes / 3) * 4;
|
|
68
|
+
case 'base64url':
|
|
69
|
+
return Math.ceil((bytes * 8) / 6);
|
|
70
|
+
case 'base62':
|
|
71
|
+
return Math.ceil((bytes * 8) / Math.log2(62));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `length` characters of base62, each drawn uniformly by rejecting the bytes 248 to 255. */
|
|
76
|
+
export function base62(length: number, random: RandomBytes = randomBytes): string {
|
|
77
|
+
let out = '';
|
|
78
|
+
while (out.length < length) {
|
|
79
|
+
// About 3% of bytes are rejected, so a few spare bytes almost always finish it in one draw.
|
|
80
|
+
for (const byte of random(new Uint8Array(length - out.length + 8))) {
|
|
81
|
+
if (byte >= BASE62_LIMIT) continue;
|
|
82
|
+
out += BASE62[byte % 62];
|
|
83
|
+
if (out.length === length) break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function randomValue(encoding: Encoding, bytes: number, random: RandomBytes = randomBytes): string {
|
|
90
|
+
if (encoding === 'base62') return base62(encodedLength('base62', bytes), random);
|
|
91
|
+
const drawn = random(new Uint8Array(bytes));
|
|
92
|
+
if (encoding === 'hex') return [...drawn].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
93
|
+
const base64 = toBase64(drawn);
|
|
94
|
+
return encoding === 'base64'
|
|
95
|
+
? base64
|
|
96
|
+
: base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function generate(recipe: Recipe): Promise<Generated> {
|
|
100
|
+
switch (recipe.kind) {
|
|
101
|
+
case 'random':
|
|
102
|
+
return { value: randomValue(recipe.encoding, recipe.bytes) };
|
|
103
|
+
case 'aes': {
|
|
104
|
+
const key = await subtle().generateKey({ name: 'AES-GCM', length: recipe.size }, true, [
|
|
105
|
+
'encrypt',
|
|
106
|
+
'decrypt',
|
|
107
|
+
]);
|
|
108
|
+
return { value: toBase64(await subtle().exportKey('raw', key)) };
|
|
109
|
+
}
|
|
110
|
+
case 'pair': {
|
|
111
|
+
const usages: KeyUsage[] = recipe.algorithm === 'ECDSA' ? ['sign', 'verify'] : ['deriveBits'];
|
|
112
|
+
const pair = await subtle().generateKey(
|
|
113
|
+
{ name: recipe.algorithm, namedCurve: recipe.curve },
|
|
114
|
+
true,
|
|
115
|
+
usages,
|
|
116
|
+
);
|
|
117
|
+
return {
|
|
118
|
+
value: toBase64(await subtle().exportKey('pkcs8', pair.privateKey)),
|
|
119
|
+
publicKey: toBase64(await subtle().exportKey('spki', pair.publicKey)),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The name a key pair's public key gets beside its private key's:
|
|
127
|
+
* `JWT_PRIVATE_KEY` gives `JWT_PUBLIC_KEY`, any other name gains `_PUBLIC`.
|
|
128
|
+
*/
|
|
129
|
+
export function publicKeyName(privateName: string): string {
|
|
130
|
+
const name = privateName.trim();
|
|
131
|
+
if (name === '') return '';
|
|
132
|
+
if (/PRIVATE/.test(name)) return name.replace(/PRIVATE/g, 'PUBLIC');
|
|
133
|
+
if (/private/.test(name)) return name.replace(/private/g, 'public');
|
|
134
|
+
return `${name}_PUBLIC`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** What stops a key pair's two names from being saved, if anything. */
|
|
138
|
+
export function pairNameProblem(privateName: string, publicName: string): string | null {
|
|
139
|
+
const names = [privateName.trim(), publicName.trim()];
|
|
140
|
+
if (names.includes('')) return 'Give each key a name.';
|
|
141
|
+
for (const name of names) {
|
|
142
|
+
const problem = secretKeyProblem(name);
|
|
143
|
+
if (problem !== null) return `${name}: ${problem}`;
|
|
144
|
+
}
|
|
145
|
+
return names[0] === names[1] ? 'The two keys need different names.' : null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Web Crypto's keys need a secure context: HTTPS, or the machine's own address. */
|
|
149
|
+
function subtle(): SubtleCrypto {
|
|
150
|
+
if (globalThis.crypto?.subtle === undefined) {
|
|
151
|
+
throw new Error('This page is not served over HTTPS, so the browser makes no keys here.');
|
|
152
|
+
}
|
|
153
|
+
return globalThis.crypto.subtle;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function toBase64(bytes: ArrayBuffer | Uint8Array): string {
|
|
157
|
+
let binary = '';
|
|
158
|
+
for (const byte of new Uint8Array(bytes)) binary += String.fromCharCode(byte);
|
|
159
|
+
return btoa(binary);
|
|
160
|
+
}
|
package/src/lib/queries.ts
CHANGED
|
@@ -55,6 +55,7 @@ export const keys = {
|
|
|
55
55
|
memberAccess: (member: string) => ['member-access', member],
|
|
56
56
|
credentials: (member: string) => ['credentials', member],
|
|
57
57
|
bindings: (member: string) => ['bindings', member],
|
|
58
|
+
githubRepositories: ['github-repositories'],
|
|
58
59
|
identities: ['identities'],
|
|
59
60
|
sessions: ['sessions'],
|
|
60
61
|
apps: ['apps'],
|
|
@@ -66,7 +67,7 @@ export const keys = {
|
|
|
66
67
|
/** Members' grants, as rows, and a row for each one whose instance role reaches the place listed. */
|
|
67
68
|
function grantRows(members: Member[]): GrantRow[] {
|
|
68
69
|
return members.flatMap((member): GrantRow[] => [
|
|
69
|
-
...(member.reachesByRole
|
|
70
|
+
...(member.reachesByRole
|
|
70
71
|
? [{
|
|
71
72
|
id: `${member.member}/instance-role`,
|
|
72
73
|
principalType: member.principalType,
|
|
@@ -97,12 +98,11 @@ function listDirectory(client: CoffreClient) {
|
|
|
97
98
|
return uiResult(async () => {
|
|
98
99
|
const { members, removed } = await client.members.list();
|
|
99
100
|
const principals: DirectoryPrincipal[] = members.map(
|
|
100
|
-
({ principalType, principalId, instanceRole, scope,
|
|
101
|
+
({ principalType, principalId, instanceRole, scope, tampered, managed, grants }) => ({
|
|
101
102
|
principalType,
|
|
102
103
|
principalId,
|
|
103
104
|
instanceRole,
|
|
104
105
|
scope,
|
|
105
|
-
isRootAdmin,
|
|
106
106
|
tampered,
|
|
107
107
|
managed,
|
|
108
108
|
grants: grants.map(({ project, environment }) => ({ project, environment })),
|
|
@@ -143,6 +143,19 @@ export const queries = {
|
|
|
143
143
|
projects: (client: CoffreClient) =>
|
|
144
144
|
queryOptions({ queryKey: keys.projects, queryFn: () => readProjects(client) }),
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* The repositories the deployment's GitHub App is installed on, for the
|
|
148
|
+
* Trust dialog's picker; `{ app: null }` without one. Each listing asks
|
|
149
|
+
* GitHub, so it is kept a minute, and not asked again on focus.
|
|
150
|
+
*/
|
|
151
|
+
githubRepositories: (client: CoffreClient) =>
|
|
152
|
+
queryOptions({
|
|
153
|
+
queryKey: keys.githubRepositories,
|
|
154
|
+
queryFn: () => client.bindings.repositories(),
|
|
155
|
+
staleTime: 60_000,
|
|
156
|
+
refetchOnWindowFocus: false,
|
|
157
|
+
}),
|
|
158
|
+
|
|
146
159
|
/** Who holds what in a project, for those who manage its access. */
|
|
147
160
|
grants: (client: CoffreClient, project: string) =>
|
|
148
161
|
queryOptions({
|
|
@@ -156,7 +169,7 @@ export const queries = {
|
|
|
156
169
|
queryFn: () => uiResult(() => client.secrets.list(`${place.project}/${place.environment}`)),
|
|
157
170
|
}),
|
|
158
171
|
|
|
159
|
-
/** What an environment lacks of its siblings' keys,
|
|
172
|
+
/** What an environment lacks of its siblings' keys, read or not, and what its team dismissed. */
|
|
160
173
|
missing: (client: CoffreClient, place: Place) =>
|
|
161
174
|
queryOptions({
|
|
162
175
|
queryKey: keys.missing(place),
|
|
@@ -311,7 +324,7 @@ export const queries = {
|
|
|
311
324
|
/**
|
|
312
325
|
* Whether the log holds, or why that is not known. Verifying is for those
|
|
313
326
|
* who read the whole log (an Auditor, Admin or Owner whose scope narrows
|
|
314
|
-
* nothing
|
|
327
|
+
* nothing): anyone else reads their projects' part of it, and a part cannot be
|
|
315
328
|
* checked as a chain, so for them it is a fact about the page, not a fault.
|
|
316
329
|
*/
|
|
317
330
|
async function verifyChain(client: CoffreClient) {
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A second secret a row writes with its own value, in the same patch: a
|
|
3
|
+
* generated key pair's public key, beside its private key. It is part of
|
|
4
|
+
* the row's edit, so saving, undoing or retrying the row takes both.
|
|
5
|
+
*/
|
|
6
|
+
export type Companion = { key: string; value: string };
|
|
7
|
+
|
|
8
|
+
export type SecretDraft = { id: number; key: string; value: string; companion?: Companion };
|
|
2
9
|
|
|
3
10
|
export type SecretChange = {
|
|
4
11
|
key: string;
|
|
5
12
|
value: string | null;
|
|
6
13
|
archived: boolean;
|
|
14
|
+
/** Only beside a new value. */
|
|
15
|
+
companion?: Companion;
|
|
7
16
|
};
|
|
8
17
|
|
|
9
18
|
type ActiveSecret = { key: string };
|
|
@@ -33,6 +42,27 @@ export type SecretEditBatchResult = {
|
|
|
33
42
|
error: unknown | null;
|
|
34
43
|
};
|
|
35
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The companions a save writes: those of new rows, and of value edits to keys
|
|
47
|
+
* still listed. An edit whose key went from the list (renamed or archived
|
|
48
|
+
* elsewhere, then refreshed) writes nothing, its companion included.
|
|
49
|
+
*/
|
|
50
|
+
export function companionsOf(
|
|
51
|
+
active: readonly ActiveSecret[],
|
|
52
|
+
drafts: readonly SecretDraft[],
|
|
53
|
+
changes: Readonly<Record<string, SecretChange>>,
|
|
54
|
+
): Companion[] {
|
|
55
|
+
return [
|
|
56
|
+
...drafts.flatMap((draft) => (draft.companion === undefined ? [] : [draft.companion])),
|
|
57
|
+
...active.flatMap((entry) => {
|
|
58
|
+
const change = secretChangeFor(changes, entry.key);
|
|
59
|
+
return change === undefined || change.archived || change.value === null || change.companion === undefined
|
|
60
|
+
? []
|
|
61
|
+
: [change.companion];
|
|
62
|
+
}),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
36
66
|
/** Return true when one save would give two pending edits the same target. */
|
|
37
67
|
export function hasSecretEditConflict(
|
|
38
68
|
active: readonly ActiveSecret[],
|
|
@@ -44,7 +74,8 @@ export function hasSecretEditConflict(
|
|
|
44
74
|
.map((entry) => secretChangeFor(changes, entry.key)?.key.trim() ?? entry.key);
|
|
45
75
|
if (new Set(finalActiveKeys).size !== finalActiveKeys.length) return true;
|
|
46
76
|
|
|
47
|
-
|
|
77
|
+
// A companion writes its key as a new row does.
|
|
78
|
+
const draftKeys = [...drafts, ...companionsOf(active, drafts, changes)].map((draft) => draft.key.trim());
|
|
48
79
|
if (new Set(draftKeys).size !== draftKeys.length) return true;
|
|
49
80
|
|
|
50
81
|
const valueEditTargets = new Set(
|
|
@@ -106,11 +137,11 @@ export async function applySecretEditBatch({
|
|
|
106
137
|
await operations.rename(sourceKey, key);
|
|
107
138
|
delete remainingChanges[sourceKey];
|
|
108
139
|
applied += 1;
|
|
109
|
-
if (change.value !== null) remainingChanges[key] = {
|
|
140
|
+
if (change.value !== null) remainingChanges[key] = { ...change, key };
|
|
110
141
|
}
|
|
111
142
|
if (change.value !== null) patch[key] = change.value;
|
|
112
143
|
}
|
|
113
|
-
for (const draft of drafts) patch[draft.key.trim()] = draft.value;
|
|
144
|
+
for (const draft of [...drafts, ...companionsOf(active, drafts, changes)]) patch[draft.key.trim()] = draft.value;
|
|
114
145
|
|
|
115
146
|
const written = Object.keys(patch).length;
|
|
116
147
|
if (written > 0) await operations.write({ ...patch });
|
|
@@ -135,7 +166,9 @@ function planEdits(
|
|
|
135
166
|
.filter((entry) => secretChangeFor(changes, entry.key)?.archived)
|
|
136
167
|
.map((entry) => entry.key),
|
|
137
168
|
);
|
|
138
|
-
const restoredByDraft = drafts.find((draft) =>
|
|
169
|
+
const restoredByDraft = [...drafts, ...companionsOf(active, drafts, changes)].find((draft) =>
|
|
170
|
+
archivedKeys.has(draft.key.trim()),
|
|
171
|
+
);
|
|
139
172
|
if (restoredByDraft) {
|
|
140
173
|
return new Error(
|
|
141
174
|
`${restoredByDraft.key.trim()}: cannot archive and write the same key in one save`,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SecretKey } from '@coffre/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How an environment's table is ordered: by name, as listed, or by when
|
|
5
|
+
* each value was written, ascending the oldest first.
|
|
6
|
+
*/
|
|
7
|
+
export type Sort = { by: 'key' | 'written'; descending: boolean };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The keys in `sort`'s order, from the listing's, by name. By age, those
|
|
11
|
+
* without a value come last either way, and keys written together keep
|
|
12
|
+
* their names' order.
|
|
13
|
+
*/
|
|
14
|
+
export function sortKeys(entries: SecretKey[], sort: Sort): SecretKey[] {
|
|
15
|
+
if (sort.by === 'key') return sort.descending ? [...entries].reverse() : entries;
|
|
16
|
+
const direction = sort.descending ? -1 : 1;
|
|
17
|
+
return [...entries].sort((a, b) => {
|
|
18
|
+
if (a.updatedAt === b.updatedAt) return 0;
|
|
19
|
+
if (a.updatedAt === null) return 1;
|
|
20
|
+
if (b.updatedAt === null) return -1;
|
|
21
|
+
return a.updatedAt < b.updatedAt ? -direction : direction;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a key press comes from inside an open dialog, which a page-wide
|
|
3
|
+
* shortcut leaves alone: Cmd/Ctrl+Enter saves the secrets page, and from a
|
|
4
|
+
* dialog it would save behind it and close it, its work unfinished.
|
|
5
|
+
*/
|
|
6
|
+
export function inDialog(target: EventTarget | null): boolean {
|
|
7
|
+
const element = target as { closest?: (selector: string) => unknown } | null;
|
|
8
|
+
return typeof element?.closest === 'function' && element.closest('[role="dialog"], [role="alertdialog"]') !== null;
|
|
9
|
+
}
|
package/src/lib/signin-errors.ts
CHANGED
|
@@ -14,7 +14,7 @@ const MESSAGES: Record<string, string> = {
|
|
|
14
14
|
'That account has no verified email address, so coffre cannot match it to an invitation.',
|
|
15
15
|
wrong_domain: 'That account is outside the organization this instance belongs to.',
|
|
16
16
|
not_in_organization:
|
|
17
|
-
'That GitHub account is not a member of the required organization. If it is, grant coffre access to the organization when GitHub asks.',
|
|
17
|
+
'That GitHub account is not a member of the required organization, or coffre cannot see its members. If it is a member, grant coffre access to the organization when GitHub asks, or ask whoever runs coffre to install its GitHub App there with the Members organization permission, read-only, and to approve that permission on the installation.',
|
|
18
18
|
not_registered:
|
|
19
19
|
'Nobody has invited that account’s email address. Ask an owner to add you under Users, then sign in again.',
|
|
20
20
|
deactivated: 'Your access to this coffre was removed. Ask an owner if that is a mistake.',
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useCoffre } from './coffre';
|
|
3
|
+
import { answered, lookupable, lookupFailure, lookupKey, lookupOf, type GitHubIds, type GitHubLookup, type GitHubLookups } from './bindings';
|
|
4
|
+
|
|
5
|
+
/** How long a name rests in its field before it is looked up. */
|
|
6
|
+
export const LOOKUP_PAUSE_MS = 700;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A GitHub repository's or owner's IDs, looked up through coffre once its
|
|
10
|
+
* name has rested in the field for `LOOKUP_PAUSE_MS`, or at once when the
|
|
11
|
+
* field loses focus (`settle`). GitHub answers 60 lookups an hour to a
|
|
12
|
+
* server that does not sign in, shared by everyone a Workers deployment
|
|
13
|
+
* serves, so each name is asked once for as long as the page lives, whatever
|
|
14
|
+
* its case. Nothing public there is final; no answer, such as when the
|
|
15
|
+
* hour's are spent, is asked again on the next `settle`.
|
|
16
|
+
*
|
|
17
|
+
* `remember` records IDs known otherwise, so that they are never asked for:
|
|
18
|
+
* a repository's owner, once the repository is found, or what a picker
|
|
19
|
+
* knows of the repositories it lists.
|
|
20
|
+
*/
|
|
21
|
+
export function useGitHubLookup(target: { kind: 'repository' | 'owner'; name: string }): {
|
|
22
|
+
lookup: GitHubLookup | null;
|
|
23
|
+
settle: () => void;
|
|
24
|
+
remember: (...found: GitHubIds[]) => void;
|
|
25
|
+
} {
|
|
26
|
+
const coffre = useCoffre();
|
|
27
|
+
const [known, setKnown] = useState<GitHubLookups>(new Map());
|
|
28
|
+
const key = lookupKey(target.name);
|
|
29
|
+
const valid = lookupable(target);
|
|
30
|
+
const lookup = lookupOf(known, target);
|
|
31
|
+
|
|
32
|
+
const record = (name: string, answer: GitHubLookup) => setKnown((current) => answered(current, name, answer));
|
|
33
|
+
|
|
34
|
+
/** IDs found stand whatever was asked before (`answered`): all of them in one change, however many a picker lists. */
|
|
35
|
+
function remember(...found: GitHubIds[]) {
|
|
36
|
+
setKnown((current) => {
|
|
37
|
+
const next = new Map(current);
|
|
38
|
+
for (const ids of found) next.set(lookupKey(ids.github), { state: 'found', ids });
|
|
39
|
+
return next;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ask(name: string) {
|
|
44
|
+
record(name, { state: 'looking' });
|
|
45
|
+
coffre.bindings.lookup({ github: name }).then(
|
|
46
|
+
(ids) => {
|
|
47
|
+
if (!('github' in ids)) return;
|
|
48
|
+
remember(ids);
|
|
49
|
+
// The owner of a repository found is known too: no lookup when the binding turns to the whole organization.
|
|
50
|
+
if ('repositoryId' in ids) remember({ github: ids.github.split('/')[0]!, ownerId: ids.ownerId });
|
|
51
|
+
},
|
|
52
|
+
(failure: unknown) => record(name, lookupFailure(name, failure)),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!valid || lookup !== null) return;
|
|
58
|
+
const timer = setTimeout(() => ask(target.name), LOOKUP_PAUSE_MS);
|
|
59
|
+
return () => clearTimeout(timer);
|
|
60
|
+
// Once per name: `ask` and the name's spelling may change each render, and a lookup under way is not asked again.
|
|
61
|
+
}, [key, valid, lookup === null]);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
lookup,
|
|
65
|
+
settle: () => {
|
|
66
|
+
if (valid && (lookup === null || lookup.state === 'failed')) ask(target.name);
|
|
67
|
+
},
|
|
68
|
+
remember,
|
|
69
|
+
};
|
|
70
|
+
}
|
package/src/pages/account.tsx
CHANGED
|
@@ -86,14 +86,13 @@ export function AccountProfilePage() {
|
|
|
86
86
|
</Fact>
|
|
87
87
|
<Fact label="Kind">{principal.type === 'user' ? 'User' : 'Token'}</Fact>
|
|
88
88
|
{principal.type === 'user' && (
|
|
89
|
-
<Fact label="
|
|
89
|
+
<Fact label="Role">
|
|
90
90
|
<InstanceRole
|
|
91
91
|
principal={{
|
|
92
92
|
principalType: 'user',
|
|
93
93
|
principalId: principal.id,
|
|
94
94
|
instanceRole: instanceRole ?? 'member',
|
|
95
95
|
scope,
|
|
96
|
-
isRootAdmin: instanceRole === 'root-admin',
|
|
97
96
|
}}
|
|
98
97
|
/>
|
|
99
98
|
</Fact>
|
package/src/pages/audit.tsx
CHANGED
|
@@ -378,7 +378,7 @@ function ChainStatus({ chain, onRetry }: { chain: ChainResult | undefined; onRet
|
|
|
378
378
|
return (
|
|
379
379
|
<Toggletip
|
|
380
380
|
align="end"
|
|
381
|
-
label="Only
|
|
381
|
+
label="Only auditors, admins and owners of the whole instance can check the log: it takes every entry, and you see only your projects'."
|
|
382
382
|
>
|
|
383
383
|
<button type="button" className="chain-note">
|
|
384
384
|
<Info size={14} />
|