This documentation provides a professional guide to implementing the DNS-01 challenge for SSL certificates using cloudflare API. Using this method allows for wildcard certificates and renewal for internal servers not exposed to the public internet.
1. Prerequisites
Before starting, ensure you have the following:
- Certbot installed on your system.
- The Cloudflare DNS plugin for Certbot (
python3-certbot-dns-cloudflare). - A Cloudflare API Token (not the Global API Key) with
Zone:DNS:EditandZone:Zone:Readpermissions.
2. Cloudflare API Configuration
Store your credentials in a restricted file to prevent unauthorized access.
Create the configuration file:
/etc/letsencrypt/cloudflare.ini
Secure the file permissions:
3. Initial Certificate Generation
Run the following command to generate your first certificate. This example includes a wildcard entry.
4. Automation with Systemd
Modern Linux distributions recommend using systemd timers over legacy cron jobs for better logging and dependency management.
A. The Service Unit
This unit defines the renewal task. It includes a post-execution hook to reload your web server.
File: /etc/systemd/system/certbot-renewal.service
B. The Timer Unit
This unit schedules the service to run twice a day.
File: /etc/systemd/system/certbot-renewal.timer
5. Deployment and Verification
Once the files are created, enable the automation:
Useful Commands for Maintenance
- Check Timer Status :
systemctl list-timers certbot-renewal.timer - Dry Run Test :
certbot renew --dry-run - View Execution Logs :
journalctl -u certbot-renewal.service