Overview
Duckling provides multiple layers of security including authentication, rate limiting, session management, and encryption. This guide covers all security features and best practices.Authentication
Duckling supports three authentication methods:1. API Key Authentication
For programmatic access (scripts, applications, integrations).API key for Bearer token authenticationGenerate a secure key:Usage:
- Store in environment variables, not in code
- Rotate regularly (recommended: every 90 days)
- Use separate keys for different environments
- Never commit to version control
2. Session-Based Authentication
For web dashboard (cookie-based login).Admin username for dashboard login
Admin password for dashboard loginPassword requirements:
- Minimum 16 characters recommended
- Mix of uppercase, lowercase, numbers, symbols
- Not based on dictionary words
- Unique to this service
Secret key for session cookie encryption
3. JWT Authentication
For stateless API access (mobile apps, SPAs).JWT signing secretFalls back to
SESSION_SECRET if not set.JWT token expiration
Shorter expiration is more secure but requires more frequent re-authentication.
Login Endpoint
Rate Limiting
Duckling includes sophisticated rate limiting to protect against abuse and ensure fair resource allocation.Enable Rate Limiting
Enable rate limiting
Rate limit enforcement mode
enforce- Block requests exceeding limits (recommended)shadow- Log violations but allow requests (testing only)
Rate Limit Categories
Different endpoint categories have different limits:Read endpoint limit (requests/minute)Applies to:
GET /tables, GET /status, GET /healthQuery endpoint limit (requests/minute)Applies to:
POST /queryWrite endpoint limit (requests/minute)Applies to:
POST /sync/*, POST /automation/*Authentication endpoint limit (requests/minute)Applies to:
POST /loginLow limit prevents brute-force attacks.
Request Costs
Different operations have different “costs” for rate limiting:Cost per query request
Cost per write requestWrite operations (sync, backup) are more expensive.
Tiered Rate Limits
Authenticated users get higher limits:| Tier | Multiplier | Applies To |
|---|---|---|
| Anonymous | 1x | Unauthenticated requests |
| JWT | 2x | JWT token authentication |
| API Key | 5x | API key authentication |
- Anonymous: 80 queries/min
- JWT: 160 queries/min (80 × 2)
- API Key: 400 queries/min (80 × 5)
Concurrency Limits
Prevent resource exhaustion from parallel queries:Max concurrent queries (JWT)
Max concurrent queries (API key)
In-flight tracking TTL (ms)Time to keep query tracking data (5 minutes).
Rate Limit Scope
Use session-based rate limiting
true- Limit per session IDfalse- Limit per IP address (default)
Include database in rate limit scope
true- Separate limits per database (recommended)false- Global limits across all databases
MySQL Protocol Authentication
Duckling exposes a MySQL-compatible wire protocol on port 3307.MySQL protocol username
MySQL protocol passwordFalls back to
DUCKLING_API_KEY if not set.CORS Configuration
Enable Cross-Origin Resource Sharing
CORS is required for browser-based applications. Disable only if all clients are server-side.
Encryption
Session Cookie Encryption
Session cookies are encrypted usingSESSION_SECRET.
S3 Backup Encryption
S3 backups support multiple encryption modes:| Mode | Security | Use Case |
|---|---|---|
none | No encryption | Development only |
sse-s3 | AWS-managed keys | Good for most cases |
sse-kms | AWS KMS + audit trail | Compliance requirements |
client-aes256 | Client-side (best) | Recommended for production |
- Encryption key never leaves your server
- Protects against compromised AWS credentials
- Protects against bucket misconfiguration
- HMAC integrity verification on restore
Security Validation
Duckling validates security configuration on startup.Check for Security Issues
JWT_SECRETusing default valueADMIN_USERNAMEorADMIN_PASSWORDemptySESSION_SECRETnot set
Network Security
Firewall Rules
Minimum required ports:Reverse Proxy with SSL/TLS
Nginx with Let’s Encrypt:VPN/Private Network
For maximum security, deploy Duckling in a private network:MySQL Source Security
Read-Only User
Create a dedicated read-only MySQL user for Duckling:Connection Encryption
Use SSL/TLS for MySQL connections:IP Allowlisting
Restrict MySQL access to Duckling server IP:Audit Logging
Enable Detailed Logging
Log Rotation
Centralized Logging
Sentry Error Tracking
Security Checklist
Authentication configured
-
DUCKLING_API_KEYset to random 64-char hex -
ADMIN_PASSWORDchanged from default (16+ characters) -
SESSION_SECRETset to random 64-char hex -
JWT_SECRETset (or usingSESSION_SECRET) - Default credentials never used in production
Rate limiting enabled
-
RATE_LIMIT_ENABLED=true -
RATE_LIMIT_MODE=enforce - Limits tuned for expected traffic
- Concurrency limits set
Network security
- Reverse proxy with SSL/TLS
- Firewall rules configured
- Unnecessary ports closed
- HTTPS enforced (no HTTP)
MySQL source security
- Read-only MySQL user created
- MySQL connection uses SSL/TLS
- IP allowlisting configured
- Strong MySQL password
Data encryption
- S3 backups use client-side encryption
- Encryption keys stored securely
- Session cookies encrypted
- HTTPS for all web traffic
Monitoring & logging
- Log level set appropriately
- Log rotation configured
- Centralized logging (optional)
- Error tracking (Sentry) configured
Access control
- Principle of least privilege
- Separate credentials per environment
- Regular credential rotation
- API keys stored in secrets manager
Credential Rotation
API Key Rotation
Session Secret Rotation
S3 Encryption Key Rotation
Incident Response
Suspected API Key Compromise
- Immediately rotate
DUCKLING_API_KEY - Review access logs for unauthorized access
- Check for data exfiltration
- Update all legitimate clients
- Consider enabling IP allowlisting
Suspected Admin Credential Compromise
- Immediately change
ADMIN_PASSWORD - Rotate
SESSION_SECRET(invalidates all sessions) - Review audit logs for unauthorized actions
- Check for configuration changes
- Verify database integrity
Suspected Database Compromise
- Immediately stop sync to prevent further damage
- Restore from known-good backup
- Review MySQL source for tampering
- Verify DuckDB file integrity
- Re-sync after validation
Compliance Considerations
GDPR
- Encrypt data at rest (S3 client-side encryption)
- Encrypt data in transit (SSL/TLS)
- Access logging and audit trails
- Right to deletion (backup cleanup)
HIPAA
- Use
sse-kmsorclient-aes256for S3 backups - Enable audit logging
- Restrict access to PHI
- Encrypt all network traffic
SOC 2
- Enable Sentry error tracking
- Centralized logging
- Access control (API keys, rate limiting)
- Regular credential rotation
- Backup encryption
Next Steps
Production Guide
Production deployment best practices
Configuration
Full environment variable reference
Docker Deployment
Docker deployment guide