Aller au contenu principal

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 carry Retry-After.
  • Public cache: GET /v1/public/* responses cached in Valkey for PUBLIC_CACHE_TTL, keyed by path, query and Accept-Language; never stored with Set-Cookie, non-200, private/no-store or oversized bodies.
  • API key cache: validation results cached APIKEY_CACHE_TTL, invalidated by authz.apikey.v1 events.

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​

KindNameNotes
HTTP/v1/auth/config, login, callback, step-up, me, logout, dev-loginAPI reference
HTTPevery other /v1/* pathproxied according to GATEWAY_ROUTES
RPC outauthz.v1.AuthzService/AuthenticateAPIKey, EffectivePermissions
Kafka outgateway.session.v1created, failed, ended (user ID, IP, user agent ≤ 256 chars, method, reason)
Kafka outaudit.records.v1gateway.session.create/login/end, gateway.apikey.authenticate (denied), gateway.apikey.request (every API key call)
Kafka inauthz.apikey.v1revoked, rotated, deleted → drop cached validations

Kafka publishing is asynchronous through a bounded buffer (EVENT_BUFFER); overflow is dropped and logged.

Data (Valkey, prefix gw:)​

KeysContent
sessionsuser ID, display name, e-mail, avatar, locale, method (oidc/dev), ACR, auth time, OAuth tokens; key = SHA-256 of the session ID
flowspending 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​

VariableDefaultDescription
HTTP_ADDR:8080Listen address
PRINCIPAL_SIGNING_KEYrequiredBase64 Ed25519 seed signing X-Atl-Principal
VALKEY_ADDR, VALKEY_PASSWORDlocalhost:6379, emptySessions, flows, rate limits, caches
KAFKA_BROKERSlocalhost:19092Audit records, session events, API key invalidation
AUTHZ_URLhttp://localhost:8081authz ConnectRPC endpoint
GATEWAY_ROUTESphase 1 tableprefix=url,...; longest prefix wins; /v1/auth is reserved
UPSTREAM_TIMEOUT30sWait for upstream response headers
WEB_ORIGINShttp://localhost:3000Allowed browser origins (CORS, CSRF)
WEB_URLfirst originWeb app URL for post-login redirects
TRUSTED_PROXIESnoneCIDRs allowed to set X-Forwarded-For
MAX_BODY_BYTES10485760Request body limit
AUTH_DEV_LOGINfalseDev login (development only; refused in production)
AUTH_DEV_USERNAME, AUTH_DEV_PASSWORDadmin, adminDev login credentials
OIDC_ISSUER_URLemptyEnables OIDC; required in production (with OIDC_CLIENT_SECRET)
OIDC_CLIENT_ID, OIDC_CLIENT_SECRETintranet, emptyConfidential client
OIDC_REDIRECT_URLhttp://localhost:8080/v1/auth/callbackCallback URL
OIDC_POST_LOGOUT_REDIRECT_URLWEB_URL/After IdP logout
OIDC_SCOPESopenid,profile,emailRequested scopes
OIDC_STEP_UP_ACRpasskeyACR required by step-up
SESSION_IDLE_TIMEOUT, SESSION_ABSOLUTE_LIFETIME2h, 12hSession lifetimes
SESSION_COOKIE_SECUREtrue except developmentMust stay true in production
AUTH_FLOW_TTL10mPending login lifetime
APIKEY_CACHE_TTL1mAPI key validation cache
RATE_LIMIT_ENABLED, RATE_LIMIT_WINDOWtrue, 1mRate limiting
RATE_LIMIT_AUTH, RATE_LIMIT_PUBLIC, RATE_LIMIT_ANONYMOUS30, 300, 120Per IP, anonymous callers
RATE_LIMIT_AUTHENTICATED1200Per user or API key
RATE_LIMIT_AUTH_FAILURES10Failed logins / API keys per IP
PUBLIC_CACHE_TTL, PUBLIC_CACHE_MAX_BYTES30s, 1048576Public cache (0s disables)
EVENT_BUFFER1024Async Kafka buffer

Plus the common APP_ENV, LOG_LEVEL, METRICS_ADDR, OTEL_EXPORTER_OTLP_ENDPOINT.