gateway
Role: the only public entry point (api.atelier-maker.fr). It handles browser sessions with the BFF
pattern (OIDC Authorization Code + PKCE against Keycloak), authenticates API keys, signs the
principal token forwarded to services, applies edge protections and proxies
/v1/* to the services.
Limits: no business logic and no database other than Valkey. It does not take authorization decisions (services ask authz); it only checks authentication, API key IP allow-lists and expiry.
Request pipeline
Security headers (HSTS in production) → CORS (allowed WEB_ORIGINS) → path canonicalisation → body limit →
CSRF origin check for unsafe methods (API keys exempt) → identity (strip X-Atl-*, authenticate, sign
principal) → rate limit → API key audit → /v1/auth/* handlers, or route check → public cache → proxy.
- Rate limiting (fixed windows in Valkey, fail open): authenticated callers per user/key
(
RATE_LIMIT_AUTHENTICATED), anonymous callers per IP on/v1/auth/*(RATE_LIMIT_AUTH),/v1/public/*(RATE_LIMIT_PUBLIC) and elsewhere (RATE_LIMIT_ANONYMOUS), plus failed logins / API keys per IP (RATE_LIMIT_AUTH_FAILURES). 429 responses carryRetry-After. - Public cache:
GET /v1/public/*responses cached in Valkey forPUBLIC_CACHE_TTL, keyed by path, query andAccept-Language; never stored withSet-Cookie, non-200,private/no-storeor oversized bodies. - API key cache: validation results cached
APIKEY_CACHE_TTL, invalidated byauthz.apikey.v1events.
Dependencies
- Services: authz (ConnectRPC
AuthenticateAPIKey,EffectivePermissions), every routed upstream. - Infrastructure: Valkey, Kafka, Keycloak (OIDC, optional in development).
- Libraries:
authzclient,httpx,kafkax,principal,audit,cloudevent,outbox,problem,config,logging,telemetry.
Inputs and outputs
| Kind | Name | Notes |
|---|---|---|
| HTTP | /v1/auth/config, login, callback, step-up, me, logout, dev-login | API reference |
| HTTP | every other /v1/* path | proxied according to GATEWAY_ROUTES |
| RPC out | authz.v1.AuthzService/AuthenticateAPIKey, EffectivePermissions | |
| Kafka out | gateway.session.v1 | created, failed, ended (user ID, IP, user agent ≤ 256 chars, method, reason) |
| Kafka out | audit.records.v1 | gateway.session.create/login/end, gateway.apikey.authenticate (denied), gateway.apikey.request (every API key call) |
| Kafka in | authz.apikey.v1 | revoked, rotated, deleted → drop cached validations |
Kafka publishing is asynchronous through a bounded buffer (EVENT_BUFFER); overflow is dropped and logged.
Data (Valkey, prefix gw:)
| Keys | Content |
|---|---|
| sessions | user ID, display name, e-mail, avatar, locale, method (oidc/dev), ACR, auth time, OAuth tokens; key = SHA-256 of the session ID |
| flows | pending logins (state, nonce, PKCE verifier), single use, AUTH_FLOW_TTL |
gw:ak:, gw:akid: | API key validation cache and key ID index |
gw:rl: | rate limit counters |
gw:pc: | public response cache |
Configuration
| Variable | Default | Description |
|---|---|---|
HTTP_ADDR | :8080 | Listen address |
PRINCIPAL_SIGNING_KEY | required | Base64 Ed25519 seed signing X-Atl-Principal |
VALKEY_ADDR, VALKEY_PASSWORD | localhost:6379, empty | Sessions, flows, rate limits, caches |
KAFKA_BROKERS | localhost:19092 | Audit records, session events, API key invalidation |
AUTHZ_URL | http://localhost:8081 | authz ConnectRPC endpoint |
GATEWAY_ROUTES | phase 1 table | prefix=url,...; longest prefix wins; /v1/auth is reserved |
UPSTREAM_TIMEOUT | 30s | Wait for upstream response headers |
WEB_ORIGINS | http://localhost:3000 | Allowed browser origins (CORS, CSRF) |
WEB_URL | first origin | Web app URL for post-login redirects |
TRUSTED_PROXIES | none | CIDRs allowed to set X-Forwarded-For |
MAX_BODY_BYTES | 10485760 | Request body limit |
AUTH_DEV_LOGIN | false | Dev login (development only; refused in production) |
AUTH_DEV_USERNAME, AUTH_DEV_PASSWORD | admin, admin | Dev login credentials |
OIDC_ISSUER_URL | empty | Enables OIDC; required in production (with OIDC_CLIENT_SECRET) |
OIDC_CLIENT_ID, OIDC_CLIENT_SECRET | intranet, empty | Confidential client |
OIDC_REDIRECT_URL | http://localhost:8080/v1/auth/callback | Callback URL |
OIDC_POST_LOGOUT_REDIRECT_URL | WEB_URL/ | After IdP logout |
OIDC_SCOPES | openid,profile,email | Requested scopes |
OIDC_STEP_UP_ACR | passkey | ACR required by step-up |
SESSION_IDLE_TIMEOUT, SESSION_ABSOLUTE_LIFETIME | 2h, 12h | Session lifetimes |
SESSION_COOKIE_SECURE | true except development | Must stay true in production |
AUTH_FLOW_TTL | 10m | Pending login lifetime |
APIKEY_CACHE_TTL | 1m | API key validation cache |
RATE_LIMIT_ENABLED, RATE_LIMIT_WINDOW | true, 1m | Rate limiting |
RATE_LIMIT_AUTH, RATE_LIMIT_PUBLIC, RATE_LIMIT_ANONYMOUS | 30, 300, 120 | Per IP, anonymous callers |
RATE_LIMIT_AUTHENTICATED | 1200 | Per user or API key |
RATE_LIMIT_AUTH_FAILURES | 10 | Failed logins / API keys per IP |
PUBLIC_CACHE_TTL, PUBLIC_CACHE_MAX_BYTES | 30s, 1048576 | Public cache (0s disables) |
EVENT_BUFFER | 1024 | Async Kafka buffer |
Plus the common APP_ENV, LOG_LEVEL, METRICS_ADDR, OTEL_EXPORTER_OTLP_ENDPOINT.