clavarium 0.2.30-next.2 → 0.2.30-next.3

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.
@@ -147,8 +147,15 @@ MESH_USER="clavarium-mesh"
147
147
  MESH_UNIT="clavarium-meshcentral"
148
148
  MESH_SETUP_UNIT="clavarium-meshcentral-setup"
149
149
  MESH_PORT="4443"
150
- MESH_PATH="/meshcentral"
150
+ # The path's base. The real path adds a per-instance random suffix (mesh_resolve_path), so the
151
+ # address is stable here but not the same, nor guessable, from one instance to another.
152
+ MESH_PATH_BASE="/meshcentral"
153
+ MESH_PATH="$MESH_PATH_BASE"
151
154
  MESH_VERSION="1.1.35"
155
+ # Modules MeshCentral would otherwise fetch from npm on its first run: installed here, with the
156
+ # network, because the running unit is locked to the loopback and cannot reach npm. Pinned to
157
+ # what MeshCentral 1.1.35 asks for (TOTP two-factor). Revisit if the MeshCentral version moves.
158
+ MESH_MODULES="otplib@10.2.3"
152
159
  # Node and npm: the release's own if it is there (always present on a server), else the system's.
153
160
  MESH_NODE="/opt/clavarium/current/node/bin/node"
154
161
  MESH_NPM="/opt/clavarium/current/node/bin/npm"
