forge: remove Darling host-runtime smoke test (root cause) + keep PostgreSQL off /dev/shm (sysv) + pin CloudHSM permalinks #144

Merged
founder merged 6 commits from fix/postgres-devshm-orphan-watchdog into main 2026-08-19 06:44:32 +00:00
Owner

Root cause (found)

The 2026-08-18 21:40→04:57 UTC PostgreSQL outage — every new backend dying with could not open shared memory segment "/PostgreSQL.<n>": No such file or directory while the postmaster stayed up — was caused by key-store-darling-smoke.service. That timer ran the setuid Darling launcher in the host mount namespace every ~6h; darlingserver does unshare(CLONE_NEWNS) then umount/mount /dev/shm before making / MS_SLAVE. On systemd's MS_SHARED root the busy umount hits EBUSY and a fresh empty tmpfs gets stacked onto the host /dev/shm, hiding PG's live segments. /proc/1/mountinfo showed 4 stacked /dev/shm layers; onsets tracked the smoke timer to the second. (Credit: parallel wave-6 RCA.)

It was a mount overlay, not a deletion — which is why the "deleter" left no journal entry, and why an unlink-audit was the wrong tool.

Fix (per direction: "remove all darling smoke testing" + "stop using /dev/shm")

  1. Remove the trigger — delete key-store-darling-smoke.service + .timer and Scripts/darling-bazel-smoke.sh. The rest of Darling (the Apple-build runner integration, agent image, setuid wrapper) is left intact.
  2. Keep PostgreSQL off /dev/shm — dynamic_shared_memory_type = "sysv" (+ kernel.shmmni 4096→32768 for SysV headroom). shared_memory_type is already mmap, so PG then keeps no /dev/shm files and is immune to any future /dev/shm remount/wipe.
  3. Unblock the build — pin the AWS CloudHSM SDK debs to immutable versioned URLs (5.18.0-1, 3.4.4-1) instead of the mutable _latest_ objects. AWS republished _latest_ on 2026-08-19, which broke the fixed-output hashes and blocked every forge rebuild; versioned permalinks can't drift.

Dropped from the earlier revision of this PR: the postgresql-shm-watchdog and /dev/shm audit layers — the audit was the wrong tool for a mount-stacking cause, and with the trigger removed + PG off /dev/shm the recovery/diagnostic layers are moot (PG FATAL/backup alerting is owned by the wave-6 patch).

Notes

  • The 4 already-stacked /dev/shm layers clear on the next reboot; do not umount the top layer while PG runs on it.
  • The darling key-store-darling-smoke.timer was manually stopped at 06:14Z; this makes the removal permanent so a switch/reboot can't re-arm it.

Validation

  • nix-instantiate --parse clean on all three files.
  • Deploy is a forge nixos-rebuild switch (restarts postgresql once for the sysv change; rebuilds the self-sourced container images, now buildable via the permalinks).
