メインコンテンツまでスキップ

CertbotのマニュアルプラグインでSSL/TLS証明書を作成する

· 約8分
moritalous

Certbotのマニュアルプラグインを使用してSSL/TLS証明書を作成しました。

Certbotとは

image.png

公式サイトには

Certbot is a free, open source software tool for automatically using Let’s Encrypt certificates on manually-administrated websites to enable HTTPS. Certbot is made by the Electronic Frontier Foundation (EFF), a 501(c)3 nonprofit based in San Francisco, CA, that defends digital privacy, free speech, and innovation.

(翻訳)

Certbot は、手動で管理する Web サイトで Let's Encrypt 証明書を自動的に使用して HTTPS を有効にするためのフリーでオープンソースのソフトウェアツールです。 Certbot は、デジタルプライバシー、言論の自由、イノベーションを擁護する、カリフォルニア州サンフランシスコに本拠を置く 501(c)3 非営利団体 Electronic Frontier Foundation (EFF) によって作成されています。

Certbotは、無料でSSL/TLS証明書を発行できるLets Encryptの証明書を簡単に生成できるツールです。

プラグインを使用するとWebサーバーへの自動配置や自動更新なども可能です。

今回はマニュアルプラグインのみを使用し、SSL/TLS証明書の作成部分を行いました。

環境

  • OS: Ubuntu 20.04.5 LTS (WSL)
  • Docker: 20.10.22

Certbotコンテナイメージの取得

CertbotはDocker Hubにて公式コンテナイメージが提供されています。(リンク

まずはコンテナイメージをPULLします。

docker pull certbot/certbot
注記

arm64アーキテクチャのイメージは別のタグで提供されています。

docker pull certbot/certbot:arm64v8-latest

Certbotの起動

docker runでコンテナを起動します。 volumeをマウントして作成した証明書を取得します。

docker run -it --rm \
-v $PWD/etc/letsencrypt:/etc/letsencrypt \
-v $PWD/var/lib/letsencrypt:/var/lib/letsencrypt \
certbot/certbot certonly --manual

証明書の作成

Certbotは対話形式のウィザードで証明書の作成を行います。

Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel):

→メールアドレスを入力

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:

→利用規約を確認し、Yを入力

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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 our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:

→メールアドレスを共有する場合はY、しない場合はNで回答

Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel):

→SSL/TLS証明書を発行するドメインを入力。ワイルドカード(*.example.com)で作成することも可能です。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.xxxxxxxxx.xxx.

with the following value:

[ラインダムな文字列]

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.xxxxxxxxx.xxx.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

ここでウィザードを中断し、表示される内容のDNS TXTレコードを作成します。

上記の例の場合

  • 名前: _acme-challenge.xxxxxxxxx.xxx.
  • 値: [ラインダムな文字列]

TXTレコードを作成した後、反映されるまで少し時間がかかるため、Google Admin Toolboxを使って作成したTXTレコードが反映されることを確認します。

反映されていることを確認したあと、ウィザードに戻り、エンターを入力します。

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/[ドメイン名]/fullchain.pem
Key is saved at: /etc/letsencrypt/live/[ドメイン名]/privkey.pem
This certificate expires on 2023-04-14.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

これで証明書の作成は完了です。$PWD/etc/letsencryptの下に証明書が生成されます。

注記

Dockerコンテナがroot権限で実行されるため生成されたファイルにアクセスできない場合は権限を変更します。

sudo chown -R `id -g`:`id -u` etc var

以下のディレクトリが作成され、liveディレクトリ内に作成した証明書があります。(正確にはarchiveディレクトリに生成されたファイルへのリンクがliveディレクトリ内に作成されます。)

tree etc -L 2
etc
└── letsencrypt
├── accounts
├── archive
├── csr
├── keys
├── live
├── renewal
└── renewal-hooks

8 directories, 0 files

SSL/TLS証明書をWebサーバーに配置すればHTTPS通信が可能です。

参考サイト

https://eff-certbot.readthedocs.io/en/stable/install.html#alternative-1-docker https://eff-certbot.readthedocs.io/en/stable/using.html#manual