「Certbot」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎Apache: リンクが飛べない問題を修正)
 
(4人の利用者による、間の51版が非表示)
1行目: 1行目:
 
[[Category:ネットワーク]]
 
[[Category:ネットワーク]]
[[Category:セキュリティ]]
+
[[Category:暗号化]]
  +
[[Category:コマンド]]
[[en:Let’s Encrypt]]
 
  +
[[Category:Electronic Frontier Foundation]]
[https://letsencrypt.org/ Let’s Encrypt] はフリーかつ自動化されたオープンな認証局です。[[Wikipedia:ja:Automated Certificate Management Environment|ACME]] プロトコルを利用しています。
 
  +
[[en:Certbot]]
 
  +
[[ru:Certbot]]
公式クライアントは '''Certbot''' という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを {{AUR|acme-tiny}} でインストールすることができます。スクリプトで使用するのに適したクライアントとして {{AUR|simp_le-git}} や {{AUR|letsencrypt-cli}} も存在します。
 
  +
[https://github.com/certbot/certbot Certbot] は Python で書かれた [https://www.eff.org/ Electronic Frontier Foundation] の [[ACME]] クライアントで、Python で記述されており、ウェブサーバの自動設定や HTTP チャレンジのためのビルトイン Web サーバといった便利な機能を持ちます。 Certbot は [https://letsencrypt.org/ Let's Encrypt] に推奨されています。
   
 
== インストール ==
 
== インストール ==
10行目: 11行目:
 
{{Pkg|certbot}} パッケージを[[インストール]]してください。
 
{{Pkg|certbot}} パッケージを[[インストール]]してください。
   
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:
+
発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:
* [[Nginx]] 用の実験的なプラグインは {{Pkg|certbot-nginx}} パッケージに入っています。
+
* [[Nginx]] 用のプラグインは {{Pkg|certbot-nginx}} パッケージに入っています。
* [[Apache HTTP Server]] 自動インストール{{Pkg|certbot-apache}} パッケージにより有効になっています。
+
* [[Apache HTTP Server]] 用のプラグインは {{Pkg|certbot-apache}} パッケージで使えます。
   
 
== 設定 ==
 
== 設定 ==
   
証明を作成・インストールする方法は [https://certbot.eff.org/docs/ Certbot のドキュメント] を参照してください。
+
証明を作成と使用方法についての詳細は [https://certbot.eff.org/docs/ Certbot のドキュメント] を参照してください。
   
=== Webroot ===
+
=== プラグイン ===
  +
{{Warning|プラグインを使用すると設定ファイルが上書きされ、Certbot 証明書の設定とパスが追加される場合があります。先に設定ファイルの'''バックアップ'''を作成することを推奨します。}}
{{Note|
 
* The Webroot method requires '''HTTP on port 80''' for Certbot to validate.
 
** For Certbot to validate using '''HTTPS on port 443''', the Nginx ('''--nginx''') or Apache ('''--apache''') plugin must be used instead of the Webroot ('''--webroot''') method.
 
* The Server Name must match that of it's corresponding DNS.
 
* Permissions may need to be altered on the host to allow read-access to {{ic|http://domain.tld/.well-known}}.
 
   
  +
==== Nginx ====
}}
 
   
  +
{{pkg|certbot-nginx}} プラグインは [[nginx]] の自動設定を提供します。このプラグインは、各ドメインの設定を検出しようとします。このプラグインは、セキュリティのために推奨される追加の設定および Certbot 証明書へのパスを追加します。例として、[[#サーバーブロックの管理]] を参照してください。
webroot メソッドを使用する場合、certbotクライアントは検証のために使用される、{{ic|/path/to/domain.tld/html/.well-known/acme-challenge/}} の中でチャレンジ/レスポンス認証が行われます。
 
   
  +
[[nginx#サーバーブロック|サーバーブロック]]を初めて設定する場合:
この使用方法は手動インストールよりも推奨されます。自動的に更新が行なわれ、証明書管理が容易になります。
 
   
  +
# certbot --nginx
{{Tip|1=以下の [Nginx#Server_blocks|nginx server]] 設定は、初めての証明書を取得するのに役立ちます:
 
{{hc|/etc/nginx/servers-available/domain.tld|
 
<nowiki>
 
server {
 
listen 80;
 
listen [::]:80;
 
server_name domain.tld;
 
root /usr/share/nginx/html;
 
location / {
 
index index.htm index.html;
 
}
 
   
  +
証明書を更新するには:
# ACME challenge
 
location ^~ /.well-known/acme-challenge/ {
 
default_type "text/plain";
 
root /var/lib/letsencrypt;
 
}
 
}
 
</nowiki>
 
}}
 
}}
 
   
  +
# certbot renew
==== 証明書を取得する ====
 
{{Accuracy|detail lacking to successfully accomplish task being taught|section=accuracy_flag}}
 
   
  +
nginx の設定ファイルに手を加えずに証明書を変更するには:
{{ic|/var/lib/letsencrypt/}} を公開アクセス可能なパスとして使用して、{{ic|domain.tld}} の証明書を要求します:
 
   
  +
# certbot --nginx certonly
# certbot certonly --email '''email@example.com''' --webroot -w '''/var/lib/letsencrypt/''' -d '''domain.tld'''
 
   
  +
詳しい情報は [https://certbot.eff.org/#arch-nginx Nginx on Arch Linux] を見てください。インストールされた証明書の状態を有効に保つ方法は[[#自動更新]]を見てください。
(サブ)ドメインを追加するには、現在のセットアップで使用されているすべての登録済みドメインを含めます:
 
   
  +
===== Nginx サーバーブロックの管理 =====
# certbot certonly --email '''email@example.com''' --webroot -w '''/var/lib/letsencrypt/''' -d '''domain.tld,sub.domain.tld'''
 
  +
サーバーブロックを手動で管理する場合、以下のように[[nginx#サーバーブロック|サーバーブロック]]で使うことができます:
  +
{{hc|/etc/nginx/sites-available/example|2=
  +
server {
  +
listen 443 ssl http2;
  +
listen [::]:443 ssl http2; # Listen on IPv6
  +
ssl_certificate /etc/letsencrypt/live/''domain''/fullchain.pem; # managed by Certbot
  +
ssl_certificate_key /etc/letsencrypt/live/''domain''/privkey.pem; # managed by Certbot
  +
include /etc/letsencrypt/options-ssl-nginx.conf;
  +
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
  +
..
  +
} }}
   
  +
詳しくは [[nginx#TLS/SSL]] を見てください。
現在の証明書を(すべて)更新するには:
 
# certbot renew
 
   
  +
別の設定ファイルを作成してサーバーブロックから include して使用することも可能です:
変わりのアプローチとして [[#自動更新]] を参照してください。
 
   
  +
{{hc|/etc/nginx/conf/001-cerbot.conf|2=
=== 手動 ===
 
  +
ssl_certificate /etc/letsencrypt/live/''domain''/fullchain.pem; # managed by Certbot
  +
ssl_certificate_key /etc/letsencrypt/live/''domain''/privkey.pem; # managed by Certbot
  +
include /etc/letsencrypt/options-ssl-nginx.conf;
  +
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
  +
}}
   
  +
{{hc|/etc/nginx/sites-available/example|<nowiki>
{{Note|
 
  +
server {
* この方法では、一時的にウェブサーバーを停止する必要があります。[[#Webroot]] の方法ではウェブサーバーを実行しながらでも認証が行えます。
 
  +
listen 443 ssl http2;
* この方法では、自動的に証明書を更新することはできません。自動更新を行いたい場合には、[[#Webroot]] メソッドを使用してください。}}
 
  +
listen [::]:443 ssl http2; # Listen on IPv6
  +
include conf/001-certbot.conf;
  +
..
  +
}
  +
</nowiki>}}
   
  +
==== Apache ====
ウェブサーバーのプラグインが存在しない場合、次のコマンドを使って下さい:
 
# certbot certonly --manual
 
   
  +
{{pkg|certbot-apache}} プラグインは、[[Apache HTTP Server]] の自動設定を提供します。このプラグインは、各ドメインの設定を検出しようとします。このプラグインは、セキュリティのために推奨される追加設定、証明書を使用するための設定、certbot 証明書へのパスを追加します。サンプルについては、[[#Apache バーチャルホストの管理]] を参照してください。
DNS の TXT レコードを利用した認証を行う場合、次のコマンドを使って下さい:
 
# certbot certonly --manual --preferred-challenges dns
 
   
  +
[[Apache_HTTP_Server#バーチャルホスト|バーチャルホスト]] の初回セットアップ:
上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は {{ic|/etc/letsencrypt/live/''your.domain''/}} に保存されます。
 
   
  +
# certbot --apache
上記のディレクトリに入っている秘密鍵と証明書を使用するように手動でウェブサーバーを設定します。
 
   
  +
証明書の更新:
{{Note|コマンドを複数回実行すると {{ic|/etc/letsencrypt/live/''your.domain''/}} に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。}}
 
   
  +
# certbot renew
== 高度な設定 ==
 
   
  +
Apache 設定ファイルを変更せずに証明書の変更:
=== Webサーバーの設定 ===
 
   
  +
# certbot --apache certonly
自動構成にプラグインを使用する代わりに、サーバーのSSLを手動で有効にすることをお勧めします。
 
   
  +
詳細は [https://certbot.eff.org/#arch-apache Certbot-Apache on Arch Linux] と [[#自動更新]] を参照してください。
{{Tip|
 
* Mozilla has a useful [https://wiki.mozilla.org/Security/Server_Side_TLS SSL/TLS article] which includes an [https://mozilla.github.io/server-side-tls/ssl-config-generator/ automated tool] to help create a more secure configuration.
 
* [https://cipherli.st Cipherli.st] provides strong SSL implementation examples and tutorial for most modern webservers.
 
}}
 
   
  +
===== Apache バーチャルホストの管理 =====
==== nginx ====
 
Let's Encrypt の署名付きSSL証明書を使用したサーバー {{ic|domain.tld}} の例:
 
   
  +
これらのファイルを手動で管理する場合は、以下の例をすべての [[Apache HTTP Server#バーチャルホスト|バーチャルホスト]] で使用することができます:
{{hc|/etc/nginx/servers-available/domain.tld|
 
<nowiki>
 
# redirect to https
 
server {
 
listen 80;
 
listen [::]:80;
 
server_name domain.tld;
 
return 301 https://$host$request_uri;
 
}
 
   
  +
{{hc|/etc/httpd/conf/extra/001-certbot.conf|2=
server {
 
  +
<IfModule mod_ssl.c>
listen 443 ssl http2;
 
  +
<VirtualHost *:443>
listen [::]:443 ssl http2;
 
  +
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
 
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
+
Include /etc/letsencrypt/options-ssl-apache.conf
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
+
SSLCertificateFile /etc/letsencrypt/live/'domain'/fullchain.pem
  +
SSLCertificateKeyFile /etc/letsencrypt/live/'domain'/privkey.pem
ssl_session_timeout 1d;
 
ssl_session_cache shared:SSL:50m;
 
ssl_session_tickets off;
 
ssl_prefer_server_ciphers on;
 
add_header Strict-Transport-Security max-age=15768000;
 
ssl_stapling on;
 
ssl_stapling_verify on;
 
server_name domain.tld;
 
..
 
}
 
   
  +
</VirtualHost>
# A subdomain uses the same SSL-certifcate:
 
  +
</IfModule>
server {
 
  +
}}
listen 443 ssl http2;
 
  +
listen [::]:443 ssl http2;
 
  +
{{hc|/etc/httpd/conf/httpd.conf|<nowiki>
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
 
  +
<IfModule mod_ssl.c>
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
 
  +
Listen 443
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
 
  +
</IfModule>
..
 
  +
server_name sub.domain.tld;
 
  +
Include conf/extra/001-certbot.conf
 
..
 
..
  +
</nowiki>}}
}
 
   
  +
詳細については、[[Apache HTTP Server#TLS]] を参照してください。
# ACME challenge
 
  +
location ^~ /.well-known {
 
  +
=== Webroot ===
allow all;
 
  +
{{Note|
alias /var/lib/letsencrypt/.well-known/;
 
  +
* Webroot 方式では Certbot で認証するために'''ポート 80 で HTTP 接続'''できるようにする必要があります。
default_type "text/plain";
 
  +
* サーバーの名前は DNS と一致している必要があります。
try_files $uri =404;
 
  +
* {{ic|http://domain.tld/.well-known}} の読み取りを許可するためにホストのパーミッションを修正する必要がある場合があります。
}
 
</nowiki>
 
 
}}
 
}}
   
  +
webroot 方式を使う場合、Certbot クライアントは {{ic|/path/to/domain.tld/html/.well-known/acme-challenge/}} の中でチャレンジ・レスポンス認証を行います。
=== マルチドメイン ===
 
   
  +
手動でインストールする場合と比べて、自動で証明書を更新したり楽に管理することができます。ただし、[[#プラグイン]]を使う時のように自動設定・自動インストールはできません。
Management of can be made easier by mapping all HTTP-requests for {{ic|/.well-known/acme-challenge/}} to a single folder, e.g. {{ic|/var/lib/letsencrypt}}.
 
   
  +
==== ACME チャレンジリクエストのマッピング ====
The path has then to be writable for the Let's Encrypt client and the web server (e.g. [[nginx]] or [[Apache]] running as user ''http''):
 
  +
  +
{{ic|.well-known/acme-challenge}} に対する HTTP リクエストを全てひとつのディレクトリ (例: {{ic|/var/lib/letsencrypt}}) にマッピングすることで管理が簡単になります。
  +
  +
Certbot やウェブサーバー (''http'' ユーザーで動作する [[nginx]] や [[Apache]] など) が書き込みできるパスを使用してください:
 
# mkdir -p /var/lib/letsencrypt/.well-known
 
# mkdir -p /var/lib/letsencrypt/.well-known
 
# chgrp http /var/lib/letsencrypt
 
# chgrp http /var/lib/letsencrypt
 
# chmod g+s /var/lib/letsencrypt
 
# chmod g+s /var/lib/letsencrypt
   
==== nginx ====
+
===== nginx =====
 
locationブロックを含むファイルを作成し、これを Serverブロック内に組み込みます:
 
   
  +
location ブロックを記述したファイルを作成してサーバーブロックから読み込むようにしてください:
{{hc|/etc/nginx/conf.d/letsencrypt.conf|
 
  +
{{hc|/etc/nginx/conf.d/letsencrypt.conf|<nowiki>
<nowiki>
 
location ^~ /.well-known {
+
location ^~ /.well-known/acme-challenge/ {
 
allow all;
 
allow all;
alias /var/lib/letsencrypt/.well-known/;
+
root /var/lib/letsencrypt/;
 
default_type "text/plain";
 
default_type "text/plain";
 
try_files $uri =404;
 
try_files $uri =404;
173行目: 150行目:
 
</nowiki>}}
 
</nowiki>}}
   
サーバー構成の例:
+
サーバー設定の例:
 
{{hc|/etc/nginx/servers-available/domain.conf|<nowiki>
 
{{hc|/etc/nginx/servers-available/domain.conf|<nowiki>
 
server {
 
server {
182行目: 159行目:
 
</nowiki>}}
 
</nowiki>}}
   
==== Apache ====
+
===== Apache =====
 
 
{{ic|/etc/httpd/conf/extra/httpd-acme.conf}} ファイルを作成してください:
 
{{ic|/etc/httpd/conf/extra/httpd-acme.conf}} ファイルを作成してください:
 
 
{{hc|/etc/httpd/conf/extra/httpd-acme.conf|<nowiki>
 
{{hc|/etc/httpd/conf/extra/httpd-acme.conf|<nowiki>
 
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
 
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
195行目: 170行目:
 
</nowiki>}}
 
</nowiki>}}
   
そして、{{ic|httpd.conf}} で上記ファイルをインクルードします:
+
{{ic|/etc/httpd/conf/httpd.conf}} で上記ファイルを読み込んでください:
 
 
{{hc|/etc/httpd/conf/httpd.conf|<nowiki>
 
{{hc|/etc/httpd/conf/httpd.conf|<nowiki>
 
Include conf/extra/httpd-acme.conf
 
Include conf/extra/httpd-acme.conf
 
</nowiki>}}
 
</nowiki>}}
  +
  +
==== 証明書の取得 ====
  +
  +
公開パスとして {{ic|/var/lib/letsencrypt/}} を使用して {{ic|domain.tld}} の証明書を取得するには:
  +
# certbot certonly --email '''email@example.com''' --webroot -w '''/var/lib/letsencrypt/''' -d '''domain.tld'''
  +
  +
(サブ)ドメインを追加するときは、登録済みの全てのドメインを一緒に指定します:
  +
# certbot certonly --email '''email@example.com''' --webroot -w '''/var/lib/letsencrypt/''' -d '''domain.tld,sub.domain.tld'''
  +
  +
登録している証明書を(全て)更新するには:
  +
# certbot renew
  +
  +
{{Note|Do not forget to include the Let's Encrypt configuration file inside all related server blocks, those handling HTTP traffic as well as those handling HTTPS traffic, especially when using - as recommended - HSTS (HTPP Strict Transport Security). This can lead one to obtain certificate(s) smoothly, and once the setup is done, to be blocked for the renewal.}}
  +
  +
証明書の更新方法については[[#自動更新]]も参照。
  +
  +
=== 手動 ===
  +
  +
ウェブサーバーのプラグインが存在しない場合、以下のコマンドを使ってください:
  +
# certbot certonly --manual
  +
  +
DNS の TXT レコードを利用して認証したい場合、以下のコマンドを使ってください:
  +
# certbot certonly --manual --preferred-challenges dns
  +
  +
上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は {{ic|/etc/letsencrypt/archive/''your.domain''/}} に保存され、{{ic|/etc/letsencrypt/live/''your.domain''/}} からリンクが張られます。
  +
  +
証明書が取得できたら手動でウェブサーバーを設定して、シンボリックリンクが存在するディレクトリの秘密鍵・証明書・証明書チェーンを参照してください。
  +
  +
{{Note|上のコマンドを複数回実行したり証明書を更新したりするとファイル名の末尾に数字が付加されたファイルが {{ic|/etc/letsencrypt/archive/''your.domain''/}} に作られます。Certbot は {{ic|/etc/letsencrypt/live/''your.domain''/}} のシンボリックリンクを自動的に最新のファイルに更新するため、証明書を更新するたびに手動でウェブサーバーの設定を更新する必要はありません。}}
  +
  +
== 高度な設定 ==
   
 
=== 自動更新 ===
 
=== 自動更新 ===
   
 
==== systemd ====
 
==== systemd ====
[[systemd]] {{ic|certbot.service}} ファイルを作成します
+
{{ic|certbot.service}} ユニットを作成:
   
 
{{hc|1=/etc/systemd/system/certbot.service|
 
{{hc|1=/etc/systemd/system/certbot.service|
214行目: 219行目:
 
ExecStart=/usr/bin/certbot renew --quiet --agree-tos}}
 
ExecStart=/usr/bin/certbot renew --quiet --agree-tos}}
   
  +
プラグインを使わずにウェブサーバーの設定を自動で管理する場合、ウェブサーバーを手動でリロードして証明書が更新されるたびにリロードが必要です。{{ic|ExecStart}} コマンドに {{ic|--post-hook "systemctl reload nginx.service"}} を追加することでリロードさせることができます [https://certbot.eff.org/docs/using.html#renewing-certificates]。適宜 {{ic|nginx.service}} のかわりに {{ic|httpd.service}} を使ってください。
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。{{ic|certbot.service}} ファイルに以下のどちらかの行を追加してください:
 
   
  +
{{Note|[[systemd/タイマー|タイマー]]を追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。サービスは遅延があるため、[https://github.com/certbot/certbot/blob/master/certbot/CHANGELOG.md#0290---2018-12-05 v0.29.0] 以降、certbot を非対話的に呼び出す際に遅延が追加されているため、サービスが完了するまでに最大480秒かかることがありますので、ご注意ください。}}
* Apache: {{ic|1=ExecStartPost=/bin/systemctl reload httpd.service}}
 
* nginx: {{ic|1=ExecStartPost=/bin/systemctl reload nginx.service}}
 
   
  +
1 日 2 回のランダムな遅延時間を設定された証明書の更新をチェックするタイマーの追加により、全員の更新要求が分散され、Let's Encrypt サーバーの負荷が軽減されます。
{{Note|[[systemd/タイマー|タイマー]]を追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。}}
 
 
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。
 
   
 
{{hc|1=/etc/systemd/system/certbot.timer|
 
{{hc|1=/etc/systemd/system/certbot.timer|
237行目: 239行目:
 
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。
 
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。
   
  +
=== ワイルドカード証明書の自動更新 ===
==== その他のサービス ====
 
   
  +
手順はかなり簡単です。ワイルドカード証明書を発行するには、[https://community.letsencrypt.org/t/acme-v2-and-wildcard-certificate-support-is-live/55579 ACMEv2 protocol を使用]して、DNS チャレンジリクエストを経由しなければなりません。
Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。
 
   
  +
証明書を手動で発行するのは簡単ですが、自動化は簡単ではありません。DNS チャレンジは、certbot によって与えられた TXT レコードを表し、ドメインゾーンファイルに手動で設定する必要があります。
===== nginx =====
 
   
  +
更新のたびにゾーンファイルを更新する必要があります。これを手動で行わないようにするには、certbot のプラグインが含まれている certbot-dns-rfc2136 により、rfc2136を使用できます。また、TXT レコードの動的更新を許可するように DNS サーバーを設定する必要があります。
{{hc|1=/etc/systemd/system/certbot.service|
 
2=[Unit]
 
Description=Let's Encrypt renewal
 
   
  +
==== rfc2136 用に BIND を設定 ====
[Service]
 
Type=oneshot
 
ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop nginx.service" --post-hook "/usr/bin/systemctl start nginx.service" --quiet --agree-tos}}
 
   
  +
TSIG 秘密鍵を生成します:
===== Apache =====
 
   
  +
$ tsig-keygen -a HMAC-SHA512 '''example-key'''
{{hc|1=/etc/systemd/system/certbot.service|
 
2=[Unit]
 
Description=Let's Encrypt renewal
 
   
  +
設定ファイルに追加します:
[Service]
 
  +
Type=oneshot
 
  +
{{hc|1=/etc/named.conf|
ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop httpd.service" --post-hook "/usr/bin/systemctl start httpd.service" --quiet --agree-tos}}
 
  +
2=...
  +
zone "'''domain.ltd'''" IN {
  +
...
  +
// this is for certbot
  +
update-policy {
  +
grant '''example-key''' name _acme-challenge.'''domain.ltd'''. txt;
  +
};
  +
...
  +
};
  +
  +
key "'''example-key'''" {
  +
algorithm hmac-sha512;
  +
secret "'''a_secret_key'''";
  +
};
  +
...}}
  +
  +
{{ic|named.service}} を [[systemd#ユニットを使う|再起動]] します。
  +
  +
==== certbot rfc2136 のための設定 ====
  +
  +
rfc2136 プラグインの設定ファイルを作成します。
  +
  +
{{hc|1=/etc/letsencrypt/rfc2136.ini|
  +
2=dns_rfc2136_server = '''IP.ADD.RE.SS'''
  +
dns_rfc2136_name = '''example-key'''
  +
dns_rfc2136_secret = '''INSERT_KEY_WITHOUT_QUOTES'''
  +
dns_rfc2136_algorithm = HMAC-SHA512}}
  +
  +
ファイルには秘密鍵のコピーが含まれているため、[[chmod]] で、グループやその他の権限を削除してファイルを保護します。
  +
  +
以下のようにテストします:
  +
# certbot certonly --dns-rfc2136 --force-renewal --dns-rfc2136-credentials /etc/letsencrypt/rfc2136.ini --server https://acme-v02.api.letsencrypt.org/directory --email '''example@domain.ltd''' --agree-tos --no-eff-email -d ''''domain.ltd'''' -d ''''*.domain.ltd''''
  +
  +
検証に合格して証明書を受け取った場合は、certbot の自動化を行っても問題ありません。そうでない場合は、問題が発生しているので、設定をデバッグする必要があります。基本的には、{{ic|certbot renew}} を実行することになります。[[#自動更新]] を参照してください。
   
 
== 参照 ==
 
== 参照 ==
   
  +
* [[Transport Layer Security#ACME クライアント]]
  +
* [[Wikipedia:ja:Let's Encrypt|Wikipedia の記事]]
  +
* [https://certbot.eff.org/ EFF の Certbot ドキュメント]
 
* [https://letsencrypt.org/docs/client-options/ ACME クライアントの一覧]
 
* [https://letsencrypt.org/docs/client-options/ ACME クライアントの一覧]
  +
  +
{{TranslationStatus|Certbot|2021-10-20|694739}}

2022年1月25日 (火) 12:38時点における最新版

Certbot は Python で書かれた Electronic Frontier FoundationACME クライアントで、Python で記述されており、ウェブサーバの自動設定や HTTP チャレンジのためのビルトイン Web サーバといった便利な機能を持ちます。 Certbot は Let's Encrypt に推奨されています。

インストール

certbot パッケージをインストールしてください。

発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:

設定

証明を作成と使用方法についての詳細は Certbot のドキュメント を参照してください。

プラグイン

警告: プラグインを使用すると設定ファイルが上書きされ、Certbot 証明書の設定とパスが追加される場合があります。先に設定ファイルのバックアップを作成することを推奨します。

Nginx

certbot-nginx プラグインは nginx の自動設定を提供します。このプラグインは、各ドメインの設定を検出しようとします。このプラグインは、セキュリティのために推奨される追加の設定および Certbot 証明書へのパスを追加します。例として、#サーバーブロックの管理 を参照してください。

サーバーブロックを初めて設定する場合:

# certbot --nginx

証明書を更新するには:

# certbot renew

nginx の設定ファイルに手を加えずに証明書を変更するには:

# certbot --nginx certonly

詳しい情報は Nginx on Arch Linux を見てください。インストールされた証明書の状態を有効に保つ方法は#自動更新を見てください。

Nginx サーバーブロックの管理

サーバーブロックを手動で管理する場合、以下のようにサーバーブロックで使うことができます:

/etc/nginx/sites-available/example
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2; # Listen on IPv6
  ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
  ..
}

詳しくは nginx#TLS/SSL を見てください。

別の設定ファイルを作成してサーバーブロックから include して使用することも可能です:

/etc/nginx/conf/001-cerbot.conf
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
/etc/nginx/sites-available/example
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2; # Listen on IPv6
  include conf/001-certbot.conf;
  ..
}

Apache

certbot-apache プラグインは、Apache HTTP Server の自動設定を提供します。このプラグインは、各ドメインの設定を検出しようとします。このプラグインは、セキュリティのために推奨される追加設定、証明書を使用するための設定、certbot 証明書へのパスを追加します。サンプルについては、#Apache バーチャルホストの管理 を参照してください。

バーチャルホスト の初回セットアップ:

# certbot --apache

証明書の更新:

# certbot renew

Apache 設定ファイルを変更せずに証明書の変更:

# certbot --apache certonly

詳細は Certbot-Apache on Arch Linux#自動更新 を参照してください。

Apache バーチャルホストの管理

これらのファイルを手動で管理する場合は、以下の例をすべての バーチャルホスト で使用することができます:

/etc/httpd/conf/extra/001-certbot.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/'domain'/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/'domain'/privkey.pem

</VirtualHost>
</IfModule>
/etc/httpd/conf/httpd.conf
  <IfModule mod_ssl.c>
  Listen 443
  </IfModule>

  Include conf/extra/001-certbot.conf
  ..

詳細については、Apache HTTP Server#TLS を参照してください。

Webroot

ノート:
  • Webroot 方式では Certbot で認証するためにポート 80 で HTTP 接続できるようにする必要があります。
  • サーバーの名前は DNS と一致している必要があります。
  • http://domain.tld/.well-known の読み取りを許可するためにホストのパーミッションを修正する必要がある場合があります。

webroot 方式を使う場合、Certbot クライアントは /path/to/domain.tld/html/.well-known/acme-challenge/ の中でチャレンジ・レスポンス認証を行います。

手動でインストールする場合と比べて、自動で証明書を更新したり楽に管理することができます。ただし、#プラグインを使う時のように自動設定・自動インストールはできません。

ACME チャレンジリクエストのマッピング

.well-known/acme-challenge に対する HTTP リクエストを全てひとつのディレクトリ (例: /var/lib/letsencrypt) にマッピングすることで管理が簡単になります。

Certbot やウェブサーバー (http ユーザーで動作する nginxApache など) が書き込みできるパスを使用してください:

# mkdir -p /var/lib/letsencrypt/.well-known
# chgrp http /var/lib/letsencrypt
# chmod g+s /var/lib/letsencrypt
nginx

location ブロックを記述したファイルを作成してサーバーブロックから読み込むようにしてください:

/etc/nginx/conf.d/letsencrypt.conf
location ^~ /.well-known/acme-challenge/ {
  allow all;
  root /var/lib/letsencrypt/;
  default_type "text/plain";
  try_files $uri =404;
}

サーバー設定の例:

/etc/nginx/servers-available/domain.conf
server {
  server_name domain.tld
   ..
  include conf.d/letsencrypt.conf;
}
Apache

/etc/httpd/conf/extra/httpd-acme.conf ファイルを作成してください:

/etc/httpd/conf/extra/httpd-acme.conf
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

/etc/httpd/conf/httpd.conf で上記ファイルを読み込んでください:

/etc/httpd/conf/httpd.conf
Include conf/extra/httpd-acme.conf

証明書の取得

公開パスとして /var/lib/letsencrypt/ を使用して domain.tld の証明書を取得するには:

# certbot certonly --email email@example.com --webroot -w /var/lib/letsencrypt/ -d domain.tld

(サブ)ドメインを追加するときは、登録済みの全てのドメインを一緒に指定します:

# certbot certonly --email email@example.com --webroot -w /var/lib/letsencrypt/ -d domain.tld,sub.domain.tld

登録している証明書を(全て)更新するには:

# certbot renew
ノート: Do not forget to include the Let's Encrypt configuration file inside all related server blocks, those handling HTTP traffic as well as those handling HTTPS traffic, especially when using - as recommended - HSTS (HTPP Strict Transport Security). This can lead one to obtain certificate(s) smoothly, and once the setup is done, to be blocked for the renewal.

証明書の更新方法については#自動更新も参照。

手動

ウェブサーバーのプラグインが存在しない場合、以下のコマンドを使ってください:

# certbot certonly --manual

DNS の TXT レコードを利用して認証したい場合、以下のコマンドを使ってください:

# certbot certonly --manual --preferred-challenges dns

上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は /etc/letsencrypt/archive/your.domain/ に保存され、/etc/letsencrypt/live/your.domain/ からリンクが張られます。

証明書が取得できたら手動でウェブサーバーを設定して、シンボリックリンクが存在するディレクトリの秘密鍵・証明書・証明書チェーンを参照してください。

ノート: 上のコマンドを複数回実行したり証明書を更新したりするとファイル名の末尾に数字が付加されたファイルが /etc/letsencrypt/archive/your.domain/ に作られます。Certbot は /etc/letsencrypt/live/your.domain/ のシンボリックリンクを自動的に最新のファイルに更新するため、証明書を更新するたびに手動でウェブサーバーの設定を更新する必要はありません。

高度な設定

自動更新

systemd

certbot.service ユニットを作成:

/etc/systemd/system/certbot.service
[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --agree-tos

プラグインを使わずにウェブサーバーの設定を自動で管理する場合、ウェブサーバーを手動でリロードして証明書が更新されるたびにリロードが必要です。ExecStart コマンドに --post-hook "systemctl reload nginx.service" を追加することでリロードさせることができます [1]。適宜 nginx.service のかわりに httpd.service を使ってください。

ノート: タイマーを追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。サービスは遅延があるため、v0.29.0 以降、certbot を非対話的に呼び出す際に遅延が追加されているため、サービスが完了するまでに最大480秒かかることがありますので、ご注意ください。

1 日 2 回のランダムな遅延時間を設定された証明書の更新をチェックするタイマーの追加により、全員の更新要求が分散され、Let's Encrypt サーバーの負荷が軽減されます。

/etc/systemd/system/certbot.timer
[Unit]
Description=Daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=0/12:00:00
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

certbot.timer起動有効化してください。

ワイルドカード証明書の自動更新

手順はかなり簡単です。ワイルドカード証明書を発行するには、ACMEv2 protocol を使用して、DNS チャレンジリクエストを経由しなければなりません。

証明書を手動で発行するのは簡単ですが、自動化は簡単ではありません。DNS チャレンジは、certbot によって与えられた TXT レコードを表し、ドメインゾーンファイルに手動で設定する必要があります。

更新のたびにゾーンファイルを更新する必要があります。これを手動で行わないようにするには、certbot のプラグインが含まれている certbot-dns-rfc2136 により、rfc2136を使用できます。また、TXT レコードの動的更新を許可するように DNS サーバーを設定する必要があります。

rfc2136 用に BIND を設定

TSIG 秘密鍵を生成します:

$ tsig-keygen -a HMAC-SHA512 example-key

設定ファイルに追加します:

/etc/named.conf
...
zone "domain.ltd" IN {
        ...
        // this is for certbot
        update-policy {
                grant example-key name _acme-challenge.domain.ltd. txt;
        };
        ...
};

key "example-key" {
        algorithm hmac-sha512;
        secret "a_secret_key";
};
...

named.service再起動 します。

certbot rfc2136 のための設定

rfc2136 プラグインの設定ファイルを作成します。

/etc/letsencrypt/rfc2136.ini
dns_rfc2136_server = IP.ADD.RE.SS
dns_rfc2136_name = example-key
dns_rfc2136_secret = INSERT_KEY_WITHOUT_QUOTES
dns_rfc2136_algorithm = HMAC-SHA512

ファイルには秘密鍵のコピーが含まれているため、chmod で、グループやその他の権限を削除してファイルを保護します。

以下のようにテストします:

# certbot certonly --dns-rfc2136 --force-renewal --dns-rfc2136-credentials /etc/letsencrypt/rfc2136.ini --server https://acme-v02.api.letsencrypt.org/directory --email example@domain.ltd --agree-tos --no-eff-email -d 'domain.ltd' -d '*.domain.ltd'

検証に合格して証明書を受け取った場合は、certbot の自動化を行っても問題ありません。そうでない場合は、問題が発生しているので、設定をデバッグする必要があります。基本的には、certbot renew を実行することになります。#自動更新 を参照してください。

参照

翻訳ステータス: このページは en:Certbot の翻訳バージョンです。最後の翻訳日は 2021-10-20 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。