Overview
Openinary uses Better Auth for authentication with SQLite as the database backend. The system supports both web-based login (email/password) and API key authentication for programmatic access.Authentication Architecture
Better Auth Configuration
Shared authentication between API and Web:- Single SQLite database at
/data/auth.db - Better Auth v1.1.9 with API Key plugin
- Automatic database initialization on first startup
- Session-based auth for web, API key for API requests
The authentication system uses a shared package that both the API and Web applications access, ensuring consistent authentication across all interfaces.
Auth Database Security
SQLite Configuration
Location:/data/auth.db (configurable via DB_PATH)
File Permissions:
- Automatically set to
600(owner read/write only) - Enforced by
scripts/secure-db.shon startup - Validated by health check endpoint
user- User accounts (passwords bcrypt-hashed)session- Web sessionsaccount- Auth providersverification- Email/phone verificationapiKey- API keys (hashed)
What’s Protected
Hashed/Encrypted:
- User passwords (bcrypt)
- API keys (hashed)
- Session tokens (secure cookies)
API Key Management
Initial Setup
- Fullstack Mode (Default)
- API Standalone Mode
Using API Keys
Authorization header:API Routes
Complete API Routes Table
| Method | Route | Description | Authentication |
|---|---|---|---|
| PUBLIC ROUTES | |||
GET | / | API health check | Public |
GET | /health | API health status | Public |
GET | /health/database | Database status | Protected |
GET | /t/* | Image/video transformation | Public |
GET | /video-status/* | Video processing status | Public |
GET | /video-status/*/size | Optimized video size | Public |
GET | /video-status/stats | Video queue statistics | Public |
GET | /queue/events | SSE stream for queue events | Public |
| PROTECTED ROUTES | |||
POST | /upload | Upload one or multiple files | Protected |
GET | /storage | List file tree structure | Protected |
GET | /storage/*/metadata | File metadata | Protected |
DELETE | /storage/* | Delete a file and its cache | Protected |
POST | /api-keys/create | Create a new API key | Protected |
GET | /api-keys/list | List user’s API keys | Protected |
DELETE | /api-keys/:keyId | Delete an API key | Protected |
PATCH | /api-keys/:keyId | Update an API key | Protected |
GET | /queue/stats | Queue statistics | Protected |
GET | /queue/jobs | List jobs (pagination) | Protected |
POST | /queue/jobs/:id/retry | Retry a failed job | Protected |
POST | /queue/jobs/:id/cancel | Cancel a pending job | Protected |
DELETE | /queue/jobs/:id | Delete a job | Protected |
GET | /queue/worker/stats | Worker statistics | Protected |
Legend
- Public: No authentication required
- Protected: API key authentication required (header
Authorization)
Important Notes
Public routes:
/queue/eventsis public (real-time SSE stream)/t/*is public for direct access to transformations- Health endpoints are mostly public except
/health/database
Docker Security
Non-Root User
All containers run as usernode:
- Prevents privilege escalation
- Limits damage if compromised
- Automatic ownership:
chown -R node:node /app
Volume Permissions
Startup Security
scripts/secure-db.sh runs automatically:
- Creates
/datadirectory - Sets database permissions to 600
- Verifies security
- Displays status
Security Best Practices
API Keys
Do:
- Store in environment variables
- Use different keys per service
- Set appropriate expiration
- Rotate regularly
- Disable unused keys
Passwords
Requirements:- Minimum 8 characters
- Mixed case, numbers, symbols
Rate Limiting
- Built-in: 100 requests/minute per API key
- Configurable in
packages/shared/src/auth.ts
Incident Response
Compromised API Key
Compromised API Key
Security checkup
| Criterion | Status |
|---|---|
| Authentication | Better Auth with API keys |
| Password Hashing | bcrypt automatic |
| API Key Hashing | Hashed in database |
| File Permissions | Enforced 600 |
| Backups | Daily automated |
| Audit Logging | Structured JSON |
| HTTPS Cookies | Production enforced |
| Secret Validation | Startup checks |
| Non-Root Containers | User node |
| Health Monitoring | /health/database |