Kubernetes forward-auth tested on Traefik ingress
1.1K
A Python-based forward authentication service for Traefik that provides OAuth 2.0 authentication with GitHub integration and user whitelisting capabilities.
# Apply the deployment
kubectl apply -f traefik-forward-auth-deploy.yaml
Example of deploy file
apiVersion: apps/v1
kind: Deployment
metadata:
name: forward-auth
namespace: forward-auth
spec:
replicas: 1
selector:
matchLabels:
app: forward-auth-python
template:
metadata:
labels:
app: forward-auth-python
spec:
containers:
- name: forward-auth-python
image: himelranaswe/forwardauth:latest # or himelranaswe/forwardauth:arm for ARM cpu
imagePullPolicy: Always
ports:
- containerPort: 4181
env:
- name: PROVIDER
value: "github"
- name: GITHUB_CLIENT_ID
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: github-client-id
- name: GITHUB_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: github-client-secret
- name: OAUTH_SCOPES
value: "read:user,user:email"
- name: SECRET
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: secret
- name: COOKIE_DOMAIN
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: cookie-domain
- name: INSECURE_COOKIE
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: insecure-cookie
- name: AUTH_HOST
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: auth-host
- name: URL_PATH
value: "/_oauth"
- name: WHITELIST
valueFrom:
secretKeyRef:
name: traefik-forward-auth-secret
key: whitelist_users
---
apiVersion: v1
kind: Service
metadata:
name: forward-auth
namespace: forward-auth
spec:
selector:
app: forward-auth
ports:
- port: 4181
targetPort: 4181
kubectl apply -f traefik-forward-auth-secret.yaml
### 3. Configure Traefik Middleware
```yaml
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: github-auth
namespace: forward-auth
spec:
forwardAuth:
address: http://forward-auth-python.forward-auth.svc.cluster.local:4181
trustForwardHeader: true
authResponseHeaders:
- X-Forwarded-User
- X-Forwarded-Email
| Variable | Description | Required | Default |
|---|---|---|---|
PROVIDER | OAuth provider (github) | Yes | github |
GITHUB_CLIENT_ID | GitHub OAuth Client ID | Yes | - |
GITHUB_CLIENT_SECRET | GitHub OAuth Client Secret | Yes | - |
OAUTH_SCOPES | OAuth scopes | No | read:user,user:email |
SECRET | JWT signing secret | Yes | - |
COOKIE_DOMAIN | Cookie domain | No | - |
INSECURE_COOKIE | Use insecure cookies | No | false |
AUTH_HOST | Auth service hostname | Yes | - |
URL_PATH | OAuth callback path | No | /_oauth |
WHITELIST | Comma-separated list of allowed emails | No | - |
apiVersion: v1
kind: Secret
metadata:
name: traefik-forward-auth-secret
namespace: forward-auth
type: Opaque
stringData:
github-client-id: "your-github-client-id"
github-client-secret: "your-github-client-secret"
secret: "your-jwt-secret-key"
cookie-domain: ".yourdomain.com"
insecure-cookie: "false"
auth-host: "auth.yourdomain.com"
whitelist_users: "[email protected],[email protected]"
https://yourdomain.comhttps://auth.yourdomain.com/_oauthAfter creating the OAuth app, you'll get:
GITHUB_CLIENT_IDGITHUB_CLIENT_SECRETapiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: protected-app
namespace: your-namespace
spec:
entryPoints:
- websecure
routes:
- match: Host(`app.yourdomain.com`)
kind: Rule
services:
- name: your-app-service
port: 80
middlewares:
- name: github-auth
namespace: your-namespace
tls:
secretName: app-tls
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: github-auth
namespace: your-namespace
spec:
forwardAuth:
address: http://forward-auth-python.forward-auth.svc.cluster.local:4181
trustForwardHeader: true
authResponseHeaders:
- X-Forwarded-User
- X-Forwarded-Email
/_oauth endpointThe forbidden page template is located at templates/forbidden.html inside container. You can customize it by mounting volume:
Users are whitelisted by email address. The whitelist is configured via the WHITELIST environment variable:
# Single user
WHITELIST="[email protected]"
# Multiple users
WHITELIST="[email protected],[email protected],[email protected]"
COOKIE_DOMAIN for proper domain scopingINSECURE_COOKIE=false for HTTPS environmentsredirect url not appropriate with this application
Solution: Ensure the callback URL in GitHub OAuth app matches your AUTH_HOST:
https://auth.yourdomain.com/_oauth
Symptoms: User sees forbidden page after successful GitHub authentication
Solution: Add user's email to the WHITELIST environment variable
kubectl -n forward-auth logs -l app=forward-auth
kubectl -n forward-auth get secret traefik-forward-auth-secret -o yaml
curl -I https://your-protected-app.com/
| Endpoint | Method | Description |
|---|---|---|
/verify | GET | Traefik middleware endpoint |
/start | GET | Initiate OAuth flow |
/_oauth | GET | OAuth callback endpoint |
/logout | GET | Clear session and logout |
Currently only support Github OAuth. You can modify and use as you like. Repo: https://github.com/Swe-HimelRana/traefik-forward-auth
This project is licensed under the MIT License.
For issues and questions:
# CVE-2025-45582
Our project’s Python base image has been flagged for CVE-2025-45582, a known tar archive extraction vulnerability.
✅ Impact on this project: None.
Our implementation does not use any tar extraction or related functionality, meaning this vulnerability cannot be exploited in the context of this project.
🔒 Status: Safe.
Although the underlying image reports the CVE, our usage of the image does not expose your environment to this vulnerability.
Content type
Image
Digest
sha256:b6c0ec8dd…
Size
47.1 MB
Last updated
12 months ago
docker pull himelranaswe/forwardauth