|
| 1 | +# ADR-006: SSL Certificate Generation Strategy |
| 2 | + |
| 3 | +## Status |
| 4 | + |
| 5 | +Accepted |
| 6 | + |
| 7 | +## Context |
| 8 | + |
| 9 | +During the implementation of HTTPS support for the Torrust Tracker Demo, we |
| 10 | +needed to decide between two approaches for SSL certificate management: |
| 11 | + |
| 12 | +1. **Generate certificates on each deployment** - Create fresh certificates during each deployment process |
| 13 | +2. **Reuse certificates across deployments** - Generate certificates once and copy them between deployments |
| 14 | + |
| 15 | +For local testing environments, we consistently use the same domain (`test.local`), |
| 16 | +which means certificates could technically be reused. However, for production |
| 17 | +environments, different domains are used for different deployment targets. |
| 18 | + |
| 19 | +## Decision |
| 20 | + |
| 21 | +We will **generate SSL certificates on each deployment** rather than reusing |
| 22 | +certificates across deployments. |
| 23 | + |
| 24 | +## Rationale |
| 25 | + |
| 26 | +### 1. Production Flexibility |
| 27 | + |
| 28 | +Different environments use different domains: |
| 29 | + |
| 30 | +- Local testing: `test.local` |
| 31 | +- Staging environments: `staging.example.com` |
| 32 | +- Production: `tracker.torrust-demo.com` |
| 33 | + |
| 34 | +Certificates must match the exact domain being used in each environment. |
| 35 | + |
| 36 | +### 2. Certificate Validity |
| 37 | + |
| 38 | +Self-signed certificates are domain-specific and must exactly match the domain |
| 39 | +being used in each deployment environment. Reusing certificates would require |
| 40 | +maintaining separate certificate sets for each domain or would fail certificate |
| 41 | +validation. |
| 42 | + |
| 43 | +### 3. Security Best Practices |
| 44 | + |
| 45 | +Fresh certificates for each deployment ensure: |
| 46 | + |
| 47 | +- No stale or leaked credentials are reused |
| 48 | +- Certificates are generated with current system time |
| 49 | +- No cross-environment certificate contamination |
| 50 | + |
| 51 | +### 4. Workflow Consistency |
| 52 | + |
| 53 | +The same deployment process works across all environments without: |
| 54 | + |
| 55 | +- Manual certificate management |
| 56 | +- Certificate copying between systems |
| 57 | +- Environment-specific deployment procedures |
| 58 | +- Certificate store maintenance |
| 59 | + |
| 60 | +### 5. Zero Configuration |
| 61 | + |
| 62 | +This approach requires no additional infrastructure: |
| 63 | + |
| 64 | +- No certificate distribution system |
| 65 | +- No certificate storage requirements |
| 66 | +- No manual certificate rotation procedures |
| 67 | + |
| 68 | +## Implementation |
| 69 | + |
| 70 | +Certificate generation happens during the application deployment phase (`make app-deploy`): |
| 71 | + |
| 72 | +1. **Self-signed certificates**: Generated using OpenSSL with domain-specific |
| 73 | + Subject Alternative Names (SAN) |
| 74 | +2. **Certificate placement**: Stored in `/var/lib/torrust/proxy/certs/` and |
| 75 | + `/var/lib/torrust/proxy/private/` on the target server |
| 76 | +3. **Container mounting**: Certificates are mounted into nginx container at runtime |
| 77 | +4. **Automatic configuration**: nginx configuration is automatically templated |
| 78 | + with the correct certificate paths |
| 79 | + |
| 80 | +## Consequences |
| 81 | + |
| 82 | +### Positive |
| 83 | + |
| 84 | +- ✅ Identical deployment workflow between local testing and production |
| 85 | +- ✅ No certificate management overhead |
| 86 | +- ✅ Domain-specific certificates always match deployment target |
| 87 | +- ✅ Enhanced security through fresh certificates |
| 88 | +- ✅ Simplified deployment automation |
| 89 | + |
| 90 | +### Negative |
| 91 | + |
| 92 | +- ❌ Slight deployment time increase (certificate generation takes ~2-3 seconds) |
| 93 | +- ❌ Cannot preserve certificate fingerprints across deployments |
| 94 | +- ❌ Requires certificate regeneration for each deployment (even if domain unchanged) |
| 95 | + |
| 96 | +### Neutral |
| 97 | + |
| 98 | +- 🔄 For local testing, certificates are regenerated even though domain remains `test.local` |
| 99 | +- 🔄 Certificate validity period is reset on each deployment (10 years for self-signed) |
| 100 | + |
| 101 | +## Alternatives Considered |
| 102 | + |
| 103 | +### Certificate Reuse Strategy |
| 104 | + |
| 105 | +We considered implementing certificate reuse for local testing: |
| 106 | + |
| 107 | +1. Generate certificates once and store them locally |
| 108 | +2. Copy stored certificates to VM during deployment |
| 109 | +3. Use fresh generation only for production deployments |
| 110 | + |
| 111 | +**Rejected because:** |
| 112 | + |
| 113 | +- Creates environment-specific deployment logic |
| 114 | +- Increases complexity for minimal time savings |
| 115 | +- Introduces certificate management overhead |
| 116 | +- Reduces consistency between local and production workflows |
| 117 | + |
| 118 | +## Related Decisions |
| 119 | + |
| 120 | +- [ADR-004: Configuration Approach Files vs Environment Variables] |
| 121 | + (004-configuration-approach-files-vs-environment-variables.md) - |
| 122 | + Template-based configuration approach |
| 123 | +- [ADR-002: Docker for All Services](002-docker-for-all-services.md) - |
| 124 | + Container-based service architecture |
| 125 | + |
| 126 | +## References |
| 127 | + |
| 128 | +- [SSL Certificate Management Documentation](../application/docs/deployment.md#ssl-certificate-management) |
| 129 | +- [Deployment Script Implementation](../infrastructure/scripts/deploy-app.sh) |
| 130 | +- [Certificate Generation Script](../application/share/bin/ssl-generate-test-certs.sh) |
0 commit comments