underpost 3.2.9 → 3.2.11

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.
Files changed (104) hide show
  1. package/.github/workflows/npmpkg.ci.yml +1 -0
  2. package/.github/workflows/pwa-microservices-template-test.ci.yml +1 -1
  3. package/.github/workflows/release.cd.yml +1 -0
  4. package/.vscode/extensions.json +9 -9
  5. package/.vscode/settings.json +20 -4
  6. package/CHANGELOG.md +195 -1
  7. package/CLI-HELP.md +92 -23
  8. package/README.md +38 -9
  9. package/bin/build.js +27 -7
  10. package/bin/build.template.js +187 -0
  11. package/bin/deploy.js +12 -2
  12. package/bin/index.js +2 -1
  13. package/bump.config.js +26 -0
  14. package/conf.js +20 -7
  15. package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
  16. package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +1 -1
  17. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  18. package/manifests/deployment/dd-test-development/deployment.yaml +4 -2
  19. package/manifests/kind-config-dev.yaml +8 -0
  20. package/manifests/lxd/lxd-admin-profile.yaml +12 -3
  21. package/manifests/mongodb/pv-pvc.yaml +44 -8
  22. package/manifests/mongodb/statefulset.yaml +55 -68
  23. package/manifests/mongodb-4.4/headless-service.yaml +10 -0
  24. package/manifests/mongodb-4.4/kustomization.yaml +3 -1
  25. package/manifests/mongodb-4.4/mongodb-nodeport.yaml +17 -0
  26. package/manifests/mongodb-4.4/pv-pvc.yaml +10 -14
  27. package/manifests/mongodb-4.4/statefulset.yaml +79 -0
  28. package/manifests/mongodb-4.4/storage-class.yaml +9 -0
  29. package/manifests/valkey/statefulset.yaml +1 -1
  30. package/manifests/valkey/valkey-nodeport.yaml +17 -0
  31. package/package.json +27 -12
  32. package/scripts/ipxe-setup.sh +52 -49
  33. package/scripts/k3s-node-setup.sh +81 -46
  34. package/scripts/lxd-vm-setup.sh +193 -8
  35. package/scripts/maas-nat-firewalld.sh +145 -0
  36. package/src/api/core/core.router.js +19 -14
  37. package/src/api/core/core.service.js +5 -5
  38. package/src/api/default/default.router.js +22 -18
  39. package/src/api/default/default.service.js +5 -5
  40. package/src/api/document/document.router.js +28 -23
  41. package/src/api/document/document.service.js +100 -23
  42. package/src/api/file/file.router.js +19 -13
  43. package/src/api/file/file.service.js +9 -7
  44. package/src/api/test/test.router.js +17 -12
  45. package/src/api/types.js +24 -0
  46. package/src/api/user/guest.service.js +5 -4
  47. package/src/api/user/user.router.js +297 -288
  48. package/src/api/user/user.service.js +100 -35
  49. package/src/cli/baremetal.js +132 -101
  50. package/src/cli/cluster.js +700 -232
  51. package/src/cli/db.js +59 -60
  52. package/src/cli/deploy.js +216 -137
  53. package/src/cli/fs.js +13 -3
  54. package/src/cli/index.js +80 -15
  55. package/src/cli/ipfs.js +4 -6
  56. package/src/cli/kubectl.js +4 -1
  57. package/src/cli/lxd.js +1099 -223
  58. package/src/cli/monitor.js +9 -3
  59. package/src/cli/release.js +334 -140
  60. package/src/cli/repository.js +68 -23
  61. package/src/cli/run.js +191 -47
  62. package/src/cli/secrets.js +11 -2
  63. package/src/cli/test.js +9 -3
  64. package/src/client/Default.index.js +9 -3
  65. package/src/client/components/core/Auth.js +5 -0
  66. package/src/client/components/core/ClientEvents.js +76 -0
  67. package/src/client/components/core/EventBus.js +4 -0
  68. package/src/client/components/core/Modal.js +82 -41
  69. package/src/client/components/core/PanelForm.js +56 -52
  70. package/src/client/components/core/Worker.js +162 -363
  71. package/src/client/sw/core.sw.js +174 -112
  72. package/src/db/DataBaseProvider.js +115 -15
  73. package/src/db/mariadb/MariaDB.js +2 -1
  74. package/src/db/mongo/MongoBootstrap.js +657 -0
  75. package/src/db/mongo/MongooseDB.js +129 -21
  76. package/src/index.js +1 -1
  77. package/src/runtime/express/Express.js +2 -2
  78. package/src/runtime/wp/Wp.js +8 -5
  79. package/src/server/auth.js +2 -2
  80. package/src/server/client-build-docs.js +1 -1
  81. package/src/server/client-build.js +94 -129
  82. package/src/server/conf.js +81 -79
  83. package/src/server/process.js +180 -19
  84. package/src/server/proxy.js +9 -2
  85. package/src/server/runtime.js +1 -1
  86. package/src/server/start.js +16 -4
  87. package/src/server/valkey.js +2 -0
  88. package/src/ws/IoInterface.js +16 -16
  89. package/src/ws/core/channels/core.ws.chat.js +11 -11
  90. package/src/ws/core/channels/core.ws.mailer.js +29 -29
  91. package/src/ws/core/channels/core.ws.stream.js +19 -19
  92. package/src/ws/core/core.ws.connection.js +8 -8
  93. package/src/ws/core/core.ws.server.js +6 -5
  94. package/src/ws/default/channels/default.ws.main.js +10 -10
  95. package/src/ws/default/default.ws.connection.js +4 -4
  96. package/src/ws/default/default.ws.server.js +4 -3
  97. package/bin/file.js +0 -202
  98. package/bin/vs.js +0 -74
  99. package/bin/zed.js +0 -84
  100. package/src/client/ssr/email/DefaultRecoverEmail.js +0 -21
  101. package/src/client/ssr/email/DefaultVerifyEmail.js +0 -17
  102. /package/src/client/ssr/{offline → views}/Maintenance.js +0 -0
  103. /package/src/client/ssr/{offline → views}/NoNetworkConnection.js +0 -0
  104. /package/src/client/ssr/{pages → views}/Test.js +0 -0
