Home Server › Containers

Setting up Authelia SSO and Forward Auth in Nginx Proxy Manager

Protect self-hosted dashboards with Authelia Forward Auth in Nginx Proxy Manager, backed by LLDAP, Redis, PostgreSQL, and OIDC single sign-on.

Setting up Authelia SSO and Forward Auth in Nginx Proxy Manager

Exposing internal admin panels directly to the internet leaves every service defending itself against brute-force logins and framework CVEs. Here is how I put Authelia in front of Nginx Proxy Manager for Forward Auth and wired it up as an OIDC provider backed by LLDAP, Redis, and PostgreSQL.

Tested with Authelia v4.38+, Nginx Proxy Manager, LLDAP, PostgreSQL, and Redis on Docker Compose.


Why self-hosted services need a central auth gate

Once a homelab grows past a handful of containers, authentication turns into the weakest link. Admin tools like Portainer or Uptime Kuma either ship with basic local login forms, lack brute-force rate limiting, or expire sessions differently from one app to the next. If a CVE lands in one web UI’s auth handler, an attacker can walk straight past it because the reverse proxy forwarded the packet untouched.

Forward Auth flips that model around. Instead of letting the backend application decide whether a request is authenticated, the reverse proxy asks a central identity gateway first. Unauthenticated traffic never reaches the upstream container.

I chose Authelia because it covers both halves of a homelab auth stack in a single lightweight binary:

  1. Forward Auth (auth_request): Sits in front of apps that don’t speak OIDC (or admin panels where you want a second outer gate) and blocks unauthenticated HTTP requests at Nginx.
  2. OIDC (OpenID Connect) provider: Issues standard OAuth2/OIDC tokens for modern apps like Gitea and Outline Wiki, so every service shares one identity store.
ApproachBest fitTrade-offs
Authelia Forward AuthLegacy dashboards, admin UIs without OIDC, extra perimeter gateRequires per-host Nginx snippets; breaks non-browser API clients unless paths are bypassed
Authelia OIDC ProviderApps with native OIDC (Gitea, Outline, Portainer BE)App-level role mapping works natively, but each client needs a registered secret and callback URI
Authentik / KeycloakLarge orgs needing SAML, complex visual flows, or SCIMHeavier memory footprint (hundreds of MB to 1GB+ RAM) than a small homelab usually needs

When not to use Forward Auth: Don’t slap Forward Auth in front of webhook receivers, mobile sync APIs, or Git over HTTPS endpoints without adding explicit bypass rules in Authelia. Those clients can’t follow a 302 redirect to an HTML login form and will fail silently with 401 or redirect errors.


How the Forward Auth pipeline works

When a browser requests a protected domain such as health.namju.kim, Nginx Proxy Manager doesn’t forward the request straight to the backend. It first fires an internal subrequest to Authelia’s /api/authz/auth-request endpoint with the original method, URL, and session cookies attached.

