mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 09:20:03 +01:00
* fix(hardcoded): give every duplicated constant one home A sweep of all 44 repos' default branches for literals that duplicate an existing source of truth. Loki's share, in four groups. WRONG, and live on the public footer. src/config/fleet-site-copy.ts still called the Zürich clinic "VitaReBa", a name retired on 2026-09-10 — its own title says "Vita · Metabolische Psychiatrie & Systemische Longevity". The generated fleet-sites.ts carried it onto loki.orangecat.ch, where it was serving until this commit. Fixed at the copy file, which is the one place that owns a site's own words, and the footer regenerated from it. WOULD HAVE WRITTEN STALE DATA. scripts/seed-fleet-site-urls.ts kept a hand-typed slug → URL map "read 2026-08-06". Two of its fifteen entries pointed at hosts retired since (aoz-wohnen.orangecat.ch, revampit.orangecat.ch), so running it would have filled empty live_url columns with addresses that only 308. It now derives the map from apps.conf — the same register the footer is generated from — which also fixes the six live sites the hand list never had. Verified: 19 sites, zero retired hosts. THE BOX ADDRESS, in seven places. scripts/hetzner/_box-env.sh has been the SSOT for it all along and sixteen scripts source it; four did not, and the shared deploy workflow — reused by ~20 repos — had the IP inline twice, so moving the box meant twenty edits. The workflow now reads the org-level Actions variable HETZNER_IP and fails loudly if it is unset, rather than ssh-ing to an empty string. loki's own deploy.yml had `vars.HETZNER_IP || '<literal>'`, a fallback that guaranteed the variable was never needed and so never noticed if wrong. ONE LAPTOP, baked into shipped code. site-cd-local.ts listed /home/g/.ssh and /home/ubuntu/.ssh as deploy-key candidates beside os.homedir() — which already IS those paths, since loki-app runs as `ubuntu` and a laptop runs as its owner; both spelled one homedir for one named person. install-push-deploy.sh wired hooks to /home/g/dev/loki, link-prod-runtime.ts to /home/g/dev/bitbaum, and scripts/fleet printed an install line only true on one machine: all now DEV_ROOT or the script's own resolved path. The two scripts in scripts/local are INSTALLED BY COPY into ~/.local/bin and run there by systemd timers, so they resolve _box-env.sh beside the real file first, then under DEV_ROOT, and exit loudly if neither exists — a security check that cannot find its target must not look like one that found nothing. Deliberately unchanged: the slug alias map (the mechanism that makes a rename safe), an executed migration's data row, the retired-handle detector's own handle list, and test fixtures reproducing past incidents. Verified: fleet-sites-derived in sync (14 sites), bash -n on every edited script, and the branch's only remaining literals are in scripts/test fixtures. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(push-deploy): the generated hook must not bake one laptop's path install-push-deploy.sh writes the hook body through an UNQUOTED heredoc, so $HERE expanded at generation time and the absolute path of one machine was committed into every repo's .husky/pre-push. kivvi and botsmann both carried it; anyone cloning those repos got a hook pointing into a stranger's home directory, and re-running the installer would have put it straight back after those repos were cleaned. The hook now resolves ${DEV_ROOT:-$HOME/dev}/loki/... at RUN time, so the generator stops re-introducing what the cleanup just removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
55 lines
2.5 KiB
Bash
Executable File
55 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Open an SSH tunnel to the box's Postgres and print the URL to use through it.
|
|
#
|
|
# Why: prod Postgres listens on 127.0.0.1 on the box and the port is firewalled,
|
|
# so anything running off-box (a sandboxed agent, a CI runner, a laptop on a
|
|
# different network) cannot reach it. That is correct security and it also
|
|
# blocked the responsive audit from minting a session token — the audit could
|
|
# not run anywhere except a machine with a direct route.
|
|
#
|
|
# Usage:
|
|
# eval "$(bash scripts/db-tunnel.sh)" # exports AUDIT_DATABASE_URL
|
|
# npm run audit:responsive
|
|
# bash scripts/db-tunnel.sh --close # tear the tunnel down
|
|
#
|
|
# Read-only by intent: this exists so tooling can READ a user row to mint a
|
|
# session. Do not point migrations through it.
|
|
set -euo pipefail
|
|
|
|
. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/hetzner/_box-env.sh" # SSOT: BOX_UBUNTU
|
|
BOX="${HETZNER_SSH:-$BOX_UBUNTU}"
|
|
LOCAL_PORT="${TUNNEL_PORT:-15432}"
|
|
|
|
if [ "${1:-}" = "--close" ]; then
|
|
pkill -f "ssh.*-L ${LOCAL_PORT}:127.0.0.1:5432" 2>/dev/null || true
|
|
echo "tunnel on :${LOCAL_PORT} closed" >&2
|
|
exit 0
|
|
fi
|
|
|
|
# Idempotent: reuse a live tunnel rather than stacking forwards.
|
|
if ! (exec 3<>"/dev/tcp/127.0.0.1/${LOCAL_PORT}") 2>/dev/null; then
|
|
ssh -o BatchMode=yes -o ExitOnForwardFailure=yes -f -N \
|
|
-L "${LOCAL_PORT}:127.0.0.1:5432" "$BOX" \
|
|
|| { echo "ERROR: could not open tunnel to $BOX" >&2; exit 1; }
|
|
sleep 1
|
|
fi
|
|
|
|
# Rewrite the box's own DATABASE_URL to point through the tunnel. Read from the
|
|
# box rather than duplicated here so the credential lives in exactly one place.
|
|
# Keep exactly ONE level of quoting on the remote side — fetch the raw line and
|
|
# strip the assignment and any surrounding quotes locally. Nesting quote styles
|
|
# through ssh is how this broke the first time.
|
|
BOX_LINE="$(ssh -o BatchMode=yes "$BOX" "sudo grep -h '^DATABASE_URL=' /opt/loki/app/.env | head -1")"
|
|
BOX_URL="${BOX_LINE#DATABASE_URL=}"
|
|
BOX_URL="${BOX_URL%\"}"; BOX_URL="${BOX_URL#\"}"
|
|
BOX_URL="${BOX_URL%\'}"; BOX_URL="${BOX_URL#\'}"
|
|
BOX_URL="$(printf '%s' "$BOX_URL" | tr -d '[:space:]')"
|
|
[ -n "$BOX_URL" ] || { echo "ERROR: no DATABASE_URL found on $BOX" >&2; exit 1; }
|
|
|
|
# sslmode is dropped with the query string: the hop is already encrypted by SSH,
|
|
# and the box's Postgres does not serve TLS on its loopback listener.
|
|
LOCAL_URL="$(printf '%s' "$BOX_URL" | sed -E "s|@[^/]+/|@127.0.0.1:${LOCAL_PORT}/|; s|\?.*$||")"
|
|
|
|
echo "export AUDIT_DATABASE_URL='${LOCAL_URL}'"
|
|
echo "tunnel ready on 127.0.0.1:${LOCAL_PORT}" >&2
|