Files
serverAppConfigs/tests/homepage_caddy.bats
T
Frank ef07e7d01a fix(caddy,authentik): auth guarded vhosts by proxying the whole request through authentik
The forward_auth target /outpost.goauthentik.io/auth/caddy does not exist
in authentik 2026.8 (verified live: 404 for every header combination; the
URL tree has no outpost auth prefix at all — the outpost worker dials back
to core over ws/outpost/<uuid>/ instead). Unauthenticated subrequests got
404, Caddy treated >=400 as 'not authenticated' and redirected browsers to
the dead path — users saw authentik's own Not-Found page.

Fix: guarded vhosts now proxy the whole request through authentik-server:9000
with X-authentik-meta-outpost/-provider/-app headers (the exact header set
this build's Traefik controller emits, adapted for Caddy). Unauthenticated
clients get the login flow served in place; once a session exists,
authentik proxies on to the provider's internal_host — now
http://caddy:8017, a new post-auth internal listener that routes straight to
the app. The chain terminates; nothing dials back into authentik.

Live DB changes applied alongside (postgres is the source of truth):
provider pk=1 authentication_flow=default-authentication-flow (was NULL —
the actual cause of the 404s) and internal_host=http://caddy:8017 (was
self-referential http://authentik-server:9000).
2026-08-28 22:28:32 -07:00

48 lines
2.1 KiB
Bash

#!/usr/bin/env bats
# Seam: the homepage site block in dankclaw/Caddyfile. Since the Anubis
# rollout the naked domain + www are guarded vhosts: the public listener
# proxies everything through Anubis (bot challenge), and the Authentik
# forward_auth for SSO runs on Caddy's internal listener (http://:8016)
# after Anubis has verified the client. caddy is not on the dev box, so the
# tests assert the structure statically.
load helpers
setup() {
CADDY="$REPO_ROOT/dankclaw/Caddyfile"
}
@test "the homepage serves /srv/homepage" {
grep -q "root \* /srv/homepage" "$CADDY"
grep -q "file_server" "$CADDY"
}
@test "the /admin/ page serves admin.html and / serves index.html" {
# Each page is served by its own 'handle' block via 'try_files'.
grep -qE "handle[[:space:]]+/admin\*" "$CADDY"
grep -qE "try_files[[:space:]]+/admin.html" "$CADDY"
grep -qE "try_files[[:space:]]+/index.html" "$CADDY"
}
@test "the shared data + assets are served to any authenticated user" {
# The data (services.json, status.json) and assets are fetched by both the
# user page and the admin page. With forward_auth, any authenticated user
# can access them (the browser's Authentik session covers these fetches).
grep -qE "@data[[:space:]]+path[[:space:]]+/services\.json[[:space:]]+/status\.json" "$CADDY"
grep -qE "handle[[:space:]]+@data" "$CADDY"
}
@test "the homepage vhost chains Anubis (public) before Authentik SSO (internal listener)" {
# Public listener: the naked domain proxies everything through Anubis.
local block
block=$(awk '/^franksdank\.cloud[[:space:]]/,/^}/' "$CADDY")
echo "$block" | grep -q 'reverse_proxy anubis:8923'
# The SSO check itself runs on the internal listener that Anubis
# forwards accepted traffic to; Host survives the hop, so per-vhost
# routing resumes there — guarded vhosts proxy the whole request
# through Authentik, which forwards authenticated traffic back on the
# post-auth listener (http://:8017) that routes straight to the app.
grep -q 'http://:8016' "$CADDY"
awk '/^http:\/\/:8016/,/^\}/' "$CADDY" | grep -q 'reverse_proxy authentik-server:9000'
}