@@ -1,39 +1,70 @@
1
1
  #!/bin/bash
2
- set -e
2
+ set -euo pipefail
3
3
 
4
4
  # ---------------------------------------------------------------------------
5
5
  # Underpost K3s Node Setup
6
+ #
7
+ # This script runs INSIDE an LXD VM. It assumes the host has already mirrored
8
+ # the project source into $ENGINE_ROOT (default /home/dd/engine) via the
9
+ # `underpost lxd [vm-id] --vm-init` flow in `src/cli/lxd.js`. There is no
10
+ # fallback to a globally installed `underpost`: every operational command
11
+ # resolves from the local project so the latest local changes are always what
12
+ # runs in the VM.
13
+ #
6
14
  # Usage:
7
- # --control Initialize as K3s control plane node (default)
8
- # --worker Initialize as K3s worker node
9
- # --control-ip=<ip> Control plane IP (required for --worker)
10
- # --token=<token> K3s node token (required for --worker)
15
+ # --engine-root=<path> Path to the mirrored engine source (default: /home/dd/engine)
16
+ # --control Initialize as K3s control plane node (default)
17
+ # --worker Initialize as K3s worker node
18
+ # --control-ip=<ip> Control plane IP (required for --worker)
19
+ # --token=<token> K3s node token (required for --worker)
11
20
  # ---------------------------------------------------------------------------
12
21
 
13
22
  ROLE="control"
14
23
  CONTROL_IP=""
15
24
  K3S_TOKEN=""
25
+ ENGINE_ROOT="/home/dd/engine"
16
26
 
17
27
  for arg in "$@"; do
18
- case $arg in
19
- --worker) ROLE="worker" ;;
20
- --control) ROLE="control" ;;
21
- --control-ip=*) CONTROL_IP="${arg#*=}" ;;
22
- --token=*) K3S_TOKEN="${arg#*=}" ;;
23
- esac
28
+ case $arg in
29
+ --worker) ROLE="worker" ;;
30
+ --control) ROLE="control" ;;
31
+ --control-ip=*) CONTROL_IP="${arg#*=}" ;;
32
+ --token=*) K3S_TOKEN="${arg#*=}" ;;
33
+ --engine-root=*) ENGINE_ROOT="${arg#*=}" ;;
34
+ esac
24
35
  done
36
+
37
+ # Fail fast if the bootstrap step did not run / left the directory empty.
38
+ # Split into two checks so `ls -A` only runs against a path that exists; this
39
+ # avoids needing an error-swallowing redirect.
40
+ if [ ! -d "$ENGINE_ROOT" ]; then
41
+ echo "ERROR: engine source directory $ENGINE_ROOT does not exist."
42
+ echo "The LXD [vm-id] --vm-init flow must mirror the project here before running this script."
43
+ exit 1
44
+ fi
45
+ if [ -z "$(ls -A "$ENGINE_ROOT")" ]; then
46
+ echo "ERROR: engine source directory $ENGINE_ROOT is empty."
47
+ echo "The LXD [vm-id] --vm-init flow must mirror the project here before running this script."
48
+ exit 1
49
+ fi
50
+
25
51
  # ---------------------------------------------------------------------------
26
- # NVM and Node.js
52
+ # NVM and Node.js — required for `node bin ...` entrypoints
27
53
  # ---------------------------------------------------------------------------
28
- echo "Installing NVM and Node.js v24.10.0..."
54
+ echo "Installing NVM and Node.js v24.15.0..."
29
55
 
30
56
  curl -o- https://cdn.jsdelivr.net/gh/nvm-sh/nvm@v0.40.1/install.sh | bash
31
57
 
32
58
  export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
59
+ # shellcheck disable=SC1090
33
60
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
34
61
 
