No.324


【Let's Encrypt】BASIC認証下でドメインを確認させる。

証明書更新失敗の通知が来た…

 Let's Encrypt の証明書を運用していると、切っても来てない作業が三ヶ月ごとの証明書の更新。
 たいていの人はcronで自動で行っていることと思う。

 かくいう自分もcronでの自動更新で運用を初めて数ヶ月、Let's Encrypt の更新レポートの中にfailureの文字を見つけた。

The following certs could not be renewed:
  /etc/letsencrypt/live/xxx.exsample.com/fullchain.pem (failure)

 詳しく見てみると

Attempting to renew cert (xxx.exsample.com) from /etc/letsencrypt/renewal/xxx.exsample.com.conf produced an unexpected error: Failed authorization procedure. xxx.exsample.com (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://xxx.exsample.com/.well-known/acme-challenge/zwJp9d9aPw56Iid5Axs3SucPOgGMB67j60e7sboS-dA: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>401 Authorization Required</title>\n</head><body>\n<h1>Auth". Skipping.

 acme-challengeで401Authエラー、つまりBASIC認証か…

 回避のため下記を.htaccessに記載して手動で更新実行、事なきを得た。(記載するのは/etc/httpd/conf.d/ssl.confなどでも問題なし)

SetEnvIf Request_URI "/.well-known/acme-challenge" acme-challenge
Order Deny,Allow
Deny from all
Allow from env=acme-challenge

 クローズドのサイトなどで公開後にBASIC認証を掛けたのを忘れて更新失敗しないように注意!(戒め