clavarium 0.2.417-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.
@@ -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 4
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" "$@"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.417-next.1",
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.417-next.1",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.417-next.1",
3
+ "version": "0.2.418-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
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
- const r = await this.#vms.exec(name, ['sudo', '-n', 'install', '-D', '-m', '0444', '-o', 'root', '-g', 'root', '/dev/stdin', OWN_PATH], { input: text, timeoutMs: 30_000 });
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
  }
@@ -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
- await run(['sudo', '-n', 'install', '-d', '-m', '0755', SECRETS_DIR]);
290
- await run(['sudo', '-n', 'find', SECRETS_DIR, '-mindepth', '1', '-delete']);
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', VM_USER, '-g', VM_USER, '/dev/stdin', `${SECRETS_DIR}/${secret.name}`], this.#vault.open(secret.sealed));
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