35
62
  nvm install 24.15.0
36
63
  nvm use 24.15.0
64
+ nvm alias default 24.15.0
65
+ ln -sf "$(command -v node)" /usr/local/bin/node
66
+ ln -sf "$(command -v npm)" /usr/local/bin/npm
67
+ ln -sf "$(command -v npx)" /usr/local/bin/npx
37
68
 
38
69
  echo "
39
70
  ██╗░░░██╗███╗░░██╗██████╗░███████╗██████╗░██████╗░░█████╗░░██████╗████████╗
@@ -43,47 +74,51 @@ echo "
43
74
  ╚██████╔╝██║░╚███║██████╔╝███████╗██║░░██║██║░░░░░╚█████╔╝██████╔╝░░░██║░░░
44
75
  ░╚═════╝░╚═╝░░╚══╝╚═════╝░╚══════╝╚═╝░░╚═╝╚═╝░░░░░░╚════╝░╚═════╝░░░░╚═╝░░░
45
76
 
46
- Installing underpost VM node...
77
+ Bringing up underpost VM node from $ENGINE_ROOT (role=$ROLE)
47
78
  "
48
79
 
49
- npm install -g underpost
50
-
51
- cd /home/dd/engine
52
-
53
- echo "Applying host configuration..."
80
+ cd "$ENGINE_ROOT"
54
81
 
82
+ # Install JS deps and generate secrets using the local engine entrypoint only.
55
83
  npm install
56
-
57
84
  node bin run secret
58
85
 
59
- node bin cluster --dev --config
60
-
61
86
  if [ "$ROLE" = "control" ]; then
62
- echo "Initializing K3s control plane..."
63
- node bin cluster --dev --k3s
64
-
65
- echo ""
66
- echo "K3s control plane is ready."
67
- echo "Node token (share with workers to join this cluster):"
68
- sudo cat /var/lib/rancher/k3s/server/node-token
69
- echo ""
70
- echo "Control plane IP addresses:"
71
- ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d/ -f1
72
-
73
- elif [ "$ROLE" = "worker" ]; then
74
- if [ -z "$CONTROL_IP" ] || [ -z "$K3S_TOKEN" ]; then
75
- echo "ERROR: --control-ip and --token are required for worker role."
76
- echo "Usage: bash k3s-node-setup.sh --worker --control-ip=<ip> --token=<token>"
77
- exit 1
78
- fi
79
-
80
- echo "Joining K3s cluster at https://${CONTROL_IP}:6443..."
81
- curl -sfL https://get.k3s.io | \
87
+ echo "Installing underpost CLI..."
88
+ npm install -g underpost
89
+ underpost --version
90
+ echo "Initializing K3s control plane via local engine..."
91
+ node bin cluster --dev --k3s
92
+ ln -s /usr/local/bin/k3s /bin/k3s
93
+ ln -s /usr/local/bin/kubectl /bin/kubectl
94
+
95
+ echo ""
96
+ echo "K3s control plane is ready."
97
+ echo "Node token (share with workers to join this cluster):"
98
+ sudo cat /var/lib/rancher/k3s/server/node-token
99
+ echo ""
100
+ echo "Control plane IP addresses:"
101
+ ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d/ -f1
102
+
103
+ elif [ "$ROLE" = "worker" ]; then
104
+ if [ -z "$CONTROL_IP" ] || [ -z "$K3S_TOKEN" ]; then
105
+ echo "ERROR: --control-ip and --token are required for worker role."
106
+ echo "Usage: bash k3s-node-setup.sh --worker --control-ip=<ip> --token=<token>"
107
+ exit 1
108
+ fi
109
+
110
+ # Worker nodes still need the minimal K3s host prep even though they join via
111
+ # the upstream installer rather than `node bin cluster --k3s`.
112
+ echo "Applying minimal K3s host configuration via local engine..."
113
+ node bin cluster --dev --config --k3s
114
+
115
+ echo "Joining K3s cluster at https://${CONTROL_IP}:6443..."
116
+ curl -sfL https://get.k3s.io | \
82
117
  K3S_URL="https://${CONTROL_IP}:6443" \
83
118
  K3S_TOKEN="${K3S_TOKEN}" \
84
119
  sh -s - agent
85
-
86
- echo ""
87
- echo "K3s worker node joined the cluster at https://${CONTROL_IP}:6443 successfully."
88
- sudo systemctl status k3s-agent --no-pager
120
+
121
+ echo ""
122
+ echo "K3s worker joined https://${CONTROL_IP}:6443 successfully."
123
+ sudo systemctl status k3s-agent --no-pager
89
124
  fi
@@ -1,23 +1,208 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
1
3
 
2
- echo "Expanding /dev/sda2 and resizing filesystem..."
4
+ # ---------------------------------------------------------------------------
5
+ # LXD VM OS base setup. Runs inside the VM via `lxc exec`. Idempotent.
6
+ # ---------------------------------------------------------------------------
3
7
 
