Authentik Authentication Service¶
Authentik is an open-source identity provider that integrates with Traefik to provide OAuth2/OIDC authentication for the infrastructure. This document covers the complete setup, configuration, and operation of the Authentik authentication system.
Overview¶
The Authentik service provides centralized authentication for web applications while maintaining API access patterns. It uses a dual-route strategy where browser access is protected by OAuth while API endpoints remain accessible for programmatic access.
Architecture¶
Service Components¶
The Authentik stack consists of three main components:
- Authentik Server (
authentik.rbnk.uk) - Main authentication interface and administration panel
- Handles OAuth flows, user management, and policy enforcement
-
Uses PostgreSQL (supa-db) for data storage and Redis for sessions
-
Authentik Worker
- Background task processor for email notifications, LDAP sync, and other async operations
-
Shares the same configuration as the server component
-
Authentik Proxy Outpost (
auth-proxy.rbnk.uk) - Separate service that handles forward authentication for Traefik
- Validates authentication tokens and provides user headers
- Deployed on dedicated subdomain for cookie domain isolation
Network Configuration¶
networks:
authentik: # Internal communication between components
traefik_proxy: # External access via Traefik
supabase_internal: # Database access
Configuration¶
Environment Variables¶
Key configuration variables in /srv/dockerdata/authentik/.env:
# Core Authentication
AUTHENTIK_SECRET_KEY=your-secret-key-here
AUTHENTIK_HOST=https://authentik.rbnk.uk
AUTHENTIK_HOST_BROWSER=https://authentik.rbnk.uk
# Database Configuration (using shared Supabase PostgreSQL)
PG_USER=authentik
PG_DB=authentik
PG_PASS=your-database-password
# Outpost Token (generated in Authentik UI)
AUTHENTIK_OUTPOST_TOKEN=your-outpost-token-here
Critical OAuth Flow Fix¶
The AUTHENTIK_HOST_BROWSER environment variable is essential for proper OAuth flow operation:
- Problem: OAuth redirects were failing when internal container names were used
- Solution: Set
AUTHENTIK_HOST_BROWSERto the public HTTPS URL - Impact: Ensures OAuth callbacks use the correct public domain for browser-based flows
Cookie Domain Configuration¶
The proxy outpost is deployed on a separate subdomain (auth-proxy.rbnk.uk) to ensure proper cookie domain handling:
- Main Service:
authentik.rbnk.uk- User interface and administration - Proxy Outpost:
auth-proxy.rbnk.uk- Forward authentication endpoint - Cookie Domain:
.rbnk.uk- Allows cookies to work across all subdomains
Protected Services¶
The following services are protected by Authentik authentication (Priority 1 router configuration):
Infrastructure Services¶
- Prometheus (
prometheus.rbnk.uk) - Monitoring metrics and web UI - Portainer (
portainer.rbnk.uk) - Docker management interface - Rclone (
rclone.rbnk.uk) - Cloud storage backup interface - Glance (
glance.rbnk.uk) - Infrastructure dashboard
Application Services¶
- LiteLLM (
llm.rbnk.uk) - AI proxy web interface - Apprise (
apprise.rbnk.uk) - Notification service web UI - Paperless-AI (
paperless-ai.rbnk.uk) - Document management - Metube (
metube.rbnk.uk) - YouTube downloader interface
API Access Patterns¶
Each protected service maintains API access through higher-priority routes that bypass Authentik:
LiteLLM API Access¶
# API routes (no authentication)
PathPrefix(/v1/) || PathPrefix(/chat/) || PathPrefix(/completions) || PathPrefix(/models) || PathPrefix(/health)
Priority: 100
Prometheus API Access¶
# Metrics and API routes (no authentication)
PathPrefix(/api/) || PathPrefix(/metrics)
Priority: 100
Apprise API Access¶
# Notification API routes (no authentication)
PathPrefix(/notify/) || PathPrefix(/json/) || PathPrefix(/get/) || PathPrefix(/add/) || PathPrefix(/del/) || PathPrefix(/form/)
Priority: 100
Traefik Integration¶
Middleware Configuration¶
Authentik integrates with Traefik through custom middleware defined in /srv/dockerdata/traefik/dynamic/authentik.yml:
http:
middlewares:
authentik:
forwardAuth:
address: http://authentik-proxy-1:9000/outpost.goauthentik.io/auth/traefik
trustForwardHeader: true
authResponseHeaders:
- X-authentik-username
- X-authentik-groups
- X-authentik-email
- X-authentik-name
- X-authentik-uid
- X-authentik-jwt
authentik-secured:
chain:
middlewares:
- redirect-to-https
- authentik
Service Label Examples¶
Browser + API Service (Dual Route)¶
labels:
# Browser access (protected)
- "traefik.http.routers.service.middlewares=authentik-secured@file"
# API access (unprotected, higher priority)
- "traefik.http.routers.service-api.rule=Host(`service.rbnk.uk`) && PathPrefix(`/api/`)"
- "traefik.http.routers.service-api.priority=100"
- "traefik.http.routers.service-api.middlewares=api-access@file"
Browser-Only Service¶
User Management¶
Default Admin User¶
After initial setup, access Authentik at https://authentik.rbnk.uk and create the initial admin user through the web interface.
User Authentication Flow¶
- User accesses protected service (e.g.,
https://prometheus.rbnk.uk) - Traefik forwards request to Authentik proxy outpost
- If not authenticated, user is redirected to Authentik login page
- After successful authentication, user is redirected back to original service
- Authentik sets authentication cookies for
.rbnk.ukdomain - Subsequent requests include authentication headers for the service
Session Management¶
- Session Storage: Redis-based session storage in Authentik stack
- Cookie Domain:
.rbnk.uk- works across all subdomains - Session Duration: Configurable in Authentik policies (default: 24 hours)
- Logout: Available from any protected service or Authentik interface
Outpost Configuration¶
Creating the Outpost Token¶
- Access Authentik admin interface at
https://authentik.rbnk.uk - Navigate to Applications → Outposts
- Create new outpost with type "Proxy"
- Generate token and add to
AUTHENTIK_OUTPOST_TOKENin.env - Restart the proxy container to apply the token
Outpost Providers¶
Create providers for each service in the Authentik interface:
- Applications → Providers → Create Proxy Provider
- Configure external host (e.g.,
https://prometheus.rbnk.uk) - Set authorization flow (default: implicit consent)
- Assign to appropriate application
OAuth2/OIDC Provider Configuration¶
Authentik can act as an OAuth2/OpenID Connect provider for external applications, allowing them to use Authentik for authentication.
Creating an OIDC Provider¶
- Navigate to Providers:
- Go to Applications → Providers in the left menu
-
Click Create → OAuth2/OpenID Provider
-
Configure the Provider:
- Name: Choose a descriptive name (e.g., "My App OIDC")
- Authorization flow: Select based on your needs:
default-provider-authorization-implicit-consent- No user consent screendefault-provider-authorization-explicit-consent- Shows consent screen
- Client type:
- Confidential: For server-side applications (provides client secret)
- Public: For SPAs, mobile apps, or CLIs (no client secret)
- Client ID: Auto-generated or set custom (e.g.,
my-app-client) - Client Secret: Auto-generated for confidential clients
- Redirect URIs: Add all valid callback URLs:
-
Scopes: Select required scopes:
openid- Required for OIDCemail- User email accessprofile- User profile informationoffline_access- Refresh tokens
-
Advanced Settings (optional):
- Access code validity: How long authorization codes are valid
- Access token validity: Token lifetime (default: hours=1)
- Refresh token validity: For offline access (default: days=30)
- Include claims in id_token: Enable for user info in ID token
Creating an Application¶
- Navigate to Applications:
- Go to Applications → Applications
-
Click Create
-
Configure the Application:
- Name: User-friendly name shown on consent screen
- Slug: URL-safe identifier
- Provider: Select the OIDC provider created above
- Policy engine mode: Any (default) or All (stricter)
-
UI settings: Logo, description, publisher
-
Assign Policies (optional):
- User/group restrictions
- Network/IP restrictions
- Time-based access
Finding OIDC Credentials¶
After creating the provider and application:
- Get Credentials:
- Go to Applications → Providers
- Click on your OAuth2/OpenID provider
-
View credentials:
- Client ID: Displayed in provider details
- Client Secret: Click "Show" button (confidential clients only)
- Issuer:
https://authentik.rbnk.uk/application/o/<provider-slug>/
-
OIDC Discovery URL:
OIDC Endpoints¶
Your application will use these endpoints:
- Authorization:
https://authentik.rbnk.uk/application/o/authorize/ - Token:
https://authentik.rbnk.uk/application/o/token/ - UserInfo:
https://authentik.rbnk.uk/application/o/userinfo/ - JWKS:
https://authentik.rbnk.uk/application/o/<provider-slug>/jwks/ - Logout:
https://authentik.rbnk.uk/application/o/<provider-slug>/end-session/
Integration Examples¶
Node.js with Passport¶
const passport = require('passport');
const { Strategy } = require('openid-client');
// Discover OIDC configuration
const issuer = await Issuer.discover('https://authentik.rbnk.uk/application/o/<provider-slug>/');
const client = new issuer.Client({
client_id: 'your-client-id',
client_secret: 'your-client-secret',
redirect_uris: ['https://myapp.com/auth/callback'],
response_types: ['code'],
});
passport.use('oidc', new Strategy({ client }, (tokenSet, userinfo, done) => {
return done(null, userinfo);
}));
Python with Authlib¶
from authlib.integrations.flask_client import OAuth
oauth = OAuth(app)
oauth.register(
name='authentik',
client_id='your-client-id',
client_secret='your-client-secret',
server_metadata_url='https://authentik.rbnk.uk/application/o/<provider-slug>/.well-known/openid-configuration',
client_kwargs={'scope': 'openid email profile'}
)
Manual Token Validation¶
# Get access token
TOKEN_RESPONSE=$(curl -X POST https://authentik.rbnk.uk/application/o/token/ \
-d "grant_type=authorization_code" \
-d "code=AUTHORIZATION_CODE" \
-d "redirect_uri=https://myapp.com/callback" \
-d "client_id=your-client-id" \
-d "client_secret=your-client-secret")
# Extract access token
ACCESS_TOKEN=$(echo $TOKEN_RESPONSE | jq -r '.access_token')
# Get user info
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
https://authentik.rbnk.uk/application/o/userinfo/
Testing OIDC Configuration¶
-
Verify Discovery Endpoint:
-
Test Authorization Flow:
- Open in browser:
https://authentik.rbnk.uk/application/o/authorize/?client_id=<client-id>&redirect_uri=<callback>&response_type=code&scope=openid%20email%20profile - Should redirect to login if not authenticated
-
After login, redirects to callback with authorization code
-
Validate Tokens:
- ID tokens are JWTs - decode at jwt.io
- Verify signature with JWKS endpoint
- Check claims match expected values
Common OIDC Use Cases¶
- Single Sign-On (SSO) for internal applications
- API Authentication with bearer tokens
- Mobile App Authentication with PKCE flow
- Third-party Integrations requiring OAuth2
- Microservices Authentication with service accounts
Security Best Practices¶
- Always use HTTPS for redirect URIs
- Validate redirect URIs strictly
- Use PKCE for public clients
- Rotate client secrets regularly
- Limit token lifetimes appropriately
- Enable consent for sensitive applications
Monitoring and Troubleshooting¶
Service Status¶
# Check all Authentik services
docker compose -f authentik/docker-compose.yml ps
# View server logs
docker compose -f authentik/docker-compose.yml logs -f server
# View proxy outpost logs
docker compose -f authentik/docker-compose.yml logs -f proxy
# View worker logs
docker compose -f authentik/docker-compose.yml logs -f worker
Common Issues¶
OAuth Flow Failures¶
- Symptom: Redirect loops or "invalid redirect URI" errors
- Solution: Verify
AUTHENTIK_HOST_BROWSERis set to public HTTPS URL - Check: Ensure outpost token is properly configured
Cookie Domain Issues¶
- Symptom: Authentication doesn't persist across services
- Solution: Verify proxy outpost is on separate subdomain (
auth-proxy.rbnk.uk) - Check: Confirm cookie domain is set to
.rbnk.uk
Database Connection Errors¶
- Symptom: Server fails to start with PostgreSQL errors
- Solution: Verify database credentials and network connectivity
- Check: Ensure
supa-dbis running and accessible
Health Checks¶
# Test Authentik server health
curl -I https://authentik.rbnk.uk
# Test proxy outpost health
curl -I https://auth-proxy.rbnk.uk
# Test forward auth endpoint
curl -I http://authentik-proxy-1:9000/outpost.goauthentik.io/auth/traefik
Security Considerations¶
Token Management¶
- Outpost tokens should be rotated regularly
- Store tokens securely in
.envfiles with proper permissions (640) - Monitor token usage in Authentik logs
Network Security¶
- Proxy outpost communicates internally with server via Docker network
- External access only through Traefik with proper TLS termination
- Database access restricted to internal network
Authentication Policies¶
- Configure appropriate session timeouts
- Implement MFA for administrative users
- Review and audit user access regularly
Backup and Recovery¶
Configuration Backup¶
# Backup Authentik configuration
docker exec authentik-server-1 ak export > authentik-config-backup.json
# Backup custom templates and media
tar -czf authentik-data-backup.tar.gz authentik/media/ authentik/custom-templates/
Database Backup¶
Authentik data is stored in the shared PostgreSQL instance and is included in the regular Supabase backup process.
Recovery Process¶
- Restore database from Supabase backup
- Restore media and template files
- Import configuration:
docker exec authentik-server-1 ak import < authentik-config-backup.json - Recreate outpost tokens and update
.envfiles
Performance Tuning¶
Redis Optimization¶
- Authentik uses dedicated Redis instance for session storage
- Monitor Redis memory usage and configure appropriate limits
- Enable Redis persistence for session recovery
Database Performance¶
- Monitor PostgreSQL connections and query performance
- Consider connection pooling for high-traffic deployments
- Regular database maintenance through Supabase procedures
Proxy Outpost Scaling¶
- Single proxy outpost handles all authentication requests
- Monitor response times and consider horizontal scaling if needed
- Load balancing multiple outposts through Traefik if required
Integration Examples¶
Adding New Protected Service¶
-
Configure Service Labels:
labels: - "traefik.http.routers.newservice.middlewares=authentik-secured@file" # Add API route if needed - "traefik.http.routers.newservice-api.rule=Host(`newservice.rbnk.uk`) && PathPrefix(`/api/`)" - "traefik.http.routers.newservice-api.priority=100" - "traefik.http.routers.newservice-api.middlewares=api-access@file" -
Create Provider in Authentik:
- External host:
https://newservice.rbnk.uk - Authorization flow: Default
-
Skip path regex:
/api/.*(if API access needed) -
Create Application:
- Link to the provider
- Set appropriate policies and user access
Custom Authentication Headers¶
Services can access user information through headers provided by Authentik:
X-authentik-username: [email protected]
X-authentik-groups: admin,users
X-authentik-email: [email protected]
X-authentik-name: John Doe
X-authentik-uid: user-uuid
Applications can use these headers for user context and authorization decisions.
Future Enhancements¶
Planned Improvements¶
- Multi-factor authentication (MFA) implementation
- LDAP/Active Directory integration
- Advanced policy configurations
- Single sign-out (SLO) implementation
- API key authentication for service-to-service communication
Scalability Considerations¶
- Horizontal scaling of proxy outposts
- Database connection pooling
- Redis cluster for session storage
- Load balancing and failover strategies