## Root cause (found) The 2026-08-18 21:40→04:57 UTC PostgreSQL outage — every new backend dying with `could not open shared memory segment "/PostgreSQL.<n>": No such file or directory` while the postmaster stayed up — was caused by **`key-store-darling-smoke.service`**. That timer ran the setuid Darling launcher in the **host** mount namespace every ~6h; `darlingserver` does `unshare(CLONE_NEWNS)` then `umount`/`mount /dev/shm` **before** making `/` `MS_SLAVE`. On systemd's `MS_SHARED` root the busy `umount` hits `EBUSY` and a fresh empty tmpfs gets **stacked** onto the host `/dev/shm`, hiding PG's live segments. `/proc/1/mountinfo` showed 4 stacked `/dev/shm` layers; onsets tracked the smoke timer to the second. (Credit: parallel wave-6 RCA.) It was a **mount overlay, not a deletion** — which is why the "deleter" left no journal entry, and why an unlink-audit was the wrong tool. ## Fix (per direction: "remove all darling smoke testing" + "stop using /dev/shm") 1. **Remove the trigger** — delete `key-store-darling-smoke.service` + `.timer` and `Scripts/darling-bazel-smoke.sh`. The rest of Darling (the Apple-build runner integration, agent image, setuid wrapper) is left intact. 2. **Keep PostgreSQL off `/dev/shm`** — `dynamic_shared_memory_type = "sysv"` (+ `kernel.shmmni` 4096→32768 for SysV headroom). `shared_memory_type` is already `mmap`, so PG then keeps **no** `/dev/shm` files and is immune to any future `/dev/shm` remount/wipe. 3. **Unblock the build** — pin the AWS CloudHSM SDK debs to **immutable versioned URLs** (`5.18.0-1`, `3.4.4-1`) instead of the mutable `_latest_` objects. AWS republished `_latest_` on 2026-08-19, which broke the fixed-output hashes and blocked every forge rebuild; versioned permalinks can't drift. Dropped from the earlier revision of this PR: the `postgresql-shm-watchdog` and `/dev/shm` audit layers — the audit was the wrong tool for a mount-stacking cause, and with the trigger removed + PG off `/dev/shm` the recovery/diagnostic layers are moot (PG FATAL/backup alerting is owned by the wave-6 patch). ## Notes - The 4 already-stacked `/dev/shm` layers clear on the next reboot; do **not** `umount` the top layer while PG runs on it. - The darling `key-store-darling-smoke.timer` was manually stopped at 06:14Z; this makes the removal permanent so a switch/reboot can't re-arm it. ## Validation - `nix-instantiate --parse` clean on all three files. - Deploy is a forge `nixos-rebuild switch` (restarts postgresql once for the sysv change; rebuilds the self-sourced container images, now buildable via the permalinks).
On 2026-08-18 21:40:18 UTC the PostgreSQL DSM control segment
/dev/shm/PostgreSQL.4007731292 was unlinked out from under the live
postmaster (PID 269679 kept running the whole time). From that instant every
NEW backend died with `could not open shared memory segment "/PostgreSQL.
4007731292": No such file or directory` + `can't attach the same segment more
than once`, so Forgejo Actions, Authentik, PostHog, agent-dispatcher and the
winrunner dispatch loop all failed for ~7h. Because the postmaster stayed up,
systemd saw nothing wrong; service only returned after a manual
`systemctl restart postgresql` at 04:57 UTC recreated the segment.

Ruled out as the deleter: logind RemoveIPC (=no on this host), systemd-tmpfiles
(no rule touches /dev/shm), a deploy/activation (none ran at 21:40), and an
OOM/crash of the postmaster (it survived). The unlink correlates tightly with
podman/authentik container-teardown churn (authentik-server had been crash-
looping on a ~30s cycle for ~42h; its container died at 21:40:18.685, the same
instant) but the exact unlink call left no journal entry and the container IPC
mode is `shareable`, so the mechanism is not yet proven from logs.

Three layers, all in nixos/keystore-forge.nix:

1. Prevention: services.postgresql.settings.dynamic_shared_memory_type = "sysv"
   moves DSM out of /dev/shm into kernel SysV IPC (still RAM-backed, protected
   by RemoveIPC=no). shared_memory_type is already mmap, so PostgreSQL then
   keeps NO files in /dev/shm and a /dev/shm wipe can no longer orphan it.
   kernel.shmmni raised 4096 -> 32768 for ample SysV segment headroom (~1 in
   use at rest; shmmax/shmall already effectively unbounded).

2. Recovery: postgresql-shm-watchdog.{service,timer} probes a fresh backend
   every 30s and, ONLY on the exact "could not open shared memory segment"
   signature, restarts postgresql (with a 5-min cooldown). Any other failure is
   left to normal systemd handling, so it cannot mask unrelated problems. Turns
   a silent multi-hour outage into a <=30s blip even if some other actor wipes
   /dev/shm in future.

