build-prerelease / Resolve version stamps + change detection (push) Successful in 20s
build-prerelease / Build cortex binary (push) Skipped
build-prerelease / Build helexa-bench binary (push) Skipped
build-prerelease / Build helexa-upstream binary (push) Skipped
build-prerelease / Build helexa-router binary (push) Skipped
build-prerelease / Build helexa-tools binary (push) Skipped
build-prerelease / Build neuron-blackwell (push) Skipped
build-prerelease / Build neuron-ampere (push) Skipped
build-prerelease / Build neuron-ada (push) Skipped
build-prerelease / Package cortex RPM (push) Skipped
build-prerelease / Package helexa-bench RPM (push) Skipped
build-prerelease / Package helexa-upstream RPM (push) Skipped
build-prerelease / Package helexa-router RPM (push) Skipped
build-prerelease / Package helexa-tools RPM (push) Skipped
build-prerelease / Package helexa-neuron-ada RPM (push) Skipped
build-prerelease / Package helexa-neuron-ampere RPM (push) Skipped
build-prerelease / Package helexa-neuron-blackwell RPM (push) Skipped
build-prerelease / Lint (fmt + clippy) (push) Successful in 2m43s
build-prerelease / Build helexa-angels binary (push) Successful in 2m58s
build-prerelease / Package helexa-angels RPM (push) Successful in 27s
build-prerelease / Test (push) Successful in 13m27s
build-prerelease / Publish to rpm.lair.cafe (unstable) (push) Successful in 15s
Descriptions of the site firewalls, edge hairpin behaviour, where monitoring admin credentials live, operator host access, and the real mail-relay mailbox now live in a private repository. Each public passage keeps the operational instruction (use the internal vhosts from inside the mesh; import the dashboard via the Grafana API) and points there. Hostnames, addresses and the functional deploy configuration are unchanged. The example angels config uses a placeholder SMTP URL. nginx and infra-setup.sh changes are comments only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VtaCXFAY23HmwX5Cyc6jhC
781 lines
37 KiB
Bash
Executable File
781 lines
37 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# One-time setup for the gitea_ci deploy-user on every host that the
|
|
# .gitea/workflows/deploy.yml workflow targets:
|
|
# - create the gitea_ci system user (if missing)
|
|
# - install the runner's pubkey into ~gitea_ci/.ssh/authorized_keys
|
|
# - install the appropriate /etc/sudoers.d/helexa_gitea_ci sudoers
|
|
# drop-in (cortex flavour on the gateway, neuron flavour on each
|
|
# neuron host)
|
|
#
|
|
# Idempotent — safe to re-run after fleet changes. Continues past
|
|
# unreachable hosts so a single offline node doesn't block the rest.
|
|
|
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
repo_path="$(cd "${script_dir}/.." && pwd)"
|
|
|
|
cortex_host=hanzalova.internal
|
|
neuron_hosts=(
|
|
beast.hanzalova.internal
|
|
benjy.hanzalova.internal
|
|
quadbrat.hanzalova.internal
|
|
)
|
|
# Bench host: runs helexa-bench (outbound-only; polls the neuron fleet).
|
|
# Also runs Agent Zero — it's a client host, not a GPU node.
|
|
bench_host=bob.hanzalova.internal
|
|
|
|
pubkey="${HOME}/.ssh/id_gitea_ci.pub"
|
|
if [[ ! -f "${pubkey}" ]]; then
|
|
echo "fatal: ${pubkey} not found" >&2
|
|
echo " copy ~/.ssh/id_gitea_ci{,.pub} from the operator workstation (roosta)." >&2
|
|
echo " Do NOT generate a new key: every project's RSYNC_SSH_KEY secret and every" >&2
|
|
echo " host's gitea_ci authorized_keys carry this one shared key — a fresh key" >&2
|
|
echo " silently breaks all other projects' deploys." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Provision gitea_ci on every host (cortex + all neurons).
|
|
#
|
|
# Quoting matters here: "${cortex_host} ${neuron_hosts[@]}" inside a
|
|
# single pair of quotes collapses the scalar and the first array
|
|
# element into one space-joined word, which then word-splits when
|
|
# referenced unquoted in `ssh ${host}` — and ssh interprets the second
|
|
# hostname as the remote command. Separate quoting fixes it.
|
|
for host in "${cortex_host}" "${neuron_hosts[@]}" "${bench_host}"; do
|
|
echo "==> ${host}"
|
|
if ! ssh "${host}" '
|
|
set -eu
|
|
if id -u gitea_ci >/dev/null 2>&1; then
|
|
echo " gitea_ci user already present"
|
|
else
|
|
sudo useradd --system --create-home \
|
|
--home-dir /var/lib/gitea_ci --shell /bin/bash gitea_ci
|
|
echo " gitea_ci user created"
|
|
fi
|
|
# `sudo install` runs as root (not as gitea_ci), which avoids
|
|
# the "sudo: unknown user gitea_ci" failure seen immediately
|
|
# after useradd — NSS caching lags briefly and `sudo -u` cant
|
|
# resolve the just-created user, but `install -o` does its
|
|
# own fresh lookup.
|
|
sudo install -d -o gitea_ci -g gitea_ci -m 0700 \
|
|
/var/lib/gitea_ci/.ssh
|
|
# Grant journal read access so the deploy workflow can capture
|
|
# `journalctl -u <unit> -I` after a service start without
|
|
# needing a sudoers entry. Idempotent — usermod -aG on an
|
|
# already-member is a no-op.
|
|
sudo usermod -aG systemd-journal gitea_ci
|
|
'; then
|
|
echo " failed to provision gitea_ci — skipping ${host}"
|
|
continue
|
|
fi
|
|
|
|
if rsync \
|
|
--archive \
|
|
--compress \
|
|
--chown gitea_ci:gitea_ci \
|
|
--chmod 0600 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${pubkey}" \
|
|
"${host}:/var/lib/gitea_ci/.ssh/authorized_keys"; then
|
|
echo " authorized_keys synced"
|
|
else
|
|
echo " failed to sync authorized_keys"
|
|
fi
|
|
done
|
|
|
|
# Install /etc/sudoers.d/helexa_gitea_ci on a host and verify the
|
|
# resulting file parses, so a typo cant lock root out.
|
|
install_sudoers() {
|
|
local host="$1" template="$2"
|
|
echo "==> ${host}: installing /etc/sudoers.d/helexa_gitea_ci"
|
|
if ! rsync \
|
|
--archive \
|
|
--compress \
|
|
--chown root:root \
|
|
--chmod 0440 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${template}" \
|
|
"${host}:/etc/sudoers.d/helexa_gitea_ci"; then
|
|
echo " failed to sync ${template##*/}"
|
|
return
|
|
fi
|
|
if ssh "${host}" 'sudo visudo -cf /etc/sudoers.d/helexa_gitea_ci' \
|
|
>/dev/null; then
|
|
echo " installed and verified"
|
|
else
|
|
echo " WARNING: visudo rejected the installed file — review on ${host}"
|
|
fi
|
|
}
|
|
|
|
install_sudoers "${cortex_host}" \
|
|
"${repo_path}/asset/sudoers.d/cortex-host.conf"
|
|
|
|
for neuron_host in "${neuron_hosts[@]}"; do
|
|
install_sudoers "${neuron_host}" \
|
|
"${repo_path}/asset/sudoers.d/neuron-host.conf"
|
|
done
|
|
|
|
install_sudoers "${bench_host}" \
|
|
"${repo_path}/asset/sudoers.d/bench-host.conf"
|
|
|
|
# bob doesn't otherwise carry the lair-cafe RPM repo (it's a client
|
|
# host, not a cortex/neuron node), so helexa-bench's `dnf install` in
|
|
# deploy.yml would have nothing to install from. Enable the unstable
|
|
# repo here, and pre-create /etc/helexa-bench so the config sync below
|
|
# lands even before the first package install. Idempotent.
|
|
echo "==> ${bench_host}: ensuring lair-cafe-unstable repo + config dir"
|
|
if ! ssh "${bench_host}" '
|
|
set -eu
|
|
if dnf repolist --all 2>/dev/null | grep -q "^lair-cafe-unstable"; then
|
|
echo " lair-cafe-unstable already present"
|
|
else
|
|
sudo dnf config-manager addrepo --from-repofile=https://rpm.lair.cafe/lair-cafe-unstable.repo
|
|
sudo dnf config-manager setopt lair-cafe-unstable.enabled=1
|
|
echo " lair-cafe-unstable enabled"
|
|
fi
|
|
sudo install -d -o root -g root -m 0755 /etc/helexa-bench
|
|
'; then
|
|
echo " failed to prepare ${bench_host} for helexa-bench"
|
|
fi
|
|
|
|
# Push the one config CI cannot own.
|
|
#
|
|
# Operator decision 2026-08-25 (#283): the automated deployment path is
|
|
# the ONLY path. `.gitea/workflows/deploy.yml` now ships models.toml to
|
|
# the gateway, asset/neuron/<short>.toml to each neuron, and
|
|
# asset/helexa-bench/<host>.toml to the bench host — digest-compared,
|
|
# restarting the service when the file changes.
|
|
#
|
|
# Those three syncs USED to live here, and that is exactly how the fleet
|
|
# drifted: benjy and quadbrat were still running pre-#197 configs months
|
|
# after the tracked assets had moved on, because deploying them meant
|
|
# remembering to re-run this script. A hand-sync that exists "for local
|
|
# iteration" is a footgun that silently overwrites, or silently fails to
|
|
# overwrite, whatever CI just placed. Do not add one back.
|
|
#
|
|
# What remains is cortex.toml, which carries the inference API keys
|
|
# ([[entitlements.keys]]) and therefore cannot be tracked in git for CI
|
|
# to read. It is the last hand-synced config on the fleet and the last
|
|
# place this drift can still happen; closing it needs the secrets to
|
|
# come from Gitea secrets at deploy time rather than from a working
|
|
# copy.
|
|
#
|
|
# Missing source files are skipped silently — re-run after editing.
|
|
# Optional 4th/5th args set the destination group and mode. Configs that
|
|
# carry secrets (API keys, JWT signing keys, SMTP/DB passwords) must land
|
|
# root:<service> 0640 so the service can read them and nothing else can —
|
|
# a world-readable 0644 hands every local account the fleet's API keys.
|
|
# The service user is created by the package's sysusers.d entry, so it
|
|
# exists by the time any config is synced. Defaults keep the historical
|
|
# root:root 0644 for non-secret configs (catalogues, per-host tuning).
|
|
sync_config() {
|
|
local host="$1" src="$2" dst="$3" group="${4:-root}" mode="${5:-0644}"
|
|
if [[ ! -f "${src}" ]]; then
|
|
echo " ${src##*/} not present locally — skipping"
|
|
return
|
|
fi
|
|
if rsync \
|
|
--archive \
|
|
--compress \
|
|
--chown "root:${group}" \
|
|
--chmod "${mode}" \
|
|
--rsync-path 'sudo rsync' \
|
|
"${src}" \
|
|
"${host}:${dst}"; then
|
|
echo " ${src##*/} → ${host}:${dst} (root:${group} ${mode})"
|
|
else
|
|
echo " failed to sync ${src##*/} to ${host}"
|
|
fi
|
|
}
|
|
|
|
echo "==> ${cortex_host}: syncing gateway secrets config"
|
|
# cortex.toml holds the inference API keys ([[entitlements.keys]]), so it
|
|
# is gitignored and CI cannot see it. The only config still synced by
|
|
# hand — everything else is deploy.yml's.
|
|
sync_config "${cortex_host}" "${repo_path}/cortex.toml" /etc/cortex/cortex.toml cortex 0640
|
|
|
|
# models.toml, asset/neuron/<short>.toml and asset/helexa-bench/<host>.toml
|
|
# are deliberately NOT synced here. deploy.yml owns them; see the note
|
|
# above sync_config().
|
|
|
|
# ── bench UI: public nginx vhost on the gateway (bench.helexa.ai) ──────
|
|
# The built SPA is rsynced to the webroot by deploy.yml; nginx serves it
|
|
# and reverse-proxies /api to the bench API on bob (internal WireGuard),
|
|
# so the UI is same-origin and the API stays off the public internet.
|
|
# This block runs as the operator (own sudo); deploy.yml only needs the
|
|
# scoped rsync grant in asset/sudoers.d/cortex-host.conf. Idempotent.
|
|
bench_ui_domain="bench.helexa.ai"
|
|
bench_ui_webroot="/var/www/${bench_ui_domain}"
|
|
# certbot via Cloudflare DNS-01 (ECDSA) — the convention used for the
|
|
# other certs on this host. DNS-01 needs neither nginx running nor :80,
|
|
# so the cert can be provisioned independently of the vhost being served.
|
|
le_email="ops@zap.pics"
|
|
cf_creds="/root/.certbot-internal"
|
|
|
|
echo "==> ${cortex_host}: bench UI nginx vhost (${bench_ui_domain})"
|
|
ssh "${cortex_host}" "sudo install -d -o root -g root -m 0755 '${bench_ui_webroot}'"
|
|
ssh "${cortex_host}" "test -f '${bench_ui_webroot}/index.html' || \
|
|
echo 'helexa bench UI — not yet deployed' | sudo tee '${bench_ui_webroot}/index.html' >/dev/null"
|
|
# SELinux (enforcing on Fedora): label the webroot httpd_sys_content_t so
|
|
# nginx can read it (else 403). New files rsynced in inherit this type.
|
|
ssh "${cortex_host}" "sudo restorecon -R '${bench_ui_webroot}'"
|
|
|
|
# /etc/letsencrypt/live is root-only (0700) — must stat it via sudo, else
|
|
# this falsely reports "no cert" and downgrades the vhost to http-only.
|
|
cert_present() { ssh "${cortex_host}" "sudo test -d '/etc/letsencrypt/live/${bench_ui_domain}'"; }
|
|
nginx_active() { ssh "${cortex_host}" "systemctl is-active --quiet nginx"; }
|
|
|
|
# Obtain the cert (idempotent: --keep-until-expiring). Cloudflare DNS-01,
|
|
# so it works even while nginx is stopped.
|
|
if ! cert_present; then
|
|
echo " obtaining Let's Encrypt cert via Cloudflare DNS-01…"
|
|
ssh "${cortex_host}" "sudo certbot certonly \
|
|
-m '${le_email}' --agree-tos --no-eff-email --noninteractive \
|
|
--cert-name '${bench_ui_domain}' --key-type ecdsa \
|
|
--dns-cloudflare --dns-cloudflare-credentials '${cf_creds}' \
|
|
--dns-cloudflare-propagation-seconds 60 \
|
|
--keep-until-expiring -d '${bench_ui_domain}'" \
|
|
|| echo " WARNING: certbot failed (Cloudflare creds for helexa.ai?) — review on ${cortex_host}"
|
|
fi
|
|
|
|
# Install the matching vhost: the full TLS config once the cert exists,
|
|
# otherwise the http-only bootstrap. This invariant keeps `nginx -t`
|
|
# passing — never reference a cert that isn't there yet.
|
|
if cert_present; then
|
|
cfg="${bench_ui_domain}.conf"
|
|
else
|
|
cfg="${bench_ui_domain}.bootstrap.conf"
|
|
fi
|
|
if rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/${cfg}" \
|
|
"${cortex_host}:/etc/nginx/sites-available/${bench_ui_domain}.conf"; then
|
|
ssh "${cortex_host}" "
|
|
set -eu
|
|
sudo ln -sf ../sites-available/${bench_ui_domain}.conf \
|
|
/etc/nginx/sites-enabled/${bench_ui_domain}.conf
|
|
sudo nginx -t
|
|
" && echo " vhost installed (${cfg})"
|
|
if nginx_active; then
|
|
ssh "${cortex_host}" "sudo systemctl reload nginx"
|
|
else
|
|
echo " NOTE: nginx is inactive on ${cortex_host} — start it to serve ${bench_ui_domain}"
|
|
echo " (this also re-activates the other enabled vhosts on the host)."
|
|
fi
|
|
else
|
|
echo " failed to install ${bench_ui_domain} vhost"
|
|
fi
|
|
|
|
# ── bench UI: internal vhost (bench.internal) on the gateway ──────────
|
|
# For clients inside the WireGuard mesh, where the public bench.helexa.ai
|
|
# doesn't resolve to a usable path (see doc/infra/edge-ingress.md in the
|
|
# private helexa/security repo). Same SPA + /api→bob proxy, but with an
|
|
# internal-CA cert
|
|
# (smallstep "lair") renewed by step@bench.timer, replicating the
|
|
# convention on oolon.kosherinata.internal.
|
|
int_domain="bench.internal"
|
|
int_cert="/etc/nginx/tls/cert/${int_domain}.pem"
|
|
int_key="/etc/nginx/tls/key/${int_domain}.pem"
|
|
|
|
echo "==> ${cortex_host}: internal vhost (${int_domain}) + step renewal"
|
|
# Install the step@ renewal units + cert/key dirs (idempotent).
|
|
for unit in step@.service step@.timer; do
|
|
rsync --archive --compress --chown root:root --chmod 0644 --rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/systemd/${unit}" \
|
|
"${cortex_host}:/etc/systemd/system/${unit}" \
|
|
|| echo " failed to install ${unit}"
|
|
done
|
|
ssh "${cortex_host}" "
|
|
set -eu
|
|
sudo systemctl daemon-reload
|
|
sudo install -d -o root -g root -m 0755 /etc/nginx/tls/cert
|
|
sudo install -d -o root -g root -m 0700 /etc/nginx/tls/key
|
|
"
|
|
|
|
# Issue the initial cert if absent. The JWK 'lair' provisioner password
|
|
# lives only on the operator's machine; rsync it to the host transiently
|
|
# (root-owned, 0600), issue, then remove it — never persisted on the host.
|
|
if ! ssh "${cortex_host}" "sudo test -f '${int_cert}'"; then
|
|
prov_pw_local="${HOME}/.step/secrets/provisioner"
|
|
prov_pw_remote="/root/.bench-provisioner-pw"
|
|
if [[ -f "${prov_pw_local}" ]]; then
|
|
echo " issuing ${int_domain} cert (JWK 'lair' provisioner)…"
|
|
if rsync --archive --chown root:root --chmod 0600 --rsync-path 'sudo rsync' \
|
|
"${prov_pw_local}" "${cortex_host}:${prov_pw_remote}"; then
|
|
ssh "${cortex_host}" "
|
|
trap 'sudo rm -f ${prov_pw_remote}' EXIT
|
|
sudo step ca certificate ${int_domain} ${int_cert} ${int_key} \
|
|
--ca-url https://ca.internal \
|
|
--root /etc/pki/ca-trust/source/anchors/root-internal.pem \
|
|
--provisioner lair \
|
|
--provisioner-password-file ${prov_pw_remote} \
|
|
--force
|
|
" || echo " WARNING: cert issuance failed — review on ${cortex_host}"
|
|
# Belt-and-suspenders: ensure the secret is gone even if the
|
|
# trap didn't fire (e.g. dropped connection).
|
|
ssh "${cortex_host}" "sudo rm -f ${prov_pw_remote}"
|
|
else
|
|
echo " failed to transfer provisioner secret to ${cortex_host}"
|
|
fi
|
|
else
|
|
echo " NOTE: no provisioner secret at ${prov_pw_local}; issue ${int_domain} cert manually."
|
|
fi
|
|
fi
|
|
|
|
# Install the vhost + renewal timer once the cert exists.
|
|
#
|
|
# The rate-limit drop-in goes FIRST and unconditionally. It defines
|
|
# http-context names the vhost references — the `limit_req_zone`s and the
|
|
# `helexa_noquery` log format — and this host was getting the vhost
|
|
# without it: helexa-ratelimit.conf was shipped to the web and angels
|
|
# hosts only, so `helexa.internal.conf` could arrive referencing a log
|
|
# format nginx had never seen.
|
|
#
|
|
# The ordering below makes that a live hazard rather than a caught
|
|
# mistake: the symlink is created before `nginx -t` runs, so a failing
|
|
# test leaves a broken config wired into sites-enabled. The running nginx
|
|
# is unaffected (it is not reloaded), but the NEXT reload or reboot —
|
|
# by anything, including certificate renewal — fails on it.
|
|
#
|
|
# deploy.yml's deploy-nginx job ships the pair in this same order for the
|
|
# same reason.
|
|
if ssh "${cortex_host}" "sudo test -f '${int_cert}'"; then
|
|
rsync --archive --compress --chown root:root --chmod 0644 --rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/helexa-ratelimit.conf" \
|
|
"${cortex_host}:/etc/nginx/conf.d/helexa-ratelimit.conf" \
|
|
|| echo " failed to install helexa-ratelimit.conf"
|
|
if rsync --archive --compress --chown root:root --chmod 0644 --rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/${int_domain}.conf" \
|
|
"${cortex_host}:/etc/nginx/sites-available/${int_domain}.conf"; then
|
|
ssh "${cortex_host}" "
|
|
set -eu
|
|
sudo ln -sf ../sites-available/${int_domain}.conf \
|
|
/etc/nginx/sites-enabled/${int_domain}.conf
|
|
sudo nginx -t
|
|
systemctl is-active --quiet nginx && sudo systemctl reload nginx || true
|
|
sudo systemctl enable --now step@bench.timer
|
|
" && echo " ${int_domain} vhost installed + step@bench.timer enabled"
|
|
else
|
|
echo " failed to install ${int_domain} vhost"
|
|
fi
|
|
else
|
|
echo " ${int_domain} cert still absent — vhost not installed"
|
|
fi
|
|
|
|
# ── helexa.ai website: public vhost on BOTH edge proxies (#161) ────────
|
|
# The built SPA (helexa.ai/dist) is rsynced to the webroot by
|
|
# deploy.yml's deploy-website job; each site's edge proxy serves it
|
|
# under server_name helexa.ai with its own Let's Encrypt cert.
|
|
# Cloudflare DNS load balancing (operator-managed) routes the public
|
|
# name to both site WAN IPs. Edge conventions are summarised in
|
|
# doc/infra/edge-ingress.md in the private helexa/security repo.
|
|
# Idempotent.
|
|
web_domain="helexa.ai"
|
|
web_webroot="/var/www/${web_domain}"
|
|
web_hosts=("${cortex_host}" "oolon.kosherinata.internal")
|
|
|
|
# oolon's gitea_ci is shared with other projects' CI — append our
|
|
# runner key only if missing rather than overwriting authorized_keys
|
|
# (the provisioning loop above owns the helexa-fleet hosts, where
|
|
# overwrite is fine; it is NOT fine on a shared host).
|
|
ensure_ci_key() {
|
|
local host="$1"
|
|
ssh "${host}" "
|
|
set -eu
|
|
sudo install -d -o gitea_ci -g gitea_ci -m 0700 /var/lib/gitea_ci/.ssh
|
|
sudo touch /var/lib/gitea_ci/.ssh/authorized_keys
|
|
sudo chown gitea_ci:gitea_ci /var/lib/gitea_ci/.ssh/authorized_keys
|
|
sudo chmod 0600 /var/lib/gitea_ci/.ssh/authorized_keys
|
|
grep -qF '$(awk '{print $2}' "${pubkey}")' /var/lib/gitea_ci/.ssh/authorized_keys 2>/dev/null \
|
|
|| echo '$(cat "${pubkey}")' | sudo tee -a /var/lib/gitea_ci/.ssh/authorized_keys >/dev/null
|
|
" && echo " gitea_ci key present" || echo " WARNING: failed to ensure gitea_ci key on ${host}"
|
|
}
|
|
|
|
echo "==> oolon.kosherinata.internal: gitea_ci key + website sudoers"
|
|
ensure_ci_key oolon.kosherinata.internal
|
|
install_sudoers oolon.kosherinata.internal \
|
|
"${repo_path}/asset/sudoers.d/web-host.conf"
|
|
|
|
for web_host in "${web_hosts[@]}"; do
|
|
echo "==> ${web_host}: website nginx vhost (${web_domain})"
|
|
ssh "${web_host}" "sudo install -d -o root -g root -m 0755 '${web_webroot}'"
|
|
ssh "${web_host}" "test -f '${web_webroot}/index.html' || \
|
|
echo 'helexa.ai — not yet deployed' | sudo tee '${web_webroot}/index.html' >/dev/null"
|
|
# SELinux (enforcing): label the webroot httpd_sys_content_t so nginx
|
|
# can read it (else 403). Files rsynced in later inherit the type.
|
|
ssh "${web_host}" "sudo restorecon -R '${web_webroot}'"
|
|
|
|
# Shared per-IP rate-limit zones (http context) used by the /v1 and
|
|
# /api locations in the vhost (#167).
|
|
rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/helexa-ratelimit.conf" \
|
|
"${web_host}:/etc/nginx/conf.d/helexa-ratelimit.conf" \
|
|
|| echo " failed to install helexa-ratelimit.conf"
|
|
|
|
# Obtain the cert (idempotent: --keep-until-expiring). Cloudflare
|
|
# DNS-01, so it works even while nginx is stopped. /root/.certbot-
|
|
# internal must hold a token scoped to the helexa.ai zone.
|
|
if ! ssh "${web_host}" "sudo test -d '/etc/letsencrypt/live/${web_domain}'"; then
|
|
echo " obtaining Let's Encrypt cert via Cloudflare DNS-01…"
|
|
ssh "${web_host}" "sudo certbot certonly \
|
|
-m '${le_email}' --agree-tos --no-eff-email --noninteractive \
|
|
--cert-name '${web_domain}' --key-type ecdsa \
|
|
--dns-cloudflare --dns-cloudflare-credentials '${cf_creds}' \
|
|
--dns-cloudflare-propagation-seconds 60 \
|
|
--keep-until-expiring -d '${web_domain}'" \
|
|
|| echo " WARNING: certbot failed (Cloudflare creds for ${web_domain}?) — review on ${web_host}"
|
|
fi
|
|
|
|
# Install the matching vhost: full TLS config once the cert exists,
|
|
# otherwise the http-only bootstrap (never reference a missing cert
|
|
# — nginx -t fails and blocks the whole server).
|
|
if ssh "${web_host}" "sudo test -d '/etc/letsencrypt/live/${web_domain}'"; then
|
|
web_cfg="${web_domain}.conf"
|
|
else
|
|
web_cfg="${web_domain}.bootstrap.conf"
|
|
fi
|
|
if rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/${web_cfg}" \
|
|
"${web_host}:/etc/nginx/sites-available/${web_domain}.conf"; then
|
|
ssh "${web_host}" "
|
|
set -eu
|
|
sudo ln -sf ../sites-available/${web_domain}.conf \
|
|
/etc/nginx/sites-enabled/${web_domain}.conf
|
|
sudo nginx -t
|
|
" && echo " vhost installed (${web_cfg})"
|
|
if ssh "${web_host}" "systemctl is-active --quiet nginx"; then
|
|
ssh "${web_host}" "sudo systemctl reload nginx"
|
|
else
|
|
echo " NOTE: nginx is inactive on ${web_host} — start it to serve ${web_domain}"
|
|
fi
|
|
else
|
|
echo " failed to install ${web_domain} vhost"
|
|
fi
|
|
done
|
|
|
|
# ── angels.internal: internal name for the investor portal ─────────────
|
|
# For networks where the public name does not work from inside — served by
|
|
# the edge nearest helexa-angels, with an internal-CA cert renewed by
|
|
# step@angels.timer. Needs a matching DNS record on the local resolver.
|
|
angels_int_host="oolon.kosherinata.internal"
|
|
angels_int_domain="angels.internal"
|
|
angels_int_cert="/etc/nginx/tls/cert/${angels_int_domain}.pem"
|
|
angels_int_key="/etc/nginx/tls/key/${angels_int_domain}.pem"
|
|
|
|
echo "==> ${angels_int_host}: internal vhost (${angels_int_domain})"
|
|
ssh "${angels_int_host}" "
|
|
set -eu
|
|
sudo install -d -o root -g root -m 0755 /etc/nginx/tls/cert
|
|
sudo install -d -o root -g root -m 0700 /etc/nginx/tls/key
|
|
"
|
|
if ! ssh "${angels_int_host}" "sudo test -f '${angels_int_cert}'"; then
|
|
prov_pw_local="${HOME}/.step/secrets/provisioner"
|
|
prov_pw_remote="/root/.helexa-provisioner-pw"
|
|
if [[ -f "${prov_pw_local}" ]]; then
|
|
echo " issuing ${angels_int_domain} cert (JWK 'lair' provisioner)…"
|
|
if rsync --archive --chown root:root --chmod 0600 --rsync-path 'sudo rsync' \
|
|
"${prov_pw_local}" "${angels_int_host}:${prov_pw_remote}"; then
|
|
ssh "${angels_int_host}" "
|
|
trap 'sudo rm -f ${prov_pw_remote}' EXIT
|
|
sudo step ca certificate ${angels_int_domain} ${angels_int_cert} ${angels_int_key} \
|
|
--ca-url https://ca.internal \
|
|
--root /etc/pki/ca-trust/source/anchors/root-internal.pem \
|
|
--provisioner lair \
|
|
--provisioner-password-file ${prov_pw_remote} \
|
|
--force
|
|
" || echo " WARNING: cert issuance failed — review on ${angels_int_host}"
|
|
ssh "${angels_int_host}" "sudo rm -f ${prov_pw_remote}"
|
|
else
|
|
echo " failed to transfer provisioner secret to ${angels_int_host}"
|
|
fi
|
|
else
|
|
echo " NOTE: no provisioner secret at ${prov_pw_local}; issue ${angels_int_domain} cert manually."
|
|
fi
|
|
fi
|
|
# Only wire the vhost once its cert exists. Without this guard a host
|
|
# with no provisioner secret takes the "issue it manually" branch above
|
|
# and then installs a vhost naming a certificate that is not there:
|
|
# `ln -sf` runs before `nginx -t`, so the broken config is already in
|
|
# sites-enabled when the test fails, and the next reload or reboot —
|
|
# including the renewal timer enabled two lines down — fails on it. The
|
|
# helexa.internal block above guards exactly this way; this one did not.
|
|
if ! ssh "${angels_int_host}" "sudo test -f '${angels_int_cert}'"; then
|
|
echo " ${angels_int_domain} cert still absent — vhost not installed"
|
|
elif
|
|
# The rate-limit drop-in first: this vhost references the
|
|
# `angels_invite` and `angels_auth` zones, which are http-context
|
|
# names defined there. It was only shipped to this host later, by the
|
|
# public-portal loop below, so on a host that had not run that yet
|
|
# `nginx -t` failed on an undefined zone.
|
|
rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/helexa-ratelimit.conf" \
|
|
"${angels_int_host}:/etc/nginx/conf.d/helexa-ratelimit.conf" \
|
|
|| echo " failed to install helexa-ratelimit.conf"
|
|
rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/${angels_int_domain}.conf" \
|
|
"${angels_int_host}:/etc/nginx/sites-available/${angels_int_domain}.conf"
|
|
then
|
|
ssh "${angels_int_host}" "
|
|
set -eu
|
|
sudo ln -sf ../sites-available/${angels_int_domain}.conf \
|
|
/etc/nginx/sites-enabled/${angels_int_domain}.conf
|
|
sudo nginx -t
|
|
sudo systemctl enable --now step@angels.timer
|
|
" && echo " vhost installed + renewal timer enabled"
|
|
if ssh "${angels_int_host}" "systemctl is-active --quiet nginx"; then
|
|
ssh "${angels_int_host}" "sudo systemctl reload nginx"
|
|
fi
|
|
else
|
|
echo " failed to install ${angels_int_domain} vhost"
|
|
fi
|
|
|
|
# ── angels.helexa.ai: the confidential investor portal ─────────────────
|
|
# Unlike the other vhosts this one serves NOTHING from disk: every byte
|
|
# comes from helexa-angels on gallumbits, which assembles each page
|
|
# server-side after checking the session. The webroot exists only so
|
|
# certbot's ACME challenge has somewhere to live.
|
|
#
|
|
# Installed on both edge proxies, matching helexa.ai, so the Cloudflare
|
|
# record can point at either site.
|
|
angels_domain="angels.helexa.ai"
|
|
angels_webroot="/var/www/${angels_domain}"
|
|
|
|
for angels_host in "${web_hosts[@]}"; do
|
|
echo "==> ${angels_host}: investor portal vhost (${angels_domain})"
|
|
ssh "${angels_host}" "sudo install -d -o root -g root -m 0755 '${angels_webroot}'"
|
|
ssh "${angels_host}" "sudo restorecon -R '${angels_webroot}'"
|
|
|
|
# Shared proxy params, included by every location in the vhost so the
|
|
# four cannot drift apart. X-Forwarded-For matters here beyond the
|
|
# usual: the access record stores the client IP, and without it every
|
|
# row would read as the edge proxy's address.
|
|
rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/angels-proxy-params.conf" \
|
|
"${angels_host}:/etc/nginx/conf.d/angels-proxy-params.conf" \
|
|
|| echo " failed to install angels-proxy-params.conf"
|
|
|
|
# Rate-limit zones (http context) — helexa-ratelimit.conf now also
|
|
# declares angels_invite and angels_auth. Re-synced here so the
|
|
# portal works even if the website section above was skipped.
|
|
rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/helexa-ratelimit.conf" \
|
|
"${angels_host}:/etc/nginx/conf.d/helexa-ratelimit.conf" \
|
|
|| echo " failed to install helexa-ratelimit.conf"
|
|
|
|
if ! ssh "${angels_host}" "sudo test -d '/etc/letsencrypt/live/${angels_domain}'"; then
|
|
echo " obtaining Let's Encrypt cert via Cloudflare DNS-01…"
|
|
ssh "${angels_host}" "sudo certbot certonly \
|
|
-m '${le_email}' --agree-tos --no-eff-email --noninteractive \
|
|
--cert-name '${angels_domain}' --key-type ecdsa \
|
|
--dns-cloudflare --dns-cloudflare-credentials '${cf_creds}' \
|
|
--dns-cloudflare-propagation-seconds 60 \
|
|
--keep-until-expiring -d '${angels_domain}'" \
|
|
|| echo " WARNING: certbot failed (Cloudflare creds for ${angels_domain}?) — review on ${angels_host}"
|
|
fi
|
|
|
|
# Never reference a cert that does not exist yet — nginx -t fails and
|
|
# takes the whole server down with it, including helexa.ai.
|
|
if ssh "${angels_host}" "sudo test -d '/etc/letsencrypt/live/${angels_domain}'"; then
|
|
angels_cfg="${angels_domain}.conf"
|
|
else
|
|
angels_cfg="${angels_domain}.bootstrap.conf"
|
|
fi
|
|
if rsync --archive --compress --chown root:root --chmod 0644 \
|
|
--rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/${angels_cfg}" \
|
|
"${angels_host}:/etc/nginx/sites-available/${angels_domain}.conf"; then
|
|
ssh "${angels_host}" "
|
|
set -eu
|
|
sudo ln -sf ../sites-available/${angels_domain}.conf \
|
|
/etc/nginx/sites-enabled/${angels_domain}.conf
|
|
sudo nginx -t
|
|
" && echo " vhost installed (${angels_cfg})"
|
|
if ssh "${angels_host}" "systemctl is-active --quiet nginx"; then
|
|
ssh "${angels_host}" "sudo systemctl reload nginx"
|
|
else
|
|
echo " NOTE: nginx is inactive on ${angels_host} — start it to serve ${angels_domain}"
|
|
fi
|
|
else
|
|
echo " failed to install ${angels_domain} vhost"
|
|
fi
|
|
done
|
|
|
|
# ── helexa website: internal vhost (helexa.internal) on the gateway ────
|
|
# For mesh clients, which can't use the public helexa.ai (see
|
|
# doc/infra/edge-ingress.md in the private helexa/security repo). Same
|
|
# SPA webroot, internal-CA cert renewed by
|
|
# step@helexa.timer. hanzalova only; both site routers carry the
|
|
# split-horizon helexa.internal → hanzalova host override.
|
|
web_int_domain="helexa.internal"
|
|
web_int_cert="/etc/nginx/tls/cert/${web_int_domain}.pem"
|
|
web_int_key="/etc/nginx/tls/key/${web_int_domain}.pem"
|
|
|
|
echo "==> ${cortex_host}: internal vhost (${web_int_domain}) + step renewal"
|
|
# step@ units + tls dirs are installed by the bench.internal section
|
|
# above; re-assert the dirs in case sections are ever reordered.
|
|
ssh "${cortex_host}" "
|
|
set -eu
|
|
sudo install -d -o root -g root -m 0755 /etc/nginx/tls/cert
|
|
sudo install -d -o root -g root -m 0700 /etc/nginx/tls/key
|
|
"
|
|
|
|
if ! ssh "${cortex_host}" "sudo test -f '${web_int_cert}'"; then
|
|
prov_pw_local="${HOME}/.step/secrets/provisioner"
|
|
prov_pw_remote="/root/.helexa-provisioner-pw"
|
|
if [[ -f "${prov_pw_local}" ]]; then
|
|
echo " issuing ${web_int_domain} cert (JWK 'lair' provisioner)…"
|
|
if rsync --archive --chown root:root --chmod 0600 --rsync-path 'sudo rsync' \
|
|
"${prov_pw_local}" "${cortex_host}:${prov_pw_remote}"; then
|
|
ssh "${cortex_host}" "
|
|
trap 'sudo rm -f ${prov_pw_remote}' EXIT
|
|
sudo step ca certificate ${web_int_domain} ${web_int_cert} ${web_int_key} \
|
|
--ca-url https://ca.internal \
|
|
--root /etc/pki/ca-trust/source/anchors/root-internal.pem \
|
|
--provisioner lair \
|
|
--provisioner-password-file ${prov_pw_remote} \
|
|
--force
|
|
" || echo " WARNING: cert issuance failed — review on ${cortex_host}"
|
|
ssh "${cortex_host}" "sudo rm -f ${prov_pw_remote}"
|
|
else
|
|
echo " failed to transfer provisioner secret to ${cortex_host}"
|
|
fi
|
|
else
|
|
echo " NOTE: no provisioner secret at ${prov_pw_local}; issue ${web_int_domain} cert manually."
|
|
fi
|
|
fi
|
|
|
|
if ssh "${cortex_host}" "sudo test -f '${web_int_cert}'"; then
|
|
if rsync --archive --compress --chown root:root --chmod 0644 --rsync-path 'sudo rsync' \
|
|
"${repo_path}/asset/nginx/${web_int_domain}.conf" \
|
|
"${cortex_host}:/etc/nginx/sites-available/${web_int_domain}.conf"; then
|
|
ssh "${cortex_host}" "
|
|
set -eu
|
|
sudo ln -sf ../sites-available/${web_int_domain}.conf \
|
|
/etc/nginx/sites-enabled/${web_int_domain}.conf
|
|
sudo nginx -t
|
|
systemctl is-active --quiet nginx && sudo systemctl reload nginx || true
|
|
sudo systemctl enable --now step@helexa.timer
|
|
" && echo " ${web_int_domain} vhost installed + step@helexa.timer enabled"
|
|
else
|
|
echo " failed to install ${web_int_domain} vhost"
|
|
fi
|
|
else
|
|
echo " ${web_int_domain} cert still absent — vhost not installed"
|
|
fi
|
|
|
|
# ── gallumbits: federation service host (helexa-router + helexa-upstream) ──
|
|
# One host at the DC site runs the federation data plane (router, tcp/8088)
|
|
# and the account/budget authority (upstream, tcp/8090). Both edge proxies
|
|
# reverse-proxy to it: /v1 → router, /api → upstream. Deploy of the RPMs is
|
|
# CI's job (deploy.yml deploy-gallumbits); this section does the one-time
|
|
# host prep and syncs the operator-owned configs (they carry secrets — DB
|
|
# password, JWT secret, operator tokens — so CI never sees them).
|
|
svc_host=gallumbits.kosherinata.internal
|
|
|
|
echo "==> ${svc_host}: gitea_ci key + service-host sudoers"
|
|
ensure_ci_key "${svc_host}"
|
|
install_sudoers "${svc_host}" \
|
|
"${repo_path}/asset/sudoers.d/gallumbits-host.conf"
|
|
|
|
echo "==> ${svc_host}: ensuring lair-cafe-unstable repo + config dirs"
|
|
if ! ssh "${svc_host}" '
|
|
set -eu
|
|
if dnf repolist --all 2>/dev/null | grep -q "^lair-cafe-unstable"; then
|
|
echo " lair-cafe-unstable already present"
|
|
else
|
|
sudo dnf config-manager addrepo --from-repofile=https://rpm.lair.cafe/lair-cafe-unstable.repo
|
|
sudo dnf config-manager setopt lair-cafe-unstable.enabled=1
|
|
echo " lair-cafe-unstable enabled"
|
|
fi
|
|
# rpm.lair.cafe publishes only a fedora/43 tree. A host still on F42
|
|
# needs the repo pinned to the 43 path (the fc43 helexa binaries need
|
|
# at most GLIBC_2.34, so they run fine there); on F43+ the stock
|
|
# $releasever URL is already correct and pinning would mask future
|
|
# release bumps, so only pin when actually on 42.
|
|
if [ "$(rpm -E %fedora)" = "42" ]; then
|
|
sudo dnf config-manager setopt lair-cafe-unstable.baseurl=https://rpm.lair.cafe/fedora/43/x86_64/unstable/
|
|
fi
|
|
sudo install -d -o root -g root -m 0755 /etc/helexa-router
|
|
sudo install -d -o root -g root -m 0755 /etc/helexa-upstream
|
|
'; then
|
|
echo " failed to prepare ${svc_host}"
|
|
fi
|
|
|
|
# ── STILL HAND-SYNCED, and tracked as such ────────────────────────────
|
|
# Everything below this line is a config CI does not yet own, which by
|
|
# the 2026-08-25 decision (#283) makes it a footgun still loaded. Two
|
|
# distinct reasons, needing two distinct fixes:
|
|
#
|
|
# * helexa-router.toml / helexa-upstream.toml / helexa-angels.toml are
|
|
# gitignored because they carry JWT secrets, SMTP passwords and
|
|
# database URLs. Same class as cortex.toml: CI cannot read them until
|
|
# the secrets come from Gitea secrets and the file is rendered at
|
|
# deploy time.
|
|
# * asset/searxng/{settings.yml,searxng.container,helexa-searxng.xml}
|
|
# ARE tracked and could move to deploy.yml today but for one thing:
|
|
# asset/sudoers.d/gallumbits-host.conf grants gitea_ci no rsync at
|
|
# all, so the deploy would fail until the grants land on the host.
|
|
# Grants first, deploy step second — wiring it the other way round
|
|
# breaks every deploy in between.
|
|
#
|
|
# See the tracking issue; do not close the gap by adding syncs here.
|
|
echo "==> ${svc_host}: syncing service configs"
|
|
# helexa-router.toml is NOT synced here any more — it is tracked and
|
|
# deploy.yml's deploy-gallumbits job owns it (#287). Two writers for one
|
|
# file is how the fleet ends up running something no commit describes,
|
|
# and this file in particular spent long enough diverging to cost an
|
|
# outage. If it needs changing, change it in the repo.
|
|
# helexa-upstream.toml holds the session JWT secret, the SMTP submission
|
|
# password (no-reply mail) and the database URL.
|
|
sync_config "${svc_host}" "${repo_path}/helexa-upstream.toml" \
|
|
/etc/helexa-upstream/helexa-upstream.toml helexa-upstream 0640
|
|
|
|
# helexa-angels.toml carries the (shared) database URL and the SMTP
|
|
# password for interest notifications — same secret posture as upstream's.
|
|
sync_config "${svc_host}" "${repo_path}/helexa-angels.toml" \
|
|
/etc/helexa-angels/helexa-angels.toml helexa-angels 0640
|
|
# Config changes only take effect on service restart; do it here (not in
|
|
# CI) so a config-only iteration doesn't need a deploy run. Ignore
|
|
# failures — first run happens before the RPMs are installed.
|
|
ssh "${svc_host}" '
|
|
systemctl is-active --quiet helexa-router.service && sudo systemctl restart helexa-router.service || true
|
|
systemctl is-active --quiet helexa-upstream.service && sudo systemctl restart helexa-upstream.service || true
|
|
' || true
|
|
|
|
# ── gallumbits: SearXNG (web_search tool backend, #177) ────────────────
|
|
# Quadlet container on the service host; the edge proxies expose it as
|
|
# GET /tools/web_search with per-IP rate limiting. The instance secret
|
|
# is operator-owned (generated once below, 0600, never in git).
|
|
echo "==> ${svc_host}: searxng quadlet + firewalld service"
|
|
ssh "${svc_host}" '
|
|
set -eu
|
|
rpm -q podman >/dev/null 2>&1 || sudo dnf install -y podman
|
|
sudo install -d -o root -g root -m 0755 /etc/searxng /etc/containers/systemd
|
|
' || echo " failed to prepare searxng dirs on ${svc_host}"
|
|
sync_config "${svc_host}" "${repo_path}/asset/searxng/settings.yml" /etc/searxng/settings.yml
|
|
sync_config "${svc_host}" "${repo_path}/asset/searxng/searxng.container" /etc/containers/systemd/searxng.container
|
|
sync_config "${svc_host}" "${repo_path}/asset/searxng/helexa-searxng.xml" /etc/firewalld/services/helexa-searxng.xml
|
|
if ! ssh "${svc_host}" '
|
|
set -eu
|
|
if [ ! -f /etc/searxng/searxng.env ]; then
|
|
echo "SEARXNG_SECRET=$(openssl rand -hex 32)" | sudo tee /etc/searxng/searxng.env >/dev/null
|
|
sudo chmod 0600 /etc/searxng/searxng.env
|
|
echo " generated /etc/searxng/searxng.env"
|
|
fi
|
|
# reload picks up the new service definition before we reference it
|
|
sudo firewall-cmd --reload >/dev/null
|
|
sudo firewall-cmd --query-service=helexa-searxng >/dev/null 2>&1 \
|
|
|| sudo firewall-cmd --permanent --add-service=helexa-searxng >/dev/null
|
|
sudo firewall-cmd --reload >/dev/null
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl restart searxng.service
|
|
'; then
|
|
echo " failed to set up searxng on ${svc_host}"
|
|
fi
|