4
- if ! command -v parted &>/dev/null; then
5
- sudo dnf install -y parted
8
+ # lxdbr0 is a plain L2 bridge: LXD runs no DHCP/DNS on it (MAAS owns
9
+ # provisioning), so VMs configure their NIC statically and deterministically.
10
+ # The host pins the gateway (10.250.250.1) on the bridge and provides NAT; no
11
+ # resolver listens there, so DNS must use public/MAAS resolvers, not the gateway.
12
+ # LXD_NET_MODE=dhcp opts back into DHCP-first for VMs on a MAAS-served segment.
13
+ LXD_NET_MODE="${LXD_NET_MODE:-static}"
14
+ LXD_FALLBACK_IPV4_CIDR="${LXD_FALLBACK_IPV4_CIDR:-10.250.250.100/24}"
15
+ LXD_FALLBACK_GATEWAY="${LXD_FALLBACK_GATEWAY:-10.250.250.1}"
16
+ LXD_FALLBACK_DNS="${LXD_FALLBACK_DNS:-1.1.1.1 8.8.8.8}"
17
+ ROCKY_MIRROR_HOST="${ROCKY_MIRROR_HOST:-mirrors.rockylinux.org}"
18
+
19
+ current_ipv4() {
20
+ ip -4 addr show "$IFACE" | awk '/inet /{print $2; exit}'
21
+ }
22
+
23
+ wait_for_ipv4() {
24
+ local current_ip=""
25
+
26
+ for _ in $(seq 1 10); do
27
+ current_ip="$(current_ipv4)"
28
+ if [ -n "$current_ip" ]; then
29
+ echo "$current_ip"
30
+ return 0
31
+ fi
32
+ sleep 1
33
+ done
34
+
35
+ return 1
36
+ }
37
+
38
+ refresh_resolver_state() {
39
+ if command -v resolvectl >/dev/null 2>&1; then
40
+ sudo resolvectl flush-caches || true
41
+ fi
42
+
43
+ if [ -f /run/NetworkManager/resolv.conf ]; then
44
+ sudo ln -sf /run/NetworkManager/resolv.conf /etc/resolv.conf || true
45
+ fi
46
+ }
47
+
48
+ verify_name_resolution() {
49
+ getent ahostsv4 "$ROCKY_MIRROR_HOST" >/dev/null 2>&1
50
+ }
51
+
52
+ retry_dnf() {
53
+ local attempt=1
54
+ local max_attempts=3
55
+
56
+ until "$@"; do
57
+ if [ "$attempt" -ge "$max_attempts" ]; then
58
+ return 1
59
+ fi
60
+
61
+ echo "DNF command failed (attempt $attempt/$max_attempts): $*"
62
+ echo "Refreshing resolver state before retry..."
63
+ refresh_resolver_state
64
+ verify_name_resolution || true
65
+ attempt=$((attempt + 1))
66
+ done
67
+ }
68
+
69
+ # k3s derives the node name from the system hostname. The Rocky image keeps
70
+ # "localhost.localdomain" for every VM, so without this every node would try to
71
+ # register under the same name — the second one is rejected ("Node password
72
+ # rejected, duplicate hostname"). Pin the hostname to the LXD instance name so
73
+ # node names are unique and deterministic (control plane labeling relies on it).
74
+ if [ -n "${LXD_NODE_NAME:-}" ] && [ "$(hostname)" != "$LXD_NODE_NAME" ]; then
75
+ echo "--- Hostname ---"
76
+ echo "Setting hostname to ${LXD_NODE_NAME} (k3s node name)..."
77
+ sudo hostnamectl set-hostname "$LXD_NODE_NAME" 2>/dev/null || sudo hostname "$LXD_NODE_NAME"
78
+ fi
79
+
80
+ echo "--- Network Configuration ---"
81
+
82
+ # 1. Detect primary non-loopback interface
83
+ IFACE=$(ip -o link show up | awk -F': ' '$2!="lo"{print $2; exit}')
84
+ echo "Using network interface: ${IFACE:-none}"
85
+
86
+ if [ -z "$IFACE" ]; then
87
+ echo "CRITICAL ERROR: No network interface detected."
88
+ exit 1
89
+ fi
90
+
91
+ # 2. Force NetworkManager initialization if interface lacks an IP address
92
+ CURRENT_IP="$(current_ipv4 || true)"
93
+
94
+ if command -v nmcli >/dev/null 2>&1 && [ -z "$CURRENT_IP" ]; then
95
+ echo "Inspecting NetworkManager profiles..."
96
+
97
+ # Check if a profile is tracking this device
98
+ NM_CON=$(nmcli -t -f NAME,DEVICE connection show | awk -F: -v iface="$IFACE" '$2==iface{print $1; exit}')
99
+
100
+ if [ -z "$NM_CON" ]; then
101
+ echo "No connection profile matches $IFACE. Forcing generation of profile 'k3s-net'..."
102
+ nmcli connection add type ethernet con-name k3s-net ifname "$IFACE"
103
+ NM_CON="k3s-net"
104
+ fi
105
+
106
+ apply_static_ipv4() {
107
+ echo "Applying static LXD bridge address ${LXD_FALLBACK_IPV4_CIDR} (gw ${LXD_FALLBACK_GATEWAY}, dns ${LXD_FALLBACK_DNS})..."
108
+ nmcli connection modify "$NM_CON" \
109
+ connection.autoconnect yes \
110
+ connection.interface-name "$IFACE" \
111
+ ipv4.method manual \
112
+ ipv4.addresses "$LXD_FALLBACK_IPV4_CIDR" \
113
+ ipv4.gateway "$LXD_FALLBACK_GATEWAY" \
114
+ ipv4.dns "$LXD_FALLBACK_DNS" \
115
+ ipv4.ignore-auto-dns yes \
116
+ ipv6.method ignore
117
+ nmcli connection up "$NM_CON"
118
+ CURRENT_IP="$(wait_for_ipv4 || true)"
119
+ }
120
+
121
+ # Static-first: lxdbr0 has no DHCP, so a DHCP attempt only adds a ~45s
122
+ # activation timeout per boot. DHCP is opt-in for VMs on a MAAS-served
123
+ # segment (LXD_NET_MODE=dhcp), with a static fallback if no lease appears.
124
+ if [ "$LXD_NET_MODE" = "dhcp" ]; then
125
+ echo "Configuring DHCP-first NetworkManager profile '$NM_CON'..."
126
+ nmcli connection modify "$NM_CON" \
127
+ connection.autoconnect yes \
128
+ connection.interface-name "$IFACE" \
129
+ ipv4.method auto \
130
+ ipv4.dhcp-client-id mac \
131
+ ipv4.ignore-auto-dns no \
132
+ ipv6.method ignore
133
+ echo "Bringing network interface up with DHCP..."
134
+ nmcli connection up "$NM_CON" || echo "DHCP activation failed; static fallback will be applied."
135
+ CURRENT_IP="$(wait_for_ipv4 || true)"
136
+ if [ -z "$CURRENT_IP" ]; then
137
+ echo "No DHCP lease on $IFACE."
138
+ apply_static_ipv4
139
+ fi
140
+ else
141
+ echo "Configuring static NetworkManager profile '$NM_CON' for the plain LXD bridge..."
142
+ apply_static_ipv4
143
+ fi
144
+ fi
145
+
146
+ # 3. Give the network interface a short window to settle and lease an IP address
147
+ echo "Waiting for IP address allocation..."
148
+ CURRENT_IP="${CURRENT_IP:-$(wait_for_ipv4 || true)}"
149
+ if [ -n "$CURRENT_IP" ]; then
150
+ echo "Interface $IFACE successfully initialized with IP: $CURRENT_IP"
151
+ fi
152
+
153
+ # 4. Verify DNS and outbound connectivity before proceeding (Fail Closed)
154
+ echo "Verifying internet and DNS connectivity..."
155
+ refresh_resolver_state
156
+ if ! verify_name_resolution; then
157
+ echo "CRITICAL ERROR: DNS lookup failed for $ROCKY_MIRROR_HOST. Diagnostic snapshot:"
158
+ echo "=== /etc/resolv.conf ==="
159
+ cat /etc/resolv.conf || true
160
+ echo "=== Interface State ==="
161
+ ip -4 addr show "$IFACE" || true
162
+ echo "=== Routing Table ==="
163
+ ip route show || true
164
+ echo "=== NetworkManager Status ==="
165
+ nmcli device status || true
166
+ exit 1
167
+ fi
168
+
169
+ if ! timeout 15 curl -fsSL --max-time 10 "https://${ROCKY_MIRROR_HOST}" -o /dev/null; then
170
+ echo "CRITICAL ERROR: Network/DNS remains unreachable. Diagnostic snapshot:"
171
+ echo "=== /etc/resolv.conf ==="
172
+ cat /etc/resolv.conf || true
173
+ echo "=== Interface State ==="
174
+ ip -4 addr show "$IFACE" || true
175
+ echo "=== Routing Table ==="
176
+ ip route show || true
177
+ echo "=== NetworkManager Status ==="
178
+ nmcli device status || true
179
+ exit 1
6
180
  fi
