Files
werewulf/scripts/B10-deploy-hpcod-portal.sh
T
ilker 6876e0c5bd Replace the Warewulf overlay UI with the HPC-on-Demand portal
hpc.example.org now serves the HPC-on-Demand portal, and the overlay UI is
gone - service, code, docs and the API it depended on.

The portal exposes phases 1 and 2 over HTTP: what the estate looks like,
which capabilities are schedulable and which are merely claimed, a dry-run
form, and the curated device map, plus a JSON API. It is entirely read-only
and provisions nothing.

It runs on the Caddy host bound to 127.0.0.1:9880, so the reverse proxy is the
only thing that can reach it - a smaller surface than the overlay UI had,
which listened on the management network. It refuses to bind off loopback
without a user file, for the same reason: the portal knows the shape and spare
capacity of the whole estate and holds read credentials for it. Discovery runs
on a two-minute timer rather than per request, since polling every backing
cloud on each page load would hammer their APIs and make the portal as slow as
its slowest site; pages report the inventory's age instead.

An unauthenticated /v1/ request now returns 401 rather than redirecting to the
login page. Sending a script an HTML form instead of a status code it can act
on is the kind of thing that wastes an afternoon.

Removing the overlay UI also disabled the Warewulf REST API on head01, which
had been enabled solely to serve it. Leaving root-equivalent access switched
on with no consumer would be a liability, so warewulf.conf and auth.conf were
restored from the pre-feature backups and the firewall rule dropped. The
cluster was re-verified afterwards: four nodes idle, an eight-rank MPI job
completing.

Also adds the phase 3 Terraform module for one tenant - isolated bridge, head
node and diskless compute nodes with deterministic MACs, since Warewulf
matches nodes by MAC and a regenerated one would orphan the registration. Not
yet applied against a real site.
2026-09-01 12:24:54 +02:00

104 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# Install the HPC-on-Demand portal on the Caddy host.
#
# It lives here rather than on a tenant head node for two reasons: it must
# reach every backing cloud's API, and binding it to loopback on the same host
# as Caddy means the reverse proxy is the only thing that can reach it at all.
#
# The portal is read-only - discovery and placement. It provisions nothing.
#
# Expects the binary at /tmp/hpcod.
set -euo pipefail
BIN=/usr/local/bin/hpcod
SRC=/tmp/hpcod
ETC=/etc/hpcod
SVCUSER=hpcod
UNIT=/etc/systemd/system/hpcod-portal.service
[ -f "${SRC}" ] || { echo "binary not found at ${SRC}"; exit 1; }
echo "==> service account"
id -u ${SVCUSER} >/dev/null 2>&1 || \
useradd --system --no-create-home --shell /usr/sbin/nologin ${SVCUSER}
echo "==> binary"
install -m 0755 -o root -g root "${SRC}" "${BIN}"
install -d -m 0750 -o root -g ${SVCUSER} "${ETC}"
echo "==> site catalogue"
if [ ! -f "${ETC}/sites.yaml" ]; then
cat > "${ETC}/sites.yaml" <<'EOF'
sites:
- id: hv01
name: Lab cluster
kind: proxmox
settings:
endpoint: https://10.0.0.10:8006
token: env:HV01_TOKEN
insecure_tls: "true"
timeout: 20s
cpu_overcommit: "2.0"
EOF
echo " wrote ${ETC}/sites.yaml"
fi
chown root:${SVCUSER} "${ETC}/sites.yaml"; chmod 0640 "${ETC}/sites.yaml"
echo "==> credentials"
if [ ! -f "${ETC}/env" ]; then
echo "HV01_TOKEN=CHANGE_ME" > "${ETC}/env"
echo " !! edit ${ETC}/env and put the real read-only Proxmox token in it"
fi
chown root:${SVCUSER} "${ETC}/env"; chmod 0640 "${ETC}/env"
echo "==> portal login"
command -v htpasswd >/dev/null || apt-get install -y -qq apache2-utils
if [ ! -f "${ETC}/users" ]; then
PW=$(head -c 40 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' | cut -c1-20)
htpasswd -bBC 12 -c "${ETC}/users" admin "${PW}" >/dev/null 2>&1
printf '\n portal login: admin / %s\n\n' "${PW}"
printf 'UI_USER=admin\nUI_PASS=%s\n' "${PW}" > /root/.hpcod-portal-login
chmod 600 /root/.hpcod-portal-login
echo " (also saved to /root/.hpcod-portal-login)"
fi
chown root:${SVCUSER} "${ETC}/users"; chmod 0640 "${ETC}/users"
echo "==> systemd unit"
cat > "${UNIT}" <<EOF
[Unit]
Description=HPC-on-Demand portal (discovery and placement, read-only)
After=network-online.target
[Service]
Type=simple
User=${SVCUSER}
Group=${SVCUSER}
EnvironmentFile=${ETC}/env
WorkingDirectory=${ETC}
ExecStart=${BIN} serve -listen 127.0.0.1:9880 -c ${ETC}/sites.yaml -users ${ETC}/users -trusted-proxy 127.0.0.1
Restart=on-failure
RestartSec=3
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=strict
ProtectHome=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_INET AF_INET6
RestrictNamespaces=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
SystemCallArchitectures=native
CapabilityBoundingSet=
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable hpcod-portal >/dev/null 2>&1 || true
echo "HPCOD PORTAL INSTALLED (start it once ${ETC}/env has a real token)"