Security: Htunn/InferMesh
Security
==============================================================================
Security Best Practices for Production Deployment
==============================================================================
DO NOT commit .env to version control
The .env file contains sensitive credentials including:
- API keys (Google Gemini, OpenAI, HuggingFace)
Use a secrets manager in production
- Docker Secrets (for Docker Swarm)
Example: Using Docker Secrets (Swarm mode)
echo "your_password" | docker secret create postgres_password -
echo "your_api_key" | docker secret create google_api_key -
2. Reference in docker-compose.yml:
GOOGLE_API_KEY_FILE: /run/secrets/google_api_key
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
3. Update backend code to read from files:
with open(os.getenv('GOOGLE_API_KEY_FILE'), 'r') as f:
api_key = f.read().strip()
Use a reverse proxy for SSL termination
Recommended: Nginx, Traefik, or Caddy in front of the application
Example: Nginx with Let's Encrypt
apt-get install certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
# Strong SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
}
}
Example: docker-compose with Traefik
Use internal network for backend services
Already configured in docker-compose.yml:
- postgres, backend, vllm on internal network
- Only frontend exposed on port 80
Configure UFW (Ubuntu) or firewalld (CentOS):
ufw allow 443/tcp # HTTPS
ufw allow 22/tcp # SSH (limit rate)
ufw deny 5432/tcp # Block PostgreSQL from external access
Strong password generation
python -c "import secrets; print(secrets.token_urlsafe(32))"
Or set up automated backups via cron:
0 2 * * * cd /path/to/app && make backup
Enable SSL for PostgreSQL connections (if across network)
POSTGRES_SSL_MODE: require
- ./certs/server-cert.pem:/var/lib/postgresql/server.crt:ro
- ./certs/server-key.pem:/var/lib/postgresql/server.key:ro
Already configured in nginx.conf:
- 20 requests/minute per IP for /api/*
Adjust based on your needs:
limit_req_zone $binary_remote_addr zone=chat_zone:10m rate=20r/m;
Already configured in backend/main.py
Update FRONTEND_ORIGIN in .env to match your domain:
RUN adduser --disabled-password --gecos '' appuser
Security options (already enabled in docker-compose.yml)
- Resource limits (memory, CPU)
- Read-only root filesystem (where applicable)
Scan images for vulnerabilities
docker scan backend:latest
trivy image backend:latest
- Database connection failures
Forward logs to centralized logging:
- ELK Stack (Elasticsearch, Logstash, Kibana)
- Review logs for anomalies
- Check for failed login attempts
- Review API usage patterns
- Update base images: make update
- Test backup restoration
- Review and update security policies
If credentials are compromised:
1. Immediately rotate all affected credentials
2. Review access logs for unauthorized access
3. Check for data exfiltration
4. Update .env and redeploy:
1. Isolate affected systems
2. Preserve evidence (logs, disk images)
3. Restore from known-good backup
4. Perform security audit
5. Update security measures
There aren't any published security advisories
You can’t perform that action at this time.