手元でPowerDNSのAPIを叩くためのDockerイメージを作った
PowerDNSのAPIを手元で叩ける環境が必要だったので用意しました。
要件は以下です。
- ローカルで動作すること
- 最低限ビルトインのAPIが動くこと
- digで問い合わせができること
インストールする
こちらを参考にDockerfileを作成します。 https://repo.powerdns.com/
CentOS7, PowerDNS4.3を使いたかったので、PowerDNS Authoritative Server - version 4.3.X
に記載されているコマンドを使います。
yum install epel-release yum-plugin-priorities && curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://repo.powerdns.com/repo-files/centos-auth-43.repo && yum install pdns
起動する
/usr/lib/systemd/system/pdns.service
の ExecStart
をみてみると、/usr/sbin/pdns_server
で起動するようなので、
CMD ["/usr/sbin/pdns_server"]
を追加します。
Dockerfileはこんな感じになりました。
FROM centos:7 RUN yum update -y \ && yum install -y epel-release yum-plugin-priorities \ && curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://repo.powerdns.com/repo-files/centos-auth-43.repo \ && yum install -y pdns \ && rm -rf /var/cache/yum \ && yum clean all CMD ["/usr/sbin/pdns_server"]
設定する
以下を参考に設定 https://doc.powerdns.com/recursor/http-api/#enabling-the-api
開発環境なので、どこからでもAPIを叩けるようにします。
設定はこんな感じになりました。
api=yes api-key=changeme launch=bind setgid=pdns setuid=pdns webserver=yes webserver-address=0.0.0.0 webserver-allow-from=0.0.0.0/0 webserver-port=8081
設定をvolumesで読み込ませ、portをbindします。
version: '3' services: powerdns: build: ./ volumes: - ./pdns.conf:/etc/pdns/pdns.conf:ro ports: - "8081:8081" - "1053:53/tcp" - "1053:53/udp"
動作確認
上記で準備ができたので、動作確認します。
APIを叩く
なんか返ってきた
curl -H 'X-API-Key: changeme' http://127.0.0.1:8081/api/v1/servers/localhost | jq . { "config_url": "/api/v1/servers/localhost/config{/config_setting}", "daemon_type": "authoritative", "id": "localhost", "type": "Server", "url": "/api/v1/servers/localhost", "version": "4.3.1", "zones_url": "/api/v1/servers/localhost/zones{/zone}" }
digで問い合わせをする
こちらもなんか返ってきた
dig +norec @localhost -p 1053 test.example.com ANY ;; Truncated, retrying in TCP mode. ; <<>> DiG 9.10.6 <<>> +norec @localhost -p 1053 test.example.com ANY ; (2 servers found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 28280 ;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;test.example.com. IN ANY ;; Query time: 4 msec ;; SERVER: ::1#1053(::1) ;; WHEN: Fri Jan 01 17:11:39 JST 2021 ;; MSG SIZE rcvd: 45
まとめ
とりあえず、APIを手元で叩けるようになりました。 実際にレコードを登録するなどは、後ほどやっていこうと思います。