├── src └── pdns-3.4.6 │ └── .gitkeep ├── jobs └── xip │ ├── templates │ ├── pdns.conf.erb │ ├── named.conf.erb │ ├── xip-pdns.conf.erb │ ├── ctl.sh │ └── xip-pdns.sh │ ├── monit │ └── spec ├── packages └── pdns-3.4.6 │ ├── pre_packaging │ ├── spec │ └── packaging ├── config ├── final.yml └── blobs.yml ├── releases └── xip │ ├── index.yml │ ├── xip-1.yml │ └── xip-2.yml ├── .final_builds ├── license │ └── index.yml ├── packages │ └── pdns-3.4.6 │ │ └── index.yml └── jobs │ └── xip │ └── index.yml ├── .gitignore ├── examples └── xip-bosh-init-aws.yml ├── README.md └── LICENSE /src/pdns-3.4.6/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /jobs/xip/templates/pdns.conf.erb: -------------------------------------------------------------------------------- 1 | <%= p('xip.pdns_conf') %> 2 | -------------------------------------------------------------------------------- /jobs/xip/templates/named.conf.erb: -------------------------------------------------------------------------------- 1 | <%= p('xip.named_conf') %> 2 | -------------------------------------------------------------------------------- /jobs/xip/templates/xip-pdns.conf.erb: -------------------------------------------------------------------------------- 1 | <%= p('xip.xip_pdns_conf') %> 2 | -------------------------------------------------------------------------------- /packages/pdns-3.4.6/pre_packaging: -------------------------------------------------------------------------------- 1 | # abort script on any command that exits with a non zero value 2 | set -e 3 | -------------------------------------------------------------------------------- /config/final.yml: -------------------------------------------------------------------------------- 1 | --- 2 | blobstore: 3 | provider: s3 4 | options: 5 | bucket_name: xip-release 6 | final_name: xip 7 | -------------------------------------------------------------------------------- /config/blobs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | pdns-3.4.6/pdns-3.4.6.tar.bz2: 3 | object_id: d424a934-a8c8-4655-bd75-650fddf3831e 4 | sha: 5b01b21e7a2807d9770fea5ed1acc4dc3ed609bd 5 | size: 1336760 6 | -------------------------------------------------------------------------------- /packages/pdns-3.4.6/spec: -------------------------------------------------------------------------------- 1 | --- 2 | name: pdns-3.4.6 3 | 4 | dependencies: 5 | 6 | files: 7 | - pdns-3.4.6/pdns-3.4.6.tar.bz2 # from https://downloads.powerdns.com/releases/pdns-3.4.6.tar.bz2 8 | -------------------------------------------------------------------------------- /releases/xip/index.yml: -------------------------------------------------------------------------------- 1 | --- 2 | builds: 3 | 3ed10ecc-d0dd-4439-b5ec-c1cabd2e18aa: 4 | version: '1' 5 | 285fc2a5-696c-4b19-9012-8162d693123a: 6 | version: '2' 7 | format-version: '2' 8 | -------------------------------------------------------------------------------- /jobs/xip/monit: -------------------------------------------------------------------------------- 1 | check process xip 2 | with pidfile /var/vcap/sys/run/xip.pid 3 | start program "/var/vcap/jobs/xip/bin/ctl start" 4 | stop program "/var/vcap/jobs/xip/bin/ctl stop" 5 | group vcap 6 | -------------------------------------------------------------------------------- /.final_builds/license/index.yml: -------------------------------------------------------------------------------- 1 | --- 2 | builds: 3 | 9841d3f4cf3430748ecd6b1c6308345f8bf9404a: 4 | version: 9841d3f4cf3430748ecd6b1c6308345f8bf9404a 5 | sha1: 391dc7051100b5045088103d52ad76ce37745ef5 6 | blobstore_id: 69f688e4-627b-436f-8a9c-a368c8851ccd 7 | format-version: '2' 8 | -------------------------------------------------------------------------------- /.final_builds/packages/pdns-3.4.6/index.yml: -------------------------------------------------------------------------------- 1 | --- 2 | builds: 3 | daa1d3f85eca4b9333885512e68339c32e61232e: 4 | version: daa1d3f85eca4b9333885512e68339c32e61232e 5 | sha1: aec29ab107ee2904a83c2f31a23c32828c7b366b 6 | blobstore_id: 153538d4-a7cb-4e0e-95e0-0029a5a3ca27 7 | format-version: '2' 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #* 2 | *# 3 | *.swp 4 | *~ 5 | .DS_Store 6 | .dev_builds 7 | .final_builds/jobs/**/*.tgz 8 | .final_builds/packages/**/*.tgz 9 | .idea 10 | .ruby-version 11 | .vagrant 12 | .blobs 13 | blobs 14 | config/dev.yml 15 | config/private.yml 16 | dev_releases 17 | releases/**/*.tgz 18 | releases/*.tgz 19 | src/* 20 | -------------------------------------------------------------------------------- /.final_builds/jobs/xip/index.yml: -------------------------------------------------------------------------------- 1 | --- 2 | builds: 3 | 43df50d5fac2b051cc7f80aff23a9cf3c6e05114: 4 | version: 43df50d5fac2b051cc7f80aff23a9cf3c6e05114 5 | sha1: 1f8bc68efa220bcc4daa6e82e33cf9183b93bf98 6 | blobstore_id: 977299bb-fef7-4ea0-9fb8-fbe33ae6d44f 7 | 31db613cda1e9f90d671c974042e43ca6bc11764: 8 | version: 31db613cda1e9f90d671c974042e43ca6bc11764 9 | sha1: 5784218516101e224f7125a88b5c81e34ce0b97c 10 | blobstore_id: bf3e4645-c027-4eba-b77f-8b40342815d2 11 | format-version: '2' 12 | -------------------------------------------------------------------------------- /releases/xip/xip-1.yml: -------------------------------------------------------------------------------- 1 | --- 2 | packages: 3 | - name: pdns-3.4.6 4 | version: daa1d3f85eca4b9333885512e68339c32e61232e 5 | fingerprint: daa1d3f85eca4b9333885512e68339c32e61232e 6 | sha1: aec29ab107ee2904a83c2f31a23c32828c7b366b 7 | dependencies: [] 8 | jobs: 9 | - name: xip 10 | version: 43df50d5fac2b051cc7f80aff23a9cf3c6e05114 11 | fingerprint: 43df50d5fac2b051cc7f80aff23a9cf3c6e05114 12 | sha1: 1f8bc68efa220bcc4daa6e82e33cf9183b93bf98 13 | license: 14 | version: 9841d3f4cf3430748ecd6b1c6308345f8bf9404a 15 | fingerprint: 9841d3f4cf3430748ecd6b1c6308345f8bf9404a 16 | sha1: 391dc7051100b5045088103d52ad76ce37745ef5 17 | commit_hash: 0f209daf 18 | uncommitted_changes: true 19 | name: xip 20 | version: '1' 21 | -------------------------------------------------------------------------------- /releases/xip/xip-2.yml: -------------------------------------------------------------------------------- 1 | --- 2 | packages: 3 | - name: pdns-3.4.6 4 | version: daa1d3f85eca4b9333885512e68339c32e61232e 5 | fingerprint: daa1d3f85eca4b9333885512e68339c32e61232e 6 | sha1: aec29ab107ee2904a83c2f31a23c32828c7b366b 7 | dependencies: [] 8 | jobs: 9 | - name: xip 10 | version: 31db613cda1e9f90d671c974042e43ca6bc11764 11 | fingerprint: 31db613cda1e9f90d671c974042e43ca6bc11764 12 | sha1: 5784218516101e224f7125a88b5c81e34ce0b97c 13 | license: 14 | version: 9841d3f4cf3430748ecd6b1c6308345f8bf9404a 15 | fingerprint: 9841d3f4cf3430748ecd6b1c6308345f8bf9404a 16 | sha1: 391dc7051100b5045088103d52ad76ce37745ef5 17 | commit_hash: 13d4f613 18 | uncommitted_changes: true 19 | name: xip 20 | version: '2' 21 | -------------------------------------------------------------------------------- /jobs/xip/spec: -------------------------------------------------------------------------------- 1 | --- 2 | name: xip 3 | templates: 4 | ctl.sh: bin/ctl 5 | xip-pdns.sh: bin/xip-pdns 6 | named.conf.erb: etc/named.conf 7 | xip-pdns.conf.erb: etc/xip-pdns.conf 8 | pdns.conf.erb: etc/pdns.conf 9 | 10 | packages: 11 | - pdns-3.4.6 12 | 13 | properties: 14 | xip.named_conf: 15 | default: '' 16 | description: "The contents of named.conf (PowerDNS's BIND backend's configuration file)" 17 | xip.pdns_conf: 18 | default: | 19 | launch=pipe 20 | pipe-command=/var/vcap/jobs/xip/bin/xip-pdns /var/vcap/jobs/xip/etc/xip-pdns.conf 21 | description: "The contents of pdns.conf (PowerDNS's configuration file)" 22 | xip.xip_pdns_conf: 23 | description: "The contents of xip-pdns.conf (xip's configuration file)" 24 | -------------------------------------------------------------------------------- /packages/pdns-3.4.6/packaging: -------------------------------------------------------------------------------- 1 | # abort script on any command that exits with a non zero value 2 | set -e 3 | 4 | # FIXME: we should rebuild dependencies from source; we should NOT use 5 | # this ugly hack to install via yum/apt-get. 6 | if [ -f /etc/redhat-release ]; then 7 | yum install -y boost-devel boost-serialization 8 | export LDFLAGS="-L/usr/lib64" 9 | elif [ -f /etc/lsb-release ]; then 10 | apt-get update 11 | apt-get install -y autoconf automake bison flex g++ git libboost-all-dev libtool make pkg-config ragel libmysqlclient-dev 12 | fi 13 | 14 | tar xvf pdns-3.4.6/pdns-3.4.6.tar.bz2 15 | cd pdns-3.4.6 16 | 17 | ./configure \ 18 | --with-modules="bind pipe remote" \ 19 | --without-lua \ 20 | --prefix=${BOSH_INSTALL_TARGET} 21 | 22 | #./configure \ 23 | # --prefix=${BOSH_INSTALL_TARGET} \ 24 | # --sysconfdir=/var/vcap/jobs/named/etc \ 25 | # --localstatedir=/var/vcap/sys 26 | make 27 | make install 28 | -------------------------------------------------------------------------------- /examples/xip-bosh-init-aws.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: xip 3 | 4 | resource_pools: 5 | - name: xip_pool 6 | network: default 7 | cloud_properties: 8 | instance_type: t2.micro 9 | ephemeral_disk: 10 | size: 4000 11 | type: gp2 12 | availability_zone: us-east-1a 13 | stemcell: 14 | url: https://bosh.io/d/stemcells/bosh-aws-xen-hvm-centos-7-go_agent?v=3063 15 | sha1: 082b4eee247bb199138ec6163fb4ea92f6b7fcc4 16 | 17 | jobs: 18 | - name: xip 19 | instances: 1 20 | templates: 21 | - { release: xip, name: xip } 22 | resource_pool: xip_pool 23 | networks: 24 | - name: vip 25 | # CHANGEME: replace the IP address with your Elastic IP 26 | # the Elastic IP must have scope 'vpc' not 'standard' 27 | static_ips: [52.0.76.229] 28 | - name: default 29 | properties: 30 | xip: 31 | xip_pdns_conf: | 32 | # Increment this timestamp when the contents of the file change. 33 | XIP_TIMESTAMP="2015090512" 34 | 35 | # The top-level domain for which the name server is authoritative. 36 | # CHANGEME: change "sslip.io" to your domain 37 | XIP_DOMAIN="sslip.io" 38 | 39 | # The public IP addresses (e.g. for the web site) of the top-level domain. 40 | # `A` queries for the top-level domain will return this list of addresses. 41 | # CHANGEME: change this to your domain's webserver's address 42 | XIP_ROOT_ADDRESSES=( "52.0.56.137" ) 43 | 44 | # The public IP addresses on which this xip-pdns server will run. 45 | # `NS` queries for the top-level domain will return this list of addresses. 46 | # Each entry maps to a 1-based subdomain of the format `ns-1`, `ns-2`, etc. 47 | # `A` queries for these subdomains map to the corresponding addresses here. 48 | # CHANGEME: change this to match your NS records; one of these IP addresses 49 | # should match the jobs(xip).networks.static_ips listed above 50 | XIP_NS_ADDRESSES=( "52.0.56.137" "78.47.249.19" ) 51 | 52 | # How long responses should be cached, in seconds. 53 | XIP_TTL=300 54 | 55 | networks: 56 | - name: default 57 | type: dynamic 58 | cloud_properties: 59 | # CHANGEME: replace the subnet with your subnet-id 60 | subnet: subnet-1c90ef6b 61 | - name: vip 62 | type: vip 63 | 64 | cloud_provider: 65 | template: {name: cpi, release: bosh-aws-cpi} 66 | 67 | ssh_tunnel: 68 | # CHANGEME: replace the IP address with your Elastic IP 69 | host: 52.0.76.229 70 | port: 22 71 | user: vcap 72 | # CHANGEME: replace with the pathname of your downloaded AWS Key Pair 73 | # (Power users: no passphrase-protection otherwise you'll see a 74 | # `asn1: structure error: tags don't match` message when deploying 75 | private_key: /Users/cunnie/.ssh/aws_nono.pem 76 | 77 | # CHANGEME: replace 'dmitriy' with a secure password 78 | mbus: https://nats:dmitriy@52.0.76.229:6868 79 | 80 | properties: 81 | aws: 82 | # CHANGEME: replace with your AWS Access Key 83 | access_key_id: AKIAxxxxxxxxxxxxxxxx 84 | # CHANGEME: replace with your AWS Secret 85 | secret_access_key: 0+B1Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 86 | # CHANGEME: replace with your AWS Key Pair name 87 | default_key_name: aws_nono 88 | # CHANGEME: replace with your security group 89 | # the Security Group MUST have the VPC ID of your VPC (e.g. 'vpc-e4250881') 90 | default_security_groups: [no-filter-vpc] 91 | region: us-east-1 92 | 93 | # CHANGEME: replace 'dmitriy' with a secure password 94 | agent: {mbus: "https://nats:dmitriy@0.0.0.0:6868"} 95 | 96 | blobstore: 97 | provider: local 98 | path: /var/vcap/micro_bosh/data/cache 99 | 100 | ntp: [0.north-america.pool.ntp.org] 101 | 102 | releases: 103 | - name: xip 104 | url: https://s3.amazonaws.com/xip-release/xip-1.tgz 105 | sha1: b544389803a6ef21b6dd05a5c13526dab0df7ac3 106 | - name: bosh-aws-cpi 107 | url: https://bosh.io/d/github.com/cloudfoundry-incubator/bosh-aws-cpi-release?v=28 108 | sha1: c7ce03393ebedd87a860dc609758ddb9654360fa 109 | -------------------------------------------------------------------------------- /jobs/xip/templates/ctl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # chkconfig: - 80 75 3 | # description: PDNS is a versatile high performance authoritative nameserver 4 | 5 | ### BEGIN INIT INFO 6 | # Provides: pdns 7 | # Required-Start: $remote_fs $network $syslog 8 | # Required-Stop: $remote_fs $network $syslog 9 | # Should-Start: 10 | # Should-Stop: 11 | # Default-Start: 2 3 4 5 12 | # Default-Stop: 0 1 6 13 | # Short-Description: PowerDNS authoritative server 14 | # Description: PowerDNS authoritative server 15 | ### END INIT INFO 16 | 17 | set -e 18 | 19 | #prefix=/usr/local 20 | prefix=/var/vcap/jobs/xip/packages/pdns-3.4.6 21 | exec_prefix=${prefix} 22 | BINARYPATH=${exec_prefix}/bin 23 | SBINARYPATH=${exec_prefix}/sbin 24 | SOCKETPATH=/var/run 25 | DAEMON_ARGS="" 26 | PIDFILE="/var/vcap/sys/run/xip.pid" 27 | LOGDIR="/var/vcap/sys/log/xip" 28 | 29 | [ -f "$SBINARYPATH/pdns_server" ] || exit 0 30 | 31 | [ -r /etc/default/pdns ] && . /etc/default/pdns 32 | 33 | [ "$START" = "no" ] && exit 0 34 | 35 | # Make sure that /var/run exists 36 | mkdir -p $SOCKETPATH 37 | cd $SOCKETPATH 38 | suffix=$(basename $0 | cut -d- -f2- -s) 39 | if [ -n "$suffix" ] 40 | then 41 | EXTRAOPTS=--config-name=$suffix 42 | PROGNAME=pdns-$suffix 43 | else 44 | PROGNAME=pdns 45 | fi 46 | 47 | # make sure LOG dir exists 48 | mkdir -p $LOGDIR 49 | 50 | pdns_server="$SBINARYPATH/pdns_server $DAEMON_ARGS $EXTRAOPTS" 51 | 52 | doPC() 53 | { 54 | ret=$($BINARYPATH/pdns_control $EXTRAOPTS $1 $2 2> /dev/null) 55 | } 56 | 57 | NOTRUNNING=0 58 | doPC ping || NOTRUNNING=$? 59 | 60 | case "$1" in 61 | status) 62 | if test "$NOTRUNNING" = "0" 63 | then 64 | doPC status 65 | echo $ret 66 | else 67 | echo "not running" 68 | exit 3 69 | fi 70 | ;; 71 | 72 | stop) 73 | echo -n "Stopping PowerDNS authoritative nameserver: " 74 | # The monit way of stopping 75 | kill $(cat $PIDFILE) 76 | ;; 77 | 78 | 79 | force-stop) 80 | echo -n "Stopping PowerDNS authoritative nameserver: " 81 | killall -v -9 pdns_server 82 | echo "killed" 83 | ;; 84 | 85 | start) 86 | echo -n "Starting PowerDNS authoritative nameserver: " 87 | # The monit way of starting up 88 | ( echo $BASHPID > $PIDFILE; exec \ 89 | > $LOGDIR/pdns_server.stdout.log \ 90 | 2> $LOGDIR/pdns_server.stderr.log \ 91 | $pdns_server --daemon=no --guardian=yes --config-dir=/var/vcap/jobs/xip/etc ) & 92 | ;; 93 | 94 | force-reload | restart) 95 | echo -n "Restarting PowerDNS authoritative nameserver: " 96 | if test "$NOTRUNNING" = "1" 97 | then 98 | echo "not running, starting" 99 | else 100 | 101 | echo -n stopping and waiting.. 102 | doPC quit 103 | sleep 3 104 | echo done 105 | fi 106 | $0 start 107 | ;; 108 | 109 | reload) 110 | echo -n "Reloading PowerDNS authoritative nameserver: " 111 | if test "$NOTRUNNING" = "0" 112 | then 113 | doPC cycle 114 | echo requested reload 115 | else 116 | echo not running yet 117 | $0 start 118 | fi 119 | ;; 120 | 121 | monitor) 122 | if test "$NOTRUNNING" = "0" 123 | then 124 | echo "already running" 125 | else 126 | $pdns_server --daemon=no --guardian=no --control-console --loglevel=9 127 | fi 128 | ;; 129 | 130 | dump) 131 | if test "$NOTRUNNING" = "0" 132 | then 133 | doPC list 134 | echo $ret 135 | else 136 | echo "not running" 137 | fi 138 | ;; 139 | 140 | show) 141 | if [ $# -lt 2 ] 142 | then 143 | echo Insufficient parameters 144 | exit 145 | fi 146 | if test "$NOTRUNNING" = "0" 147 | then 148 | echo -n "$2=" 149 | doPC show $2 ; echo $ret 150 | else 151 | echo "not running" 152 | fi 153 | ;; 154 | 155 | mrtg) 156 | if [ $# -lt 2 ] 157 | then 158 | echo Insufficient parameters 159 | exit 160 | fi 161 | if test "$NOTRUNNING" = "0" 162 | then 163 | doPC show $2 ; echo $ret 164 | if [ "$3x" != "x" ] 165 | then 166 | doPC show $3 ; echo $ret 167 | else 168 | echo 0 169 | fi 170 | doPC uptime ; echo $ret 171 | echo PowerDNS daemon 172 | else 173 | echo "not running" 174 | fi 175 | 176 | ;; 177 | 178 | cricket) 179 | if [ $# -lt 2 ] 180 | then 181 | echo Insufficient parameters 182 | exit 183 | fi 184 | if test "$NOTRUNNING" = "0" 185 | then 186 | doPC show $2 ; echo $ret 187 | else 188 | echo "not running" 189 | fi 190 | 191 | ;; 192 | 193 | 194 | 195 | *) 196 | echo pdns [start\|stop\|force-reload\|reload\|restart\|status\|dump\|show\|mrtg\|cricket\|monitor] 197 | 198 | ;; 199 | esac 200 | 201 | 202 | -------------------------------------------------------------------------------- /jobs/xip/templates/xip-pdns.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | shopt -s nocasematch 4 | 5 | # 6 | # Configuration 7 | # 8 | XIP_DOMAIN="xip.test" 9 | XIP_ROOT_ADDRESSES=( "127.0.0.1" ) 10 | XIP_NS_ADDRESSES=( "127.0.0.1" ) 11 | XIP_MX_RECORDS=( ) 12 | XIP_TIMESTAMP="0" 13 | XIP_TTL=300 14 | 15 | if [ -a "$1" ]; then 16 | source "$1" 17 | fi 18 | 19 | 20 | # 21 | # Protocol helpers 22 | # 23 | read_cmd() { 24 | local IFS=$'\t' 25 | local i=0 26 | local arg 27 | 28 | read -ra CMD 29 | for arg; do 30 | eval "$arg=\"\${CMD[$i]}\"" 31 | let i=i+1 32 | done 33 | } 34 | 35 | send_cmd() { 36 | local IFS=$'\t' 37 | printf "%s\n" "$*" 38 | } 39 | 40 | fail() { 41 | send_cmd "FAIL" 42 | log "Exiting" 43 | exit 1 44 | } 45 | 46 | read_helo() { 47 | read_cmd HELO VERSION 48 | [ "$HELO" = "HELO" ] && [ "$VERSION" = "1" ] 49 | } 50 | 51 | read_query() { 52 | read_cmd TYPE QNAME QCLASS QTYPE ID IP 53 | } 54 | 55 | send_answer() { 56 | local type="$1" 57 | shift 58 | send_cmd "DATA" "$QNAME" "$QCLASS" "$type" "$XIP_TTL" "$ID" "$@" 59 | } 60 | 61 | log() { 62 | printf "[xip-pdns:$$] %s\n" "$@" >&2 63 | } 64 | 65 | 66 | # 67 | # xip.io domain helpers 68 | # 69 | XIP_DOMAIN_PATTERN="(^|\.)${XIP_DOMAIN//./\.}\$" 70 | NS_SUBDOMAIN_PATTERN="^ns-([0-9]+)\$" 71 | IP_SUBDOMAIN_PATTERN="(^|\.)(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\$" 72 | DASHED_IP_SUBDOMAIN_PATTERN="(^|-|\.)(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\$" 73 | BASE36_SUBDOMAIN_PATTERN="(^|\.)([a-z0-9]{1,7})\$" 74 | 75 | qtype_is() { 76 | [ "$QTYPE" = "$1" ] || [ "$QTYPE" = "ANY" ] 77 | } 78 | 79 | qname_matches_domain() { 80 | [[ "$QNAME" =~ $XIP_DOMAIN_PATTERN ]] 81 | } 82 | 83 | qname_is_root_domain() { 84 | [ "$QNAME" = "$XIP_DOMAIN" ] 85 | } 86 | 87 | extract_subdomain_from_qname() { 88 | SUBDOMAIN="${QNAME:0:${#QNAME}-${#XIP_DOMAIN}}" 89 | SUBDOMAIN="${SUBDOMAIN%.}" 90 | } 91 | 92 | subdomain_is_ns() { 93 | [[ "$SUBDOMAIN" =~ $NS_SUBDOMAIN_PATTERN ]] 94 | } 95 | 96 | subdomain_is_ip() { 97 | [[ "$SUBDOMAIN" =~ $IP_SUBDOMAIN_PATTERN ]] 98 | } 99 | 100 | subdomain_is_dashed_ip() { 101 | [[ "$SUBDOMAIN" =~ $DASHED_IP_SUBDOMAIN_PATTERN ]] 102 | } 103 | 104 | subdomain_is_base36() { 105 | [[ "$SUBDOMAIN" =~ $BASE36_SUBDOMAIN_PATTERN ]] 106 | } 107 | 108 | resolve_ns_subdomain() { 109 | local index="${SUBDOMAIN:3}" 110 | echo "${XIP_NS_ADDRESSES[$index-1]}" 111 | } 112 | 113 | resolve_ip_subdomain() { 114 | [[ "$SUBDOMAIN" =~ $IP_SUBDOMAIN_PATTERN ]] || true 115 | echo "${BASH_REMATCH[2]}" 116 | } 117 | 118 | resolve_dashed_ip_subdomain() { 119 | [[ "$SUBDOMAIN" =~ $DASHED_IP_SUBDOMAIN_PATTERN ]] || true 120 | echo "${BASH_REMATCH[2]//-/.}" 121 | } 122 | 123 | resolve_base36_subdomain() { 124 | [[ "$SUBDOMAIN" =~ $BASE36_SUBDOMAIN_PATTERN ]] || true 125 | local ip=$(( 36#${BASH_REMATCH[2]} )) 126 | printf "%d.%d.%d.%d" $(( ip&0xFF )) $(( (ip>>8)&0xFF )) $(( (ip>>16)&0xFF )) $(( (ip>>24)&0xFF )) 127 | } 128 | 129 | answer_soa_query() { 130 | send_answer "SOA" "admin.$XIP_DOMAIN ns-1.$XIP_DOMAIN $XIP_TIMESTAMP $XIP_TTL $XIP_TTL $XIP_TTL $XIP_TTL" 131 | } 132 | 133 | answer_ns_query() { 134 | local i=1 135 | local ns_address 136 | for ns_address in "${XIP_NS_ADDRESSES[@]}"; do 137 | send_answer "NS" "ns-$i.$XIP_DOMAIN" 138 | let i+=1 139 | done 140 | } 141 | 142 | answer_root_a_query() { 143 | local address 144 | for address in "${XIP_ROOT_ADDRESSES[@]}"; do 145 | send_answer "A" "$address" 146 | done 147 | } 148 | 149 | answer_mx_query() { 150 | set -- "${XIP_MX_RECORDS[@]}" 151 | while [ $# -gt 1 ]; do 152 | send_answer "MX" "$1 $2" 153 | shift 2 154 | done 155 | } 156 | 157 | answer_subdomain_a_query_for() { 158 | local type="$1" 159 | local address="$(resolve_${type}_subdomain)" 160 | if [ -n "$address" ]; then 161 | send_answer "A" "$address" 162 | fi 163 | } 164 | 165 | 166 | # 167 | # PowerDNS pipe backend implementation 168 | # 169 | trap fail err 170 | read_helo 171 | send_cmd "OK" "xip.io PowerDNS pipe backend (protocol version 1)" 172 | 173 | while read_query; do 174 | log "Query: type=$TYPE qname=$QNAME qclass=$QCLASS qtype=$QTYPE id=$ID ip=$IP" 175 | 176 | if qname_matches_domain; then 177 | if qname_is_root_domain; then 178 | if qtype_is "SOA"; then 179 | answer_soa_query 180 | fi 181 | 182 | if qtype_is "NS"; then 183 | answer_ns_query 184 | fi 185 | 186 | if qtype_is "A"; then 187 | answer_root_a_query 188 | fi 189 | 190 | if qtype_is "MX"; then 191 | answer_mx_query 192 | fi 193 | 194 | elif qtype_is "A"; then 195 | extract_subdomain_from_qname 196 | 197 | if subdomain_is_ns; then 198 | answer_subdomain_a_query_for ns 199 | 200 | elif subdomain_is_dashed_ip; then 201 | answer_subdomain_a_query_for dashed_ip 202 | 203 | elif subdomain_is_ip; then 204 | answer_subdomain_a_query_for ip 205 | 206 | elif subdomain_is_base36; then 207 | answer_subdomain_a_query_for base36 208 | fi 209 | fi 210 | fi 211 | 212 | send_cmd "END" 213 | done 214 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xip Release 2 | 3 | xip is a [BOSH release](https://bosh.io/docs/create-release.html) 4 | of the [PowerDNS](https://www.powerdns.com/) nameserver combined with an enhanced [xip.io](http://xip.io/) [*Pipe*](https://doc.powerdns.com/md/authoritative/backend-pipe/) backend. 5 | 6 | Deploying this release will create a DNS nameserver that will reply to xip.io-style queries, e.g. a query for the [A record](https://support.dnsimple.com/articles/a-record/) of the hostname "192.168.0.1.xip.io" will return the IP address "192.168.0.1". The domain can be customized (it does not need to be *xip.io*) 7 | 8 | The enhanced xip.io *Pipe* backend allows the lookup of hostnames with dashes as separators (not solely dots), for example, "172-16-100-1.xip.io" resolves to 172.16.100.1. 9 | 10 | ## xip BOSH Manifest 11 | 12 | ### 1. Job Properties 13 | 14 | xip's BOSH Properties are 15 | scoped under the `xip` element. A typical BOSH manifest has the following 16 | layout: 17 | 18 | ```yaml 19 | jobs: 20 | - name: xip 21 | properties: 22 | xip: 23 | xip_pdns_conf: | 24 | ... 25 | named_conf: | 26 | ... 27 | pdns_conf: | 28 | ... 29 | ``` 30 | 31 | xip has the following job properties: 32 | 33 | * `xip_pdns_conf`: *Required*. This is the configuration for the xip.io backend. It is a bash script that sets the environment variables that configure the behavior (e.g. the domain name). In the following example, we configure the domain name to be "sslip.io": 34 | 35 | ```bash 36 | XIP_TIMESTAMP="2015081600" 37 | XIP_DOMAIN="sslip.io" 38 | XIP_ROOT_ADDRESSES=( "52.0.56.137" ) 39 | XIP_NS_ADDRESSES=( "52.0.56.137" "78.47.249.19" ) 40 | XIP_TTL=300 41 | ``` 42 | 43 | * `pdns_conf`: *Optional*. Defaults to: 44 | 45 | ``` 46 | launch=pipe 47 | pipe-command=/var/vcap/jobs/xip/bin/xip-pdns /var/vcap/jobs/xip/etc/xip-pdns.conf 48 | ``` 49 | 50 | To use PowerDNS's *BIND* backend, include and configure it here, for example, 51 | 52 | ``` 53 | launch=bind:first,pipe:second 54 | slave=yes 55 | bind-first-config=/var/vcap/jobs/xip/etc/named.conf 56 | pipe-second-command=/var/vcap/jobs/xip/bin/xip-pdns /var/vcap/jobs/xip/etc/xip-pdns.conf 57 | ``` 58 | 59 | * `named_conf`: *Optional*. Defaults to empty string. If using PowerDNS's *BIND* backend, populate this property. For example, to configure a slave nameserver for the domain *nono.com*, 60 | 61 | ``` 62 | zone "nono.com" { 63 | type slave; 64 | file "/var/vcap/jobs/xip/etc/nono.com"; 65 | masters { 24.23.190.188; }; 66 | }; 67 | ``` 68 | 69 | ### 2. Upload Release to BOSH Director 70 | 71 | If using BOSH (not *bosh-init*), upload the release to the BOSH director: 72 | 73 | ``` 74 | bosh upload release https://s3.amazonaws.com/xip-release/xip-1.tgz 75 | ``` 76 | 77 | If using *bosh-init*, the BOSH manifest must contain the URL and SHA of the release, for example: 78 | 79 | ``` 80 | releases: 81 | - name: xip 82 | url: https://s3.amazonaws.com/xip-release/xip-1.tgz 83 | sha1: b544389803a6ef21b6dd05a5c13526dab0df7ac3 84 | ``` 85 | 86 | ### 3. Install Required boost library 87 | 88 | *Note: this step should be fixed in the release. Pull requests are welcome.* 89 | 90 | ``` 91 | yum install -y boost-serialization 92 | ``` 93 | 94 | ## Deploying a Custom Version of xip to Amazon AWS 95 | 96 | In this example, we deploy custom version of xip.io to a t2.micro instance on Amazon AWS: 97 | 98 | ### 1. Create the Amazon AWS infrastructure 99 | 100 | The BOSH documentation has an excellent [walk-through](http://bosh.io/docs/init-aws.html#prepare-aws) that describes how to create the proper infrastructure. After we have finished the walk-through, we have the following items which we will use to populate our BOSH manifest: 101 | 102 | * Elastic IP: **52.0.76.229** 103 | * Subnet: **subnet-1c90ef6b** 104 | * Private Key: **/Users/cunnie/.ssh/aws_nono.pem** 105 | * Access Key: **AKIAxxxxxxxxxxxxx** 106 | * Access Key Secret: **0+B1Xxxxxxxxxxxxxxxxxxxxxxxxxx** 107 | * AWS Key Pair name: **aws_nono** 108 | * Security Group: **no-filter-vpc** 109 | 110 | ### 2. Customize xip's Configuration 111 | 112 | In addition to the infrastructure items above, we also need to customize our xip-specific information, which we will use in the `jobs.properties.xip.xip_pdns_conf` section of our BOSH manifest: 113 | 114 | * a current timestamp: **2015090512** 115 | * our domain name: **sslip.io** 116 | * our domain's nameservers (as verified by `nslookup -query=ns sslip.io`): **52.0.56.137** and **78.47.249.19** 117 | * our domain's webserver's IP address (for http://slip.io): **52.0.56.137** 118 | 119 | ### 3. Construct the BOSH Manifest 120 | 121 | We construct a manifest using the information gathered in the previous steps. Our manifest looks like [this](https://github.com/cloudfoundry-community/xip-release/blob/master/examples/xip-bosh-init-aws.yml). *(Hint: search for all occurrences of 'CHANGEME' within the manifest and update appropriately)* 122 | 123 | ### 4. Deploy 124 | 125 | We deploy our manifest using [bosh-init](https://github.com/cloudfoundry/bosh-init) 126 | 127 | ``` 128 | bosh-init deploy examples/xip-bosh-init-aws.yml 129 | ``` 130 | 131 | ### 5. Test 132 | 133 | We test our newly-deployed nameserver to make sure it's functioning properly: 134 | 135 | ```bash 136 | export NAMESERVER_IP=52.0.76.229 137 | dig +short @$NAMESERVER_IP 127.0.0.1.sslip.io 138 | # 127.0.0.1 139 | dig +short @$NAMESERVER_IP 192-168-0-1.sslip.io 140 | # 192.168.0.1 141 | dig +short @$NAMESERVER_IP google.com 142 | # '', no answer, does not perform recursive queries 143 | ``` 144 | 145 | ### 6. Update Domain's Registrar's Nameserver Records 146 | 147 | Now that we're satisfied that our newly-deployed nameserver is functioning properly, we log into our registrar and update our domain's (sslip.io's) nameserver records to include our new nameserver. 148 | 149 | Note that we need to repeat this process at least one more time in order to have two nameservers (minimum requirement for a domain), and we must not forget to retire our old nameservers. 150 | 151 | ## BUGS 152 | 153 | * The BOSH packaging script uses `apt-get` and `yum` to install dependencies (boost). This is considered undesirable, for good reason. It's also wonderfully convenient. 154 | * PowerDNS is not built with database backends, only the *Pipe*, [*Remote*](https://doc.powerdns.com/md/authoritative/backend-remote/), and [*BIND*](https://doc.powerdns.com/md/authoritative/backend-bind/) backends. 155 | * This release has only been tested on a CentOS stemcell (not Ubuntu),only deployed with *bosh-init* (not with a BOSH director), only deployed to Amazon AWS (not vSphere or OpenStack). 156 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------