From 060f2881073b16ae698d0f5f3698744b3d9cf2e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 00:21:13 +0000 Subject: [PATCH] Fix authelia.sh skipping the real Caddy snippet due to a commented example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit grep -q "(authelia)" matches caddy.sh's starter Caddyfile's own commented- out example block ("# (authelia) {", included as documentation), so authelia.sh believed the real snippet already existed and never wrote it. Any later service adding `import authelia` to its own site block then references a snippet that only exists as a comment. Confirmed live: this takes Caddy down completely, not just the Authelia-protected site — "Error: adapting config using caddyfile: File to import not found: authelia" is a load-time failure, so Caddy restart-loops and every site it fronts goes with it. Anchor the check to an actual uncommented snippet definition (^\(authelia\)\s*\{) instead of a bare substring match. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01H4k6J1qXXyYxhGEgnJaMvn --- services/authelia.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/authelia.sh b/services/authelia.sh index c31c91a..365c1fb 100644 --- a/services/authelia.sh +++ b/services/authelia.sh @@ -425,7 +425,16 @@ AUTHELIA_USERS local CADDY_FILE="$DOCKER_DIR/caddy/Caddyfile" if [ -f "$CADDY_FILE" ]; then echo " Configuring Caddy for Authelia..." - if ! grep -q "(authelia)" "$CADDY_FILE"; then + # Anchored to an actual, uncommented snippet definition — a bare + # `grep -q "(authelia)"` also matches the commented-out example + # block caddy.sh's starter Caddyfile ships ("# (authelia) {" as + # documentation). Confirmed live: that false match made this skip + # writing the real snippet entirely, leaving any later `import + # authelia` reference elsewhere in the file dangling — Caddy then + # refuses to start at all ("File to import not found: authelia"), + # taking down every site it fronts, not just the Authelia-protected + # one. + if ! grep -qE '^\(authelia\)[[:space:]]*\{' "$CADDY_FILE"; then cp "$CADDY_FILE" "$CADDY_FILE.backup.$(date +%Y%m%d-%H%M%S)" { cat << 'SNIPPET_EOF' # ── Authelia forward auth snippet ─────────────────────────────────────────────