@@ -552,6 +559,26 @@ wifi_record() {
552
559
  # ---- THE REMOTE SCREEN (MeshCentral) ----
553
560
  # Installed: the npm tree and a written config are both there. Running: its unit is active.
554
561
  mesh_installed() { [ -f "$MESH_DATA/node_modules/meshcentral/package.json" ] && [ -f "$MESH_DATA/meshcentral-data/config.json" ]; }
562
+ # The path's per-instance random suffix: made once, kept in root's state, reused ever after -- so the
563
+ # address is stable for this server yet not guessable, and differs from one install to the next.
564
+ # Defence in depth, on top of the sign-in and the isolation. In --test a fixed suffix keeps it checkable.
565
+ mesh_resolve_path() {
566
+ if [ -n "$TEST" ]; then MESH_PATH="$MESH_PATH_BASE-test"; return 0; fi
567
+ local f="$MESH_STATE/path" tok=""
568
+ # No "| head" on an endless source: head closing early makes the left side take SIGPIPE, which
569
+ # under pipefail would stop the whole program. od reads a fixed count, so nothing closes early.
570
+ if [ -f "$f" ]; then tok="$(LC_ALL=C tr -cd 'a-z0-9' < "$f" 2>/dev/null)"; tok="${tok:0:16}"; fi
571
+ if ! [[ "$tok" =~ ^[a-z0-9]{8,16}$ ]]; then
572
+ tok="$(od -An -tx1 -N16 /dev/urandom 2>/dev/null | LC_ALL=C tr -cd '0-9a-f')"; tok="${tok:0:12}"
573
+ [[ "$tok" =~ ^[a-z0-9]{8,16}$ ]] || tok="$(date +%s)0"
574
+ # Keep it only on a real run; "say only" invents nothing on disk.
575
+ if [ "$SAY" != yes ]; then
576
+ install -d -m 0700 "$MESH_STATE" 2>/dev/null || true
577
+ { printf '%s' "$tok" > "$f"; } 2>/dev/null && chmod 0600 "$f" 2>/dev/null || true
578
+ fi
579
+ fi
580
+ MESH_PATH="$MESH_PATH_BASE-$tok"
581
+ }
555
582
  mesh_running() { [ -z "$TEST" ] && systemctl is-active --quiet "$MESH_UNIT.service" 2>/dev/null; }
556
583
  # The version as the installed package declares it, or nothing.
557
584
  mesh_version() {
@@ -613,6 +640,10 @@ mesh_write_config() {
613
640
  install -d -m 0750 "$MESH_DATA/meshcentral-data"
614
641
  [ -n "$TEST" ] || chown -R "$MESH_USER:$MESH_USER" "$MESH_DATA/meshcentral-data"
615
642
  [ ! -f "$MESH_DATA/meshcentral-data/config.json" ] || return 0
643
+ # MeshCentral serves under a path through a NAMED domain (its key is the path): a domain keyed
644
+ # "meshcentral" is reached at /meshcentral/. The empty key would serve at the root, which the
645
+ # front has no path for. Derived from MESH_PATH so the two never drift apart.
646
+ local dom="${MESH_PATH#/}"
616
647
  local tmp; tmp="$(mktemp -p "$MESH_DATA/meshcentral-data" .clavarium-mesh.XXXXXX)" || return 1
617
648
  cat > "$tmp" <<MESHCONF
618
649
  {
@@ -628,7 +659,7 @@ mesh_write_config() {
628
659
  "SelfUpdate": false
629
660
  },
630
661
  "domains": {
631
- "": {
662
+ "$dom": {
632
663
  "certUrl": "https://127.0.0.1:$MESH_PORT/"
633
664
  }
634
665
  },
@@ -655,6 +686,9 @@ Wants=network-online.target
655
686
  User=$MESH_USER
656
687
  Group=$MESH_USER
657
688
  WorkingDirectory=$MESH_DATA
689
+ # node's directory on PATH: MeshCentral installs a module or two on first run by spawning npm,
690
+ # whose shebang is \`/usr/bin/env node\`; without this it stalls at "Installing modules".
691
+ Environment=PATH=$(dirname "$node"):/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
658
692
  ExecStart=$node $MESH_DATA/node_modules/meshcentral --datapath $MESH_DATA/meshcentral-data
659
693
  Restart=on-failure
660
694
  RestartSec=5
@@ -666,7 +700,9 @@ PrivateTmp=yes
666
700
  ProtectControlGroups=yes
667
701
  ProtectKernelModules=yes
668
702
  ProtectKernelTunables=yes
669
- RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
703
+ # AF_NETLINK too: Node reads the host's network interfaces (os.networkInterfaces) through it, and
704
+ # MeshCentral lists them at startup; without it the server dies with "uv_interface_addresses ... 97".
705
+ RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
670
706
  RestrictSUIDSGID=yes
671
707
  LockPersonality=yes
672
708
  ReadWritePaths=$MESH_DATA
@@ -683,6 +719,9 @@ MESHUNIT
683
719
  [ $# -ge 2 ] || usage
684
720
  AREA="$1"; VERB="$2"; shift 2
685
721
 
722
+ # The remote screen's path carries a per-instance suffix: resolve it before any of its verbs run.
723
+ [ "$AREA" = meshcentral ] && mesh_resolve_path
724
+
686
725
  case "$AREA $VERB" in
687
726
  "vm launch")
688
727
  [ $# -eq 2 ] || usage; vm_of "$1"; memory_ok "$2"
@@ -1706,8 +1745,10 @@ case "$AREA $VERB" in
1706
1745
  npm="$MESH_NPM"; [ -x "$npm" ] || npm="$(command -v npm || true)"
1707
1746
  [ -n "$npm" ] || refuse "there is no npm on this server to install the remote screen"
1708
1747
  # No secret is printed: npm's own output (and only it) goes to a root-only log.
1709
- if ! HOME="$MESH_DATA" npm_config_cache="$MESH_DATA/.npm" "$npm" install --prefix "$MESH_DATA" \
1710
- --no-save --no-audit --no-fund --omit=dev "meshcentral@$MESH_VERSION" > "$MESH_STATE/install.log" 2>&1; then
1748
+ # npm finds node through PATH (its own shebang is `/usr/bin/env node`), so node's own
1749
+ # directory is put on PATH; without it npm exits at once with "env: node: not found".
1750
+ if ! HOME="$MESH_DATA" npm_config_cache="$MESH_DATA/.npm" PATH="$(dirname "$npm"):$(dirname "$MESH_NODE"):$PATH" "$npm" install --prefix "$MESH_DATA" \
1751
+ --no-save --no-audit --no-fund --omit=dev "meshcentral@$MESH_VERSION" $MESH_MODULES > "$MESH_STATE/install.log" 2>&1; then
1711
1752
  refuse "MeshCentral could not be installed (see $MESH_STATE/install.log on the server)"
1712
1753
  fi
1713
1754
  [ -f "$MESH_DATA/node_modules/meshcentral/package.json" ] || refuse "MeshCentral was not installed as expected"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.30-next.2",
3
+ "version": "0.2.30-next.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.30-next.2",
9
+ "version": "0.2.30-next.3",
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.30-next.2",
3
+ "version": "0.2.30-next.3",
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.",