3. Diagnostic: enable auditd + audit unlink/rename under /dev/shm by non-postgres
   uids (key dev_shm_delete). auditd/inotify-tools were both absent, so nothing
   could name the deleter; `ausearch -k dev_shm_delete` will capture pid/comm/exe
   on the next occurrence.

Deploy is founder-gated (in-flight KSE-0182 OpenBao work on the forge).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The forge already runs systemd-journald-audit.socket (active/enabled) and
grafana-alloy-journal, which ships the journal to Loki. security.auditd would
only write /var/log/audit/audit.log, which Alloy does not read, so those events
would never reach Grafana. Drop security.auditd.enable and keep just the audit
rule (security.audit.enable): the journald audit socket captures the records as
_TRANSPORT=audit and Alloy ships them to Loki -> visible/alertable in Grafana
(filter key=dev_shm_delete). On-box: journalctl _TRANSPORT=audit -g dev_shm_delete.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
flake: refresh AWS CloudHSM SDK5 (cli, pkcs11) deb hashes for the moved "latest"
Some checks failed
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 27s
Build: Web / Build (Web) (pull_request) Successful in 3m7s
Build: Apple / Check (SwiftLint) (pull_request) Failing after 2m41s
Build: Apple / Build (iOS) (pull_request) Has been skipped
Build: Apple / Build (macOS) (pull_request) Has been skipped
Build: Apple / Build (visionOS) (pull_request) Has been skipped
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been cancelled
Build: Linux / Build (Linux x86_64) (pull_request) Has been cancelled
f1be86ddd5
AWS republished cloudhsm-{cli,pkcs11}_latest_u24.04_amd64.deb on 2026-08-19
01:01-01:02 UTC (x-amz-version-id changed), so the pinned fixed-output hashes
stopped matching. This broke every forge toplevel rebuild that touches the
flake source (the CloudHSM SDK image is self-sourced) with:
  error: hash mismatch in fixed-output derivation '...cloudhsm-cli_latest...deb'
Re-pinned to the current content. The u18.04 (SDK3/kmu) deb is unchanged.
Added a note: these track AWS's mutable "latest" objects and will drift again;
a versioned CloudHsmClient URL would be the durable fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
flake: pin CloudHSM debs to immutable versioned URLs (no more "_latest_")
Some checks failed
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 25s
Build: Web / Build (Web) (pull_request) Successful in 34s
Build: Apple / Check (SwiftLint) (pull_request) Failing after 2m20s
Build: Apple / Build (iOS) (pull_request) Has been skipped
Build: Apple / Build (macOS) (pull_request) Has been skipped
Build: Apple / Build (visionOS) (pull_request) Has been skipped
Build: Linux / Build (Linux x86_64) (pull_request) Successful in 6m43s
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been skipped
c7e9d108d2
Replace the mutable "_latest_" CloudHsmClient S3 objects with versioned
permalinks so a build can never break again when AWS republishes "latest"
in place (root cause of the 2026-08-19 forge rebuild breakage):
  cloudhsm-pkcs11 -> 5.18.0-1 (u24.04)
  cloudhsm-cli    -> 5.18.0-1 (u24.04)
  cloudhsm-client -> 3.4.4-1  (u18.04, SDK3 kmu; was implicitly "latest")
Each versioned URL returns HTTP 200 and byte-identical content to the
"latest" it replaced (hashes unchanged from the prefetch). Bump instructions
are in the comment above the derivations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
forge: remove Darling host-runtime smoke test (root cause of the /dev/shm outage); drop now-moot PG watchdog+audit
Some checks failed
Build: Apple / Check (SwiftLint) (pull_request) Failing after 20s
Build: Apple / Build (iOS) (pull_request) Has been skipped
Build: Apple / Build (macOS) (pull_request) Has been skipped
Build: Apple / Build (visionOS) (pull_request) Has been skipped
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been cancelled
Build: Web / Build (Web) (pull_request) Has been cancelled
Build: Linux / Build (Linux x86_64) (pull_request) Has been cancelled
Build: KaiOS / Build (KaiOS) (pull_request) Has been cancelled
e5a6dd6429
Root cause of the 2026-08-18 21:40->04:57 PostgreSQL outage (wave-6 RCA,
confirmed by the host mount table): key-store-darling-smoke.service ran the
setuid Darling launcher in the HOST mount namespace every ~6h. darlingserver
unshares CLONE_NEWNS then umount/mounts /dev/shm BEFORE making / MS_SLAVE; on
systemd's MS_SHARED root the busy umount hits EBUSY and stacks a fresh empty
tmpfs onto the host /dev/shm, hiding PostgreSQL's live segments so every NEW
backend fails with `could not open shared memory segment ... No such file or
directory` while the postmaster stays up (silent, systemd sees it healthy).
/proc/1/mountinfo showed 4 stacked /dev/shm layers; onsets tracked the smoke
timer to the second.

