現在のワイルドカード証明書で重要な点
ワイルドカード証明書はDNS-01認証が必要です。手動でTXTレコードを追加する方法では完全自動更新できないため、利用DNSに対応したCertbot DNSプラグインまたは安全な更新フックを検討します。
sudo certbot certificates
sudo certbot renew --dry-run
systemctl list-timers | grep certbot
- DNS APIトークンは対象ゾーンと必要操作だけに権限を絞る
- 認証情報ファイルはrootのみ読み取り可能にする
- 更新後にApache/Nginxへ証明書が反映されることを確認する
- 失効・更新失敗の通知先を設定する
この後のCentOS 7、古いCertbot導入方法は旧環境の記録です。新規導入はCertbot公式の環境別手順を使用してください。
2018年3月よりLet’s EncryptのSSLサーバ証明書でワイルドカードが利用可能となりましたので、設定手順を記しておきます。有効期限が90日(約3ヶ月)と短いですが、自動更新設定しておくことで定期的に更新されますので、手動で更新する必要が無くなります。 自動更新設定は以下サイト参照certbot+certbot-dns-cloudflare でワイルドカード証明書を取得&自動更新する - Qiita
1. certbot をインストール CentOS 7 なら epel にワイルドカード証明書対応版 (v0.22) があるので、それをインストールする。 yum install --enablerepo=epel certbot 2. c […]
実施環境
環境は以下の通りです。- CentOS 7.2
- Apache 2.4.25
Certbotインストール
まずは以下のコマンドでCertbotをインストールします。(インストール済みの場合は不要です) Certbotは0.22.0からACMEv2に対応しており、DNS-01チャレンジにも対応しているそうです。yum -y install certbot
SSLサーバ証明書のファイル生成
以下のコマンドで証明書ファイルを生成します。 ワイルドカードで生成する場合は *.hogehoge.com と記述します。certbot certonly --agree-tos --manual-public-ip-logging-ok --manual -d "[*.hogehoge.com]" --preferred-challenges dns-01 --email [hogehoge@hogehoge.com] --server https://acme-v02.api.letsencrypt.org/directory
途中でメール送付の同意を求められるので、N+Enter
me-v02.api.letsencrypt.org/directory
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: N
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for [hogehoge.com]
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.[hogehoge.com] with the following value:
nGNi1RAdKbZD79bPo-harcARZ66b2XJWlMsmrUHtiHc
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
すると、_acme-challenge.[hogehoge.com]に対して、トークンが発行されますので、
指定ドメインのTXTレコードに上記で指定されたトークを設定します。
DNSサーバを自前で用意していない場合は、ドメインを管理しているレジストラ(お名前.comやムームードメインなど)で設定します。
DNSの設定は、反映に時間がかかる場合がありますので、反映されるまで暫く待機します。
DNSの反映が済みましたら、Enter押下で照合・証明書ファイル生成が行われます。
Waiting for verification...
Resetting dropped connection: acme-v02.api.letsencrypt.org
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/hogehoge.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/hogehoge.com/privkey.pem
Your cert will expire on 2018-06-14. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
ちなみに、失敗すると以下のようなエラーメッセージが表示されます。
Failed authorization procedure. [hogehoge.com] (dns-01): urn:ietf:params:acme:error:connection :: The server could not connect to the client to verify the domain :: DNS problem: NXDOMAIN looking up TXT for _acme-challenge.[hogehoge.com]
SSLサーバ証明書の確認
上記で証明書ファイルの生成を行うと、以下ディレクトリが生成されていますので、確認してみましょう。(ドメイン名に応じて任意のディレクトリとなっているはずです。)[root@hogehoge hogehoge.com]# ls -la /etc/letsencrypt/live/hogehoge.com/
total 12
drwxr-xr-x 2 root root 4096 Mar 16 21:40 .
drwx------ 3 root root 4096 Mar 16 21:40 ..
lrwxrwxrwx 1 root root 34 Mar 16 21:40 cert.pem -> ../../archive/hogehoge.com/cert1.pem
lrwxrwxrwx 1 root root 35 Mar 16 21:40 chain.pem -> ../../archive/hogehoge.com/chain1.pem
lrwxrwxrwx 1 root root 39 Mar 16 21:40 fullchain.pem -> ../../archive/hogehoge.com/fullchain1.pem
lrwxrwxrwx 1 root root 37 Mar 16 21:40 privkey.pem -> ../../archive/hogehoge.com/privkey1.pem
-rw-r--r-- 1 root root 543 Mar 16 21:40 README
シンボリックリンクで、数字付きのファイルを見ていますが、証明書を更新する際ににシンボリックリンクの向きも更新されますので、特にパスの変更は必要ありません。
SSLサーバ証明書の設定
Apache2.4の場合の記述です。 httpd-ssl.conf 等で上記の証明書を読むように指定します。 SSLの暗号化強度の設定等はここでは割愛します。 SSLEngine on
SSLCertificateKeyFile /etc/letsencrypt/live/hogehoge.com/privkey.pem
SSLCertificateFile /etc/letsencrypt/live/hogehoge.com/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/hogehoge.com/chain.pem
上記を記述後にapacheの記述にシンタックスエラーが出なければ、再起動をして完了です。
apachectl configtest
apachectl graceful
Webサイトの場合はブラウザから証明書を確認してみると、無事更新されています。
証明書の自動更新設定
先述のとおり、Let’s Encryptは90日間の有効期限ですので、自動更新の設定をしておくべきです。DNSの設定でエラーが発生したので、以下のサイトを参考にcloudflareでネームサーバを変更すれば対応可能です。certbot+certbot-dns-cloudflare でワイルドカード証明書を取得&自動更新する - Qiita
1. certbot をインストール CentOS 7 なら epel にワイルドカード証明書対応版 (v0.22) があるので、それをインストールする。 yum install --enablerepo=epel certbot 2. c […]


