Skip to content
ENNO
← Back to blog
·4 min read·

Building a Self-Hosted Identity Layer with Authentik

Forward auth, OIDC and LDAP from one Authentik install, the Traefik config that ties it together, and three things that bit me along the way.

Building a Self-Hosted Identity Layer with Authentik

Every self-hosted service ships with its own login page. Sonarr has one, Grafana has one, Jellyfin has one. Before Authentik I kept a spreadsheet of credentials and dreaded adding anything new. Now there's one login for all of it, and most of the apps behind it don't even know it's there.

Authentik is a self-hosted identity provider, a small Okta of your own. It speaks OIDC, SAML, LDAP and proxy auth, and I ended up using three of those for different reasons.

Diagram of three ways apps use Authentik. Forward auth, where Traefik asks Authentik before the request reaches the app: Sonarr, Radarr, Jellystat, IT-Tools, Hoppscotch, the Traefik dashboard, a ledger API and an internal status page, 8 routers. OIDC, where the app talks to Authentik and gets a real user: Seerr and Shelfmark. LDAP, where the app checks passwords against Authentik's LDAP outpost: Jellyfin.
What each app can do decides which way it uses Authentik.

Forward auth does most of the work

Traefik has a forwardAuth middleware. Every request to a protected host goes to Authentik first, and only gets through to the app if you have a session. I don't attach it to services one by one. It's part of a chain, and a service either uses the auth chain or the public one:

yaml
authentik: forwardAuth: address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik trustForwardHeader: true authResponseHeaders: - X-authentik-username - X-authentik-groups - X-authentik-email auth-chain: chain: middlewares: - rate-limit - secure-headers - authentik public-chain: chain: middlewares: - rate-limit - secure-headers

So a router just says middlewares: [auth-chain] and it's done. Eight of my routers do that right now. For a couple of the apps I also let the proxy handle login completely, so there's only one prompt. If you do that, make very sure the app can't be reached any other way than through the proxy, or you've just turned its login off.

When the app needs to know who you are

Forward auth tells an app that you're allowed in, not who you are. For Sonarr that's fine, nobody needs their own Sonarr account. For a request app it isn't. When a family member asks for a book in Shelfmark, it needs to be their request under their name, so Shelfmark and Seerr talk OIDC to Authentik directly and get real accounts.

Moving Shelfmark from forward auth to OIDC taught me to do things in the right order. Shelfmark works out its auth mode from its settings, and if it doesn't have both a local admin and a complete OIDC config, it falls back to no auth at all. The forward auth in front was the only thing protecting it, so taking that off first would have left the public URL wide open. The order that worked was to create a local admin, point the app at a new OIDC provider (forward auth then fails closed with a 403), save the OIDC settings in Shelfmark, and only then switch its Traefik router to the public chain.

LDAP for Jellyfin

Jellyfin's TV and phone apps log in with a plain username and password, so it uses Authentik's LDAP outpost instead. That's a separate container that answers LDAP on port 389 and checks against the same users.

One thing caught me out there. Since Authentik 2024.8, binding to LDAP and searching it are two separate permissions. Policy bindings on the application decide who can log in. Who can list users comes from a "Search full LDAP directory" permission on the provider, given to a role. Without it, the service account Jellyfin binds as only ever finds itself, and nobody else can log in. The old "Search group" field that used to do this is just gone from the UI.

The bug that looked like a network problem

My freelance ledger is a small React app behind forward auth, installable as a PWA. On my PC it worked. On my phone it said "network error" and showed no data.

It wasn't the network. The service worker served the cached app shell without going near Authentik, so the page loaded fine. Then the API calls went out with an expired session, Authentik answered with a redirect to the login domain, the browser followed it cross-origin, the CORS preflight failed, and fetch threw a TypeError that the app showed as "network error". The API container looked perfectly healthy the whole time, because those requests never reached it. The answer was in Authentik's outpost logs.

The fix had two halves. In the app, API calls use redirect: 'manual' and send you to /outpost.goauthentik.io/start to log in again when they hit a redirect. In Traefik, the site got two routers: the API paths behind the auth chain, and the static app on the public one.

yaml
ledger-api: rule: "Host(`ledger.example.com`) && (PathPrefix(`/api`) || PathPrefix(`/outpost.goauthentik.io`))" middlewares: - auth-chain priority: 100

The /outpost.goauthentik.io path has to be on the protected router. My first version left it on the public one, where the app's fallback served index.html for it, and the login just looped.

#authentik#sso#traefik#security#self-hosting