Fix per founder direction ("remove all darling smoke testing" + "stop using
/dev/shm"):
- Remove key-store-darling-smoke.service + .timer (the recurring trigger) and
  Scripts/darling-bazel-smoke.sh. The rest of Darling (the Apple-build runner
  integration, agent image, setuid wrapper) is left intact.
- Keep PostgreSQL off /dev/shm: dynamic_shared_memory_type=sysv (+ kernel.shmmni
  headroom). With shared_memory_type already mmap, PG keeps NO /dev/shm files
  and is immune to any future /dev/shm remount/wipe.
- Drop the earlier postgresql-shm-watchdog and /dev/shm audit layers: the
  unlink-audit was the wrong tool for a mount-stacking cause, and with the
  trigger removed + PG off /dev/shm the recovery/diagnostic layers are moot
  (PG FATAL/backup alerting is owned by the wave-6 patch).

The 4 stacked /dev/shm layers already present clear on the next reboot; do NOT
umount the top layer while PG runs on it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
founder changed title from forge postgres: move DSM off /dev/shm (sysv) + orphaned-segment watchdog + /dev/shm audit to forge: remove Darling host-runtime smoke test (root cause) + keep PostgreSQL off /dev/shm (sysv) + pin CloudHSM permalinks 2026-08-19 06:25:37 +00:00
Merge origin/main (windows licensing commits) into fix/postgres-devshm-orphan-watchdog
Some checks failed
Build: Apple / Check (SwiftLint) (pull_request) Failing after 19s
Build: Apple / Build (iOS) (pull_request) Has been skipped
Build: Apple / Build (macOS) (pull_request) Has been skipped
Build: Apple / Build (visionOS) (pull_request) Has been skipped
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 28s
Build: Web / Build (Web) (pull_request) Successful in 31s
Build: Linux / Build (Linux x86_64) (pull_request) Successful in 5m41s
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been skipped
Namespace: Build Images / Refresh macOS runner lane (push) Successful in 3s
Release: If Needed / Check (Release Needed) (push) Successful in 9s
Release: Signing Preflight / Release (Signing Preflight) (push) Successful in 1m3s
Build: Apple / Check (SwiftLint) (push) Has been cancelled
Build: Apple / Build (iOS) (push) Has been cancelled
Build: Apple / Build (macOS) (push) Has been cancelled
Build: Apple / Build (visionOS) (push) Has been cancelled
Deploy: API / Deploy (API) (push) Has been cancelled
Namespace: Build Images / Refresh macOS Nix snapshot application (push) Has been cancelled
Deploy: Web / Deploy (Web) (push) Has been cancelled
Build: Web / Build (Web) (push) Has been cancelled
Namespace: Build Images / Refresh Linux runner image (push) Has been cancelled
Build: KaiOS / Build (KaiOS) (push) Has been cancelled
Build: Linux / Build (Linux x86_64) (push) Successful in 7m3s
Build: Linux / Build (keystore-forge x86_64) (push) Has been skipped
0afc446bc7
founder deleted branch fix/postgres-devshm-orphan-watchdog 2026-08-19 06:44:32 +00:00
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
key-store/key.store!144
No description provided.