Skip to content

Authentik Hardening

Your identity provider is the crown jewel: it is the single key to every application that uses SSO, and (behind an identity-aware proxy) a foothold toward the internal network. A flaw in Authentik is not one app down — it is every app down. This guide is the hardening checklist for a self-hosted Authentik instance. For installation and day-to-day use see Authentik installation; for putting apps behind it, Identity-Aware Proxies.

1. Trusted proxies — the forwarded-header bypass (most important)

Section titled “1. Trusted proxies — the forwarded-header bypass (most important)”

Authentik resolves the client IP from X-Forwarded-For, but only trusts it from sources named in AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS. Get this wrong and you re-open CVE-2024-47070 / GHSA-7jxf-mmg9-9hg7 (CVSS 9.0): an unparsable X-Forwarded-For: a skipped a policy stage and allowed passwordless login to any account whose username was known. The official Traefik guide shipped trustForwardHeader: true, so many instances were exposed. Patched in 2024.6.5 / 2024.8.3 — but the NVD notes it “is not reproducible from behind a correctly-configured reverse proxy,” so the residual risk is entirely your CIDR config.

  • Name only the real reverse proxy (loopback + the tunnel/ingress address). Never 0.0.0.0/0. A whole shared Docker range (e.g. 172.23.0.0/16) is too broad — every container on that network can then spoof X-Forwarded-For and defeat IP-based policies, rate limits and session IP logging.
  • The proxy must OVERWRITE, not append to, X-Forwarded-For. If it appends, the attacker’s leftmost value survives.
  • Where the proxy actually connects from matters. If cloudflared reaches Authentik via localhost:28080 → docker-proxy, the source Authentik sees is the Docker gateway (172.23.0.1), not loopback. Trust that /32, not the whole /16. Verify after changing: a request through the tunnel must resolve to a real client IP, not the gateway.

Verified example (this operator’s stack): narrowing 127.0.0.0/8,::1/128,172.23.0.0/16 → 127.23.0.1/32 (the gateway) kept the tunnel resolving real client IPs while removing 22 containers’ ability to spoof. See the full model in Reverse-Proxy & IAP Hardening.

  • Enable admin mode and disable password sign-in (SSO only). Keep root as break-glass via the Django console (ak shell), not a daily login.
  • Admin API calls need a PAT with the admin_mode scope; a plain api PAT returns 403. Mint short-lived admin tokens on demand and revoke them immediately after use.
  • ak shell bypasses all permission checks — use it when the API refuses (bulk ORM edits, flow-binding fixes, token minting), then verify the change from the outside.
  • Require MFA / passkeys for admins (and ideally everyone). Authentik supports WebAuthn and TOTP.
  • PolicyBinding.target must be the policybindingmodel_ptr_id, not the FlowStageBinding.pk. The wrong one silently creates an ungated binding that lets everyone through. A policy bound to the binding (not the stage) is what gates the stage.
  • authenticator-validate with webauthn first in device_classes auto-fires WebAuthn and hides TOTP. Don’t rely on not_configured_action: skip as a safety net — WebAuthn-only users silently skip MFA.
  • The signing_key signs ID tokens for every app — a leak lets an attacker forge tokens for all of them. Protect it like a root credential; rotate on any suspicion; never commit it.
  • Providers created via ORM/API start with empty grant_types → code exchange fails with invalid_request. Set ["authorization_code", "refresh_token"].
  • signing_key must be set or jwks_uri returns {}. Refresh tokens need offline_access in property_mappings. Keep access_token_validity sane (5 min default is too short for mail bridges / IAPs — but long TTLs widen the blast radius of a stolen token).
  • Outposts (e.g. the LDAP outpost used by TAK) are separate containers holding an AUTHENTIK_TOKEN. Their cached view of users/groups lags new memberships by ~2–3 min.
  • Binds fail with operationsError when the provider’s bind/flow wiring and the outpost’s settings disagree (login attr cn vs uid, member vs uniqueMember, and a bind flow that actually grants a session). Check the outpost logs alongside the server.

Point upgrades can reset default-* flow bindings, MFA order and orphan stage bindings. After every upgrade:

  1. List bindings on default-authentication-flow — check count and order.
  2. Confirm each *-mfa-required stage is bound, with its policy on the binding.
  3. Confirm the identification stage still points at its passwordless / WebAuthn / password stages.
  4. Test sign-in as: normal user (password, passkey), admin (password + MFA, passkey).
  5. The sub claim format changes across versions (UUID → SHA256). Compare against stored provider_uid values; check for orphans (provider_name='oidc' AND user_id IS NULL).
  6. Export changed flows to version control.

Back up the database on a schedule (Authentik’s backup script dumps authentik_db). After a DB restore, PostgreSQL sequences for authentik_core_user can desync and user creation silently fails with HTTP 405 — setval(...) to fix.

Recent changes

  1. docs(wiki): add Authentik + Reverse-Proxy/IAP hardening guides gitayam