clavarium 0.2.2 → 0.2.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy/install.sh +4 -0
- package/deploy/updater.mjs +18 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +3 -0
- package/server/main.mjs +2 -0
- package/server/secrets.mjs +18 -0
- package/server/voice.mjs +5 -0
- package/web/app.js +36 -2
- package/web/index.html +3 -0
- package/web/style.css +3 -0
package/deploy/install.sh
CHANGED
|
@@ -536,6 +536,10 @@ upstreams = ["http://127.0.0.1:$PORT/"]
|
|
|
536
536
|
# identity headers are stripped there, so nobody can claim to be an operator.
|
|
537
537
|
skip_auth_routes = ["^/c/"]
|
|
538
538
|
skip_auth_strip_headers = true
|
|
539
|
+
# Two sign-ins at once (two tabs, a reload during it) each have their own CSRF
|
|
540
|
+
# cookie; and there is time to type a password (deploy/updater.mjs, PROXY_LINES).
|
|
541
|
+
cookie_csrf_per_request = true
|
|
542
|
+
cookie_csrf_expire = "30m"
|
|
539
543
|
PROXY
|
|
540
544
|
install -o root -g root -m 0600 "$proxy" /etc/oauth2-proxy/oauth2-proxy.cfg; rm -f -- "$proxy"
|
|
541
545
|
else
|
package/deploy/updater.mjs
CHANGED
|
@@ -84,6 +84,23 @@ const LOG_MAX = 12_000;
|
|
|
84
84
|
export const DROP_IN = '/etc/systemd/system/clavarium.service.d/restart.conf';
|
|
85
85
|
export const DROP_IN_TEXT = '# Written by the Clavarium updater: a crash loop never locks the service out.\n[Unit]\nStartLimitIntervalSec=0\n\n[Service]\nRestartSec=3\n';
|
|
86
86
|
|
|
87
|
+
/* THE SIGN-IN PROXY, kept by the updater: two sign-ins started at once (two tabs, a page reloaded
|
|
88
|
+
during it, the installed app and the browser) shared one CSRF cookie, and the first to come back
|
|
89
|
+
was refused ("Unable to find a valid CSRF token", found 20-10). One cookie per sign-in, and time
|
|
90
|
+
to type a password. Added to a file that lacks them, the proxy restarted; nothing else touched. */
|
|
91
|
+
export const PROXY_CFG = '/etc/oauth2-proxy/oauth2-proxy.cfg';
|
|
92
|
+
export const PROXY_LINES = ['cookie_csrf_per_request = true', 'cookie_csrf_expire = "30m"'];
|
|
93
|
+
export async function ensureProxySettings({ file = PROXY_CFG, run = runCommand } = {}) {
|
|
94
|
+
let text;
|
|
95
|
+
try { text = readFileSync(file, 'utf8'); } catch { return false; }
|
|
96
|
+
const missing = PROXY_LINES.filter((l) => !text.split('\n').some((x) => x.trim().startsWith(l.split(' =')[0])));
|
|
97
|
+
if (!missing.length) return false;
|
|
98
|
+
writeFileSync(`${file}.new`, `${text.replace(/\n*$/, '\n')}# Added by the Clavarium updater: one CSRF cookie per sign-in.\n${missing.join('\n')}\n`, { mode: 0o600 });
|
|
99
|
+
renameSync(`${file}.new`, file);
|
|
100
|
+
if (process.getuid?.() === 0) await run(['systemctl', 'try-restart', 'oauth2-proxy.service'], { timeoutMs: 60_000 });
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
87
104
|
export class Refused extends Error {}
|
|
88
105
|
|
|
89
106
|
/* SEMANTIC VERSIONS, compared as npm does: a pre-release comes before its release. */
|
|
@@ -785,6 +802,7 @@ async function main(argv) {
|
|
|
785
802
|
update that brought it ran the PREVIOUS release's code. Idempotent; never stops the turn. */
|
|
786
803
|
try { const [{ installWatch }, { realSys }] = await Promise.all([import('./doctor.mjs'), import('./online.mjs')]); if (await installWatch(realSys())) console.error('updater: the certificate timer set up'); } catch (error) { console.error(`updater: the certificate timer could not be set up: ${error.message}`); }
|
|
787
804
|
try { if (await u.ensureDropIn()) console.error('updater: the drop-in of the server\'s unit written'); } catch (error) { console.error(`updater: the drop-in could not be written: ${error.message}`); }
|
|
805
|
+
try { if (await ensureProxySettings()) console.error('updater: the sign-in proxy takes one CSRF cookie per sign-in'); } catch (error) { console.error(`updater: the sign-in proxy could not be set: ${error.message}`); }
|
|
788
806
|
const r = await u.runOnce(); console.log(typeof r === 'string' ? r : 'done'); return; }
|
|
789
807
|
case 'set': if (rest.length !== 2) throw new Refused('set <mode|channel|window|port> <value>'); return print(u.set(rest[0], rest[1]));
|
|
790
808
|
case 'prepare': { const r = await u.prepare({ version: value('--version'), fromDir: value('--from-dir') }); console.log(r.id); return; }
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.3-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
* GET /api/secrets names only: a value never comes back
|
|
66
66
|
* POST /api/secrets {name, value} create or replace
|
|
67
67
|
* POST /api/secrets/<NAME>/remove
|
|
68
|
+
* POST /api/secrets/<NAME>/rename {name}: its value and where it is handed go with it
|
|
68
69
|
* POST /api/conversations/<name>/secrets {secret, attached}
|
|
69
70
|
* GET /api/shortcuts
|
|
70
71
|
* POST /api/shortcuts {label, text, enter}
|
|
@@ -305,6 +306,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
305
306
|
if (fetched && mailboxes) return send(200, await mailboxes.sync(fetched[1])), true;
|
|
306
307
|
if (pathname === '/api/shortcuts' && shortcuts) return send(201, shortcuts.add(body)), true;
|
|
307
308
|
if (pathname === '/api/secrets' && secrets) { const made = secrets.set(body); setup?.secretAdded(made.name); return send(201, made), true; }
|
|
309
|
+
const renaming = /^\/api\/secrets\/([A-Z][A-Z0-9_]{0,39})\/rename$/.exec(pathname);
|
|
310
|
+
if (renaming && secrets) return send(200, secrets.rename(renaming[1], String(body.name ?? '').trim())), true;
|
|
308
311
|
const dropped = /^\/api\/secrets\/([A-Z][A-Z0-9_]{0,39})\/remove$/.exec(pathname);
|
|
309
312
|
if (dropped && secrets) { secrets.remove(dropped[1]); return send(200, { ok: true }), true; }
|
|
310
313
|
if (pathname === '/api/alerts' && alerts) return send(201, alerts.add(body.subscription, body.label)), true;
|
package/server/main.mjs
CHANGED
|
@@ -258,6 +258,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
258
258
|
};
|
|
259
259
|
const door = { devices, conversations: all, resources: folders, shortcuts, voice, originOk, headers: HEADERS, secure: Boolean(publicOrigin?.startsWith('https:')), repair: (name) => repairTerminal(name) };
|
|
260
260
|
const secrets = new Secrets({ store: new Store(`${dataDir}/secrets.json`), vault, vms, grants });
|
|
261
|
+
/* A secret renamed: what names it follows (the key of dictation). `voice` is made below. */
|
|
262
|
+
secrets.renamed = (from, to) => voice.secretRenamed(from, to);
|
|
261
263
|
const signin = new SignInMailboxes({ store: new Store(`${dataDir}/signin.json`), vault, rules: (name) => all.signinRules(name) });
|
|
262
264
|
/* Each opening: the runner and the attached secrets are put in the VM,
|
|
263
265
|
and the tool is started through the runner. */
|
package/server/secrets.mjs
CHANGED
|
@@ -80,6 +80,24 @@ export class Secrets {
|
|
|
80
80
|
return { name };
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/* RENAMED: its value (still sealed, never opened) and the conversations it is handed to go with
|
|
84
|
+
it; `renamed(from, to)` tells what else names it (dictation's key). Delivered under its new
|
|
85
|
+
name at each conversation's next start. */
|
|
86
|
+
rename(from, to) {
|
|
87
|
+
const secret = this.#store.get(from);
|
|
88
|
+
if (!secret) throw new Refusal(404, 'No such secret.');
|
|
89
|
+
if (!isSecretName(to)) throw new Refusal(400, 'A secret is named like a variable: capitals, digits and underscores, starting with a letter.');
|
|
90
|
+
if (to === from) return { name: to };
|
|
91
|
+
if (this.#store.get(to)) throw new Refusal(409, `A secret is already named ${to}.`);
|
|
92
|
+
this.#store.put({ ...secret, name: to });
|
|
93
|
+
for (const g of this.#grants.on(`secret:${from}`)) this.#grants.give(g.subject, `secret:${to}`, g.rights);
|
|
94
|
+
this.#grants.forgetAsset(`secret:${from}`);
|
|
95
|
+
this.#store.remove(from);
|
|
96
|
+
this.renamed(from, to);
|
|
97
|
+
return { name: to };
|
|
98
|
+
}
|
|
99
|
+
renamed = () => {};
|
|
100
|
+
|
|
83
101
|
remove(name) {
|
|
84
102
|
if (!this.#store.get(name)) throw new Refusal(404, 'No such secret.');
|
|
85
103
|
this.#store.remove(name);
|
package/server/voice.mjs
CHANGED
|
@@ -154,6 +154,11 @@ export class Dictation {
|
|
|
154
154
|
constructor({ file = new JsonFile(undefined, {}), env = process.env, secret = () => undefined, lookup = (host) => dnsLookup(host, { all: true }), fetcher = fetch } = {}) {
|
|
155
155
|
this.#file = file; this.#env = env; this.#secret = secret; this.#lookup = lookup; this.#fetcher = fetcher;
|
|
156
156
|
}
|
|
157
|
+
/* A secret renamed: the key of dictation follows it. */
|
|
158
|
+
secretRenamed(from, to) {
|
|
159
|
+
const kept = this.#file.get();
|
|
160
|
+
if (kept?.secret === from) this.#file.set({ ...kept, secret: to });
|
|
161
|
+
}
|
|
157
162
|
#saved() { const kept = this.#file.get(); return kept?.on === true && !dictationProblem(kept) ? kept : undefined; }
|
|
158
163
|
#configOf(c) {
|
|
159
164
|
return { url: c.url, model: c.model, language: c.language || undefined, key: c.secret ? this.#secret(c.secret) : undefined, provider: c.provider };
|
package/web/app.js
CHANGED
|
@@ -2776,7 +2776,22 @@
|
|
|
2776
2776
|
const r = chosen.resource;
|
|
2777
2777
|
/* State, in a line. */
|
|
2778
2778
|
if (chosen.kind === 'mailbox') detail.append(el('p', chosen.box?.failure ? 'error' : 'hint', boxSub(chosen.box)));
|
|
2779
|
-
if (chosen.kind === 'secret')
|
|
2779
|
+
if (chosen.kind === 'secret') {
|
|
2780
|
+
detail.append(el('p', 'hint', 'Its value is never shown again. A change takes effect the next time the tool starts.'));
|
|
2781
|
+
/* Renamed: its value and the conversations it is handed to go with it. */
|
|
2782
|
+
const form = el('form', 'row secret-rename'); form.autocomplete = 'off';
|
|
2783
|
+
const name = el('input'); name.id = 'secret-rename-name'; name.value = chosen.name; name.maxLength = 40; name.pattern = '[A-Z][A-Z0-9_]*'; name.spellcheck = false; name.autocapitalize = 'characters'; name.setAttribute('aria-label', 'New name');
|
|
2784
|
+
const go = el('button', '', 'Rename'); go.type = 'submit';
|
|
2785
|
+
form.append(name, go);
|
|
2786
|
+
form.addEventListener('submit', async (event) => {
|
|
2787
|
+
event.preventDefault();
|
|
2788
|
+
$('assets-error').hidden = true;
|
|
2789
|
+
try { const done = await post(`${API}/secrets/${chosen.name}/rename`, { name: name.value.trim() }); assetOpen = `secret:${done.name}`; }
|
|
2790
|
+
catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
|
|
2791
|
+
await paintAssets();
|
|
2792
|
+
});
|
|
2793
|
+
detail.append(form);
|
|
2794
|
+
}
|
|
2780
2795
|
/* Used by: each conversation that has it, what it may do; "+" offers the others. */
|
|
2781
2796
|
const options = chosen.kind === 'secret' ? [['off', 'Off'], ['use', 'Use']] : chosen.kind === 'mailbox' ? [['none', 'Off'], ['read', 'Read']] : [['none', 'Off'], ['read', 'Read'], ['write', 'Write']];
|
|
2782
2797
|
const has = (c) => (chosen.kind === 'secret' ? (chosen.secret.conversations.includes(c.name) ? 'use' : 'off') : r.attachments?.[c.name] ?? 'none');
|
|
@@ -2976,10 +2991,29 @@
|
|
|
2976
2991
|
});
|
|
2977
2992
|
$('git-key-copy').addEventListener('click', () => { void copyField($('git-key-public'), $('git-key-copy')); });
|
|
2978
2993
|
/* Secrets: a name, and which conversations' tools are handed it. A value goes in and never comes back. */
|
|
2994
|
+
/* A VALUE OF SEVERAL LINES (a PEM or SSH key, a certificate): a box of its own, masked like the
|
|
2995
|
+
line. Pasted into the line, whose input keeps one line only, it comes there whole by itself. */
|
|
2996
|
+
const secretLines = (on, text) => {
|
|
2997
|
+
$('secret-lines').hidden = !on; $('secret-value').hidden = on;
|
|
2998
|
+
$('secret-value').required = !on; $('secret-lines').required = on;
|
|
2999
|
+
$('secret-lines-switch').textContent = on ? 'One line' : 'Several lines (a key, a certificate)';
|
|
3000
|
+
if (on) { $('secret-lines').value = text ?? $('secret-value').value; $('secret-value').value = ''; $('secret-lines').focus(); }
|
|
3001
|
+
else { $('secret-value').value = (text ?? $('secret-lines').value).split('\n')[0]; $('secret-lines').value = ''; }
|
|
3002
|
+
};
|
|
3003
|
+
$('secret-lines-switch').addEventListener('click', () => secretLines($('secret-lines').hidden));
|
|
3004
|
+
$('secret-value').addEventListener('paste', (event) => {
|
|
3005
|
+
const text = event.clipboardData?.getData('text') ?? '';
|
|
3006
|
+
if (!/[\r\n]/.test(text.replace(/[\r\n]+$/, ''))) return;
|
|
3007
|
+
event.preventDefault();
|
|
3008
|
+
secretLines(true, text.replace(/\r\n?/g, '\n'));
|
|
3009
|
+
});
|
|
2979
3010
|
$('secret-new').addEventListener('submit', async (event) => {
|
|
2980
3011
|
event.preventDefault();
|
|
2981
3012
|
$('assets-error').hidden = true;
|
|
2982
|
-
|
|
3013
|
+
const lines = !$('secret-lines').hidden;
|
|
3014
|
+
/* A key's last line ends with a line break: kept as it was pasted. */
|
|
3015
|
+
const value = lines ? $('secret-lines').value.replace(/\r\n?/g, '\n') : $('secret-value').value;
|
|
3016
|
+
try { await post(`${API}/secrets`, { name: $('secret-name').value.trim(), value }); assetOpen = `secret:${$('secret-name').value.trim()}`; assetsAdding = ''; $('secret-name').value = ''; secretLines(false, ''); }
|
|
2983
3017
|
catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
|
|
2984
3018
|
await paintAssets();
|
|
2985
3019
|
});
|
package/web/index.html
CHANGED
|
@@ -521,6 +521,9 @@
|
|
|
521
521
|
<div class="row"><input id="secret-name" maxlength="40" pattern="[A-Z][A-Z0-9_]*" title="Capitals, digits and underscores, starting with a letter. Example: MODEL_KEY" placeholder="MODEL_KEY" spellcheck="false" autocapitalize="characters" required>
|
|
522
522
|
<input id="secret-value" type="password" placeholder="value (never shown again)" autocomplete="new-password" required>
|
|
523
523
|
<button type="submit" class="primary">Save</button></div>
|
|
524
|
+
<!-- A key or a certificate is several lines: pasted into the line above, they come here by themselves. -->
|
|
525
|
+
<textarea id="secret-lines" class="secret-lines" rows="7" spellcheck="false" autocomplete="off" autocapitalize="off" placeholder="-----BEGIN ...----- ... -----END ...-----" aria-label="Value, several lines (never shown again)" hidden></textarea>
|
|
526
|
+
<button type="button" id="secret-lines-switch" class="as-link">Several lines (a key, a certificate)</button>
|
|
524
527
|
</form>
|
|
525
528
|
</div>
|
|
526
529
|
<details id="gitview-remote-box">
|
package/web/style.css
CHANGED
|
@@ -1270,3 +1270,6 @@ select.pill { appearance: auto; }
|
|
|
1270
1270
|
/* Something is being fetched: a small turning ring before the words (a still ring without motion). */
|
|
1271
1271
|
.busy::before { content: ""; display: inline-block; width: .95em; height: .95em; margin-right: .5em; vertical-align: -.17em; border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: var(--brass); }
|
|
1272
1272
|
@media (prefers-reduced-motion: no-preference) { .busy::before { animation: busy-turn .8s linear infinite; } @keyframes busy-turn { to { transform: rotate(360deg); } } }
|
|
1273
|
+
|
|
1274
|
+
/* A secret of several lines (a key): masked as the line is, never shown as it is typed. */
|
|
1275
|
+
.secret-lines { width: 100%; min-height: 6rem; margin-top: .5rem; font: .8rem ui-monospace, Menlo, Consolas, monospace; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); resize: vertical; -webkit-text-security: disc; }
|