7
181
 
182
+ echo "--- Disk Resizing ---"
183
+ if ! command -v parted >/dev/null 2>&1; then
184
+ sudo dnf install -y parted
185
+ fi
186
+
187
+ set +e
8
188
  sudo parted /dev/sda ---pretend-input-tty <<EOF
9
189
  unit s
10
190
  resizepart 2 100%
11
191
  Yes
12
192
  quit
13
193
  EOF
194
+ set -e
14
195
 
15
196
  sudo resize2fs /dev/sda2
16
- echo "Disk resized."
197
+ echo "Disk partition and filesystem resized successfully."
17
198
 
18
- echo "Installing essential packages..."
19
- sudo dnf install -y tar bzip2 git curl jq epel-release
20
- sudo dnf -y update
199
+ echo "--- Package Installation ---"
200
+ retry_dnf sudo dnf install -y epel-release
201
+ retry_dnf sudo dnf install -y tar bzip2 git curl jq
202
+ retry_dnf sudo dnf -y update
21
203
 
22
- echo "Loading br_netfilter module..."
204
+ echo "--- Kernel Modules for K3s ---"
23
205
  sudo modprobe br_netfilter
206
+ echo "br_netfilter" | sudo tee /etc/modules-load.d/k3s-br_netfilter.conf > /dev/null
207
+
208
+ echo "Setup complete. System is ready for k3s-node-setup.sh"
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # MAAS NAT + firewall helper
5
+ # - Enables IPv4 forwarding and masquerading for the MAAS/provisioning subnet
6
+ # - Opens the MAAS API on the uplink zone when requested
7
+ # - Opens provisioning and optional NFS services on the zone bound to MAAS_LAN_CIDR
8
+ #
9
+ # Usage examples:
10
+ # sudo MAAS_LAN_CIDR="192.168.1.0/24" PUBLIC_ZONE="public" ./maas-nat-firewalld.sh
11
+ # sudo NFS_MODE="v3" CONFIGURE_NFS_V3_PORTS="true" ./maas-nat-firewalld.sh
12
+
13
+ MAAS_LAN_CIDR="${MAAS_LAN_CIDR:-192.168.1.0/24}"
14
+ PUBLIC_ZONE="${PUBLIC_ZONE:-public}"
15
+ TRUSTED_ZONE="${TRUSTED_ZONE:-trusted}"
16
+ NFS_MODE="${NFS_MODE:-v4}" # v4 or v3
17
+ CONFIGURE_NFS_V3_PORTS="${CONFIGURE_NFS_V3_PORTS:-false}"
18
+ EXPOSE_MAAS_API_PUBLIC="${EXPOSE_MAAS_API_PUBLIC:-true}"
19
+
20
+ # Fixed NFSv3 ports (only used when CONFIGURE_NFS_V3_PORTS=true)
21
+ NFS_MOUNTD_PORT="${NFS_MOUNTD_PORT:-20048}"
22
+ NFS_STATD_PORT="${NFS_STATD_PORT:-32765}"
23
+ # Outgoing port must differ from the listen port; rpc.statd exits 255 if they match.
24
+ NFS_STATD_OUTGOING_PORT="${NFS_STATD_OUTGOING_PORT:-32766}"
25
+ NFS_LOCKD_PORT="${NFS_LOCKD_PORT:-32803}"
26
+ NFS_LOCKD_UDP_PORT="${NFS_LOCKD_UDP_PORT:-${NFS_LOCKD_PORT}}"
27
+ NFS_CONF_DROPIN="/etc/nfs.conf.d/99-maas-nfs-v3-ports.conf"
28
+
29
+ case "${NFS_MODE}" in
30
+ v3|v4) ;;
31
+ *)
32
+ echo "[ERROR] NFS_MODE must be 'v3' or 'v4'." >&2
33
+ exit 1
34
+ ;;
35
+ esac
36
+
37
+ # Ensure the kernel NFS server is enabled and actually running. `exportfs -rav` only populates the
38
+ # export table; it does not start nfsd, and `systemctl try-restart` is a no-op when the unit is
39
+ # stopped. Without this, clients hang on mount because nothing listens on 2049/mountd.
40
+ ensure_nfs_server_running() {
41
+ if [[ "${NFS_MODE}" == "v3" ]]; then
42
+ # NFSv3 depends on the portmapper and the status monitor.
43
+ sudo systemctl enable --now rpcbind 2>/dev/null || true
44
+ sudo systemctl enable --now rpc-statd 2>/dev/null || true
45
+ fi
46
+
47
+ local unit=""
48
+ for candidate in nfs-server nfs-kernel-server; do
49
+ if systemctl cat "${candidate}.service" >/dev/null 2>&1; then
50
+ unit="${candidate}"
51
+ break
52
+ fi
53
+ done
54
+ if [[ -z "${unit}" ]]; then
55
+ echo "[ERROR] No NFS server unit found (nfs-server/nfs-kernel-server). Install nfs-utils or nfs-kernel-server." >&2
56
+ return 1
57
+ fi
58
+
59
+ echo "[INFO] Enabling and (re)starting ${unit} to apply exports and fixed ports..."
60
+ sudo systemctl enable "${unit}" 2>/dev/null || true
61
+ sudo systemctl restart "${unit}"
62
+ }
63
+
64
+ echo "[INFO] Enabling firewalld..."
65
+ sudo systemctl enable --now firewalld
66
+
67
+ echo "[INFO] Enabling kernel forwarding..."
68
+ sudo tee /etc/sysctl.d/99-maas-nat.conf >/dev/null <<'EOF'
69
+ net.ipv4.ip_forward = 1
70
+ EOF
71
+
72
+ sudo sysctl --system >/dev/null
73
+
74
+ echo "[INFO] Allowing NAT for the MAAS LAN..."
75
+ sudo firewall-cmd --permanent --zone="${PUBLIC_ZONE}" --add-masquerade
76
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-source="${MAAS_LAN_CIDR}"
77
+
78
+ echo "[INFO] Opening MAAS services on the MAAS LAN zone..."
79
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port=5240/tcp
80
+ for service in dns dhcp tftp; do
81
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-service="${service}"
82
+ done
83
+
84
+ if [[ "${EXPOSE_MAAS_API_PUBLIC}" == "true" ]]; then
85
+ echo "[INFO] Opening MAAS API on the uplink zone..."
86
+ sudo firewall-cmd --permanent --zone="${PUBLIC_ZONE}" --add-port=5240/tcp
87
+ fi
88
+
89
+ echo "[INFO] Opening NFS ports on the MAAS LAN zone..."
90
+
91
+ if [[ "${NFS_MODE}" == "v4" ]]; then
92
+ # NFSv4 normally needs only TCP 2049.
93
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port=2049/tcp
94
+ else
95
+ # NFSv3 side-band daemons need fixed ports for deterministic firewall rules.
96
+ if [[ "${CONFIGURE_NFS_V3_PORTS}" != "true" ]]; then
97
+ echo "[ERROR] NFSv3 requires CONFIGURE_NFS_V3_PORTS=true for consistent firewalld rules." >&2
98
+ echo "[ERROR] Re-run with CONFIGURE_NFS_V3_PORTS=true or switch to NFS_MODE=v4." >&2
99
+ exit 1
100
+ fi
101
+
102
+ echo "[INFO] Writing fixed NFSv3 port configuration..."
103
+ sudo install -d -m 0755 /etc/nfs.conf.d
104
+ sudo tee "${NFS_CONF_DROPIN}" >/dev/null <<EOF
105
+ [nfsd]
106
+ vers3=y
107
+
108
+ [mountd]
109
+ port=${NFS_MOUNTD_PORT}
110
+
111
+ [statd]
112
+ port=${NFS_STATD_PORT}
113
+ outgoing-port=${NFS_STATD_OUTGOING_PORT}
114
+
115
+ [lockd]
116
+ port=${NFS_LOCKD_PORT}
117
+ udp-port=${NFS_LOCKD_UDP_PORT}
118
+ EOF
119
+
120
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-service=rpc-bind
121
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port=2049/tcp
122
+ for proto in tcp udp; do
123
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port="${NFS_MOUNTD_PORT}/${proto}"
124
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port="${NFS_STATD_PORT}/${proto}"
125
+ # Outgoing port is the fixed source for SM_NOTIFY; peers need to reach it.
126
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port="${NFS_STATD_OUTGOING_PORT}/${proto}"
127
+ done
128
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port="${NFS_LOCKD_PORT}/tcp"
129
+ sudo firewall-cmd --permanent --zone="${TRUSTED_ZONE}" --add-port="${NFS_LOCKD_UDP_PORT}/udp"
130
+ fi
131
+
132
+ ensure_nfs_server_running
133
+
134
+ echo "[INFO] Reloading firewall..."
135
+ sudo firewall-cmd --reload
136
+
137
+ echo
138
+ echo "[INFO] Firewall status:"
139
+ sudo firewall-cmd --zone="${PUBLIC_ZONE}" --list-all
140
+ echo
141
+ echo "[INFO] MAAS LAN zone (${TRUSTED_ZONE}):"
142
+ sudo firewall-cmd --zone="${TRUSTED_ZONE}" --list-all
143
+
144
+ echo
145
+ echo "[INFO] MAAS NAT + firewall configuration completed."
@@ -5,20 +5,25 @@ import express from 'express';
5
5
 
