# Multi-Domain Authentication for *.aipice.fr This guide shows how to use a single authentication service to protect multiple subdomains under `aipice.fr`. ## π― Architecture Overview ``` βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β auth.aipice.fr β β arti-api.aipice β β *.aipice.fr β β β β .fr β β β β Auth Service βββββΆβ Protected API β β Other Services β β (Login Page) β β (with auth) β β (with auth) β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β β β ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ β βββββββββββββββββββ β Active Directoryβ β Validation β βββββββββββββββββββ ``` ## π Quick Setup for aipice.fr ### 1. Deploy the Authentication Service ```bash # Run the deployment script ./deploy-aipice.sh # This will: # - Create wildcard certificate for *.aipice.fr # - Deploy auth service at auth.aipice.fr # - Protect arti-api.aipice.fr with authentication # - Create reusable ForwardAuth middleware ``` ### 2. Access Your Services - **Authentication**: https://auth.aipice.fr - **Protected API**: https://arti-api.aipice.fr (requires login) - **Public endpoints**: https://arti-api.aipice.fr/ and /health (no auth) ## π How Multi-Domain Protection Works ### Authentication Flow 1. **User visits** `https://arti-api.aipice.fr/users` 2. **Traefik checks** auth via ForwardAuth middleware 3. **No token?** β Redirect to `https://auth.aipice.fr/?return_url=https://arti-api.aipice.fr/users` 4. **User logs in** β JWT token stored in cookie for `.aipice.fr` domain 5. **User redirected** back to `https://arti-api.aipice.fr/users` 6. **Traefik validates** token β Access granted ### Cross-Domain Cookie Sharing The auth service sets cookies with `domain=.aipice.fr`, making them available to all subdomains: ```python response.set_cookie( key="auth_token", value=token, domain=".aipice.fr", # Works for all *.aipice.fr httponly=True, secure=True, samesite="lax" ) ``` ## π‘οΈ Protecting Additional Services To protect any new subdomain (e.g., `grafana.aipice.fr`), simply add the ForwardAuth middleware: ```yaml apiVersion: traefik.io/v1alpha1 kind: IngressRoute metadata: name: grafana-protected spec: entryPoints: - websecure routes: - match: Host(`grafana.aipice.fr`) kind: Rule services: - name: grafana port: 3000 middlewares: - name: auth-forward namespace: infrastructure--artifactory--service # Where auth service is deployed tls: secretName: wildcard-aipice-fr ``` ## π Configuration Examples ### Multiple Protection Levels You can create different auth requirements for different services: ```yaml # Public service (no auth) - match: Host(`public.aipice.fr`) services: - name: public-service port: 80 # Basic auth required - match: Host(`internal.aipice.fr`) services: - name: internal-service port: 80 middlewares: - name: auth-forward # Admin-only access (custom verification) - match: Host(`admin.aipice.fr`) services: - name: admin-service port: 80 middlewares: - name: admin-auth-forward # Custom middleware with admin check ``` ### Group-Based Access Control Use Active Directory groups for fine-grained access: ```python # In your backend service def require_admin_group(x_auth_groups: str = Header(None)): groups = x_auth_groups.split(',') if x_auth_groups else [] admin_groups = [ 'CN=Domain Admins,CN=Users,DC=aipice,DC=fr', 'CN=IT Team,CN=Groups,DC=aipice,DC=fr' ] if not any(group in groups for group in admin_groups): raise HTTPException(status_code=403, detail="Admin access required") ``` ## π§ Advanced Configuration ### Environment Variables The auth service supports these domain-specific variables: ```yaml env: - name: ALLOWED_DOMAINS value: "aipice.fr,yourdomain.com" # Multiple domains supported - name: AUTH_DOMAIN value: "auth.aipice.fr" - name: CORS_ORIGINS value: "https://*.aipice.fr,https://*.yourdomain.com" ``` ### Wildcard Certificate For automatic SSL across all subdomains: ```yaml apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: wildcard-aipice-fr spec: secretName: wildcard-aipice-fr issuerRef: name: letsencrypt kind: ClusterIssuer commonName: "*.aipice.fr" dnsNames: - "aipice.fr" - "*.aipice.fr" ``` ## π¨ Customizing the Login Page Update the login page branding for your domain: ```html
Sign in to access Aipice services