2016-11-29 06:15:00 +07:00
[![Build Status ](https://travis-ci.org/joohoi/acme-dns.svg?branch=master )](https://travis-ci.org/joohoi/acme-dns) [![Coverage Status ](https://coveralls.io/repos/github/joohoi/acme-dns/badge.svg?branch=master )](https://coveralls.io/github/joohoi/acme-dns?branch=master) [![Go Report Card ](https://goreportcard.com/badge/github.com/joohoi/acme-dns )](https://goreportcard.com/report/github.com/joohoi/acme-dns)
2016-11-29 05:39:46 +07:00
# acme-dns
2016-11-14 21:55:27 +07:00
2016-11-29 05:39:46 +07:00
A simplified DNS server with a RESTful HTTP API to provide a simple way to automate ACME DNS challenges.
2016-11-14 21:55:27 +07:00
2016-11-29 05:39:46 +07:00
## Why?
2016-11-14 21:55:27 +07:00
2016-12-02 22:44:58 +07:00
Many DNS servers do not provide an API to enable automation for the ACME DNS challenges. Those which do, give the keys way too much power.
Leaving the keys laying around your random boxes is too often a requirement to have a meaningful process automation.
2016-11-14 21:55:27 +07:00
2016-12-04 00:36:46 +07:00
Acme-dns provides a simple API exclusively for TXT record updates and should be used with ACME magic "\_acme-challenge" - subdomain CNAME records. This way, in the unfortunate exposure of API keys, the effetcs are limited to the subdomain TXT record in question.
2016-12-03 16:33:43 +07:00
2016-11-29 05:43:24 +07:00
So basically it boils down to **accessibility** and **security**
2016-11-14 21:55:27 +07:00
2016-11-29 05:39:46 +07:00
## Features
2016-11-29 05:43:24 +07:00
- Simplified DNS server, serving your ACME DNS challenges (TXT)
- Custom records (have your required A, AAAA, NS, etc. records served)
- HTTP API automatically acquires and uses Let's Encrypt TLS certificate
2016-12-03 16:33:43 +07:00
- Limit /update API endpoint access to specific CIDR mask(s), defined in the /register request
2016-11-29 05:43:24 +07:00
- Supports SQLite & PostgreSQL as DB backends
2018-01-22 17:47:26 +07:00
- Rolling update of two TXT records to be able to answer to challenges for certificates that have both names: `yourdomain.tld` and `*.yourdomain.tld` , as both of the challenges point to the same subdomain.
2016-12-03 16:33:43 +07:00
- Simple deployment (it's Go after all)
2016-11-14 21:55:27 +07:00
2016-11-29 06:06:16 +07:00
## Usage
2018-03-15 18:40:45 +07:00
A Certbot authentication hook for acme-dns is available at: [https://github.com/joohoi/acme-dns-certbot ](https://github.com/joohoi/acme-dns-certbot ).
2016-12-03 20:44:50 +07:00
[![asciicast ](https://asciinema.org/a/94903.png )](https://asciinema.org/a/94903)
2016-11-29 17:48:36 +07:00
2017-01-30 14:32:01 +07:00
Using acme-dns is a three-step process (provided you already have the self-hosted server set up):
2016-11-29 06:06:16 +07:00
2016-12-03 16:33:43 +07:00
- Get credentials and unique subdomain (simple POST request to eg. https://auth.acme-dns.io/register)
2016-11-29 06:06:16 +07:00
- Create a (ACME magic) CNAME record to your existing zone, pointing to the subdomain you got from the registration. (eg. `_acme-challenge.domainiwantcertfor.tld. CNAME a097455b-52cc-4569-90c8-7a4b97c6eba8.auth.example.org` )
- Use your credentials to POST a new DNS challenge values to an acme-dns server for the CA to validate them off of.
2016-11-30 13:26:46 +07:00
- Crontab and forget.
2016-11-29 06:06:16 +07:00
2016-11-29 05:39:46 +07:00
## API
2016-11-14 21:55:27 +07:00
2016-11-29 05:39:46 +07:00
### Register endpoint
2016-11-14 21:59:00 +07:00
2016-11-30 13:26:46 +07:00
The method returns a new unique subdomain and credentials needed to update your record.
2016-12-03 16:33:43 +07:00
Fulldomain is where you can point your own `_acme-challenge` subdomain CNAME record to.
With the credentials, you can update the TXT response in the service to match the challenge token, later referred as \_\_\_validation\_token\_recieved\_from\_the\_ca\_\_\_, given out by the Certificate Authority.
2016-11-14 21:55:27 +07:00
2016-12-03 16:33:43 +07:00
**Optional:**: You can POST JSON data to limit the /update requests to predefined source networks using CIDR notation.
2016-11-14 21:55:27 +07:00
2016-12-03 16:33:43 +07:00
```POST /register```
#### OPTIONAL Example input
```json
{
"allowfrom": [
"192.168.100.1/24",
"1.2.3.4/32",
2017-09-01 13:37:22 +07:00
"2002:c0a8:2a00::0/40"
]
2016-12-03 16:33:43 +07:00
}
```
2016-11-14 21:55:27 +07:00
2016-11-29 05:43:24 +07:00
```Status: 201 Created```
2016-12-03 16:33:43 +07:00
```json
2016-11-29 05:43:24 +07:00
{
2016-12-03 16:33:43 +07:00
"allowfrom": [
"192.168.100.1/24",
2017-09-01 13:37:22 +07:00
"1.2.3.4/32",
"2002:c0a8:2a00::0/40"
2016-12-03 16:33:43 +07:00
],
2016-11-29 05:43:24 +07:00
"fulldomain": "8e5700ea-a4bf-41c7-8a77-e990661dcc6a.auth.acme-dns.io",
"password": "htB9mR9DYgcu9bX_afHF62erXaH2TS7bg9KW3F7Z",
"subdomain": "8e5700ea-a4bf-41c7-8a77-e990661dcc6a",
"username": "c36f50e8-4632-44f0-83fe-e070fef28a10"
}
```
2016-11-14 21:55:27 +07:00
2016-11-29 05:39:46 +07:00
### Update endpoint
2016-11-14 21:55:27 +07:00
2016-11-29 05:43:24 +07:00
The method allows you to update the TXT answer contents of your unique subdomain. Usually carried automatically by automated ACME client.
2016-11-14 21:55:27 +07:00
2016-11-29 05:43:24 +07:00
```POST /update```
2016-11-14 21:55:27 +07:00
2016-11-29 05:43:24 +07:00
#### Required headers
| Header name | Description | Example |
| ------------- |--------------------------------------------|-------------------------------------------------------|
| X-Api-User | UUIDv4 username recieved from registration | `X-Api-User: c36f50e8-4632-44f0-83fe-e070fef28a10` |
| X-Api-Key | Password recieved from registration | `X-Api-Key: htB9mR9DYgcu9bX_afHF62erXaH2TS7bg9KW3F7Z` |
2016-11-14 21:55:27 +07:00
2016-11-29 05:43:24 +07:00
#### Example input
2016-12-03 16:33:43 +07:00
```json
2016-11-29 05:43:24 +07:00
{
"subdomain": "8e5700ea-a4bf-41c7-8a77-e990661dcc6a",
2017-09-01 13:37:22 +07:00
"txt": "___validation_token_recieved_from_the_ca___"
2016-11-29 05:43:24 +07:00
}
```
2016-11-15 04:53:58 +07:00
2016-11-29 05:43:24 +07:00
#### Response
2016-11-15 04:53:58 +07:00
2016-11-29 06:09:38 +07:00
```Status: 200 OK```
```json
2016-11-29 05:43:24 +07:00
{
2017-09-01 13:37:22 +07:00
"txt": "___validation_token_recieved_from_the_ca___"
2016-11-29 05:43:24 +07:00
}
```
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
## Self-hosted
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
You are encouraged to run your own acme-dns instance, because you are effectively authorizing the acme-dns server to act on your behalf in providing the answer to challengeing CA, making the instance able to request (and get issued) a TLS certificate for the domain that has CNAME pointing to it.
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
Check out how in the INSTALL section.
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
## Installation
2016-11-15 04:53:58 +07:00
2017-11-13 04:40:15 +07:00
1) Install [Go 1.9 or newer ](https://golang.org/doc/install )
2016-11-15 04:53:58 +07:00
2018-03-01 01:38:44 +07:00
2) Install acme-dns: `go get github.com/joohoi/acme-dns/...`
2016-11-15 04:56:13 +07:00
2018-03-01 01:38:44 +07:00
3) Edit config.cfg to suit your needs (see [configuration ](#configuration )). `acme-dns` will read the configuration file from `/etc/acme-dns/config.cfg` or `./config.cfg`
2016-11-15 04:56:13 +07:00
2018-03-01 01:38:44 +07:00
4) Run acme-dns. Please note that acme-dns needs to open a privileged port (53, domain), so it needs to be run with elevated privileges.
2016-11-24 03:24:59 +07:00
2018-01-22 17:35:07 +07:00
## Using Docker
1) Pull the latest acme-dns Docker image: `docker pull joohoi/acme-dns`
2) Create directories: `config` for the configuration file, and `data` for the sqlite3 database.
3) Copy [configuration template ](https://raw.githubusercontent.com/joohoi/acme-dns/master/config.cfg ) to `config/config.cfg`
4) Modify the config.cfg to suit your needs.
5) Run Docker, this example expects that you have `port = "80"` in your config.cfg:
```
docker run --rm --name acmedns \
-p 53:53 \
-p 80:80 \
-v /path/to/your/config:/etc/acme-dns:ro \
-v /path/to/your/data:/var/lib/acme-dns \
-d joohoi/acme-dns
```
## Docker Compose
1) Create directories: `config` for the configuration file, and `data` for the sqlite3 database.
2) Copy [configuration template ](https://raw.githubusercontent.com/joohoi/acme-dns/master/config.cfg ) to `config/config.cfg`
3) Copy [docker-compose.yml from the project ](https://raw.githubusercontent.com/joohoi/acme-dns/master/docker-compose.yml ), or create your own.
4) Edit the `config/config.cfg` and `docker-compose.yml` to suit your needs, and run `docker-compose up -d`
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
## Configuration
2016-11-15 04:53:58 +07:00
2016-11-29 06:09:38 +07:00
```bash
2016-11-29 05:39:46 +07:00
[general]
# dns interface
listen = ":53"
# protocol, "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "udp"
2016-11-30 13:26:46 +07:00
# domain name to serve the requests off of
2016-11-29 05:39:46 +07:00
domain = "auth.example.org"
# zone name server
nsname = "ns1.auth.example.org"
2016-11-30 13:26:46 +07:00
# admin email address, where @ is substituted with .
2016-11-29 05:39:46 +07:00
nsadmin = "admin.example.org"
2016-11-30 13:26:46 +07:00
# predefined records served in addition to the TXT
2016-11-29 05:39:46 +07:00
records = [
# default A
"auth.example.org. A 192.168.1.100",
# A
"ns1.auth.example.org. A 192.168.1.100",
"ns2.auth.example.org. A 192.168.1.100",
# NS
"auth.example.org. NS ns1.auth.example.org.",
"auth.example.org. NS ns2.auth.example.org.",
]
# debug messages from CORS etc
debug = false
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
[database]
# Database engine to use, sqlite3 or postgres
engine = "sqlite3"
# Connection string, filename for sqlite3 and postgres://$username:$password@$host/$db_name for postgres
connection = "acme-dns.db"
# connection = "postgres://user:password@localhost/acmedns_db"
[api]
# domain name to listen requests for, mandatory if using tls = "letsencrypt"
api_domain = ""
2018-03-15 04:35:39 +07:00
# disable registration endpoint
disable_registration = false
2018-02-01 15:53:34 +07:00
# autocert HTTP port, eg. 80 for answering Let's Encrypt HTTP-01 challenges. Mandatory if using tls = "letsencrypt".
autocert_port = "80"
2018-02-28 09:45:13 +07:00
# listen ip, default "" listens on all interfaces/addresses
ip = "127.0.0.1"
2016-11-29 05:39:46 +07:00
# listen port, eg. 443 for default HTTPS
port = "8080"
# possible values: "letsencrypt", "cert", "none"
tls = "none"
# only used if tls = "cert"
tls_cert_privkey = "/etc/tls/example.org/privkey.pem"
tls_cert_fullchain = "/etc/tls/example.org/fullchain.pem"
# CORS AllowOrigins, wildcards can be used
corsorigins = [
"*"
]
[logconfig]
# logging level: "error", "warning", "info" or "debug"
loglevel = "debug"
# possible values: stdout, TODO file & integrations
logtype = "stdout"
# file path for logfile TODO
# logfile = "./acme-dns.log"
# format, either "json" or "text"
logformat = "text"
2016-12-03 16:33:43 +07:00
# use HTTP header to get the client ip
use_header = false
# header name to pull the ip address / list of ip addresses from
header_name = "X-Forwarded-For"
2016-11-29 05:39:46 +07:00
```
2016-11-15 04:53:58 +07:00
2018-03-15 18:40:45 +07:00
## Client
A Certbot authentication hook for acme-dns is available at: [https://github.com/joohoi/acme-dns-certbot ](https://github.com/joohoi/acme-dns-certbot ).
2018-03-18 21:01:46 +07:00
Client library for Python is available at PyPI: [https://pypi.python.org/pypi/pyacmedns/ ](https://pypi.python.org/pypi/pyacmedns/ )
2016-12-05 05:35:51 +07:00
## Changelog
2018-03-15 05:47:36 +07:00
- v0.4 Clear error messages for bad TXT record content, proper handling of static CNAME records, fixed IP address parsing from the request, added option to disable registration endpoint in the configuration.
2018-02-01 21:10:24 +07:00
- v0.3.2 Dockerfile was fixed for users using autocert feature
- v0.3.1 Added goreleaser for distributing binary builds of the releases
2018-02-01 15:53:34 +07:00
- v0.3 Changed autocert to use HTTP-01 challenges, as TLS-SNI is disabled by Let's Encrypt
2018-01-22 17:47:26 +07:00
- v0.2 Now powered by httprouter, support wildcard certificates, Docker images
2016-12-05 05:35:51 +07:00
- v0.1 Initial release
2016-11-29 05:39:46 +07:00
## TODO
2016-11-15 04:53:58 +07:00
2016-12-03 16:33:43 +07:00
- Logging to a file
2018-01-22 17:47:26 +07:00
- DNSSEC
2016-11-29 05:43:24 +07:00
- Want to see something implemented, make a feature request!
2016-11-29 05:39:46 +07:00
## Contributing
2016-11-15 04:53:58 +07:00
2016-11-29 06:05:14 +07:00
acme-dns is open for contributions.
2018-01-22 17:47:26 +07:00
If you have an idea for improvement, please open an new issue or feel free to write a PR!
2016-11-15 04:53:58 +07:00
2016-11-29 05:39:46 +07:00
## License
2016-11-15 04:53:58 +07:00
2016-11-29 05:43:24 +07:00
acme-dns is released under the [MIT License ](http://www.opensource.org/licenses/MIT ).