diff --git a/Caddyfile b/Caddyfile index bee4f77..5d65203 100644 --- a/Caddyfile +++ b/Caddyfile @@ -275,21 +275,12 @@ stash.ginnoir.com { } } -# BOOKS — chaptarr / CWA / storyteller behind forward_auth; ABS uses native OIDC -# (forward_auth would break the mobile app). All internal_only — remote access +# BOOKS — CWA / storyteller behind forward_auth; chaptarr + ABS use native OIDC +# (forward_auth would break the ABS mobile app). All internal_only — remote access # is via the tailnet (100.64.0.0/10 is already allowed by internal_only). chaptarr.ginnoir.com { import internal_only - route { - import authentik_outpost - handle /api/* { - reverse_proxy chaptarr:8789 - } - handle { - import authentik_forward_auth - reverse_proxy chaptarr:8789 - } - } + reverse_proxy chaptarr:8789 } books.ginnoir.com { diff --git a/scripts/run-books-auth.sh b/scripts/run-books-auth.sh index b18f3c6..706d637 100755 --- a/scripts/run-books-auth.sh +++ b/scripts/run-books-auth.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash # Creates the books-stack Authentik providers/apps (idempotent). Run on valhalla. -# Prints the audiobookshelf OIDC client id/secret path on success. +# Copies the OIDC client ids/secrets out on success. set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" docker cp "$here/setup-books-auth.py" authentik_server:/tmp/setup-books-auth.py docker exec authentik_server ak shell -c "exec(open('/tmp/setup-books-auth.py').read())" 2>&1 | grep -E '^(PROXY|OIDC)|Error|Traceback' -docker cp authentik_server:/tmp/books-abs-oidc.env "${1:-./books-abs-oidc.env}" -docker exec authentik_server rm -f /tmp/books-abs-oidc.env /tmp/setup-books-auth.py +docker cp authentik_server:/tmp/books-oidc.env "${1:-./books-oidc.env}" +docker exec authentik_server rm -f /tmp/books-oidc.env /tmp/setup-books-auth.py diff --git a/scripts/setup-books-auth.py b/scripts/setup-books-auth.py index a9c5bff..9e6f200 100644 --- a/scripts/setup-books-auth.py +++ b/scripts/setup-books-auth.py @@ -1,8 +1,9 @@ # Authentik objects for the books stack (see stacks/media/BOOKS.md). # Idempotent. Run via scripts/run-books-auth.sh (ak shell inside authentik_server). -# - forward_single proxy providers for chaptarr / books (CWA) / storyteller, -# cloned from homelab-sonarr and attached to the embedded outpost -# - native OIDC provider for audiobookshelf (Pattern A) +# - forward_single proxy providers for books (CWA) / storyteller, cloned from +# homelab-sonarr and attached to the embedded outpost (Pattern B) +# - native OIDC providers for chaptarr + audiobookshelf (Pattern A) +# Writes the OIDC client ids/secrets to /tmp/books-oidc.env in the container. from authentik.core.models import Application from authentik.crypto.models import CertificateKeyPair from authentik.flows.models import Flow @@ -24,7 +25,6 @@ outpost = Outpost.objects.get(managed="goauthentik.io/outposts/embedded") FORWARD = [ # (slug, app name, host) - ("chaptarr", "Chaptarr", "chaptarr.ginnoir.com"), ("books", "Calibre-Web Automated", "books.ginnoir.com"), ("storyteller", "Storyteller", "storyteller.ginnoir.com"), ] @@ -50,31 +50,54 @@ for slug, app_name, host in FORWARD: ) print(f"PROXY {slug}: provider pk={p.pk} created={created} app={app.slug}") -outpost.save() # nudge the embedded outpost to pick up new providers +# chaptarr started on forward_auth; it has native OIDC, so drop the proxy provider. +old = ProxyProvider.objects.filter(name="homelab-chaptarr").first() +if old: + outpost.providers.remove(old) + old.delete() + print("PROXY chaptarr: removed old forward_auth provider") -abs_host = "audiobooks.ginnoir.com" -abs_p, created = OAuth2Provider.objects.get_or_create( - name="homelab-audiobooks", - defaults=dict( - client_type="confidential", - authorization_flow=AUTH_FLOW, - invalidation_flow=INVALIDATION_FLOW, - sub_mode="hashed_user_id", - signing_key=SIGNING_KEY, - grant_types=["authorization_code", "refresh_token"], - _redirect_uris=[ - {"url": f"https://{abs_host}/auth/openid/callback", "matching_mode": "strict", "redirect_uri_type": "authorization"}, - {"url": f"https://{abs_host}/auth/openid/mobile-redirect", "matching_mode": "strict", "redirect_uri_type": "authorization"}, - {"url": "audiobookshelf://oauth", "matching_mode": "strict", "redirect_uri_type": "authorization"}, - ], - ), -) -if created: - abs_p.property_mappings.set(SCOPES) -Application.objects.update_or_create( - slug="audiobooks", - defaults=dict(name="Audiobookshelf", provider=abs_p, meta_launch_url=f"https://{abs_host}"), -) -print(f"OIDC audiobooks: provider pk={abs_p.pk} created={created}") -with open("/tmp/books-abs-oidc.env", "w") as f: - f.write(f"ABS_OIDC_CLIENT_ID={abs_p.client_id}\nABS_OIDC_CLIENT_SECRET={abs_p.client_secret}\n") +outpost.save() # nudge the embedded outpost to pick up provider changes + + +def redirect(url): + return {"url": url, "matching_mode": "strict", "redirect_uri_type": "authorization"} + + +OIDC = [ + # (slug, app name, host, env prefix, redirect URIs) + ("chaptarr", "Chaptarr", "chaptarr.ginnoir.com", "CHAPTARR_OIDC", [ + redirect("https://chaptarr.ginnoir.com/signin-oidc"), + ]), + ("audiobooks", "Audiobookshelf", "audiobooks.ginnoir.com", "ABS_OIDC", [ + redirect("https://audiobooks.ginnoir.com/auth/openid/callback"), + redirect("https://audiobooks.ginnoir.com/auth/openid/mobile-redirect"), + redirect("audiobookshelf://oauth"), + ]), +] + +lines = [] +for slug, app_name, host, prefix, uris in OIDC: + p, created = OAuth2Provider.objects.get_or_create( + name=f"homelab-{slug}", + defaults=dict( + client_type="confidential", + authorization_flow=AUTH_FLOW, + invalidation_flow=INVALIDATION_FLOW, + sub_mode="hashed_user_id", + signing_key=SIGNING_KEY, + grant_types=["authorization_code", "refresh_token"], + _redirect_uris=uris, + ), + ) + if created: + p.property_mappings.set(SCOPES) + Application.objects.update_or_create( + slug=slug, + defaults=dict(name=app_name, provider=p, meta_launch_url=f"https://{host}"), + ) + print(f"OIDC {slug}: provider pk={p.pk} created={created}") + lines += [f"{prefix}_CLIENT_ID={p.client_id}", f"{prefix}_CLIENT_SECRET={p.client_secret}"] + +with open("/tmp/books-oidc.env", "w") as f: + f.write("\n".join(lines) + "\n") diff --git a/stacks/media/BOOKS.md b/stacks/media/BOOKS.md index 8f7c326..7149238 100644 --- a/stacks/media/BOOKS.md +++ b/stacks/media/BOOKS.md @@ -12,7 +12,7 @@ storyteller reads both libraries :ro ─► /storage1/labdata/storyteller (align | Service | Container:port | Host port | URL | |---|---|---|---| -| chaptarr | `chaptarr:8789` | 8789 | https://chaptarr.ginnoir.com (forward_auth, `/api/*` bypass) | +| chaptarr | `chaptarr:8789` | 8789 | https://chaptarr.ginnoir.com (native OIDC, LAN + tailnet only) | | calibre-web-automated | `calibre-web-automated:8083` | 8083 | https://books.ginnoir.com (forward_auth, `/opds*` + `/kobo/*` bypass) | | audiobookshelf | `audiobookshelf:80` | 13378 | https://audiobooks.ginnoir.com (native OIDC, LAN + tailnet only) | | storyteller | `storyteller:8001` | 8001 | https://storyteller.ginnoir.com (forward_auth, `/api/*` bypass) | @@ -35,7 +35,12 @@ sudo chown -R 1000:1000 /config/chaptarr /config/calibre-web-automated /config/a `scripts/run-books-auth.sh` creates everything below (idempotent, runs `scripts/setup-books-auth.py` through `ak shell`). **Done on 2026-10-18.** -- **chaptarr / books / storyteller (Pattern B):** proxy providers `homelab-{chaptarr,books,storyteller}` (pk 43–45). They're `forward_single`, cloned from `homelab-sonarr`, attached to the embedded outpost, and each has an app with the same slug. +- **books / storyteller (Pattern B):** proxy providers `homelab-{books,storyteller}` (pk 44–45). They're `forward_single`, cloned from `homelab-sonarr`, attached to the embedded outpost, and each has an app with the same slug. +- **Chaptarr (Pattern A):** OIDC provider `homelab-chaptarr` (pk 47) plus app `chaptarr`, with the strict redirect URI `https://chaptarr.ginnoir.com/signin-oidc`. This replaced the forward_auth provider it started with (pk 43). The client ID and secret are in `stack.env` (`CHAPTARR_OIDC_CLIENT_*`). + In Chaptarr, go to Settings → General → Authentication, choose OIDC, and fill in: + - OIDC Authority: `https://auth.ginnoir.com/application/o/chaptarr/` + - Scopes: `openid profile email` + - Allowed Emails: your Authentik account email(s) - **Audiobookshelf (Pattern A):** OIDC provider `homelab-audiobooks` (pk 46) plus app `audiobooks`. Its strict redirect URIs are `https://audiobooks.ginnoir.com/auth/openid/{callback,mobile-redirect}` and `audiobookshelf://oauth`. The client ID and secret are in `stack.env` (`ABS_OIDC_CLIENT_*`). **Still to do in the ABS UI** (it keeps OIDC settings in its own database): go to Settings → Authentication → OpenID Connect. - Issuer URL: `https://auth.ginnoir.com/application/o/audiobooks/`. Click *Auto-populate*, then paste the client ID and secret. diff --git a/stacks/media/stack.env b/stacks/media/stack.env index 7e0d0bc..1c24590 100644 --- a/stacks/media/stack.env +++ b/stacks/media/stack.env @@ -12,3 +12,8 @@ STORYTELLER_SECRET_KEY=5b41f526eb62c2fbe17527b65a0e71ff06d5927fbeb869541f52e812b # ABS stores OIDC config in its own DB (Settings → Authentication). ABS_OIDC_CLIENT_ID=H617VXaM04KA0URJyWI52ThBpC3crIAZY77UYlzt ABS_OIDC_CLIENT_SECRET=1Tmw0PLw8CP82JX4Vz5nuOfpykh6XKngrU8a4Vspc6ZsIarJn3mG5GwKre1D5DnVqfF7MXbOc5g83lkR7NUcHPjlj3QgPX4BFnbUdl2r09LHrcH9X8CY4gJP0Sl1hdcr + +# chaptarr — Authentik OIDC client (homelab-chaptarr, pk 47). Reference only: +# chaptarr stores OIDC config in its own DB (Settings → General → Authentication). +CHAPTARR_OIDC_CLIENT_ID=BlQNRexLVkgUuH8j0ybmFSiD93dw1mBUF6tsjG6b +CHAPTARR_OIDC_CLIENT_SECRET=THoqN0qLbPuni9cg0vqeid200VsgXKs1WihOSYV8NqciIcp6eCTmvYeRHKYWxF7jOiCBUdL3kP6e4e06SeQr0vwzFSz8rLYYCRomQqizv1iWfRGv0HjfDgkNj49rwrz6