6
6
  const logger = loggerFactory(import.meta);
7
7
 
8
- const CoreRouter = (options) => {
9
- const router = express.Router();
10
- const authMiddleware = options.authMiddleware;
11
- router.post(`/:id`, authMiddleware, adminGuard, async (req, res) => await CoreController.post(req, res, options));
12
- router.post(`/`, authMiddleware, adminGuard, async (req, res) => await CoreController.post(req, res, options));
13
- router.get(`/:id`, authMiddleware, adminGuard, async (req, res) => await CoreController.get(req, res, options));
14
- router.get(`/`, authMiddleware, adminGuard, async (req, res) => await CoreController.get(req, res, options));
15
- router.put(`/:id`, authMiddleware, adminGuard, async (req, res) => await CoreController.put(req, res, options));
16
- router.put(`/`, authMiddleware, adminGuard, async (req, res) => await CoreController.put(req, res, options));
17
- router.delete(`/:id`, authMiddleware, adminGuard, async (req, res) => await CoreController.delete(req, res, options));
18
- router.delete(`/`, authMiddleware, adminGuard, async (req, res) => await CoreController.delete(req, res, options));
19
- return router;
20
- };
8
+ class CoreRouter {
9
+ /**
10
+ * @param {import('../types.js').RouterOptions} options
11
+ * @returns {import('express').Router}
12
+ */
13
+ static router(options) {
14
+ const router = express.Router();
15
+ router.post(`/:id`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.post(req, res, options));
16
+ router.post(`/`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.post(req, res, options));
17
+ router.get(`/:id`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.get(req, res, options));
18
+ router.get(`/`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.get(req, res, options));
19
+ router.put(`/:id`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.put(req, res, options));
20
+ router.put(`/`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.put(req, res, options));
21
+ router.delete(`/:id`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.delete(req, res, options));
22
+ router.delete(`/`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.delete(req, res, options));
23
+ return router;
24
+ }
25
+ }
21
26
 
