APC 技術ブログ

株式会社エーピーコミュニケーションズの技術ブログです。

株式会社 エーピーコミュニケーションズの技術ブログです。

実サーバー無しでLet's Encryptの証明書を発行する

はじめに

先進サービス開発事業部の山岡です。

先日所用で手元の端末にLet's Encryptの証明書を発行したのですが、これには公式推奨ツールであるcertbotを使う必要があります。

単純にインストールする方法の他にDockerを使って使い捨てることもでき、今回その方法を試したので手順を書きたいと思います(Dockerはインストール済みの前提です)。

Dockerコマンド

基本的なコマンドは以下の書式ですが -d を発行したいドメイン(ワイルドカード・複数可)、 -m を自分が所有するメールアドレスに置き換えて下さい。

$ docker run -it --rm \
--name certbot \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
certbot/certbot certonly \
--manual \
-d example.com \
-d *.example.com \
-m example@example.com \
--agree-tos \
--manual-public-ip-logging-ok \
--preferred-challenges dns-01 \
--server https://acme-v02.api.letsencrypt.org/directory

DNS認証

 ※以降の手順は通常と変わらないので、ご存知の方はスキップしてOKです

Electronic Frontier FoundationなるNPOにメールアドレスを共有していいか聞かれますのでお好みで選択して下さい。その後下記のようにチャレンジトークンが発行され確認待ち状態になるのでこれを _acme-challenge.example.com のTXTレコードとして設定します。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:

xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

DNSサーバーに設定が適用され値が引けるようになることが確認できたらEnterを押します。

$ dig _acme-challenge.example.com TXT

; <<>> DiG 9.11.3-1ubuntu1.5-Ubuntu <<>> _acme-challenge.example.com TXT
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48402
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;_acme-challenge.example.com.   IN  TXT

;; ANSWER SECTION:
_acme-challenge.example.com. 54 IN  TXT "xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx"

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Mar 26 11:14:20 JST 2019
;; MSG SIZE  rcvd: 113

特にエラー等が出ること無く、下記のメッセージが出たら完了です。発行された証明書や秘密鍵は /etc/letsencrypt/archive/example.com/ の中に入っていますので所定の場所に配置して下さい。

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-18. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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