๐ Certificate Lifecycle Patterns¶
Never let a certificate expire again.
Managing SSL/TLS certificates is critical but error-prone. This pattern automates the entire lifecycle: request, validation, installation, and renewal.
๐ง The AI Advantage¶
- Discovery: Scans your network for unknown/expiring certs.
- Validation: Verifies the certificate chain and ciphers after installation.
- Smart Reload: Knows which services need reloading (Nginx? Apache? Postfix?) when a cert changes.
๐ ๏ธ Implementation¶
1. Certificate Definitions¶
managed_certificates:
- domain: "api.example.com"
provider: "letsencrypt"
services: ["nginx", "postfix"]
deploy_to:
- "/etc/nginx/ssl/"
- "/etc/postfix/certs/"
2. The Renewal Logic¶
The cert_manager role handles the complexity:
- Checks expiration date (local file AND live socket)
- Runs
certbotor API calls to provider - Distributes files to correct paths with correct permissions
- Restarts defined services only if cert changed
3. Emergency Revocation¶
If a key is compromised, trigger the Panic Mode:
This instantly revokes the cert, generates a new key/cert pair, and deploys it everywhere.
๐ค Example Workflow¶
- Daily Check finds
db.example.comcert expires in 29 days. - Automation requests renewal from CA.
- Validation confirms new cert is valid for 365 days.
- Deployment copies cert to database servers.
- Service Restart reloads PostgreSQL gracefully.
- Final Check connects to port 5432 to verify SSL handshake.