使用 certbot 申請 Let’s Encrypt Wildcard 憑證

系統: Centos 7
需求: 包含自行管理DNS的網域(bind)以及免費 no-ip網域, 若為其它代管業者可以到certbot查詢是否有範本或plugin.

安裝

在提供服務的主機

yum install certbot
yum install python2-pip

DNS若為自行管理, 需要安裝 certbot-dns-rfc2136 PLUGIN以自動更新DNS TXT RECORD讓 Let’s Encrypt 確認您擁有網域管理權

pip install certbot-dns-rfc2136

設定

在提供服務的主機上新增 /etc/letsencrypt/rfc2136.ini 檔案, 檔案權限須為0600, 內容如下

# Target DNS server
dns_rfc2136_server = 10.0.0.1
# Target DNS port
dns_rfc2136_port = 53
# TSIG key name
dns_rfc2136_name = rndckey
# TSIG key secret
dns_rfc2136_secret = mP1z2QD3R156ULti97TbdsRbPBcxe8zoBlaBla
# TSIG key algorithm
dns_rfc2136_algorithm = HMAC-MD5

TSIG Key 是用來更新 named.conf 中區域的字串 , 產生方式如下

dnssec-keygen -a HMAC-SHA512 -b 512 -n HOST rndckey

修改 DNS 管理主機上的 named.conf , 指定需要自動更新的ZONE & 增加控制的TSIG KEY

key rndckey {
                algorithm hmac-md5;
                secret “mP1z2QD3R156ULti97TbdsRbPBcxe8zoBlaBla”;
                };

zone “example.com” {
                type master;
                file “/var/named/example.com.hosts”;
                allow-update {
                                key “rndckey”;
                                };
                };

若考慮安全性可用 update-policy 取代 allow-update, 但需要Bind9以上的版本

測試是否能動態更新DNS

certbot certonly –dry-run –dns-rfc2136 –dns-rfc2136-credentials /etc/letsencrypt/rfc2136.ini –dns-rfc2136-propagation-seconds 30 -d example.com -d *.example.com

若訊息顯示沒有問題就可以以正式取得憑證

certbot certonly –dns-rfc2136 –dns-rfc2136-credentials /etc/letsencrypt/rfc2136.ini –dns-rfc2136-propagation-seconds 30 -d example.com -d *.example.com

若為no-ip 網域因無法使用DNS驗證則測試方式改為(非wildcard憑證)

certbot certonly –dry-run –webroot -w /var/www/html -d yourdomain.no-ip.com

正式取得

certbot certonly –webroot -w /var/www/html -d yourdomain.no-ip.com

申請完成後因為憑證期限為3個月 所以我們需要排成3個約一次執行該指令 另外需要重啟相關使用憑證的服務, 例如:

certbot certonly –dns-rfc2136 –dns-rfc2136-credentials /etc/letsencrypt/rfc2136.ini –dns-rfc2136-propagation-seconds 30 -d example.com -d *.example.com –post-hook ‘systemctl restart httpd;systemctl restart dovecot;systemctl restart sendmail’

如果管理的網域很多也可以直接使用 certbot renew , 但因為certbot版本更新很快, 不是很確定所有狀況 renew 都可以正確更新 , 所以這邊直接使用完整指令更新

參考文獻:

https://certbot-dns-rfc2136.readthedocs.io/en/stable/
https://certbot.eff.org/docs/using.html?highlight=renew
https://evermeet.cx/wiki/Let%27s_Encrypt_with_Apache,_dovecot,_and_sendmail

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。