clavarium 0.2.416-next.1 → 0.2.418-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/config/machine/clavarium-enter +10 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +8 -3
- package/server/guide.mjs +4 -1
- package/server/secrets.mjs +8 -4
- package/server/vm.mjs +5 -0
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
# /tools is the machine's (the same for all, read-only),
|
|
9
9
|
# ~ is /home/c-NAME (closed to the others),
|
|
10
10
|
# /tmp is its own,
|
|
11
|
+
# /run/secrets and /etc/clavarium/conversation.md are its own (/run/clavarium/own/NAME, /etc/clavarium/own/NAME.md),
|
|
11
12
|
# within a slice of its own (memory, processes: /etc/clavarium/limits/NAME, set by Clavarium). Seen from inside,
|
|
12
13
|
# a conversation is alone in its machine: no tool, no agent needs to know.
|
|
13
14
|
set -eu
|
|
@@ -24,18 +25,25 @@ fi
|
|
|
24
25
|
chmod 700 "/home/$user"
|
|
25
26
|
mkdir -p "$base/work" "$base/resources" "$base/tmp"
|
|
26
27
|
chown "$user:$user" "$base/tmp"; chmod 700 "$base/tmp"
|
|
28
|
+
# Its secrets and its guide: its own, written by Clavarium, shown at the usual places (never the others').
|
|
29
|
+
own="/run/clavarium/own/$name"; mkdir -p "$own/secrets"; chmod 711 /run/clavarium /run/clavarium/own
|
|
30
|
+
chown "$user:$user" "$own/secrets"; chmod 700 "$own/secrets"
|
|
31
|
+
mkdir -p /etc/clavarium/own /run/secrets; [ -e "/etc/clavarium/own/$name.md" ] || install -m 0444 /dev/null "/etc/clavarium/own/$name.md"
|
|
32
|
+
[ -e /etc/clavarium/conversation.md ] || install -m 0444 /dev/null /etc/clavarium/conversation.md
|
|
27
33
|
# Its limits (memory in MB, processes), when Clavarium set them.
|
|
28
34
|
mem=""; procs=""
|
|
29
35
|
[ -r "/etc/clavarium/limits/$name" ] && . "/etc/clavarium/limits/$name"
|
|
30
36
|
# Into its own mount namespace: its /work, its resources, its /tmp; then its user, in its slice.
|
|
31
37
|
exec unshare --mount --propagation private -- sh -c '
|
|
32
38
|
set -eu
|
|
33
|
-
base="$1"; user="$2"; mem="$3"; procs="$4"; shift
|
|
39
|
+
base="$1"; user="$2"; mem="$3"; procs="$4"; name="$5"; shift 5
|
|
34
40
|
mkdir -p /work /resources
|
|
35
41
|
mount --bind "$base/work" /work
|
|
36
42
|
mount -t tmpfs -o mode=755,size=1m none /resources
|
|
37
43
|
for r in "$base"/resources/*; do [ -e "$r" ] || continue; mkdir -p "/resources/$(basename "$r")"; mount --rbind "$r" "/resources/$(basename "$r")"; done
|
|
38
44
|
mount --bind "$base/tmp" /tmp
|
|
45
|
+
mount --bind "/run/clavarium/own/$name/secrets" /run/secrets
|
|
46
|
+
mount --bind "/etc/clavarium/own/$name.md" /etc/clavarium/conversation.md
|
|
39
47
|
# The processes of the others hidden (a procfs of its own, Linux 5.8+): only its own are seen.
|
|
40
48
|
mount -t proc -o hidepid=invisible proc /proc 2>/dev/null || true
|
|
41
49
|
cd "/home/$user" 2>/dev/null || cd /
|
|
@@ -44,4 +52,4 @@ exec unshare --mount --propagation private -- sh -c '
|
|
|
44
52
|
exec systemd-run --quiet --scope --slice="clavarium-$user" ${mem:+-p MemoryMax=${mem}M} ${procs:+-p TasksMax=$procs} -- "$@"
|
|
45
53
|
fi
|
|
46
54
|
exec "$@"
|
|
47
|
-
' clavarium-enter "$base" "$user" "$mem" "$procs" "$@"
|
|
55
|
+
' clavarium-enter "$base" "$user" "$mem" "$procs" "$name" "$@"
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.418-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.418-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -993,7 +993,8 @@ export class Conversations {
|
|
|
993
993
|
if (memory > size) throw new Refusal(400, `The machine ${machine} has ${size} MB of memory: ${tool.label} needs ${tool.memoryMb} MB.`);
|
|
994
994
|
const state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
|
|
995
995
|
if (tool.state && state !== 'Running') throw new Refusal(409, 'Its machine is not running: open the conversation first, so that its tool\'s state can come along.', { retry: false });
|
|
996
|
-
|
|
996
|
+
/* A new shared machine takes its size; its own, running, is stopped before it starts: that memory is given back. */
|
|
997
|
+
if (there === undefined) await this.room({ kind: 'create', memoryMb: Math.max(0, size - (state === 'Running' ? Number(c.memoryMb) || 0 : 0)) });
|
|
997
998
|
const act = this.#take(name, 'move');
|
|
998
999
|
this.#cancelStop(name);
|
|
999
1000
|
const now = new Date().toISOString();
|
|
@@ -1040,13 +1041,16 @@ export class Conversations {
|
|
|
1040
1041
|
return back(`${why.replace(/\.?$/, '.')}`);
|
|
1041
1042
|
}
|
|
1042
1043
|
if (tool.state) {
|
|
1043
|
-
|
|
1044
|
+
/* Not opened while its state is put back: building still, to the end. */
|
|
1045
|
+
this.#store.patch(name, { phase: 'building', step: `Putting ${tool.label}'s state back` });
|
|
1044
1046
|
this.drop(name);
|
|
1045
1047
|
try { await this.#unpack(name, c.tool, createReadStream(carried)); } catch (error) {
|
|
1048
|
+
this.#store.patch(name, { phase: 'ready', step: undefined });
|
|
1046
1049
|
this.ready(name);
|
|
1047
1050
|
this.renewed(name, `Moved to the shared machine ${machine}, but ${tool.label}'s state did not come along (${error.message}): it starts afresh. Its old machine is kept, stopped.`, true);
|
|
1048
1051
|
return undefined;
|
|
1049
1052
|
}
|
|
1053
|
+
this.#store.patch(name, { phase: 'ready', step: undefined });
|
|
1050
1054
|
this.ready(name);
|
|
1051
1055
|
}
|
|
1052
1056
|
await this.#vms.removeVm(old).catch(() => {});
|
|
@@ -1213,7 +1217,8 @@ export class Conversations {
|
|
|
1213
1217
|
|
|
1214
1218
|
/* What the VM manager says the machine has, written in its record. */
|
|
1215
1219
|
async reconcile(name) {
|
|
1216
|
-
|
|
1220
|
+
/* In a shared machine (#221): what the machine has is the machine's; its memory is its own limit there. */
|
|
1221
|
+
if (!this.#store.get(name) || this.#store.get(name).sharedMachine) return;
|
|
1217
1222
|
const real = await this.#vms.size(name).catch(() => ({}));
|
|
1218
1223
|
const patch = {};
|
|
1219
1224
|
if (real.memoryMb !== undefined && real.memoryMb !== this.#store.get(name).memoryMb) patch.memoryMb = real.memoryMb;
|
package/server/guide.mjs
CHANGED
|
@@ -36,6 +36,7 @@ import { Refusal } from './conversations.mjs';
|
|
|
36
36
|
import { isConversationName } from './names.mjs';
|
|
37
37
|
import { originFolder } from './resources.mjs';
|
|
38
38
|
import { TOOLS_PATH, NOTES } from './toolbox.mjs';
|
|
39
|
+
import { ownGuideFile } from './vm.mjs';
|
|
39
40
|
|
|
40
41
|
export const COMMON_PATH = `${TOOLS_PATH}/${NOTES}`;
|
|
41
42
|
export const OWN_PATH = '/etc/clavarium/conversation.md';
|
|
@@ -245,7 +246,9 @@ export class Guide {
|
|
|
245
246
|
/* ---- into the machine ---- */
|
|
246
247
|
async #writeOwn(name) {
|
|
247
248
|
const text = this.own(name);
|
|
248
|
-
|
|
249
|
+
/* In a shared machine, its own file: its door shows it at OWN_PATH (#221). */
|
|
250
|
+
const path = this.#vms.shared?.(name) === true ? ownGuideFile(name) : OWN_PATH;
|
|
251
|
+
const r = await this.#vms.exec(name, ['sudo', '-n', 'install', '-D', '-m', '0444', '-o', 'root', '-g', 'root', '/dev/stdin', path], { input: text, timeoutMs: 30_000 });
|
|
249
252
|
if (r.code !== 0) throw new Error(`its guide could not be written: ${firstLine(r.stderr) || `exit ${r.code}`}`);
|
|
250
253
|
this.#written.set(name, text);
|
|
251
254
|
}
|
package/server/secrets.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
25
25
|
import { Refusal } from './conversations.mjs';
|
|
26
26
|
import { Grants, conversationSubject } from './grants.mjs';
|
|
27
27
|
import { isConversationName } from './names.mjs';
|
|
28
|
-
import { VM_USER } from './vm.mjs';
|
|
28
|
+
import { VM_USER, ownSecretsDir, sharedUser } from './vm.mjs';
|
|
29
29
|
|
|
30
30
|
export const SECRETS_DIR = '/run/secrets';
|
|
31
31
|
export const RUNNER = '/usr/local/bin/clv-run';
|
|
@@ -286,10 +286,14 @@ export class Secrets {
|
|
|
286
286
|
if (r.code !== 0) throw new Refusal(502, `The machine could not be prepared: ${firstLine(r.stderr)}`);
|
|
287
287
|
};
|
|
288
288
|
await run(['sudo', '-n', 'install', '-m', '0755', '/dev/stdin', RUNNER], RUNNER_SCRIPT);
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
/* In a shared machine, its own folder (its door shows it as /run/secrets), its own user: never the others'. */
|
|
290
|
+
const shared = this.#vms.shared?.(conversation) === true;
|
|
291
|
+
const dir = shared ? ownSecretsDir(conversation) : SECRETS_DIR;
|
|
292
|
+
const user = shared ? sharedUser(conversation) : VM_USER;
|
|
293
|
+
await run(['sudo', '-n', 'install', '-d', '-m', shared ? '0700' : '0755', ...(shared ? ['-o', user, '-g', user] : []), dir]);
|
|
294
|
+
await run(['sudo', '-n', 'find', dir, '-mindepth', '1', '-delete']);
|
|
291
295
|
for (const secret of this.#given(conversation)) {
|
|
292
|
-
await run(['sudo', '-n', 'install', '-m', '0600', '-o',
|
|
296
|
+
await run(['sudo', '-n', 'install', '-m', '0600', '-o', user, '-g', user, '/dev/stdin', `${dir}/${secret.name}`], this.#vault.open(secret.sealed));
|
|
293
297
|
}
|
|
294
298
|
}
|
|
295
299
|
}
|
package/server/vm.mjs
CHANGED
|
@@ -14,6 +14,11 @@ import { isConversationName } from './names.mjs';
|
|
|
14
14
|
directory: the path then names nobody, and sits next to /resources. */
|
|
15
15
|
export const WORK = '/work';
|
|
16
16
|
export const VM_USER = 'ubuntu';
|
|
17
|
+
/* In a shared machine (#221), what is a conversation's own though machine-wide in a machine of its own: written
|
|
18
|
+
by the server here, shown by its door at the usual place (/run/secrets, /etc/clavarium/conversation.md). */
|
|
19
|
+
export const ownSecretsDir = (conversation) => `/run/clavarium/own/${conversation}/secrets`;
|
|
20
|
+
export const ownGuideFile = (conversation) => `/etc/clavarium/own/${conversation}.md`;
|
|
21
|
+
export const sharedUser = (conversation) => `c-${conversation}`;
|
|
17
22
|
/* What sharing a folder needs inside a machine (see conversations.mjs). */
|
|
18
23
|
export const SHARING_STEP = Object.freeze(['sudo', '-n', 'snap', 'install', 'multipass-sshfs']);
|
|
19
24
|
/* Attached folders appear in every VM under /resources/<name>: the host
|