clavarium 0.2.399-next.1 → 0.2.400-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 +47 -0
- package/deploy/clavarium-host +36 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# THE DOOR OF A CONVERSATION IN A SHARED MACHINE (#221), run as root by Clavarium for everything it runs for
|
|
3
|
+
# that conversation: clavarium-enter NAME -- COMMAND [ARGS...]
|
|
4
|
+
#
|
|
5
|
+
# The command runs as the conversation's own user (c-NAME, no sudo), in a mount namespace of its own where
|
|
6
|
+
# /work is THIS conversation's work (the host mounts it at /srv/clavarium/NAME/work),
|
|
7
|
+
# /resources/* are only those given to it (/srv/clavarium/NAME/resources),
|
|
8
|
+
# /tools is the machine's (the same for all, read-only),
|
|
9
|
+
# ~ is /home/c-NAME (closed to the others),
|
|
10
|
+
# /tmp is its own,
|
|
11
|
+
# within a slice of its own (memory, processes: /etc/clavarium/limits/NAME, set by Clavarium). Seen from inside,
|
|
12
|
+
# a conversation is alone in its machine: no tool, no agent needs to know.
|
|
13
|
+
set -eu
|
|
14
|
+
[ "$(id -u)" -eq 0 ] || { echo "clavarium-enter: run as root" >&2; exit 77; }
|
|
15
|
+
name="${1:-}"; shift || true
|
|
16
|
+
[ "${1:-}" = "--" ] && shift
|
|
17
|
+
printf '%s' "$name" | grep -Eq '^[a-z]([a-z0-9-]{0,30}[a-z0-9])?$' || { echo "clavarium-enter: not a conversation name" >&2; exit 64; }
|
|
18
|
+
[ $# -gt 0 ] || { echo "clavarium-enter: no command" >&2; exit 64; }
|
|
19
|
+
user="c-$name"; base="/srv/clavarium/$name"
|
|
20
|
+
# Its user, made at its first entry: a home of its own, closed to the others; no sudo, ever.
|
|
21
|
+
if ! id "$user" >/dev/null 2>&1; then
|
|
22
|
+
useradd --create-home --home-dir "/home/$user" --shell /bin/bash --user-group "$user"
|
|
23
|
+
fi
|
|
24
|
+
chmod 700 "/home/$user"
|
|
25
|
+
mkdir -p "$base/work" "$base/resources" "$base/tmp"
|
|
26
|
+
chown "$user:$user" "$base/tmp"; chmod 700 "$base/tmp"
|
|
27
|
+
# Its limits (memory in MB, processes), when Clavarium set them.
|
|
28
|
+
mem=""; procs=""
|
|
29
|
+
[ -r "/etc/clavarium/limits/$name" ] && . "/etc/clavarium/limits/$name"
|
|
30
|
+
# Into its own mount namespace: its /work, its resources, its /tmp; then its user, in its slice.
|
|
31
|
+
exec unshare --mount --propagation private -- sh -c '
|
|
32
|
+
set -eu
|
|
33
|
+
base="$1"; user="$2"; mem="$3"; procs="$4"; shift 4
|
|
34
|
+
mkdir -p /work /resources
|
|
35
|
+
mount --bind "$base/work" /work
|
|
36
|
+
mount -t tmpfs -o mode=755,size=1m none /resources
|
|
37
|
+
for r in "$base"/resources/*; do [ -e "$r" ] || continue; mkdir -p "/resources/$(basename "$r")"; mount --rbind "$r" "/resources/$(basename "$r")"; done
|
|
38
|
+
mount --bind "$base/tmp" /tmp
|
|
39
|
+
# The processes of the others hidden (a procfs of its own, Linux 5.8+): only its own are seen.
|
|
40
|
+
mount -t proc -o hidepid=invisible proc /proc 2>/dev/null || true
|
|
41
|
+
cd "/home/$user" 2>/dev/null || cd /
|
|
42
|
+
set -- setpriv --reuid="$user" --regid="$user" --init-groups --reset-env -- env HOME="/home/$user" USER="$user" LOGNAME="$user" SHELL=/bin/bash PATH=/usr/local/bin:/usr/bin:/bin "$@"
|
|
43
|
+
if [ -n "$mem$procs" ] && command -v systemd-run >/dev/null 2>&1; then
|
|
44
|
+
exec systemd-run --quiet --scope --slice="clavarium-$user" ${mem:+-p MemoryMax=${mem}M} ${procs:+-p TasksMax=$procs} -- "$@"
|
|
45
|
+
fi
|
|
46
|
+
exec "$@"
|
|
47
|
+
' clavarium-enter "$base" "$user" "$mem" "$procs" "$@"
|
package/deploy/clavarium-host
CHANGED
|
@@ -1106,6 +1106,42 @@ case "$AREA $VERB" in
|
|
|
1106
1106
|
*) refuse "a mount is of a folder, of a view, of a work folder or of the tools" ;;
|
|
1107
1107
|
esac
|
|
1108
1108
|
run "$MULTIPASS" mount -u "$4:$VM_ID" -g "$5:$VM_ID" "$source" "$target" ;;
|
|
1109
|
+
"vm share"|"vm unshare")
|
|
1110
|
+
# A SHARED MACHINE (#221): the conversations that live in it, kept here (DATA/shared/<vm>), so that a
|
|
1111
|
+
# work folder or a resource only ever goes into the machine its conversation lives in. <vm> <conversation>
|
|
1112
|
+
[ $# -eq 2 ] || usage; vm_of "$1"; is_name "$2" || refuse "not a conversation name: $2"
|
|
1113
|
+
[ "$1" != "clv-$2" ] || refuse "a conversation of its own is not shared"
|
|
1114
|
+
list="$DATA/shared/$1"
|
|
1115
|
+
if [ "$SAY" = "yes" ]; then printf '%s %s %s\n' "$VERB" "$list" "$2"; exit 0; fi
|
|
1116
|
+
mkdir -p "$DATA/shared"; touch "$list"
|
|
1117
|
+
if [ "$VERB" = "share" ]; then
|
|
1118
|
+
grep -qx "$2" "$list" || printf '%s\n' "$2" >> "$list"
|
|
1119
|
+
else
|
|
1120
|
+
grep -vx "$2" "$list" > "$list.new" || true; mv "$list.new" "$list"
|
|
1121
|
+
fi
|
|
1122
|
+
exit 0 ;;
|
|
1123
|
+
"vm smount")
|
|
1124
|
+
# <vm> <conversation> <work|folder|view> <resource> <uid> <gid>: into the conversation's own place in a
|
|
1125
|
+
# shared machine (/srv/clavarium/<conversation>/...), where its door (clavarium-enter) finds it -- only for
|
|
1126
|
+
# a conversation that lives in that machine.
|
|
1127
|
+
[ $# -eq 6 ] || usage; vm_of "$1"; is_name "$2" || refuse "not a conversation name: $2"; is_name "$4" || refuse "not a folder name: $4"; number "$5"; number "$6"
|
|
1128
|
+
[ -f "$DATA/shared/$1" ] && grep -qx "$2" "$DATA/shared/$1" || refuse "$2 does not live in $1"
|
|
1129
|
+
case "$3" in
|
|
1130
|
+
work) [ "$4" = "$2" ] || refuse "a work folder belongs to its own conversation"
|
|
1131
|
+
kept work; source="$MNT/work/$2"; held "$source"
|
|
1132
|
+
[ "$SAY" = "yes" ] || mountpoint -q "$source" || refuse "the work disk of $2 is not in place"
|
|
1133
|
+
target="$1:/srv/clavarium/$2/work" ;;
|
|
1134
|
+
folder) folder_of "$4"; source="$MNT/resources/$4"; target="$1:/srv/clavarium/$2/resources/$4" ;;
|
|
1135
|
+
view) kept views; source="$MNT/views/$4"; held "$source"
|
|
1136
|
+
[ "$SAY" = "yes" ] || mountpoint -q "$source" || refuse "the read-only view of $4 is not in place"
|
|
1137
|
+
target="$1:/srv/clavarium/$2/resources/$4" ;;
|
|
1138
|
+
*) refuse "a shared mount is of a work folder, a folder or a view" ;;
|
|
1139
|
+
esac
|
|
1140
|
+
run "$MULTIPASS" mount -u "$5:$VM_ID" -g "$6:$VM_ID" "$source" "$target" ;;
|
|
1141
|
+
"vm sumount")
|
|
1142
|
+
# <vm> <conversation> <work|resource name>: taken out of its place in a shared machine.
|
|
1143
|
+
[ $# -eq 3 ] || usage; vm_of "$1"; is_name "$2" || refuse "not a conversation name: $2"; is_name "$3" || refuse "not a name: $3"
|
|
1144
|
+
if [ "$3" = "work" ]; then run "$MULTIPASS" umount "$1:/srv/clavarium/$2/work"; else run "$MULTIPASS" umount "$1:/srv/clavarium/$2/resources/$3"; fi ;;
|
|
1109
1145
|
"vm unwork")
|
|
1110
1146
|
# The work folder is taken out of its machine (its work moves to the
|
|
1111
1147
|
# machine's own disk, or a move is undone).
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.400-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.400-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|