Skip to main content

Architecture

Keyline is a unified authentication proxy service that replaces the existing Authelia + elastauth stack. It provides dual authentication modes (OIDC and Basic Auth) simultaneously, supports three deployment modes (forwardAuth, auth_request, standalone proxy), and automatically injects Elasticsearch credentials into authenticated requests.

Design Goals

  • Unified Service: Single binary replacing two-service architecture
  • Dual Authentication: Support both interactive (OIDC) and programmatic (Basic Auth) access simultaneously
  • Deployment Flexibility: Work with Traefik, Nginx, or as standalone proxy
  • Security First: Implement PKCE, secure session management, and cryptographic best practices
  • Production Ready: Built-in observability, health checks, and graceful shutdown
  • Full Observability: OpenTelemetry tracing and structured logging from day one
  • Unified Caching: Single cache interface for sessions, state tokens, and OIDC data

High-Level Architecture

Component Responsibilities

Observability Layer

ComponentPurpose
otelechoAutomatic OpenTelemetry tracing for all HTTP requests
slog-echoAutomatic structured logging for all HTTP requests with trace correlation
loggergoGlobal slog configuration (JSON/text format, log levels)

Transport Adapter Layer

ComponentPurpose
ForwardAuth AdapterHandles Traefik X-Forwarded-* headers, returns auth decisions
Auth_Request AdapterHandles Nginx X-Original-* headers, returns auth decisions
Standalone ProxyProxies authenticated requests to upstream, handles WebSocket upgrades

Core Authentication Engine

ComponentPurpose
OIDC HandlerManages authorization flow, token exchange, ID token validation
Basic Auth ValidatorValidates local user credentials using bcrypt
Session ManagerCreates, validates, extends, and deletes user sessions
ES Credential MapperMaps authenticated users to Elasticsearch credentials

Cache Layer (cachego)

FeatureDescription
Unified InterfaceSingle cache interface for all storage needs
SessionsStores user sessions with TTL (key: session:{id})
State TokensStores OIDC CSRF tokens with 5-minute TTL (key: state:{id})
OIDC DiscoveryCaches discovery documents (key: oidc:discovery:{issuer})
JWKSCaches JSON Web Key Sets (key: oidc:jwks:{issuer})
Backend AgnosticSupports Redis or in-memory backends via configuration

Technology Stack

LayerTechnology
LanguageGo 1.22+
Web FrameworkEcho v4
ConfigurationViper
Cache Layercachego (unified interface for Redis/in-memory)
Loggingloggergo (global slog setup)
Echo Loggingslog-echo (request logging middleware)
Tracingotelgo (OpenTelemetry setup)
Echo Tracingotelecho (request tracing middleware)
OIDCcoreos/go-oidc v3 + golang.org/x/oauth2
Proxynet/http/httputil.ReverseProxy
Cryptocrypto/rand, bcrypt

Authentication Flow

OIDC Authentication Flow

Dynamic User Management Flow

Deployment Modes

ForwardAuth Mode (Traefik/Nginx)

Standalone Mode

Next Steps