diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..315843a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +etc/xip-pdns.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1db7d27 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:14.04 + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get upgrade -y --force-yes && \ + apt-get install -y pdns-server pdns-backend-pipe + +# remove all other pdns backends +RUN rm -f /etc/powerdns/pdns.d/* + +# install our source and powerdns backend configurations +ADD bin/xip-pdns /usr/local/bin/xip-pdns +ADD etc/xip-pdns.backend.conf.example /etc/powerdns/pdns.d/xip.conf + +# expose dns ports +EXPOSE 53/udp 53/tcp + +CMD ["pdns_server", "--master", "--daemon=no", "--local-address=0.0.0.0"] diff --git a/README.md b/README.md index b4d628e..107c3b1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,95 @@ -#### xip-pdns +# XIP PowerDNS Backend Adapter -This is the source of the [PowerDNS](http://powerdns.com/) pipe backend adapter powering [xip.io](http://xip.io/). +This is the source of the [PowerDNS](http://powerdns.com/) pipe backend +adapter powering [xip.io](http://xip.io/). -Install this on your system, adjust [etc/xip-pdns.conf](etc/xip-pdns.conf.example) to your liking, and configure PowerDNS as follows: +## Deploying Manually - launch=pipe - pipe-command=/path/to/xip-pdns/bin/xip-pdns /path/to/xip-pdns/etc/xip-pdns.conf +Copy `etc/xip-pdns.conf.example` to `/etc/xip-pdns.conf`, and modify to meet +your needs. +Example: + +**/etc/xip-pdns.conf** + +``` +# Increment this timestamp when the contents of the file change. +XIP_TIMESTAMP="2014102800" + +# The top-level domain for which the name server is authoritative. +XIP_DOMAIN="xip.test" + +# The public IP addresses (e.g. for the web site) of the top-level domain. +# `A` queries for the top-level domain will return this list of addresses. +XIP_ROOT_ADDRESSES=( "1.2.3.1" ) + +# The public IP addresses on which this xip-pdns server will run. +# `NS` queries for the top-level domain will return this list of addresses. +# Each entry maps to a 1-based subdomain of the format `ns-1`, `ns-2`, etc. +# `A` queries for these subdomains map to the corresponding addresses here. +XIP_NS_ADDRESSES=( "1.2.3.4" "1.2.3.5" ) + +# How long responses should be cached, in seconds. +XIP_TTL=300 +``` + +Then copy `etc/xip-pdns.backend.conf.example` to +`/etc/powerdns/pdns.d/xip.conf` (or the appropriate PowerDNS backend adapter +configuration location for your system), and modify to meet your needs. + +Example: + +**/etc/powerdns/pdns.d/xip.conf** + +``` +launch=pipe +pipe-command=/usr/local/bin/xip-pdns /etc/xip-pdns.conf +``` + +Finally, copy `bin/xip-pdns` to `/usr/local/bin/xip-pdns` (or wherever you +prefer). + +Restart PowerDNS, and test. + +``` +$ dig test.10.0.0.1.xip.test @localhost +;; ANSWER SECTION: +test.10.0.0.1.xip.test. 300 IN A 10.0.0.1 +``` + +*Note: Replace `localhost` with the address of the host running PowerDNS.* + +## Deploying with Docker + +XIP PDNS can easily be deployed with the included Dockerfile as follows. +First copy `etc/xip-pdns.conf.example` to `/path/to/xip-pdns.conf` (wherever +you want it), and modify for your needs. Build, and run with Docker: + +``` +$ cp -a etc/xip-pdns.conf.example etc/xip-pdns.conf + +$ docker build -t 'xip-pdns' . + +$ docker run -it \ + -p 0.0.0.0:53:53/tcp \ + -p 0.0.0.0:53:53/udp \ + -v ./etc/xip-pdns.conf:/etc/xip-pdns.conf \ + xip-pdns +``` + +Alternatively, the above can be run with Docker Compose using the included +`docker-compose.yml`: + +``` +$ docker-compose up +``` + +And test: + +``` +$ dig test.10.0.0.1.xip.test @localhost +;; ANSWER SECTION: +test.10.0.0.1.xip.test. 300 IN A 10.0.0.1 +``` + +*Note: Replace `localhost` with the host running the Docker container.* diff --git a/bin/xip-pdns b/bin/xip-pdns index 8a1efb4..a06715c 100755 --- a/bin/xip-pdns +++ b/bin/xip-pdns @@ -3,18 +3,20 @@ set -e shopt -s nocasematch # -# Configuration +# Source Configuration File Defaults # -XIP_DOMAIN="xip.test" -XIP_ROOT_ADDRESSES=( "127.0.0.1" ) -XIP_NS_ADDRESSES=( "127.0.0.1" ) -XIP_TIMESTAMP="0" -XIP_TTL=300 - if [ -a "$1" ]; then source "$1" fi +# +# Configuration Default Settings (if not yet provided) +# +[ -z "$XIP_DOMAIN" ] && XIP_DOMAIN="xip.test" +[ -z "$XIP_ROOT_ADDRESSES" ] && XIP_ROOT_ADDRESSES=( "127.0.0.1" ) +[ -z "$XIP_NS_ADDRESSES" ] && XIP_NS_ADDRESSES=( "127.0.0.1" ) +[ -z "$XIP_TIMESTAMP" ] && XIP_TIMESTAMP="0" +[ -z "$XIP_TTL" ] && XIP_TTL=300 # # Protocol helpers diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0cd655c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +--- +version: '2' +services: + xip: + build: . + volumes: + - ./etc/xip-pdns.conf:/etc/xip-pdns.conf + ports: + - "53:53/tcp" + - "53:53/udp" + diff --git a/etc/xip-pdns.backend.conf.example b/etc/xip-pdns.backend.conf.example new file mode 100644 index 0000000..c61e8cd --- /dev/null +++ b/etc/xip-pdns.backend.conf.example @@ -0,0 +1,2 @@ +launch=pipe +pipe-command=/usr/local/bin/xip-pdns /etc/xip-pdns.conf