Authentication
Use JWT-based authentication with RSA key pairs so only authorized users interact with the platform. Actionable steps:- Generate an RSA key pair (example):
- Validate JWTs in your backend with the public key.
- Rotate signing keys every 30-90 days for long-running deployments.
Secrets management
Centralize and encrypt sensitive data such as passwords, API keys, database credentials, and tokens. Avoid storing secrets directly in environment variables or committing them to configuration files. Use secrets managers or mounted secret files instead.HashiCorp Vault (recommended for enterprise)
Vault provides enterprise-grade secrets management with RBAC, audit logging, and encrypted storage: Key features:- Dynamic secrets with automatic rotation
- Fine-grained access control policies
- Comprehensive audit trails for compliance
- Encryption as a service
- Multi-cloud and hybrid support
- Use Vault APIs or client libraries to retrieve secrets at runtime
- Implement automatic secret rotation without service restarts
- Configure lease durations and renewal policies
- Enable audit logging for all secret access
Docker Swarm secrets
For simpler deployments, use Docker Swarm’s built-in secrets management: Create and use secrets:/run/secrets/ directory:
- Encrypted in transit and at rest
- Only accessible to authorized services
- Automatically removed when service is deleted
- Immutable (must delete and recreate to update)
Best practices
- Principle of least privilege: Grant secrets access only to services that need them
- Regular rotation: Rotate secrets on a defined schedule (30-90 days)
- Audit logging: Monitor and log all secret access for security analysis
- Backup and recovery: Maintain secure backups of secrets management systems
- Separation of duties: Require multiple approvals for sensitive secret operations
Network security
Run backend services on private overlay networks and expose only NGINX to the internet. Actionable steps:- Create a private overlay network:
- Harden firewall rules to allow only the necessary ports (80/443) and block the rest. Apply firewall rules at the host or network perimeter level, not inside containers:
TLS configuration
Encrypt all traffic with modern TLS protocols and strong cipher suites.NGINX TLS configuration
Configure NGINX with security best practices:Certificate management
Obtain certificates:- Let’s Encrypt: Free, automated certificates with 90-day validity
- Commercial CA: Extended validation (EV) certificates for enterprise trust
- Internal CA: For internal services and development environments
- Use Certbot or similar tools for automatic renewal
- Configure renewal hooks to reload NGINX after certificate updates
- Monitor certificate expiration dates (alert 30 days before expiry)
Internal service encryption
Docker Swarm overlay network encryption:- Automatic encryption of all inter-service communication
- No application code changes required
- Protects against network sniffing within the cluster
- Enable TLS for TiDB, MongoDB, and Redis connections
- Use certificate-based authentication where supported
- Encrypt backup data in transit and at rest
Additional security measures
- Rate limiting: protect against abuse or DDoS using NGINX rate limits. Tune rate limits based on expected traffic patterns to avoid impacting legitimate users:
- IP allowlisting: restrict access to sensitive services:
- Log monitoring: collect and monitor logs (e.g., Prometheus alerts, Grafana dashboards, ELK/Loki) to detect suspicious activity.