Let's Encrypt ワイルドカード certbot-dns-route53 設定手順 CentOS7
2018/03/30
Let's Encryptのワイルドカード利用が開始されました。
https://letsencrypt.jp/blog/2018-03-14.html
ワイルドカード指定+Route53の自動更新手順をまとめてみます。
あくまで当方の環境に合わせたメモレベルです。
環境
- EC2 (CentOS7)
- Nginx (1.12.2)
- pip (python 3.7)
- DNSサーバー (Route53)
1.Linux > certbotインストール
下記のURLからインストール手順を表示する。
https://certbot.eff.org/
yum -y install yum-utils yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional sudo yum install certbot-nginx
2.Route53 > DNS-01チャレンジでワイルドカードが取得できるか確認する
certbot certonly --manual -d example.net -d *.example.net --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory -m yourmail@mail.com ~中略~ ------------------------------------------------------------------------------- Please deploy a DNS TXT record under the name _acme-challenge.example.net with the following value: JG1t16hnucN1Vkpozvzz4w3WtbEahguVtmRRiybfuzQ Before continuing, verify the record is deployed. ------------------------------------------------------------------------------- Press Enter to Continue
このメッセージがでたら、Route53で、TXTレコードを作成する。
ただし、すぐにはDNS反映されないので、
nslookupでTXTレコードの内容が上記と同じになっていることを確認する。
※「-d example.net -d *.example.net」の2つドメインを指定しているので、
メッセージは2回表示され、TXTレコードも2回作成します。
> Windowsコマンドプロンプト
nslookup -q=txt _acme-challenge.example.net サーバー: UnKnown Address: xxx.xxx.xxx.xxx 権限のない回答: _acme-challenge.example.net text = "JG1t16hnucN1Vkpozvzz4w3WtbEahguVtmRRiybfuzQ"
3.AWS > IAM Management Console で、実行ユーザーとポリシーを作成
以下画面イメージで手順説明。
>3.1. ユーザーを追加
>3.2. ユーザー名を入力、アクセスの種類の「プログラムによるアクセス」にチェック
>3.3. ユーザーのアクセス権限を設定と確認
>3.4. ユーザー作成完了後、「アクセスキーID」と「シークレットアクセスキー」をメモしておく。
>3.5. Route53で、対象ドメインの「Hosted Zone ID」をメモしておく
>3.6. ポリシーコマンドのサンプルを取得
下記のURLから、サンプルコードを取得し、赤枠のソースを取得し、「3.5.」でメモしたIDに書き換えておく
https://certbot-dns-route53.readthedocs.io/en/latest/index.html#module-certbot_dns_route53
>3.7. IAM Management Consoleへ戻り、ポリシーを作成
※この時「Review policy」を押下すると上記のように検証エラーになります。
「管理ポリシーのインポート」を設定します。
管理ポリシーをインポートしましたが、すべて必要ではないので、下記のように書き換えます。
なお、「Hosted Zone ID」は、マスクしています。
また、ID行があるとエラーになった為、削除しています。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "route53:ListHostedZones", "route53:GetChange" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "route53:ChangeResourceRecordSets" ], "Resource": [ "arn:aws:route53:::hostedzone/xxxxxxxxxxxxxx" ] } ] }
>3.8. ポリシー名を設定し、作成する
>3.9. ポリシーに「3.4.」で作成ユーザーをアタッチする
4.Linux > certbot-dns-route53 プラグインをインストールする
pip install certbot-dns-route53
5.Linux > certbot に certbot-dns-route53 を使う設定をする
mkdir ~/.aws vi ~/.aws/config --------------------------- [default] aws_access_key_id=#「3.4.」で作成したAMIユーザーのアクセスキーID aws_secret_access_key=#「3.4.」で作成したAMIユーザーのシークレットアクセスキーID --------------------------- #certbotに認証の種類を登録する。(登録だけでキーは使わない) #内容がちょっと違っているかもしれない・・・。 [root@example.net ~]# certbot -i nginx Saving debug log to /var/log/letsencrypt/letsencrypt.log Starting new HTTP connection (1): xxx.xxx.xxx.xxx (<-接続クライアントのグローバルIP) How would you like to authenticate with the ACME CA? ------------------------------------------------------------------------------- 1: Obtain certificates using a DNS TXT record (if you are using AWS Route53 for DNS). (dns-route53) 2: Nginx Web Server plugin - Alpha (nginx) 3: Spin up a temporary webserver (standalone) 4: Place files in webroot directory (webroot) ------------------------------------------------------------------------------- Select the appropriate number [1-4] then [enter] (press 'c' to cancel): 1 Plugins selected: Authenticator dns-route53, Installer nginx Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): youraddress@mail.com Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org ------------------------------------------------------------------------------- Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v01.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel: a ------------------------------------------------------------------------------- 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: y Starting new HTTPS connection (1): supporters.eff.org Which names would you like to activate HTTPS for? ------------------------------------------------------------------------------- 1: example.net 2: ml.example.net ------------------------------------------------------------------------------- Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): Obtaining a new certificate Performing the following challenges: dns-01 challenge for example.net dns-01 challenge for ml.example.net Cleaning up challenges Unable to locate credentials To use certbot-dns-route53, configure credentials as described at https://boto3.readthedocs.io/en/la test/guide/configuration.html#best-practices-for-configuring-credentials and add the necessary permi ssions for Route53 access. IMPORTANT NOTES: - 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.
6.Linux > certbot に ワイルドカードドメイン、RSA-4096bitで正式設定
#上記の更新方法を基に、ワイルドカード指定とRSA-4096bitに設定して再度取得する [root@example.net ~]# certbot certonly --dns-route53 --force-renew --rsa-key-size 4096 -d example.net -d *.example.net --server https://acme-v02.api.letsencrypt.org/directory Saving debug log to /var/log/letsencrypt/letsencrypt.log Credentials found in config file: ~/.aws/config Plugins selected: Authenticator dns-route53, Installer None Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Renewing an existing certificate Performing the following challenges: dns-01 challenge for example.net dns-01 challenge for example.net Starting new HTTPS connection (1): route53.amazonaws.com Waiting 10 seconds for DNS changes to propagate Waiting for verification... Cleaning up challenges Resetting dropped connection: route53.amazonaws.com IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.net/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.net/privkey.pem Your cert will expire on 2018-xx-xx. 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
7.証明書のワイルドカード確認
下記のURLで詳細確認ができます。
ワイルドカードを含んだドメインが表示されていることを確認出来ればOKです。
https://www.ssllabs.com/ssltest/index.html
8.Linux > 自動更新の設定
cronなどで上記の同じコマンド、または、「certbot renew」を登録する。
1か月くらいで自動更新するのがよいと思われます。
更新後に、Webサーバーをrestart か、reloadする必要があります。