sequenceDiagram
    autonumber
    actor User as Browser
    participant NPM as Nginx Proxy Manager
    participant Auth as Authelia
    participant App as Backend (Uptime Kuma)

    User->>NPM: GET https://health.namju.kim
    NPM->>Auth: auth_request (check session cookie)
    alt Unauthenticated (401)
        Auth-->>NPM: 401 + Location (https://auth.namju.kim)
        NPM-->>User: 302 Redirect to login portal
        User->>Auth: Submit credentials (LLDAP)
        Auth-->>User: Set session cookie & redirect back
    else Authenticated (200)
        Auth-->>NPM: 200 OK + Remote-User / Remote-Groups
        NPM->>App: Proxy original request
        App-->>User: Render dashboard
    end

Notice what happens on failure: Authelia returns HTTP 401 along with a Location header pointing to https://auth.namju.kim/?rd=.... Nginx catches that 401 via error_page 401 =302 $redirection_url; and turns it into a browser redirect. Once the user signs in against LLDAP, Authelia stores the session in Redis, sets a wildcard cookie scoped to .namju.kim, and sends the browser back to the original URL.


Authelia Docker Compose and configuration

In identity/docker-compose.yaml, Authelia waits until LLDAP passes its health check before starting. I also enable X_AUTHELIA_CONFIG_FILTERS: template so Authelia can read secret files (like the OIDC RSA private key) directly inside configuration.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# identity/docker-compose.yaml (Authelia service excerpt)
  authelia:
    image: authelia/authelia:latest
    container_name: authelia
    restart: unless-stopped
    depends_on:
      lldap:
        condition: service_healthy
    environment:
      TZ: Asia/Seoul
      X_AUTHELIA_CONFIG_FILTERS: template
      AUTHELIA_AUTHENTICATION_BACKEND_LDAP_PASSWORD: "${LLDAP_ADMIN_PASSWORD:?required}"
      AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET: "${AUTHELIA_JWT_SECRET:?required}"
      AUTHELIA_SESSION_SECRET: "${AUTHELIA_SESSION_SECRET:?required}"
      AUTHELIA_STORAGE_ENCRYPTION_KEY: "${AUTHELIA_STORAGE_ENCRYPTION_KEY:?required}"
      AUTHELIA_STORAGE_POSTGRES_PASSWORD: ${AUTHELIA_DB_PASSWORD:?required}
    volumes:
      - ./authelia:/config
    networks:
      - proxy_network
      - identity_backend
      - database_network

Core Authelia configuration (authelia/configuration.yml)

The configuration ties together four pieces: LLDAP for user/group lookups, Redis for active sessions, PostgreSQL (from the shared homelab database stack) for persistent state, and domain-level access control rules with default_policy: deny.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# identity/authelia/configuration.yml
server:
  address: "tcp://:9091"

log:
  level: info

totp:
  issuer: "namju.kim"

authentication_backend:
  password_reset:
    disable: true
  password_change:
    disable: true
  ldap:
    implementation: custom
    address: "ldap://lldap:3890"
    base_dn: "dc=namju,dc=kim"
    additional_users_dn: "ou=people"
    users_filter: "(&(|({username_attribute}={input})({mail_attribute}={input}))(objectClass=person))"
    username_attribute: "uid"
    mail_attribute: "mail"
    display_name_attribute: "displayName"
    additional_groups_dn: "ou=groups"
    groups_filter: "(member={dn})"
    group_name_attribute: "cn"
    user: "uid=admin,ou=people,dc=namju,dc=kim"

access_control:
  default_policy: deny
  rules:
    - domain: health.namju.kim
      subject:
        - "group:admin"
      policy: one_factor

    - domain: traffic.namju.kim
      subject:
        - "group:admin"
      policy: one_factor

    - domain: git.namju.kim
      subject:
        - "group:developer"
      policy: one_factor

    - domain: outline.namju.kim
      subject:
        - "group:guest"
        - "group:admin"
        - "group:developer"
      policy: one_factor

session:
  cookies:
    - domain: "namju.kim"
      authelia_url: "https://auth.namju.kim"
      inactivity: "5 minutes"
      expiration: "1 hour"
      remember_me: "1 month"
  redis:
    host: redis
    port: 6379
    database_index: 0

storage:
  postgres:
    address: tcp://postgres:5432
    database: authelia
    username: authelia_user
    password: ${AUTHELIA_DB_PASSWORD:?required}

identity_providers:
  oidc:
    hmac_secret: "54c5a054c396ad124500b89b1e7d603b39ecbc35c37b26b9ce56d3bd921be7296423442308e23463289beb4ad3c169543e3b3b5c76e148692639e39cd0a3c5ca"
    jwks:
      - key: '{{ secret "/config/secrets/oidc/private.pem" | mindent 10 "|" | msquote }}'
    clients:
      - client_id: portainer
        client_name: Portainer BE
        client_secret: "$pbkdf2-sha512$310000$gI2d1fup36kXKjCy.OvgqQ$1nvV5YblpBtrIOfBhvtEKvbnVKchCsxtZ64upAKVI/21jQr2crhPJOp/n/e49blfHkSjLRvF4ONuLywII9lt7w"
        public: false
        authorization_policy: one_factor
        redirect_uris:
          - https://portainer.namju.kim
        scopes:
          - openid
          - profile
          - groups
          - email
        response_types:
          - code
        grant_types:
          - authorization_code
        token_endpoint_auth_method: client_secret_post

Generating hashed OIDC client secrets

Starting with Authelia v4.38, plaintext client_secret values are rejected at startup. Generate a random secret and its PBKDF2-SHA512 digest directly from the running container, store the digest in configuration.yml, and paste the plaintext value into the client app:

1
2
3
4
5
6
docker exec authelia \
  authelia crypto hash generate pbkdf2 \
  --variant sha512 \
  --random \
  --random.length 64 \
  --random.charset rfc3986

Wiring up Nginx Proxy Manager snippets

To avoid pasting 30 lines of Nginx directives into every proxy host, mount a local snippets directory into Nginx Proxy Manager (- ./npm/snippets:/snippets) and drop in two reusable files.

1. Internal auth subrequest endpoint (authelia-location.conf)

This snippet defines the internal location block that proxies the auth check to Authelia without forwarding the original request body.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# /snippets/authelia-location.conf
set $upstream_authelia http://authelia:9091/api/authz/auth-request;

location /internal/authelia/authz {
    internal;
    proxy_pass $upstream_authelia;

    proxy_set_header X-Original-Method $request_method;
    proxy_set_header X-Original-URL $scheme://$host$request_uri;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Content-Length "";
    proxy_set_header Connection "";

    proxy_pass_request_body off;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
    proxy_redirect http:// $scheme://;
    proxy_http_version 1.1;
    proxy_cache_bypass $cookie_session;
    proxy_no_cache $cookie_session;
    proxy_buffers 4 32k;
    client_body_buffer_size 128k;

    send_timeout 5m;
    proxy_read_timeout 240;
    proxy_send_timeout 240;
    proxy_connect_timeout 240;
}

2. Auth enforcement and header forwarding (authelia-authrequest.conf)

The second snippet invokes auth_request, copies identity headers (Remote-User, Remote-Groups, Remote-Email, Remote-Name) to the upstream service, and converts 401 responses into 302 redirects.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# /snippets/authelia-authrequest.conf
auth_request /internal/authelia/authz;

auth_request_set $user $upstream_http_remote_user;
auth_request_set $groups $upstream_http_remote_groups;
auth_request_set $name $upstream_http_remote_name;
auth_request_set $email $upstream_http_remote_email;

proxy_set_header Remote-User $user;
proxy_set_header Remote-Groups $groups;
proxy_set_header Remote-Email $email;
proxy_set_header Remote-Name $name;

auth_request_set $redirection_url $upstream_http_location;
error_page 401 =302 $redirection_url;

Applying the snippets and verifying the flow

In Nginx Proxy Manager, open any proxy host you want to protect (for example, health.namju.kim), switch to the Advanced tab, and include both snippets:

1
2
include /snippets/authelia-location.conf;
include /snippets/authelia-authrequest.conf;
flowchart TD
    Browser["Browser (signed out)"] -->|"GET health.namju.kim"| NPM["Nginx Proxy Manager"]
    NPM -->|"Subrequest returns 401"| Redirect["302 to auth.namju.kim"]
    Redirect -->|"LLDAP login succeeds"| Cookie["Session cookie set (.namju.kim)"]
    Cookie -->|"Replay original request"| App["Uptime Kuma dashboard"]

Save the host and open https://health.namju.kim in a private browser window. Instead of seeing Uptime Kuma, you should land immediately on https://auth.namju.kim. Sign in with an LLDAP account belonging to group:admin, and Authelia sets the shared session cookie and redirects you back to the dashboard.


Production caveats and checklist

Container DNS resolution: set $upstream_authelia http://authelia:9091/... relies on Nginx Proxy Manager and Authelia sharing proxy_network. If you recreate the Authelia container and its IP changes while Nginx keeps a stale DNS cache, add resolver 127.0.0.11 valid=30s; inside the location block so Nginx re-resolves Docker’s embedded DNS.

Cookie scope and TLS: Authelia refuses to set session cookies over plain HTTP. Make sure auth.namju.kim and every protected subdomain terminate HTTPS at Nginx Proxy Manager under the same root domain (namju.kim).

Before rolling this out across all your homelab hosts, double-check:

  • default_policy: deny is set in access_control, with explicit rules for every protected subdomain.
  • OIDC client_secret values are PBKDF2 hashes generated via authelia crypto hash generate, never plaintext strings.
  • X_AUTHELIA_CONFIG_FILTERS: template is set when using {{ secret "..." }} in configuration.yml.
  • Any API or webhook path that can’t handle browser redirects has a dedicated bypass rule or uses OIDC/token auth instead of Forward Auth.
  • Authelia logs (docker logs authelia) show clean startup with zero LDAP bind or Redis connection errors.
This post is licensed under CC BY 4.0 by the author.