Ory Hydra Configuration Rules
This module (`avarc-ory-hydra`) provides Ory Hydra OAuth2 and OpenID Connect server configuration. Hydra handles OAuth2/OIDC flows, token management, and client administration.
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
Related Documents
Design Document: BharatSeva AI
BharatSeva AI is a multi-agent orchestration system built on AWS using Amazon Bedrock Agents with Claude 3.5 Sonnet as the foundation model. The system deploys 10 AI agents (1 Master Orchestrator + 9 Specialist Agents) to assist India's informal sector workers in navigating government schemes across three domains: PM Vishwakarma (artisan credit), PMFBY (crop insurance), and BOCW (construction worker welfare).
OpenClaw Enterprise Transformation Plan
Transform OpenClaw from a single-user personal AI assistant into a **dual-mode platform** that is simultaneously:
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Daniel Sandner, for article on https://sandner.art/
Qwen3-TTS — Model Reference
Models: `Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice` and `Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice`