forge: authentik-smoke never pipes curl into an early-exiting reader (exit 23 on healthy IdP) #157

Merged
founder merged 1 commit from claude/epic-torvalds-c8fe5d into main 2026-08-19 07:17:39 +00:00
Owner

authentik-smoke.service failed on every hourly run for days (curl: Failed writing body, status=23) while Authentik itself was healthy.

Cause — the three SAML metadata probes were curl -fsSL … | grep -q 'entityID=…'. The entityID sits on line 1 of the ~6.4 KB metadata; curl writes the body into the pipe in two chunks (4096 + rest); grep -q exits on the first match; curl's second write hits EPIPE → exit 23, and under pipefail that is the pipeline's status because grep exited 0. Reproduced on the forge: the deployed script passes 5/10 (the Zulip metadata pipeline alone fails 7/10).

Fix — every HTTP body lands in a shell variable before anything inspects it: new check_oidc_discovery / check_saml_metadata_entity_id helpers, and the JWKS loop + check_saml_metadata_cert fetch first and run jq/grep on a here-string. No curl stdout ever feeds a reader that can stop early, so exit 23 cannot occur. fetch adds --max-time 60 (the oneshot has TimeoutStartSec=infinity, so a stalled upstream would otherwise park the unit and starve the timer). The discovery / entityID checks now say which provider failed instead of exiting 1 silently. All assertions are kept (readiness, per-provider issuer, authorize probes, SAML entityIDs, SAML/OIDC certificate checks).

Verification on the forge (script rendered with nix eval .#nixosConfigurations.keystore-forge.config.systemd.services.authentik-smoke.script, run under the unit's own PATH):

  • new script: 10/10 passes; old deployed script in the same minute: 5/10 (all rc=23)
  • outage shapes, each in a fresh bash so set -e matches the unit: IdP connection refused → rc 7; Caddy-style 502 (local TLS stub) → rc 22 The requested URL returned error: 502; upstream accepts and never answers → rc 28 (--max-time); unknown provider (404) → rc 22; wrong issuer / non-JSON / empty body → rc 1 with … discovery document does not publish its own issuer; wrong or prefix entityID → rc 1 with … does not publish entityID …
  • controls: real discovery docs (forgejo/redmine/mcp/metrics/office) and real SAML entityIDs pass.

Follow-up after merge: forge switch, then systemctl status authentik-smoke after the next timer run.

`authentik-smoke.service` failed on every hourly run for days (`curl: Failed writing body`, status=23) while Authentik itself was healthy. **Cause** — the three SAML metadata probes were `curl -fsSL … | grep -q 'entityID=…'`. The entityID sits on line 1 of the ~6.4 KB metadata; curl writes the body into the pipe in two chunks (4096 + rest); `grep -q` exits on the first match; curl's second write hits EPIPE → exit 23, and under `pipefail` that is the pipeline's status because grep exited 0. Reproduced on the forge: the deployed script passes 5/10 (the Zulip metadata pipeline alone fails 7/10). **Fix** — every HTTP body lands in a shell variable before anything inspects it: new `check_oidc_discovery` / `check_saml_metadata_entity_id` helpers, and the JWKS loop + `check_saml_metadata_cert` fetch first and run `jq`/`grep` on a here-string. No curl stdout ever feeds a reader that can stop early, so exit 23 cannot occur. `fetch` adds `--max-time 60` (the oneshot has `TimeoutStartSec=infinity`, so a stalled upstream would otherwise park the unit and starve the timer). The discovery / entityID checks now say which provider failed instead of exiting 1 silently. All assertions are kept (readiness, per-provider issuer, authorize probes, SAML entityIDs, SAML/OIDC certificate checks). **Verification on the forge** (script rendered with `nix eval .#nixosConfigurations.keystore-forge.config.systemd.services.authentik-smoke.script`, run under the unit's own PATH): - new script: 10/10 passes; old deployed script in the same minute: 5/10 (all rc=23) - outage shapes, each in a fresh bash so `set -e` matches the unit: IdP connection refused → rc 7; Caddy-style 502 (local TLS stub) → rc 22 `The requested URL returned error: 502`; upstream accepts and never answers → rc 28 (`--max-time`); unknown provider (404) → rc 22; wrong issuer / non-JSON / empty body → rc 1 with `… discovery document does not publish its own issuer`; wrong or prefix entityID → rc 1 with `… does not publish entityID …` - controls: real discovery docs (forgejo/redmine/mcp/metrics/office) and real SAML entityIDs pass. Follow-up after merge: forge switch, then `systemctl status authentik-smoke` after the next timer run.
forge: authentik-smoke never pipes curl into an early-exiting reader (exit 23 on healthy IdP)
Some checks failed
Namespace: Build Images / Refresh macOS runner lane (push) Successful in 3s
Namespace: Build Images / Refresh macOS Nix snapshot application (push) Successful in 36s
Namespace: Build Images / Refresh Linux runner image (push) Successful in 58s
Deploy: Web / Deploy (Web) (push) Successful in 2m37s
Deploy: API / Deploy (API) (push) Successful in 2m55s
Release: If Needed / Check (Release Needed) (push) Has been cancelled
ef4d4347c3
authentik-smoke.service failed on every hourly run for days with
`curl: Failed writing body` / status=23 while Authentik was healthy.
The three SAML metadata probes were `curl -fsSL … | grep -q 'entityID=…'`:
the entityID sits on line 1 of the ~6.4 KB metadata, curl writes the body
to the pipe in two chunks (4096 + rest), grep -q exits on the first match,
curl's second write hits EPIPE → 23, and under `pipefail` that is the
pipeline's status (grep exited 0). Reproduced on the forge: the deployed
script passes 5/10 (7/10 failures on the Zulip metadata pipeline alone).

Fix: every HTTP body now lands in a shell variable before anything looks
at it — `check_oidc_discovery`, `check_saml_metadata_entity_id`, the JWKS
loop and `check_saml_metadata_cert` all `fetch` first and run jq/grep on
a here-string, so no curl stdout ever feeds a reader that can stop early.
`fetch` also adds `--max-time 60` (the oneshot has TimeoutStartSec=infinity;
a stalled upstream would otherwise park the unit and starve the timer).
The discovery/entityID checks now print which provider failed instead of
exiting 1 silently. Assertions are unchanged (readiness, per-provider
issuer, authorize probes, entityIDs, SAML/OIDC cert checks).

Verified on the forge (script rendered with `nix eval …authentik-smoke.script`,
run under the unit's PATH): 10/10 passes; negative cases fail as required —
IdP connection refused → 7, Caddy 502 stub → 22, stalled upstream → 28,
unknown provider (404) → 22, wrong issuer / non-JSON / empty body → 1,
wrong or prefix entityID → 1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
founder deleted branch claude/epic-torvalds-c8fe5d 2026-08-19 07:17:39 +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!157
No description provided.