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
Mode:
MODE=fullstack (default)1
Create admin account
Visit
/setup to create your first admin account.2
Create API keys
Go to
/api-keys to create API keys via the web UI.Using API Keys
Authorization header:GET /t/*- Image and video transformationPOST /upload/*- File uploadGET/POST /storage/*- Storage operations
API Key Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /api-keys/create | Create new API key |
| GET | /api-keys/list | List user’s API keys |
| PATCH | /api-keys/:keyId | Update API key |
| DELETE | /api-keys/:keyId | Delete API key |
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 (12+ in production)
- 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
1
Disable immediately
Disable the key via web UI at
/api-keys.2
Review audit logs
3
Generate new key
Create a replacement API key with appropriate permissions.
4
Update applications
Update all applications using the compromised key.
Database Corruption
Database Corruption
1
Check integrity
2
Restore from backup
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 |