clavarium 0.2.417-next.1 → 0.2.419-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 +18 -5
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/guide.mjs +9 -4
- package/server/secrets.mjs +8 -4
- package/server/vm.mjs +5 -0
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
# /resources/* are only those given to it (/srv/clavarium/NAME/resources),
|
|
8
8
|
# /tools is the machine's (the same for all, read-only),
|
|
9
9
|
# ~ is /home/c-NAME (closed to the others),
|
|
10
|
-
# /tmp
|
|
10
|
+
# /tmp, /var/tmp and /dev/shm are 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
|
|
@@ -22,20 +23,32 @@ if ! id "$user" >/dev/null 2>&1; then
|
|
|
22
23
|
useradd --create-home --home-dir "/home/$user" --shell /bin/bash --user-group "$user"
|
|
23
24
|
fi
|
|
24
25
|
chmod 700 "/home/$user"
|
|
25
|
-
mkdir -p "$base/work" "$base/resources" "$base/tmp"
|
|
26
|
-
|
|
26
|
+
mkdir -p "$base/work" "$base/resources" "$base/tmp" "$base/vartmp"
|
|
27
|
+
# Its place closed to the others (its own views of it are made below, as root): never another's /work by its path.
|
|
28
|
+
chown root:root /srv/clavarium "$base"; chmod 711 /srv/clavarium; chmod 700 "$base"
|
|
29
|
+
chown "$user:$user" "$base/tmp" "$base/vartmp"; chmod 700 "$base/tmp" "$base/vartmp"
|
|
30
|
+
# Its secrets and its guide: its own, written by Clavarium, shown at the usual places (never the others').
|
|
31
|
+
own="/run/clavarium/own/$name"; mkdir -p "$own/secrets"; chmod 711 /run/clavarium /run/clavarium/own
|
|
32
|
+
chown "$user:$user" "$own/secrets"; chmod 700 "$own/secrets"
|
|
33
|
+
mkdir -p /etc/clavarium/own /run/secrets; chmod 711 /etc/clavarium/own
|
|
34
|
+
[ -e "/etc/clavarium/own/$name.md" ] || install -m 0440 -o root -g "$user" /dev/null "/etc/clavarium/own/$name.md"
|
|
35
|
+
[ -e /etc/clavarium/conversation.md ] || install -m 0444 /dev/null /etc/clavarium/conversation.md
|
|
27
36
|
# Its limits (memory in MB, processes), when Clavarium set them.
|
|
28
37
|
mem=""; procs=""
|
|
29
38
|
[ -r "/etc/clavarium/limits/$name" ] && . "/etc/clavarium/limits/$name"
|
|
30
39
|
# Into its own mount namespace: its /work, its resources, its /tmp; then its user, in its slice.
|
|
31
40
|
exec unshare --mount --propagation private -- sh -c '
|
|
32
41
|
set -eu
|
|
33
|
-
base="$1"; user="$2"; mem="$3"; procs="$4"; shift
|
|
42
|
+
base="$1"; user="$2"; mem="$3"; procs="$4"; name="$5"; shift 5
|
|
34
43
|
mkdir -p /work /resources
|
|
35
44
|
mount --bind "$base/work" /work
|
|
36
45
|
mount -t tmpfs -o mode=755,size=1m none /resources
|
|
37
46
|
for r in "$base"/resources/*; do [ -e "$r" ] || continue; mkdir -p "/resources/$(basename "$r")"; mount --rbind "$r" "/resources/$(basename "$r")"; done
|
|
38
47
|
mount --bind "$base/tmp" /tmp
|
|
48
|
+
mount --bind "$base/vartmp" /var/tmp
|
|
49
|
+
mount -t tmpfs -o mode=1777,size=64m none /dev/shm
|
|
50
|
+
mount --bind "/run/clavarium/own/$name/secrets" /run/secrets
|
|
51
|
+
mount --bind "/etc/clavarium/own/$name.md" /etc/clavarium/conversation.md
|
|
39
52
|
# The processes of the others hidden (a procfs of its own, Linux 5.8+): only its own are seen.
|
|
40
53
|
mount -t proc -o hidepid=invisible proc /proc 2>/dev/null || true
|
|
41
54
|
cd "/home/$user" 2>/dev/null || cd /
|
|
@@ -44,4 +57,4 @@ exec unshare --mount --propagation private -- sh -c '
|
|
|
44
57
|
exec systemd-run --quiet --scope --slice="clavarium-$user" ${mem:+-p MemoryMax=${mem}M} ${procs:+-p TasksMax=$procs} -- "$@"
|
|
45
58
|
fi
|
|
46
59
|
exec "$@"
|
|
47
|
-
' clavarium-enter "$base" "$user" "$mem" "$procs" "$@"
|
|
60
|
+
' 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.419-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.419-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
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, sharedUser } from './vm.mjs';
|
|
39
40
|
|
|
40
41
|
export const COMMON_PATH = `${TOOLS_PATH}/${NOTES}`;
|
|
41
42
|
export const OWN_PATH = '/etc/clavarium/conversation.md';
|
|
@@ -79,7 +80,7 @@ export function commonText() {
|
|
|
79
80
|
return [
|
|
80
81
|
'# Where you are (Clavarium)',
|
|
81
82
|
'',
|
|
82
|
-
'- A throw-away machine, yours alone: you are root (sudo works). Install what you need.',
|
|
83
|
+
'- A throw-away machine, yours alone: you are root (sudo works). Install what you need. (In a shared machine, not so: ' + OWN_PATH + ' says it.)',
|
|
83
84
|
'- /work: where you work. /resources/<name>: folders and repositories you were given, read-only or read-write. /tools: tools offered, read-only (/tools/index.json says what each is).',
|
|
84
85
|
`- What this conversation has, and what its owner asks of you: ${OWN_PATH} (read-only; written again by the server when your setup changes).`,
|
|
85
86
|
'- Git: commit your work. The person reviews it and sends it from their screen, or the server sends it by itself where they allowed it. You have no push key: never push.',
|
|
@@ -101,9 +102,11 @@ const list = (items) => items.join(', ');
|
|
|
101
102
|
/* THE PART OF ONE CONVERSATION, from its facts:
|
|
102
103
|
{ name, tool, workKept, resources: [{ name, access, type, origin }], chat, online, secrets: [names], lines, reread }
|
|
103
104
|
`reread`: the command that reads the end of its chat after a restart (the owner's choice, talk.mjs). */
|
|
104
|
-
export function ownText({ name, tool, workKept, resources = [], chat, online, secrets = [], lines = [], reread }) {
|
|
105
|
+
export function ownText({ name, tool, shared, workKept, resources = [], chat, online, secrets = [], lines = [], reread }) {
|
|
105
106
|
const out = [`# This conversation: ${plain(name, 40)}`, ''];
|
|
106
107
|
if (tool) out.push(`- Tool running here: ${plain(tool, 40)}.`);
|
|
108
|
+
/* #221: in a shared machine, its own user without sudo -- not what /tools/CLAVARIUM.md says of a machine of its own. */
|
|
109
|
+
if (shared) out.push(`- A machine shared with other conversations: you are its user c-${plain(name, 40)}, NOT root (no sudo). Install in your home (npm --prefix ~/.local, pip install --user); what needs root, ask the person.`);
|
|
107
110
|
out.push(workKept ? '- /work is kept by the server: the person sees it in Files, and it outlives the machine.' : '- /work is on this machine\'s own disk: it goes with the machine.');
|
|
108
111
|
const where = (r) => `/resources/${plain(r.name, 40)}${r.type === 'mailbox' ? ' (mail)' : r.type === 'git' ? ' (git)' : ''}`;
|
|
109
112
|
const write = resources.filter((r) => r.access === 'write');
|
|
@@ -224,7 +227,7 @@ export class Guide {
|
|
|
224
227
|
const type = this.#resources.get(r.name)?.type ?? 'folder';
|
|
225
228
|
return { name: r.name, access: r.access, type, origin: type === 'git' && this.#resources.hasOrigin?.(r.name) ? originFolder(r.name) : undefined };
|
|
226
229
|
});
|
|
227
|
-
return ownText({ name, tool: this.#tool(c)?.label ?? c.tool, workKept: c.work === 'kept', resources, chat: Boolean(this.#chat(name)), online: c.offline !== true, secrets: (this.#secrets?.given ?? this.#secrets?.of)?.call(this.#secrets, name) ?? [], lines: this.lines(name), reread: this.#reread() });
|
|
230
|
+
return ownText({ name, tool: this.#tool(c)?.label ?? c.tool, shared: this.#vms.shared?.(name) === true, workKept: c.work === 'kept', resources, chat: Boolean(this.#chat(name)), online: c.offline !== true, secrets: (this.#secrets?.given ?? this.#secrets?.of)?.call(this.#secrets, name) ?? [], lines: this.lines(name), reread: this.#reread() });
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
/* What the page shows: the exact texts, where each is, and the line in the tool's own file. */
|
|
@@ -245,7 +248,9 @@ export class Guide {
|
|
|
245
248
|
/* ---- into the machine ---- */
|
|
246
249
|
async #writeOwn(name) {
|
|
247
250
|
const text = this.own(name);
|
|
248
|
-
|
|
251
|
+
/* In a shared machine, its own file, readable by its own user only: its door shows it at OWN_PATH (#221). */
|
|
252
|
+
const shared = this.#vms.shared?.(name) === true;
|
|
253
|
+
const r = await this.#vms.exec(name, ['sudo', '-n', 'install', '-D', '-m', shared ? '0440' : '0444', '-o', 'root', '-g', shared ? sharedUser(name) : 'root', '/dev/stdin', shared ? ownGuideFile(name) : OWN_PATH], { input: text, timeoutMs: 30_000 });
|
|
249
254
|
if (r.code !== 0) throw new Error(`its guide could not be written: ${firstLine(r.stderr) || `exit ${r.code}`}`);
|
|
250
255
|
this.#written.set(name, text);
|
|
251
256
|
}
|
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
|