無料SSL(TLS)のLet's encryptワイルドカードをインストールしたメモ

2019年3月17日

セキュリティ テクノロジー

無料SSLで話題のLet's enctyptが、2018年3月からワイルドカード対応したとのことで、以前から気になっていたのだが、この度仕事の必要に応じてセットしてみることにした。 もともと無料SSLとしては利用していたのだが、ワイルドカードを使うことで、複数のサブドメインを1サーバーでセキュアにできるので、コストカットに最適な構成が作れそうです。 これまでの無料SSLとどのように設定方法が違うのかがポイントになると思うのでその点と、完了するまでに色々と戸惑った点があったので、そうした事を備忘録として書いておきます。

環境

まず、今回の環境は一般的ではなく、DNS管理をバリュードメインで行うという事で、下記のような構成になっています。 route53を使った全てAWS構成にしていれば、比較的プレイヤーも多いので情報もWEBで探せたんですが、同じ環境の人がもしいたら、幸いです。
ドメイン管理&DNS管理 : バリュードメイン サーバー : AWS(ec2) CGIモジュール : Nginx

certbotアプリは今までと同じもの

Let's Encryptの非公式ページは事前に参照しておきましょう。 公式ページ https://letsencrypt.org/ 非公式ページ https://free-ssl.jp/ 2019年3月現在では、certbot-autoモジュールをダウンロードして使うのが良さそうなので、以下のようにインストール wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto mkdir -p /path/to cp certbot-auto /path/to/ 次にcertbot-autoの実行だが、ここでワイルドカードは今までと違うオプション構成になる。 これまでは、certbot-autoをそのまま起動して支持に従うだけでよかったのだが、以下のようにセットするといいらしい。 ./certbot-auto certonly \ --manual \ --domain 'example.com' \ --domain '*.example.com' \ --email user@mail.com \ --agree-tos \ --manual-public-ip-logging-ok \ --preferred-challenges dns-01 \ --server https://acme-v02.api.letsencrypt.org/directory 細かい解説は他のページを見てもらったほうがいいので割愛するが、ドメインとメールアドレスは自分のモノを使ってくだされ。 そして、ワイルドカードは、ドメイン指定が2つあることに気がつくと思うが、この時に別のドメインでも指定可能らしい。 好きなだけ登録できてしまうようだが、上限は300個だったかな?どっかの規約に書かれていたはず。 そして、上記コマンドを実行すると、ドメイン指定した数だけ、「DNSのtxtをセットせよ」との命令が下る。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.example.com with the following value: Xnh**********66N8w Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.example.com with the following value: ixsbXf7********Iwf0RmwhM Before continuing, verify the record is deployed. (This must be set up in addition to the previous challenges; do not remove, replace, or undo the previous challenge tasks yet. Note that you might be asked to create multiple distinct TXT records with the same name. This is permitted by DNS standards.) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - とにかくめんどくさいのがこの点で、この次に"press enter"と表示されても、DNS設定を行って、値が反映されなければ、次に進んではいけないというトラップに要注意だ。 次に、バリュードメインのDNS設定で上記指定のサブドメインのtxtレコードに、指定の文字列をセットする。 txt _acme-challenge XnhD4Qc**********kp66N8w txt _acme-challenge ixsbXf**********RmwhM 気長に待たなければいけないのが辛いのだが、値が反映されたか確認するコマンドは以下を参考にしてくだされ。 とりあえず3パターンぐらい書いておきます。 $ nslookup -q=txt _acme-challenge.example.com Server: 192.168.0.1 Address: 192.168.0.1#53 Non-authoritative answer: _acme-challenge.example.com text = "XnhD4Qc**********fkp66N8w" _acme-challenge.example.com text = "ixsbXf7I**********0RmwhM" $ dig TXT _acme-challenge.example.com ; <<>> DiG 9.10.6 <<>> TXT _acme-challenge..example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1384 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;_acme-challenge.example.com. IN TXT ;; ANSWER SECTION: _acme-challenge.example.com. 119 IN TXT "ixsbXf7Idrp2**********f0RmwhM" _acme-challenge.example.com. 119 IN TXT "XnhD4Qcc**********gfkp66N8w" ;; Query time: 108 msec ;; SERVER: 192.168.0.1#53(192.168.0.1) ;; WHEN: Wed Mar 13 16:18:44 JST 2019 ;; MSG SIZE rcvd: 171 $ host -t txt _acme-challenge.example.com _acme-challenge.example.com descriptive text "ixsbXf7Id**********D9Gwf0RmwhM" _acme-challenge.example.com descriptive text "XnhD4Q**********Jgtgfkp66N8w" お好きなコマンドで確認できたら、いよいよenterを押して以下の表示が出たら完了です。 Press Enter to Continue Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2019-06-11. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto 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 そして忘れてはいけないのが、nginxの設定をやらないと、証明書だけセットしても、SSL対応はできません。 rootドメインのセットだけをサンプルに載せておきます。 # 通常の80ポート設定 listen 80; server_name example.com; # 通常の443ポート設定 listen 443; server_name example.com; ssl on; ssl_certificate /etc/letsencrypt/live/example.com/cert.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; SSL関連を追記して、取得して作成された証明書を記述してあげるといいようです。 これで、nginxを再起動したら、無事にhttpsで表示できるはずです。 systemctl restart nginx

対応事後の個人的見解

ワイルドカードを使って、1サーバーで複数サイトを管理するよりも、1サーバー1サイトで無料SSLを利用するほうが、管理する上で定期更新のバッチが使えるので、この点をケチらずにした方が良いことが今回分かりました・・・orz 1サーバーで複数設定をとるか、運用の手軽さのどちらを取るかで、今後の動き方が変わるかもしれませんが、とりあえず、3ヶ月後にはキレイに忘れているかと思うので、この記事を参考にする自分を予測しておくとしましょう。

人気の投稿

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。

ブログ アーカイブ