Ory Hydra Configuration Rules
Documents Ory Hydra OAuth2/OIDC server configuration with YAML settings, environment variables, build process, and security checklist.
What this file does
Documents Ory Hydra OAuth2/OIDC server configuration with YAML settings, environment variables, build process, and security checklist.
When to use it
- Setting up Ory Hydra for OAuth2/OIDC in a microservices architecture
- Configuring Hydra with PostgreSQL and Docker buildx
- Integrating Hydra with a consent and login frontend
- Reviewing production security hardening for Hydra
Assumes this stack
Ory Hydra Configuration Rules
Overview
This module (avarc-ory-hydra) provides Ory Hydra OAuth2 and OpenID Connect server configuration. Hydra handles OAuth2/OIDC flows, token management, and client administration.
Architecture
- Base Image:
oryd/hydra:v${ory.version}(version from parent POM property) - Configuration: YAML-based configuration file (
hydra/hydra.yml) - Database: PostgreSQL with
oryschema (configured via DSN environment variable) - Build: Docker buildx with Maven resource filtering for version substitution
Key Responsibilities
- OAuth2/OIDC Server: Handles authorization and token endpoints
- Client Management: Admin API for OAuth2 client CRUD operations
- Consent Flow: Manages user consent challenges and sessions
- Token Management: Issues and validates access tokens, refresh tokens, ID tokens
Configuration Structure (hydra.yml)
API Endpoints
- Public API (port 4444): OAuth2/OIDC endpoints for clients
/.well-known/openid-configuration: OIDC discovery/oauth2/auth: Authorization endpoint/oauth2/token: Token endpoint/oauth2/auth/sessions/consent/{challenge}: Consent management
- Admin API (port 4445): Client and session management
/admin/clients: OAuth2 client CRUD/admin/oauth2/auth/sessions/consent/{challenge}: Consent session management
CORS Configuration
- Enabled for public API
- Allowed origins:
http://localhost:3000,http://localhost:8080 - Supports standard HTTP methods (GET, POST, PUT, PATCH, DELETE, OPTIONS)
- Allows credentials
URL Configuration
self.issuer: Public URL of Hydra instanceconsent: URL of consent applicationlogin: URL of login applicationerror: URL for error handlinglogout: URL for logout handling- All URLs can be overridden via environment variables
OAuth2 Settings
- Access token TTL: 1h
- Refresh token TTL: 720h (30 days)
- ID token TTL: 1h
- Auth code TTL: 10m
- Access token strategy: JWT
- Scope strategy: exact
- Hasher algorithm: bcrypt (cost: 10)
OIDC Configuration
- Subject identifier types: pairwise, public
- Pairwise salt: configurable (default: "please-change-me-in-production")
Environment Variables
DSN: Database connection string (PostgreSQL withoryschema)SECRETS_SYSTEM: Secret key for cookie encryption (REQUIRED in production)URLS_SELF_ISSUER: Override issuer URLURLS_CONSENT: Override consent URLURLS_LOGIN: Override login URLURLS_ERROR: Override error URLURLS_LOGOUT: Override logout URLOIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT: Override pairwise salt
Database Configuration
- Uses PostgreSQL with
oryschema (created by database init scripts) - DSN format:
postgres://user:password@host:port/database?sslmode=disable&max_conns=20&max_idle_conns=4 - Migrations run automatically via
hydra-migratecontainer usingmigrate sqlcommand
Build Process
- Maven resource filtering processes
Dockerfileto substitute${ory.version} - Filtered Dockerfile stored in
target/docker/Dockerfile(cleaned bymvn clean) - Docker buildx builds image using filtered Dockerfile
- Configuration file copied to
/etc/config/hydra/hydra.ymlin container
Dockerfile Structure
- Base:
oryd/hydra:v${ory.version}(filtered at build time) - Copies
hydra/hydra.ymlto/etc/config/hydra/hydra.yml - Uses
chown=1000:1000for proper file ownership
Runtime Commands
- Migration:
migrate sql -e --yes -c /etc/config/hydra/hydra.yml - Server:
serve all -c /etc/config/hydra/hydra.yml --dev(remove--devin production)
Integration Points
- Frontend: Handles login, consent, error, logout flows
- Backend: Validates OAuth2 tokens, integrates with user management
- Database: Stores clients, tokens, sessions in
oryschema - NGINX: Proxies public and admin APIs (when
ENABLE_HYDRA_PROXY=true)
Security Considerations
- Production Checklist:
- Change
SECRETS_SYSTEMsecret - Change
OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT - Configure proper CORS origins
- Enable TLS/HTTPS
- Remove
--devflag - Set up rate limiting
- Configure monitoring and logging
- Review OAuth2 client configurations
- Secure admin API (IP whitelist, authentication)
- Change
Development Guidelines
- Use environment variables to override configuration values
- Keep
hydra.ymlas base configuration with sensible defaults - Version is managed via parent POM property
ory.version - Filtered Dockerfile must be in
target/dockerfor proper cleanup - Always use
--devflag only in development environments - Log level set to
debugin development (change toinfoorwarnin production)
Testing
- Verify OIDC discovery endpoint returns correct configuration
- Test OAuth2 authorization flow
- Validate token issuance and validation
- Test consent flow with frontend integration
- Verify database migrations run successfully
- Check CORS headers in responses
Future Integration
- Kratos: Will share
oryschema for user identity management - Backend: Will validate tokens and integrate with user sessions
- Frontend: Will implement login/consent flows using Hydra endpoints
What's inside
9 sections covering architecture, configuration, environment variables, build, commands, integration, security, development, and testing.
Change this for your project
- Replace
avarc-ory-hydrawith your module name - Replace
please-change-me-in-productionwith a secure pairwise salt - Replace
http://localhost:3000andhttp://localhost:8080with your CORS origins
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Using environment variable overrides for all URLs and secrets to keep YAML as base config
- Separating public and admin API ports with distinct CORS policies
- Including a production checklist as a reminder for security steps
Related Documents
PCB Design Sources for Industry-Scale Testing
Lists GitHub repos and communities where you can download real PCB designs for testing optimization at scale.
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.