Enterprise SSO Implementation
Set up single sign-on across my homelab — one login for everything from the documentation wiki to the code editor. Authentik validates credentials against Active Directory, then issues a session cookie the reverse proxy checks on every request. Log in once; everything just works after that.
- logins
- one AD login for every protected app
- new app
- ~5 minutes to put behind SSO
- auth failures
- none since going live
- audit
- every login attempt logged in Authentik
The Problem
What I Started With
- A growing set of self-hosted apps in my homelab (documentation wiki, dashboard, code editor, etc.)
- Each app had its own login page and password
- I was either reusing passwords (bad security) or forgetting which password went with which app
- No way to see who accessed what, or block access globally if needed
Why This Sucks
- Security risk: Weak passwords get reused, or you write them down
- Time waste: Managing users separately in every app
- No control: Can't revoke someone's access to everything at once
- Annoying: Logging in again for every app I checked
The Solution
How It Works
First Time Visiting an App:
- You type in the URL:
https://docs.homelab.local - Reverse proxy (like a security guard) stops you: "Show me your session cookie"
- You don't have one yet, so it redirects you to the login page
- You enter your username/password (which gets checked against Active Directory)
- Login works → You get a session cookie → Redirected back to the app
- Now the security guard sees your cookie and lets you through
Every Time After That:
- Your browser automatically sends the session cookie with each request
- Security guard checks cookie → Valid → Lets you through
- You don't see any of this - the app just loads instantly
The Tech Stack
- Active Directory: 2 domain controllers storing users and credentials
- Authentik: Identity provider — handles the login page, validates credentials against AD, and issues session tokens
- Nginx Proxy Manager: Reverse proxy — every request passes through it before reaching the app
- Docker: All components run containerized on the same server
What I Actually Built
The Main Pieces
Active Directory (The User Database)
- Set up 2 domain controllers — if one fails, the other keeps auth working
- All usernames and credentials live here
- Authentik talks to it over LDAP to verify logins
Authentik (The Login System)
- Handles the login page and authentication flows
- Validates credentials against Active Directory over LDAP
- Issues and manages session cookies after successful login
Nginx Proxy Manager (The Security Gate)
- Sits in front of all applications
- Checks every request: "Do you have a valid session?"
- If yes → Let you through. If no → Send you to login.
Docker (How It All Runs)
- Each component runs in its own container on the same host
- Containers communicate over an internal Docker network
- Can restart or update Authentik without touching the apps behind it
Key Technical Decisions
- Forward auth works with any HTTP(S) application — no changes to the app itself
- Application never sees credentials
- Auth enforced at the network edge before requests reach the app
- Same pattern applies to any app you add later
- Trade-off: Double authentication if the app has its own native auth (acceptable here)
- Performance isolation (auth validation vs login flows, LDAP queries, UI)
- Separation of concerns (auth validation vs identity management)
- Mirrors enterprise IdP architecture (e.g., Okta agents)
The Challenges
What Went Wrong:
Error: LDAP bind failed - Invalid credentials
The Problem:
- I was using email format:
admin@domain.local - LDAP doesn't understand email format - it needs a specific path
- Required format:
CN=Admin,OU=Users,DC=domain,DC=local
The Fix:
Used the full Distinguished Name (DN) path instead of email/UPN format.
Lesson Learned:
LDAP has its own addressing format. Email-style usernames won't work for bind operations.
What Went Wrong:
401 Unauthorized (even after successful login)
The Problem:
- nginx's
auth_requestonly accepts 2xx as "allow" - Authentik was returning 401 for "not logged in" (correct)
- But nginx wasn't properly handling the redirect flow
The Fix:
Configured proper error_page 401 = @authentik handling and set up the redirect location block correctly.
Lesson Learned:
HTTP status codes have specific meanings in auth flows. Need to understand how nginx interprets subrequest responses.
What Went Wrong:
Login works, but redirected back to login immediately
The Problem:
- Cookies have domain restrictions
- Cookie set for
auth.domain.localwasn't being sent toapp.domain.local - Browser security feature, not a bug
The Fix:
Configured Authentik to set cookies for the parent domain .domain.local so they're sent to all subdomains.
Lesson Learned:
When login involves redirects between subdomains, you have to understand cookie policies. This took reading browser documentation and testing different settings.
Results
- Every protected app behind one login
- One set of AD credentials for everything — no per-app passwords
- ~5 minutes to add a new application to SSO
- No authentication failures since going live
- Every login attempt logged in Authentik
Reusable Pattern
Adding SSO to a new application takes ~5 minutes:
- In Authentik: Create Proxy Provider + Application (3 clicks)
- In Authentik: Assign application to outpost (1 click)
- In NPM: Add
auth_requestlocation blocks to proxy host (paste config) - Test: Access app → redirect to login → authenticate → access granted
Currently protected by this pattern:
- Documentation platform (Bookstack)
- Web IDE (code-server)
- Earlier: a dashboard (Glance) and a backup tool (Duplicati), both retired in October 2026
And works for any future HTTP(S) application without touching the app itself.
The Short Version
I was running a set of self-hosted applications with independent user management — password fatigue, reused credentials, no centralized audit trail. The goal was to implement SSO that would work across everything, including apps without native SSO support. I deployed Authentik as the identity provider backed by a 2-DC Active Directory environment, then placed authentication at the reverse proxy layer so every HTTP request gets validated before it reaches the application. That's the same architecture Cloudflare Access uses — auth enforced at the edge, apps never see credentials directly.
The hard parts were protocol-level: LDAP bind operations require Distinguished Name format (CN=Admin,OU=Users,DC=domain,DC=local), not the UPN email format I first tried. nginx's auth_request only treats 2xx responses as "allow," which required correctly wiring the error_page 401 = @authentik redirect flow. And session cookies set on auth.domain.local don't propagate to app.domain.local without explicitly scoping them to the parent domain. Once those three pieces clicked, the rest was just configuration — and the pattern now takes about 5 minutes to apply to any new application.