@coffre/ui 0.6.2 → 0.8.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/{audit-sentence-BVv_9_nq.js → audit-sentence-C_wMpAqr.js} +99 -26
- package/dist/chunks/audit-sentence-C_wMpAqr.js.map +1 -0
- package/dist/chunks/{connected-apps-rBF9XUob.js → connected-apps-Bn5rEoV2.js} +2 -2
- package/dist/chunks/{connected-apps-rBF9XUob.js.map → connected-apps-Bn5rEoV2.js.map} +1 -1
- package/dist/chunks/{delete-place-CkGezx5R.js → delete-place-CQCDHkne.js} +3 -3
- package/dist/chunks/{delete-place-CkGezx5R.js.map → delete-place-CQCDHkne.js.map} +1 -1
- package/dist/chunks/{directory-SRN01yP6.js → directory-BQNOdze_.js} +6 -5
- package/dist/chunks/{directory-SRN01yP6.js.map → directory-BQNOdze_.js.map} +1 -1
- package/dist/chunks/{grants-1E1vqkM0.js → grants-CJIBrkod.js} +3 -3
- package/dist/chunks/{grants-1E1vqkM0.js.map → grants-CJIBrkod.js.map} +1 -1
- package/dist/chunks/{offboarding-Bt7KSixm.js → offboarding-CrgwaetA.js} +3 -3
- package/dist/chunks/offboarding-CrgwaetA.js.map +1 -0
- package/dist/chunks/personal-tokens-B8rkT-DI.js +138 -0
- package/dist/chunks/personal-tokens-B8rkT-DI.js.map +1 -0
- package/dist/chunks/{principal-page-Cbx2l6XL.js → principal-page-Cv5PheS9.js} +25 -12
- package/dist/chunks/principal-page-Cv5PheS9.js.map +1 -0
- package/dist/chunks/{project-page-DKo2AFYg.js → project-page-BI--vjt3.js} +2 -2
- package/dist/chunks/{project-page-DKo2AFYg.js.map → project-page-BI--vjt3.js.map} +1 -1
- package/dist/chunks/{queries-BvSw1xBN.js → queries-epz4MIuW.js} +19 -5
- package/dist/chunks/queries-epz4MIuW.js.map +1 -0
- package/dist/chunks/{references-DCoSPtvw.js → references-DImfw0cz.js} +3 -3
- package/dist/chunks/{references-DCoSPtvw.js.map → references-DImfw0cz.js.map} +1 -1
- package/dist/chunks/{role-field-D98CvNEg.js → role-field-C1KhNaIR.js} +2 -2
- package/dist/chunks/{role-field-D98CvNEg.js.map → role-field-C1KhNaIR.js.map} +1 -1
- package/dist/chunks/{use-action-Bv7yQ0DW.js → use-action-BB-RcHo1.js} +2 -2
- package/dist/chunks/{use-action-Bv7yQ0DW.js.map → use-action-BB-RcHo1.js.map} +1 -1
- package/dist/chunks/{use-change-DIQTGXER.js → use-change-CQyDpCqw.js} +268 -17
- package/dist/chunks/use-change-CQyDpCqw.js.map +1 -0
- package/dist/chunks/{use-shell-DhFoHjDS.js → use-shell-C_NmvCt_.js} +2 -2
- package/dist/chunks/{use-shell-DhFoHjDS.js.map → use-shell-C_NmvCt_.js.map} +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/pages/account.d.ts +1 -1
- package/dist/pages/account.js +26 -9
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/audit.js +52 -32
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/environment.js +520 -192
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +1 -1
- package/dist/pages/project-access.js +8 -8
- package/dist/pages/project-access.js.map +1 -1
- package/dist/pages/project-environments.js +106 -19
- package/dist/pages/project-environments.js.map +1 -1
- package/dist/pages/project-settings.js +6 -6
- package/dist/pages/project.js +1 -1
- package/dist/pages/projects.js +4 -4
- package/dist/pages/service-account.js +278 -29
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +4 -4
- package/dist/pages/settings.js +4 -4
- package/dist/pages/unregistered.js +1 -1
- package/dist/pages/user.js +5 -5
- package/dist/pages/users.js +4 -4
- package/package.json +3 -3
- package/src/components/actions-log.tsx +2 -1
- package/src/components/directory.tsx +1 -0
- package/src/components/generate-value.tsx +15 -7
- package/src/components/offboarding.tsx +1 -1
- package/src/components/personal-tokens.tsx +131 -0
- package/src/components/principal-page.tsx +20 -3
- package/src/components/regenerate.tsx +72 -0
- package/src/components/service-tokens.tsx +3 -3
- package/src/components/trusted-workloads.tsx +177 -8
- package/src/lib/audit-sentences.ts +110 -12
- package/src/lib/bindings.ts +41 -3
- package/src/lib/changes.ts +155 -20
- package/src/lib/generate.ts +3 -146
- package/src/lib/queries.ts +15 -4
- package/src/lib/recipes.ts +63 -0
- package/src/lib/reveal.ts +7 -1
- package/src/lib/secret-edit-batch.ts +64 -5
- package/src/options.ts +5 -1
- package/src/pages/account.tsx +27 -5
- package/src/pages/audit.tsx +23 -7
- package/src/pages/environment.tsx +357 -39
- package/src/pages/project-access.tsx +1 -1
- package/src/pages/project-environments.tsx +85 -12
- package/src/parity.ts +19 -2
- package/src/styles/globals.css +56 -3
- package/dist/chunks/audit-sentence-BVv_9_nq.js.map +0 -1
- package/dist/chunks/offboarding-Bt7KSixm.js.map +0 -1
- package/dist/chunks/principal-page-Cbx2l6XL.js.map +0 -1
- package/dist/chunks/queries-BvSw1xBN.js.map +0 -1
- package/dist/chunks/use-change-DIQTGXER.js.map +0 -1
package/src/lib/generate.ts
CHANGED
|
@@ -1,139 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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.
|
|
2
|
+
* What the Generate dialog checks of the names it saves a key pair under.
|
|
3
|
+
* The values themselves, and their recipes, are `@coffre/core/recipe`'s,
|
|
4
|
+
* which the CLI makes them by too.
|
|
7
5
|
*/
|
|
8
6
|
import { secretKeyProblem } from './validation.ts';
|
|
9
7
|
|
|
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
8
|
/** What stops a key pair's two names from being saved, if anything. */
|
|
138
9
|
export function pairNameProblem(privateName: string, publicName: string): string | null {
|
|
139
10
|
const names = [privateName.trim(), publicName.trim()];
|
|
@@ -144,17 +15,3 @@ export function pairNameProblem(privateName: string, publicName: string): string
|
|
|
144
15
|
}
|
|
145
16
|
return names[0] === names[1] ? 'The two keys need different names.' : null;
|
|
146
17
|
}
|
|
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
|
@@ -51,6 +51,7 @@ export const keys = {
|
|
|
51
51
|
secrets: ({ project, environment }: Place) => ['secrets', project, environment],
|
|
52
52
|
references: (path: string) => ['references', path],
|
|
53
53
|
missing: ({ project, environment }: Place) => ['missing', project, environment],
|
|
54
|
+
personal: (project: string) => ['personal', project],
|
|
54
55
|
directory: ['directory'],
|
|
55
56
|
report: (member: string) => ['report', member],
|
|
56
57
|
memberAccess: (member: string) => ['member-access', member],
|
|
@@ -178,6 +179,13 @@ export const queries = {
|
|
|
178
179
|
queryFn: () => uiResult(() => client.environments.missing(`${place.project}/${place.environment}`)),
|
|
179
180
|
}),
|
|
180
181
|
|
|
182
|
+
/** A project's personal configs, for whoever manages its environments: whose, of what, and their key names. */
|
|
183
|
+
personal: (client: CoffreClient, project: string) =>
|
|
184
|
+
queryOptions({
|
|
185
|
+
queryKey: keys.personal(project),
|
|
186
|
+
queryFn: () => uiResult(() => client.environments.personal(project)),
|
|
187
|
+
}),
|
|
188
|
+
|
|
181
189
|
/** The live references into and out of a place, and who reads through them, for whoever manages its access. */
|
|
182
190
|
references: (client: CoffreClient, path: string) =>
|
|
183
191
|
queryOptions({
|
|
@@ -624,10 +632,13 @@ export function managedProjects(projects: ProjectSummary[]): ProjectSummary[] {
|
|
|
624
632
|
* change also lands in the audit log, which is always read fresh.
|
|
625
633
|
*/
|
|
626
634
|
export const affects = {
|
|
627
|
-
/**
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
635
|
+
/**
|
|
636
|
+
* A project or environment made, renamed or archived: the tree, where you
|
|
637
|
+
* hold access, and the personal configs listed of it, which go with it.
|
|
638
|
+
*/
|
|
639
|
+
places: (): QueryKey[] => [keys.projects, keys.me, ['personal']],
|
|
640
|
+
/** Secrets written, renamed, restored or archived: the environment, the counts, and the personal configs' key names. */
|
|
641
|
+
secrets: (place: Place): QueryKey[] => [keys.secrets(place), keys.projects, ['references'], ['missing'], ['personal']],
|
|
631
642
|
/**
|
|
632
643
|
* Someone's access in a project changed: its grants, their report, and, as
|
|
633
644
|
* it may be your own, what you can see.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { SecretKey } from '@coffre/client';
|
|
2
|
+
import type { Generation } from '@coffre/core/recipe';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A listed key's recipe, as far as the page may act on it: a key pair's
|
|
6
|
+
* only while the list holds both its halves, live, each saying the same of
|
|
7
|
+
* the pair. The server lists a pair by that rule; this holds the page to it
|
|
8
|
+
* between a change shown at once and the list read back, while a value
|
|
9
|
+
* typed over one half, or an archive, has not reached the other half yet.
|
|
10
|
+
*/
|
|
11
|
+
export function liveGeneration(entry: SecretKey, entries: readonly SecretKey[]): Generation | null {
|
|
12
|
+
const { generated } = entry;
|
|
13
|
+
if (generated === null || generated.pair === undefined) return generated;
|
|
14
|
+
const { pair, recipe } = generated;
|
|
15
|
+
const holds = (key: string) =>
|
|
16
|
+
entries.some(
|
|
17
|
+
(each) =>
|
|
18
|
+
each.key === key &&
|
|
19
|
+
!each.archived &&
|
|
20
|
+
each.generated?.recipe === recipe &&
|
|
21
|
+
each.generated.pair?.private === pair.private &&
|
|
22
|
+
each.generated.pair.public === pair.public,
|
|
23
|
+
);
|
|
24
|
+
return holds(pair.private) && holds(pair.public) ? generated : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The list after keys were renamed, `from` to `to`: each pair names its
|
|
29
|
+
* halves as they are now, in both halves, as the server lists them.
|
|
30
|
+
*/
|
|
31
|
+
export function renamePairs(entries: readonly SecretKey[], renames: ReadonlyMap<string, string>): SecretKey[] {
|
|
32
|
+
if (renames.size === 0) return [...entries];
|
|
33
|
+
const now = (key: string) => renames.get(key) ?? key;
|
|
34
|
+
return entries.map((entry) =>
|
|
35
|
+
entry.generated?.pair === undefined
|
|
36
|
+
? entry
|
|
37
|
+
: {
|
|
38
|
+
...entry,
|
|
39
|
+
generated: {
|
|
40
|
+
...entry.generated,
|
|
41
|
+
pair: { private: now(entry.generated.pair.private), public: now(entry.generated.pair.public) },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The keys regenerating a key writes: itself, or a key pair's two halves. */
|
|
48
|
+
export function regeneratedKeys(key: string, generated: Generation): string[] {
|
|
49
|
+
return generated.pair === undefined ? [key] : [generated.pair.private, generated.pair.public];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether a key's Regenerate waits: while the key, or either half of its
|
|
54
|
+
* pair, is busy, being edited or with a save on its way. A regenerate
|
|
55
|
+
* addresses keys by name, so one sent beside a rename of a half could land
|
|
56
|
+
* on either side of it: before, and the rename fails with the old name
|
|
57
|
+
* holding the old private key beside a new public key; after, and it
|
|
58
|
+
* writes the old name again. Regenerate's own save marks every key it
|
|
59
|
+
* writes busy (`regenerateSecret`), so neither half is edited meanwhile.
|
|
60
|
+
*/
|
|
61
|
+
export function regenerateWaits(key: string, generated: Generation, busy: (key: string) => boolean): boolean {
|
|
62
|
+
return [key, ...regeneratedKeys(key, generated)].some(busy);
|
|
63
|
+
}
|
package/src/lib/reveal.ts
CHANGED
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
export type Reveal = {
|
|
10
10
|
value: string;
|
|
11
11
|
version: number | null;
|
|
12
|
+
/**
|
|
13
|
+
* Where the value was held, when that can change under one version
|
|
14
|
+
* number: a fork's key reset to its parent's reads another secret's v1.
|
|
15
|
+
*/
|
|
16
|
+
from?: string;
|
|
12
17
|
/** When the read happened, in ms since the epoch; drives the auto-hide. */
|
|
13
18
|
at: number;
|
|
14
19
|
};
|
|
@@ -16,6 +21,7 @@ export type Reveal = {
|
|
|
16
21
|
export function revealIsCurrent(
|
|
17
22
|
reveal: Reveal | null,
|
|
18
23
|
currentVersion: number | null,
|
|
24
|
+
currentFrom?: string,
|
|
19
25
|
): reveal is Reveal {
|
|
20
|
-
return reveal !== null && reveal.version === currentVersion;
|
|
26
|
+
return reveal !== null && reveal.version === currentVersion && reveal.from === currentFrom;
|
|
21
27
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Generation } from '@coffre/core/recipe';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A second secret a row writes with its own value, in the same patch: a
|
|
3
5
|
* generated key pair's public key, beside its private key. It is part of
|
|
@@ -5,7 +7,14 @@
|
|
|
5
7
|
*/
|
|
6
8
|
export type Companion = { key: string; value: string };
|
|
7
9
|
|
|
8
|
-
export type SecretDraft = {
|
|
10
|
+
export type SecretDraft = {
|
|
11
|
+
id: number;
|
|
12
|
+
key: string;
|
|
13
|
+
value: string;
|
|
14
|
+
companion?: Companion;
|
|
15
|
+
/** The recipe a generated value was made by, saved with it; typing over the value drops it. */
|
|
16
|
+
recipe?: string;
|
|
17
|
+
};
|
|
9
18
|
|
|
10
19
|
export type SecretChange = {
|
|
11
20
|
key: string;
|
|
@@ -13,12 +22,62 @@ export type SecretChange = {
|
|
|
13
22
|
archived: boolean;
|
|
14
23
|
/** Only beside a new value. */
|
|
15
24
|
companion?: Companion;
|
|
25
|
+
/** Only beside a generated value. */
|
|
26
|
+
recipe?: string;
|
|
16
27
|
};
|
|
17
28
|
|
|
18
29
|
type ActiveSecret = { key: string };
|
|
19
30
|
|
|
20
|
-
/**
|
|
21
|
-
|
|
31
|
+
/**
|
|
32
|
+
* A merge patch: a string sets a key, adding it if it is new; a value with
|
|
33
|
+
* how it was generated sets it with its recipe; `null` archives it.
|
|
34
|
+
*/
|
|
35
|
+
export type SecretPatch = Record<string, string | { value: string; generated: Generation } | null>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* How a row's generated value was made, as its write says it: its recipe,
|
|
39
|
+
* and for a key pair the names both halves are saved under.
|
|
40
|
+
*/
|
|
41
|
+
function generationOf(key: string, edit: { recipe?: string; companion?: Companion }): Generation | undefined {
|
|
42
|
+
if (edit.recipe === undefined) return undefined;
|
|
43
|
+
return edit.companion === undefined
|
|
44
|
+
? { recipe: edit.recipe }
|
|
45
|
+
: { recipe: edit.recipe, pair: { private: key, public: edit.companion.key.trim() } };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What a row writes under each key: its value, and its companion's beside it. */
|
|
49
|
+
function rowPatch(key: string, value: string, edit: { recipe?: string; companion?: Companion }): SecretPatch {
|
|
50
|
+
const generated = generationOf(key, edit);
|
|
51
|
+
const entry = (each: string) => (generated === undefined ? each : { value: each, generated });
|
|
52
|
+
const patch: SecretPatch = Object.create(null);
|
|
53
|
+
patch[key] = entry(value);
|
|
54
|
+
if (edit.companion !== undefined) patch[edit.companion.key.trim()] = entry(edit.companion.value);
|
|
55
|
+
return patch;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The recipe each key a save writes will hold, by its name after the save:
|
|
60
|
+
* what the list shows of it until it is read back.
|
|
61
|
+
*/
|
|
62
|
+
export function generationsOf(
|
|
63
|
+
active: readonly ActiveSecret[],
|
|
64
|
+
drafts: readonly SecretDraft[],
|
|
65
|
+
changes: Readonly<Record<string, SecretChange>>,
|
|
66
|
+
): Map<string, Generation> {
|
|
67
|
+
const out = new Map<string, Generation>();
|
|
68
|
+
const add = (key: string, edit: { recipe?: string; companion?: Companion }) => {
|
|
69
|
+
const generated = generationOf(key, edit);
|
|
70
|
+
if (generated === undefined) return;
|
|
71
|
+
out.set(key, generated);
|
|
72
|
+
if (edit.companion !== undefined) out.set(edit.companion.key.trim(), generated);
|
|
73
|
+
};
|
|
74
|
+
for (const draft of drafts) add(draft.key.trim(), draft);
|
|
75
|
+
for (const entry of active) {
|
|
76
|
+
const change = secretChangeFor(changes, entry.key);
|
|
77
|
+
if (change !== undefined && !change.archived && change.value !== null) add(change.key.trim(), change);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
22
81
|
|
|
23
82
|
type SecretEditOperations = {
|
|
24
83
|
rename: (key: string, nextKey: string) => Promise<void>;
|
|
@@ -139,9 +198,9 @@ export async function applySecretEditBatch({
|
|
|
139
198
|
applied += 1;
|
|
140
199
|
if (change.value !== null) remainingChanges[key] = { ...change, key };
|
|
141
200
|
}
|
|
142
|
-
if (change.value !== null) patch
|
|
201
|
+
if (change.value !== null) Object.assign(patch, rowPatch(key, change.value, change));
|
|
143
202
|
}
|
|
144
|
-
for (const draft of
|
|
203
|
+
for (const draft of drafts) Object.assign(patch, rowPatch(draft.key.trim(), draft.value, draft));
|
|
145
204
|
|
|
146
205
|
const written = Object.keys(patch).length;
|
|
147
206
|
if (written > 0) await operations.write({ ...patch });
|
package/src/options.ts
CHANGED
|
@@ -323,7 +323,11 @@ export const accountSessions = {
|
|
|
323
323
|
loader: async ({ context }: Loader) => {
|
|
324
324
|
const { coffre, queryClient } = coffreOf(context);
|
|
325
325
|
if (!(await ownSignIn(context))) throw redirect({ to: '/account' });
|
|
326
|
-
await queryClient
|
|
326
|
+
const { principal } = await loadShell(queryClient, coffre);
|
|
327
|
+
await Promise.all([
|
|
328
|
+
queryClient.fetchQuery(queries.sessions(coffre)),
|
|
329
|
+
...(principal?.type === 'user' ? [queryClient.fetchQuery(queries.credentials(coffre, memberRef('user', principal.id), true))] : []),
|
|
330
|
+
]);
|
|
327
331
|
},
|
|
328
332
|
};
|
|
329
333
|
|
package/src/pages/account.tsx
CHANGED
|
@@ -12,13 +12,14 @@ import { ConfirmButton, CopyButton, EmptyState, ErrorLine, Notice, Timestamp } f
|
|
|
12
12
|
import { Link as LinkIcon, Monitor, ProviderMark, SignOut, Sun, Terminal, User, X } from '../components/icons';
|
|
13
13
|
import { signinErrorMessage } from '../lib/signin-errors';
|
|
14
14
|
import { useOneTime } from '../lib/one-time';
|
|
15
|
-
import { useCoffre } from '../lib/coffre';
|
|
15
|
+
import { memberRef, useCoffre } from '../lib/coffre';
|
|
16
16
|
import { useMounted } from '../lib/mounted';
|
|
17
|
-
import { disconnectApp, endSession, unlinkIdentity } from '../lib/changes';
|
|
17
|
+
import { disconnectApp, endSession, revokeCredential, unlinkIdentity } from '../lib/changes';
|
|
18
18
|
import { queries } from '../lib/queries';
|
|
19
19
|
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
20
20
|
import { RowFailure, RowPending, rowClass } from '../components/row-state';
|
|
21
21
|
import { ConnectedAppsCard } from '../components/connected-apps';
|
|
22
|
+
import { PersonalTokensCard } from '../components/personal-tokens';
|
|
22
23
|
import { pageRoute } from '../lib/page-route';
|
|
23
24
|
import type { accountProfile } from '../options';
|
|
24
25
|
|
|
@@ -107,12 +108,33 @@ export function AccountProfilePage() {
|
|
|
107
108
|
);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
/** Where you are signed in, browsers and command lines. */
|
|
111
|
+
/** Where you are signed in, browsers and command lines, and the personal tokens that act as you. */
|
|
111
112
|
export function AccountSessionsPage() {
|
|
112
|
-
const { auth } = useShell();
|
|
113
|
+
const { auth, principal } = useShell();
|
|
113
114
|
const { data: sessions } = useSuspenseQuery(queries.sessions(useCoffre()));
|
|
114
115
|
if (!sessions.ok) return <ErrorLine error={sessions.error} />;
|
|
115
|
-
return
|
|
116
|
+
return (
|
|
117
|
+
<>
|
|
118
|
+
<Sessions sessions={sessions.sessions} providers={auth.signin?.providers ?? []} />
|
|
119
|
+
{principal?.type === 'user' && <PersonalTokens email={principal.id} />}
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The personal tokens you made, for a script or an agent: each acts as you, within what it reaches, until it expires or you revoke it. */
|
|
125
|
+
function PersonalTokens({ email }: { email: string }) {
|
|
126
|
+
const client = useCoffre();
|
|
127
|
+
const member = memberRef('user', email);
|
|
128
|
+
const { data: tokens } = useSuspenseQuery(queries.credentials(client, member, true));
|
|
129
|
+
return (
|
|
130
|
+
<PersonalTokensCard
|
|
131
|
+
tokens={tokens === null ? [] : tokens.ok ? tokens.tokens : { error: tokens.error }}
|
|
132
|
+
change={revokeCredential(client, member)}
|
|
133
|
+
description="Tokens that act as you, for a script or an agent, within what each reaches and never beyond what you hold. Every entry one makes names it."
|
|
134
|
+
empty="Make one with the CLI, for an hour unless told:"
|
|
135
|
+
emptyActions={<CopyLine value="coffre tokens issue --label cursor-agent --scope <project>/<environment>=viewer --expires-in 4h" label="Copy the command" />}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
116
138
|
}
|
|
117
139
|
|
|
118
140
|
/** How to connect Claude, then the apps you connected. */
|
package/src/pages/audit.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
decidedBy,
|
|
9
9
|
describe,
|
|
10
10
|
lines,
|
|
11
|
+
perSecret,
|
|
11
12
|
runLabel,
|
|
12
13
|
who,
|
|
13
14
|
type Part,
|
|
@@ -182,7 +183,11 @@ export function AuditPage() {
|
|
|
182
183
|
type Entry = AuditEntryView;
|
|
183
184
|
type Filters = { decision?: 'deny'; actorId?: string };
|
|
184
185
|
|
|
185
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* One action: an entry, or a batch of them under one operation, which opens
|
|
188
|
+
* to each; a read of several secrets, logged as one entry, opens to each
|
|
189
|
+
* secret, under its entry's number.
|
|
190
|
+
*/
|
|
186
191
|
function Line({
|
|
187
192
|
batch,
|
|
188
193
|
filters,
|
|
@@ -199,13 +204,18 @@ function Line({
|
|
|
199
204
|
const lead = batch[0]!;
|
|
200
205
|
const sentence = describe(batch);
|
|
201
206
|
const seqs = batch.map((entry) => entry.seq);
|
|
202
|
-
const
|
|
207
|
+
const each = batch.flatMap(perSecret);
|
|
208
|
+
const grouped = each.length > 1;
|
|
209
|
+
const [unit, units] = each.length === batch.length ? ['entry', 'entries'] : ['secret', 'secrets'];
|
|
210
|
+
// A read of several breaks at its first secret's row.
|
|
211
|
+
const breakRow = each.findIndex((entry) => entry.seq === breakAt);
|
|
212
|
+
const [first, last] = [Math.min(...seqs), Math.max(...seqs)];
|
|
203
213
|
|
|
204
214
|
return (
|
|
205
215
|
<>
|
|
206
216
|
<Row
|
|
207
217
|
entry={lead}
|
|
208
|
-
seq={
|
|
218
|
+
seq={first === last ? String(first) : `${first}–${last}`}
|
|
209
219
|
parts={sentence.parts}
|
|
210
220
|
refused={sentence.refused}
|
|
211
221
|
decided={decidedBy(batch)}
|
|
@@ -219,7 +229,7 @@ function Line({
|
|
|
219
229
|
type="button"
|
|
220
230
|
className="batch-toggle"
|
|
221
231
|
aria-expanded={open}
|
|
222
|
-
aria-label={open ?
|
|
232
|
+
aria-label={open ? `Hide each ${unit}` : `Show each of ${each.length} ${units}`}
|
|
223
233
|
onClick={() => setOpen(!open)}
|
|
224
234
|
>
|
|
225
235
|
<ChevronRight size={14} />
|
|
@@ -229,11 +239,11 @@ function Line({
|
|
|
229
239
|
/>
|
|
230
240
|
{grouped &&
|
|
231
241
|
open &&
|
|
232
|
-
|
|
242
|
+
each.map((entry, i) => {
|
|
233
243
|
const one = describe([entry]);
|
|
234
244
|
return (
|
|
235
245
|
<Row
|
|
236
|
-
key={entry.seq}
|
|
246
|
+
key={`${entry.seq}:${i}`}
|
|
237
247
|
entry={entry}
|
|
238
248
|
seq={String(entry.seq)}
|
|
239
249
|
parts={one.parts}
|
|
@@ -241,7 +251,7 @@ function Line({
|
|
|
241
251
|
decided={decidedBy([entry])}
|
|
242
252
|
filters={filters}
|
|
243
253
|
detail={detail}
|
|
244
|
-
breaks={
|
|
254
|
+
breaks={i === breakRow}
|
|
245
255
|
marked={false}
|
|
246
256
|
child
|
|
247
257
|
/>
|
|
@@ -314,6 +324,12 @@ function Row({
|
|
|
314
324
|
{runLabel(entry.run)}
|
|
315
325
|
</small>
|
|
316
326
|
)}
|
|
327
|
+
{entry.token != null && (
|
|
328
|
+
// The personal token the person made the request with, by the label it was made with.
|
|
329
|
+
<small className="actor-run" title={`Personal token ${entry.token.id}`}>
|
|
330
|
+
via token “{entry.token.label}”
|
|
331
|
+
</small>
|
|
332
|
+
)}
|
|
317
333
|
</td>
|
|
318
334
|
<td className="cell-sentence" data-label="What they did">
|
|
319
335
|
<span className="sentence">
|