8 Commits
Author SHA1 Message Date
CatoandClaude Sonnet 5.5 52a9c5e039 fix(laptop-security-check): key ephemeral ports by program, not number (#1770)
kdeconnectd re-rolls its UDP ports on every restart; each one paged as a
NEW PORT (16 Telegram alerts in a day). Ports >= 32768 are now keyed by the
owning program, so a re-roll is silent and a new program still alerts.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-26 16:06:38 +01:00
CatoandClaude Opus 5 58174f45ef fix(hardcoded): give every duplicated constant one home (#758)
* 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>
2026-09-17 02:03:58 -07:00
CatoandClaude Opus 5 baa8e2e6fb chore(aoz): follow bitbaum/aoz-housing -> bitbaum/aoz-begleitung (#732)
The repo was renamed today. It was the last place the product was still called
Housing: the name row in fleet's registers/retired.json retired "AOZ Housing" as
the PRODUCT name on 2026-09-10, but the repo kept it, and the repo is public.

The deploy name `aoz-wohnen` is deliberately NOT renamed with it. It is an
infrastructure identifier — systemd unit, /opt path, database — nothing on the
box keys on the repo name, and moving it would touch a live site for no visible
gain. apps.conf's comment block already said as much and still does.

The load-bearing change is apps.conf's fourth field. repo-metadata-audit.mjs
keys the register on that path's BASENAME, so while it read /home/g/dev/
aoz-housing the join against GitHub missed and every metadata check for this
repo was silently skipped — the audit went green by not looking at it. The local
checkout was moved to match and its three worktrees repaired (`git worktree
repair`), not pruned: they hold branches.

Two test failures worth keeping, because both were the rename telling the truth:

  - project-mention asserted that "the AOZ housing rebuild" resolves to the
    project. With the slug renamed it does not, and should not. The case exists
    to prove "a slug with a hyphen, typed with a space" matches, so the INPUT
    moved to the current name rather than the expectation being loosened.
  - tab-match asserted a terminal tab literally named "AOZ Housing" matches the
    slug. Same thing: the fixture now uses the name the tab would actually have.

Consequence worth naming: someone who types "aoz housing" at Loki will no longer
be understood. There is an alias mechanism for exactly this shape
(register/build.ts maps the deploy name to the repo), but wiring the retired
name into mention-matching is a product decision, not a rename chore.

Left alone on purpose: scripts/db/retire-stale-projects.ts, whose data row
records the project names the database actually held when that migration ran;
and content/thoughts/*.md, published essays — one of which quotes a filesystem
path observed during a debugging session, so rewriting it would falsify the
anecdote.

The production user_projects row was updated too (name and git_url), because the
database is a second copy of the repo identity and a past rename left 21 rows
pointing at a dead account. New URL proven to resolve: 431bae7.

Tests green: fleet-register 44, project-mention 28, tab-match 10, fleet-map 7,
loki-project-ranking all.


Claude-Session: https://claude.ai/code/session_01NLZ6vs1jsWw2kKbpWTZHf2

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 12:17:25 -07:00
CatoandClaude Fable 5.1 df113dc811 feat(security): threat detection for the box, the GitHub org and the laptop (#708)
A 2026-09-14 posture audit found the box well guarded (default-deny ufw,
keys-only SSH, fail2ban, unattended upgrades, offsite restic) but blind: no
intrusion or integrity detection at all, and the GitHub org with secret
scanning off on all 48 repos and every marketplace action allowed with the
box's root SSH key in an org secret. This adds the detection layer on the
existing alert channel, so a break-in becomes one Telegram message within
five minutes instead of a discovery months later.

- install-security-watch.sh: security-check.sh (5-min timer) alerts on
  CHANGE only — guards down, sshd drift, edits to the files an intruder
  touches (sshd/sudoers/authorized_keys/cron/PAM/ld.so.preload/Caddy/ufw/
  monitoring/units), new internet-facing ports, new privileged accounts,
  SSH logins from never-seen IPs that are not GitHub runners, processes
  from /tmp or miners, new setuid binaries, new containers, stale offsite
  backup, week-old pending reboot. Baselines seed silently; one grouped
  message per tick; every message ends with what to do.
- github-security-check.sh (daily): new secret-scanning alert, new critical
  dependency alert, repo turning public, new member/collaborator/deploy
  key, Actions allowlist loosened. Every API call guarded: a failed call
  skips its check and keeps the baseline (the first version paged an error
  body as a policy change, and a wiped baseline would flood "new" next day).
- Caddy JSON access log on every vhost (snippet + sync-infra template) and
  a fail2ban caddy-scan jail: 8 probes for /.env, /.git, wp-login, cgi-bin
  … in 10 min = 24h ban. Proven by scanning orangecat.ch from the laptop
  (tenth request refused); a real scanner was banned within minutes.
- sshd drop-in: 3 tries, no X11, dead-peer detection, AllowUsers root ubuntu.
- scripts/local/laptop-security-check (user timer, 30 min): new network
  listener, sshd running, screen lock off, upgrades off, ~/.ssh changes,
  new login account, gh identity change, week-old reboot; delivered through
  the box's lib-alert over SSH, desktop notification as fallback.
- test-security-check.sh (test:ops): 39 assertions extracting the shipped
  heredocs; the property under test is "speaks once on change, never when
  nothing changed".
- docs/telegram-notifications.md: every new message registered.

Applied outside the repo in the same session: secret scanning + push
protection on 41/44 active repos (3 private repos are not eligible on the
plan) and as org defaults; Dependabot alerts + automated security fixes on
all 44; org Actions policy = GitHub-owned + verified + an explicit allowlist
of the 11 third-party actions the fleet uses.


Claude-Session: https://claude.ai/code/session_01G6ax7X9GfarifcZUiqsVJm

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 04:29:11 -07:00
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00
CatoandClaude Opus 5 4f465c9582 feat(check): does each registered site's widget actually activate (#640)
Two live sites had had no working widget for months and nothing could have told
us. aoz-housing's token was bound to https://aoz-wohnen.orangecat.ch while the
site is served at aoz.orangecat.ch; sbb-lost-found's was bound to
https://sbb.orangecat.ch, renamed to sbbfundbuero.orangecat.ch. The origin is
written once at provisioning and never looked at again; the host is renamed
whenever the project is.

The state is silent. widget.js loads 200, /api/widget-boot authenticates 200 and
answers {"active":false}, the launcher never mounts, nothing is logged, the page
looks finished. Both are fixed — a rebind updates origins in place and keeps the
token value, so neither site needed a rebuild or a redeploy.

THE FIRST VERSION OF THIS CHECK WAS WRONG AND TESTING CAUGHT IT

It compared each token's `origins` against the register's hosts. Run against
real data it flagged four sites that were completely fine: annushka and
orangecat.ch are not register rows but serve working widgets, fleetcrown does
not put a widget on itself, and one token belonged to an OrangeCat project page
that is not a hosted site. The register is not the universe of hosts with
widgets, so "origins ⊆ register" was never the property anyone wanted.

So ask the site instead. For each registered host: fetch the page, take the
token out of it, ask widget-boot with that host as Origin whether it activates.
No database, no name-mapping between register rows and FleetCrown projects
(exactly the mapping that is unreliable — aoz-wohnen is aoz-housing), and it
catches every way a widget can be dead rather than the one way it can be
mis-bound.

AND IT REPORTS THREE ANSWERS, NOT TWO

The token is injected client-side by next/script, so it reaches the HTML only
inside Next's flight payload. surf-your-life and evig put it there later still —
one preloads the script and attaches the token after hydration — so curl sees no
token on two sites whose widgets work. An earlier sweep called that shape
"widget: NO" on four healthy sites. This prints "token not present in the server
HTML — NOT judged either way" and does not fail on it.

It also self-skips when FleetCrown is unreachable: offline, every site would
look dead, and an instrument failure must not print what an outage prints.

Wired into fleet-register-check beside the shape and reality checks — it needs
the network, which CI does not have. Mutation-proven: pointing a register row at
a host its token does not allow makes it fail and name the site. Against the
real fleet: 23 activate, 2 unjudgeable, 0 dead.


Claude-Session: https://claude.ai/code/session_01G2LBioUzJP4oBL9LeH9qAe

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-11 05:00:47 -07:00
CatoandClaude Opus 5 b5143dac0b feat(register): check the register against reality, and judge it with its own commit (#594)
Two problems, one theme: a fact written in more than one place, and nothing
comparing the copies.

1. NOTHING ASKED WHETHER THE REGISTER STILL DESCRIBED THE BOX

check-deploy-ready.sh judges the register's SHAPE — field count, unique names,
unique ports — and judges it well. Every drift found on 2026-09-10 was
shape-valid and still wrong:

  - aoz-wohnen's `domains` named a host that only 308s. sync-infra.sh rewrites
    each vhost from that field with an unconditional `tee`, so the next sync
    would have deleted the site block that actually serves a live client.
  - revamp-info listed hirnli.orangecat.ch, which has its own hand-written
    vhost — a sync would have declared the host twice, failing `caddy validate`
    and aborting the reload for every OTHER app with it.
  - annushka's API held 4030 with no row while new-site.sh allocated
    max(registered)+1. Four sites away that morning; two by the evening.

None of those fail loudly. A redirect answers 200. An unregistered port is
invisible until something else binds it. A duplicate host does not break until
the next reload.

check-register-reality.sh asks the three questions the shape check cannot:
does every registered domain SERVE ITSELF; is any vhost on the box unbacked by
a row; is anything listening in 4000-4099 the register does not know.

Exceptions are decisions, not silences: register-reality.allow carries a reason
per line. Registering those would be actively WRONG — sync-infra would replace
each hand-written vhost with a plain proxy. Its first run found 4001-4004, which
apps.conf excludes in prose; prose is not machine-readable, so that same fact is
now in a form a script can hold.

2. THE DAILY CHECK READ THE REGISTER FROM origin/main AND THE JUDGE FROM THE TREE

fleet-register-check took great care to read apps.conf from the committed ref,
with a comment explaining that ~15 sessions share the working tree so it is a
scratchpad — then ran `bash scripts/ci/check-deploy-ready.sh` out of that same
scratchpad.

Caught today: ~/dev/fleetcrown sat on another session's branch whose
check-deploy-ready.sh predated #567, so an OLD judge called three perfectly good
rows of a NEW register "drift". The register and the code that judges it now
come from ONE commit (`git archive $REF scripts`), which is what the shim in
~/.local/bin already does one level up for this very reason.

3. A PIPEFAIL TRAP, MEASURED

`printf '%s\n' "$x" | grep -q ...` under `set -o pipefail` reports FAILURE on a
SUCCESSFUL match: grep -q exits at the first hit, the writer takes SIGPIPE, and
pipefail surfaces the writer's death as the pipeline's status. Measured before
believing it: 20/20 false failures on a large payload, 0/20 on a small one —
which is why it presents as a gate that flakes rather than one that is wrong.
Every such construct here is a here-string, which is not a pipeline and has
nothing to signal. (Raised by another session hitting it in
test-site-template.sh; verified independently here.)

Verified: register-reality 10 passed (new — curl and ssh stubbed on PATH, so
every case is offline and deterministic), port-alloc 6, client-ledger 13,
deploy-ready 20. Live run against the box is clean on all three questions.


Claude-Session: https://claude.ai/code/session_01HVudRzEmLqLHvGNqFSpJq6

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 16:21:55 -07:00
644de633b0 fix(ops): a message is worth sending only if a human must act on it (#433)
* fix(ops): a message is worth sending only if a human must act on it

Thirteen Telegrams reached George on the evening of 2026-08-28. Two of them
were real, and one of those two was an outage nobody had told him about in a
way he could act on. This makes every category of the other eleven impossible.

- lib-alert: one delivery point. alert_once/alert_clear give every sender a
  per-subject cooldown; an identical-text floor sits under the UNKEYED path so
  a caller with no state (the register check, which sent the same failure twice
  in 60s) still cannot repeat itself. Keyed senders bypass the floor — two
  mechanisms arguing about one message means the quieter one silently wins.
  ALERT_DRY_RUN=1 journals without delivering, because at 22:14 a test of a new
  check rang a real phone with a message saying it was a test. Suppressed is
  never invisible: the journal gets every alert, including the suppressed ones.

- notify-failure: a oneshot that a retry has already fixed is not an incident.
  restic-check failed at 18:41:42 on a 25-day-old stale lock, was re-run at
  18:42:28, finished clean at 18:44:46 — and paged, because OnFailure fires on
  the failing run and nothing looked again. It looks again. The unit template
  gains TimeoutStartSec: DefaultTimeoutStartSec is 90s, so the notifier would
  otherwise be killed inside its own grace window and the page never sent.

- host-check: an app whose .env its own unit User= cannot read is REPAIRED and
  reported, not asked about. This took two apps down today (vitareba 18:38,
  botsmann 20:16, both root-owned .env, both crash-looping) and both times the
  remedy was one deterministic command — the owner is not a guess, it is the
  unit's User=. deploy.sh asserts the same invariant where the file is written.

- cloud-init-hotplugd is masked. Failed since 2026-07-22 with nothing to do, it
  was the member that pinned the old aggregate latch at `bad` for six weeks;
  per-unit keying turned that silence into a recurring page. A unit that can
  only produce noise should not be in the failed set at all, so that
  `systemctl --failed` keeps meaning "something is wrong".

- fleet-register-check moves into the repo (it was untracked, which is why
  neither of its bugs was ever reviewed) and now judges the register as
  COMMITTED. It read a working tree that ~15 agent sessions share and paged
  twice about a duplicate port that had never been committed. CI still judges
  the tree, which is right there — in CI the tree IS the commit under review.

Six mutations, each reintroducing one of the above, each turning the suite red.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AqzRcMP1uJzd7Tav5fNxQz

* fix(ops): the watchdog had its own copy of the send path

watch.sh carried a byte-identical alert(), so every property added to the
shared one — the duplicate floor, ALERT_DRY_RUN, the journal-always guarantee
— silently did not apply to the watchdog's DOWN/RECOVERED messages. A second
copy of a send path is exactly how the fleet register check ended up able to
page twice in sixty seconds with no state at all: nothing is wrong with the
copy on the day it is made, and nothing updates it afterwards.

Falls back to journal-only if lib-alert.sh is somehow absent, rather than
going silent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AqzRcMP1uJzd7Tav5fNxQz

---------

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 20:48:02 +00:00