1
0
mirror of https://github.com/vbrandl/bind9-api.git synced 2024-11-22 06:43:49 +01:00
Go to file
2019-05-26 00:32:39 +02:00
ci Fix before_deploy script 2018-07-15 21:38:11 +02:00
client Merge pull request #5 from vbrandl/dependabot/cargo/hyper-0.12.9 2019-05-26 00:29:46 +02:00
crypto Bump proptest from 0.8.3 to 0.8.7 2019-05-25 21:24:56 +00:00
data Bump serde_derive from 1.0.69 to 1.0.91 2019-05-25 22:27:31 +00:00
letsencrypt Initial commit 2018-07-08 01:08:56 +02:00
server Bump pretty_env_logger from 0.2.3 to 0.3.0 2019-05-25 22:28:37 +00:00
.gitignore Initial commit 2018-07-08 01:08:56 +02:00
.travis.yml Use rust environment in travis 2018-07-15 20:34:56 +02:00
Cargo.lock Merge pull request #5 from vbrandl/dependabot/cargo/hyper-0.12.9 2019-05-26 00:29:46 +02:00
Cargo.toml Enable LTO 2018-07-08 12:01:11 +02:00
LICENSE-APACHE Add licenses 2018-07-08 01:17:39 +02:00
LICENSE-MIT Add licenses 2018-07-08 01:17:39 +02:00
README.md Explain how to obtain a cert 2018-07-15 20:17:02 +02:00

BIND9 API

Travis Build Status License License

This is an attempt to implement an API to create, update or delete DNS records on a BIND9 DNS server.

Server

The server will wait for incoming requests and uses the nsupdate command to perform operations on the BIND9 nameserver. For the server to work, a DNS key is needed to perform the updates.

$ dnssec-keygen -r /dev/urandom -a HMAC-SHA256 -b 256 -n HOST dnskey

Copy the Key section of the resulting Kdnskey*.private file into a file that looks like this:

key "dns-key" {
    algorithm hmac-sha256;
    secret "<your secret>";
}

And extend the zone section of the zones you'd like to modify in your named.conf.local

zone "example.com" {
    type master;
    file "/var/lib/bind/db.example.com";
    ...
    allow-update { key "dns-key"; };
    ...
}

Now you can start the server:

$ ./bind9-api -k <path to dnskey> -t <your api token>

By default, the server will bind to 0.0.0.0:8000. The host and port to bind to, can be changed using the -h and -p flags respectively. For production use, you should bind to a private IP address (LAN or VLAN) or to 127.0.0.1 and put the server behind a reverse proxy that offers TLS.

Client

The client is used to perform changes to the DNS zone from any server. My use case is to perform LetsEncrypt DNS challenges. The client will look for a configuration file in /etc/bind9apiclient.toml which looks like this:

# API server host
host = "http://127.0.0.1:8080"
# API secret
secret = "topsecret"

The client can perform two operations: Creating/updating and deleting DNS records. The client is invoked like this

$ ./bind9-api-client -d foo.example.com -r TXT update -v foobar
$ ./bind9-api-client -d foo.example.com -r TXT delete

API Description

POST /record
X-Api-Token: <api-token>

{
    "name": "foo.example.com",
    "value": "127.0.0.1",
    "record": "A",
    "ttl": 1337
}
DELETE /record
X-Api-Token: <api-token>

{
    "name": "foo.example.com",
    "record": "A"
}

The API token is a SHA256 HMAC over the request body using a pre-shared secret.

Security Considerations

The current API design does not migrate replay attacks. An attacker that is able to intercept a request to the API can resend the same request again to execute the same operation. To prevent these kinds of attacks, you should use a reverse proxy and encrypt the connections using TLS. Future versions of the server might provide TLS functionality by itself.

Usage with LetsEncrypt

In letsencrypt/, two example scripts can be found to use the client as a certbot hook for DNS challenges. It assumes that the client is located somewhere in $PATH and that the configurations file exists.

To obtain a new certificate, certbot can be invoked as followed:

certbot certonly -n --agree-tos --server https://acme-v02.api.letsencrypt.org/directory --preferred-challenges=dns-01
--manual --manual-auth-hook /usr/lib/letsencrypt-bind9/certbot-bind9-auth --manual-cleanup-hook
/usr/lib/letsencrypt-bind9/certbot-bind9-cleanup --manual-public-ip-logging-ok -d example.com -d '*.example.com'

License

This project is licensed under either of

at your option.