

にほんブログ村
先日、以下のようなメールが届きました。
メールの送信元は、弊サイトで利用しているLet's EncryptというSSL/TLSサーバ証明書を無料で発行してくれるサービスからのものでした。
送信元
Let's Encrypt Expiry Bot
本文(抜粋)
Hello,
Your certificate (or certificates) for the names listed below will expire in 19 days (on 23 May 19 17:14 +0000). Please make sure to renew your certificate before then, or visitors to your website will encounter errors.
We recommend renewing certificates automatically when they have a third of their total lifetime left. For Let's Encrypt's current 90-day certificates, that means renewing 30 days before expiration. See https://letsencrypt.org/docs/integration-guide/ for details.
弊サイトでは、Let's Encryptを使ってサイトの証明書を作成し、毎月のcronで証明書の更新を行っていました。
サイトの証明書の作成や自動更新のやり方については、以下のサイトを参考にして行っており、少なくとも1年半以上は、証明書の自動更新もうまくいっていました。
・Webサーバー間通信内容暗号化(Apache+mod_SSL+Certbot)(https://www.centossrv.com/apache-certbot.shtml)
・Let's Encrypt 総合ポータル(https://free-ssl.jp/)
しかし、メールの内容を見ると、どうやら自動更新ができておらず、あと19日で証明書の有効期限が切れるようでした。
実際にサイトの証明書を見ると、有効期限が5/24までとなっており、なぜ証明書の自動更新ができなくなってしまったかを調べてみました。
まず、自動更新のcronに登録しているシェルを実行してみると、以下のようなエラーとなりました。
Upgrading certbot-auto 0.34.0 to 0.34.2...
Replacing certbot-auto...
Creating virtual environment...
Installing Python packages...
Installation succeeded.
usage:
certbot-auto [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...
Certbot can obtain and install HTTPS/TLS/SSL certificates. By default,
it will attempt to use a webserver both for obtaining and installing the
certificate.
certbot: error: argument --webroot-path/-w: expected one argument
明らかにコマンドを実行するための何か引数的な要素が足らないか間違っていることが分かりました。
しかし、これまで特に設定も何も変更したことがないので何が変わったのかわからなかったので、他のサイトでも似たようなことが無いか調べたところ、次の2点の怪しいことが分かりました。
/usr/local/certbot/certbot-auto(証明書の更新を行うコマンド)において、
・-w ${webroot}を削れば治る
・そもそも${webroot}がちゃんと取得できているか?
とのこと。
現状は、certbot-autoは以下のように使用していました。
/usr/local/certbot/certbot-auto certonly --webroot -w ${webroot} -d ${domain} --renew-by-default >> ${log} 2>&1
これまで設定を変更したこともなく、ずっと証明書の更新ができていたことから、関連パッケージの更新により仕様が変わったのか?と思って-w ${webroot}を削ってみたが、状況は変わらず。
では${webroot}がちゃんと取得できているかを確認してみたところ、シェルの中に記載していた以下の部分を手動で実行してみると、なんとwebrootが空であったことがわかりました。
webroot=`grep -A 1 webroot_map /etc/letsencrypt/renewal/${conf}|grep =|awk '{print $3}'`
よって、今回の問題の対処方法は、/etc/letsencrypt/renewal配下の設定ファイルの最下部の[[webroot_map]]の設定が無くなっていたことが原因でしたので、弊サイトでは
[[webroot_map]]
yun-craft.com = /var/xyz/wwwroot
のような設定行うことで、証明書の自動更新ができるようになりました。
どうしてこの設定が無くなってしまったのかは正直言って不明ですが、とりあえず復旧したので良しとしました。
しかし、なぜ設定が無くなったのか...
元の設定をバックアップせずに上書きしてしまったので、今後はバックアップを残すことにします。
関連記事



