🎍

powerdns で DNS-01チャレンジ の件

に公開

Lets'encrypt - DNS-01チャレンジ

  • lets'encrypt / ACME プロトコルによる ドメイン存在と管理実体に依拠する電子証明書取得サービスは、有料化されても最早納得せざるを得ないほどの手軽さで普及している。

  • ACME プロトコルは、 Webクライアント-サーバが媒介する検証手続きである HTTP-01チャレンジと、DNS/RRsetのTXT-RRの更新を以て管理実体を検証する DNS-01 チャレンジの2つがある..
    https://letsencrypt.org/ja/docs/challenge-types/

  • 本稿は、DNS-01 チャレンジを行うにあたって、以下の条件で行う。

  1. python実装の certbot を用いて
  2. powerdns で 運用されている domain で
  3. ワイルドカード証明書を自動取得する

DNS-01 を用いて、証明書を手動で取得する手続き

  • RRを手で書き換えることで動作を確かめる。
$ certbot certonly --manual --dry-run--preferred-challenges dns  -d \*.hoge.jp
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Account registered.
Simulating renewal of an existing certificate for *.hoge.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.hoge.jp.

with the following value:

_hMJwtx95liHN3KJ6jmjmiGdGUkM158B7ctLxULsHdw

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.hoge.jp.
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

  • hoge.jp のゾーン情報に 上記の TXT RR を追加
; Warning - every name in this file is ABSOLUTE!
$ORIGIN .
hoge.jp  3600    IN      SOA     ns1.hoge.jp hostmaster.hoge.jp 2024123101 14400 3600 1048576 2560
hoge.jp  3600    IN      A       203.0.113.33
hoge.jp  3600    IN      NS      ns1.hoge.jp
hoge.jp  3600    IN      MX      0 mx.hoge.jp
hoge.jp  3600    IN      TXT     "v=spf1 mx/24 ~all"
_acme-challenge.hoge.jp  300     IN      TXT     "_hMJwtx95liHN3KJ6jmjmiGdGUkM158B7ctLxULsHdw"
mx.hoge.jp       3600    IN      A       203.0.113.33
ns1.hoge.jp      3600    IN      A       203.0.113.33

  • などとしてから、 "Enter" を押すと
The dry run was successful.

  • マニュアルで取得できていることを確認する → /var/log/letsencrypt.log

certbot プラグインを選ぶ

  • FreeBSD では、 security/py-certbot-dns-powerdns があるようだが、筆者環境(+執筆日時近傍)で fail するとわかったので、利用を諦めた
  • githubを渉猟していると、https://github.com/kaechele/certbot-dns-pdns を探り当てられた。これは現在も更新が続いている。 今回はこちらを利用することになった。
  • plugins 複数あるとこんな感じである。
# certbot plugins
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* dns-pdns
Description: Obtain certificates using a DNS TXT record (if you are using
PowerDNS for DNS).
Interfaces: Authenticator, Plugin
Entry point: EntryPoint(name='dns-pdns',
value='certbot_dns_pdns.dns_pdns:Authenticator', group='certbot.plugins')

* dns-powerdns
Description: Obtain certificates using a DNS TXT record (if you are using
PowerDNS for DNS.)
Interfaces: Authenticator, Plugin
Entry point: EntryPoint(name='dns-powerdns',
value='certbot_dns_powerdns.dns_powerdns:Authenticator',
group='certbot.plugins')

...

powerdns で (Web)API 設定をする

  • pdns.conf に API 設定(HTTP設定も)をする。
api=yes
api-key=hogehogehogehoge-hogehoge
webserver=yes
webserver-password=hogegeho
webserver-port=8081
webserver-allow-from=10.0.0.0/8

powerdns / api 機能するか確認する。

$ curl -sk -H 'X-API-Key: hogehogehogehoge-hogehoge' -X GET http://10.0.0.53:8081/api/v1/servers/localhost/zones

~/pdns-credentials.ini を編集する。

https://github.com/kaechele/certbot-dns-pdns#usage

テスト

# certbot certonly --dry-run --authenticator dns-pdns --dns-pdns-credentials ~/pdns-credentials.ini -d \*.hoge.jp
Simulating renewal of an existing certificate for *.hoge.jp
Waiting 30 seconds for DNS changes to propagate
The dry run was successful.

実運用について

  • 管理対象ドメインの殆どが HTTP-01の自動化で対応しているので、DNS-01、マニュアルで対応していたが、テスト良好なので切り替えて行く所存。

Discussion