22
- const ApiRouter = CoreRouter;
27
+ const ApiRouter = (options) => CoreRouter.router(options);
23
28
 
24
29
  export { ApiRouter, CoreRouter };
@@ -1,4 +1,4 @@
1
- import { DataBaseProvider } from '../../db/DataBaseProvider.js';
1
+ import { DataBaseProviderService } from '../../db/DataBaseProvider.js';
2
2
  import { loggerFactory } from '../../server/logger.js';
3
3
  import { shellExec } from '../../server/process.js';
4
4
 
@@ -7,22 +7,22 @@ const logger = loggerFactory(import.meta);
7
7
  class CoreService {
8
8
  static post = async (req, res, options) => {
9
9
  /** @type {import('./core.model.js').CoreModel} */
10
- const Core = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Core;
10
+ const Core = DataBaseProviderService.getModel("Core", options);
11
11
  return await new Core(req.body).save();
12
12
  };
13
13
  static get = async (req, res, options) => {
14
14
  /** @type {import('./core.model.js').CoreModel} */
15
- const Core = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Core;
15
+ const Core = DataBaseProviderService.getModel("Core", options);
16
16
  return await Core.findById(req.params.id);
17
17
  };
18
18
  static put = async (req, res, options) => {
19
19
  /** @type {import('./core.model.js').CoreModel} */
20
- const Core = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Core;
20
+ const Core = DataBaseProviderService.getModel("Core", options);
21
21
  return await Core.findByIdAndUpdate(req.params.id, req.body);
22
22
  };
23
23
  static delete = async (req, res, options) => {
24
24
  /** @type {import('./core.model.js').CoreModel} */
25
- const Core = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Core;
25
+ const Core = DataBaseProviderService.getModel("Core", options);
26
26
  return await Core.findByIdAndDelete(req.params.id);
27
27
  };
28
28
  }
