Let’s Encryptでのワイルドカード証明書更新をDNS認証で行う
ワイルドカード証明書をDNS認証で更新した時に、エラーが出たのでその対策。
webrootで証明書を更新する場合はドキュメントルート直下の.well-known配下にチャレンジを自動的に生成するみたいだが、DNS認証では–manualで証明書を作成しているため、renew時には-–manual-auth-hookでDNSのTXTレコードを更新する自作スクリプトか、専用のプラグインの指定が必要になる。
https://shizuka-na-kazushi.style/2021/04/25/nodejsexpress-lets-encrypt-certbot-renewal/
指定しなかったのでCloudFlare側でオリジンからデータが取得できなくなり 526エラーが出ていた。
オリジンサーバ側でrenewをした時のエラー
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Could not choose appropriate plugin: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.')
Failed to renew certificate perverseperson.net with error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.')
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All renewals failed. The following certificates could not be renewed:
/etc/letsencrypt/live/example.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
自作スクリプトで更新する場合、renew時に–manual-auth-hookと–manual-cleanup-hookを使用してスクリプトを指定し、追加と削除を同時に行う。
チャレンジは環境変数で提供され、CERTBOT_VALIDATION変数内にランダムな文字列が代入されている。 この文字列をDNSの_acme-challenge.[ドメイン名]のTXTレコードを作成した時に追加する。
クリーンアップでは追加したTXTレコードを削除する
https://eff-certbot.readthedocs.io/en/latest/using.html#hooks
https://eff-certbot.readthedocs.io/en/latest/using.html#manual-renewal
ちなみにCloudFlareのAPIドキュメントはこれ https://developers.cloudflare.com/api/operations/dns-records-for-a-zone-create-dns-record
主要なホスティングサービス向けのプラグインも公開されている
https://eff-certbot.readthedocs.io/en/latest/using.html#id2
必要に応じてサービスの再起動設定なども追加