@@ -4,24 +4,28 @@ import express from 'express';
4
4
 
5
5
  const logger = loggerFactory(import.meta);
6
6
 
7
- const DefaultRouter = (options) => {
8
- const router = express.Router();
9
- const authMiddleware = options.authMiddleware;
10
- router.post(`/:id`, async (req, res) => await DefaultController.post(req, res, options));
11
- router.post(`/`, async (req, res) => await DefaultController.post(req, res, options));
12
- router.get(
13
- `/:id`,
14
- // authMiddleware,
15
- async (req, res) => await DefaultController.get(req, res, options),
16
- );
17
- router.get(`/`, async (req, res) => await DefaultController.get(req, res, options));
18
- router.put(`/:id`, async (req, res) => await DefaultController.put(req, res, options));
19
- router.put(`/`, async (req, res) => await DefaultController.put(req, res, options));
20
- router.delete(`/:id`, async (req, res) => await DefaultController.delete(req, res, options));
21
- router.delete(`/`, async (req, res) => await DefaultController.delete(req, res, options));
22
- return router;
23
- };
7
+ class DefaultRouter {
8
+ /**
9
+ * @param {import('../types.js').RouterOptions} options
10
+ * @returns {import('express').Router}
11
+ */
12
+ static router(options) {
13
+ const router = express.Router();
14
+ router.post(`/:id`, async (req, res) => await DefaultController.post(req, res, options));
15
+ router.post(`/`, async (req, res) => await DefaultController.post(req, res, options));
16
+ router.get(`/:id`,
17
+ // options.authMiddleware,
18
+ async (req, res) => await DefaultController.get(req, res, options),
19
+ );
20
+ router.get(`/`, async (req, res) => await DefaultController.get(req, res, options));
21
+ router.put(`/:id`, async (req, res) => await DefaultController.put(req, res, options));
22
+ router.put(`/`, async (req, res) => await DefaultController.put(req, res, options));
23
+ router.delete(`/:id`, async (req, res) => await DefaultController.delete(req, res, options));
24
+ router.delete(`/`, async (req, res) => await DefaultController.delete(req, res, options));
25
+ return router;
26
+ }
27
+ }
24
28
 
25
- const ApiRouter = DefaultRouter;
29
+ const ApiRouter = (options) => DefaultRouter.router(options);
26
30
 
27
31
  export { ApiRouter, DefaultRouter };