From 3b1e0ceb51551e745a436c7de7b8d3fd5c908eeb Mon Sep 17 00:00:00 2001 From: Alex Vidal Date: Tue, 24 Feb 2015 16:00:36 -0600 Subject: [PATCH 1/2] Support xip.io wildcard DNS as a VHOST http://xip.io xip.io is a service by Basecamp that provides a wildcard DNS service on the public internet. Any .xip.io will return a DNS response for the IP address, same with ..xip.io. The domains plugin in dokku uses a regex to match IP4 and IP6 addresses in the VHOST file, and disables VHOST support if found. This PR changes those patterns to require that the VHOST entry **ends with** the IP address. This is a gist where my VHOST setting is "127.0.0.1.xip.io" that demonstrates the original output, linked directly to the line from `plugins/domains/commands`: https://gist.github.com/anonymous/c529177f20b36beda80d#file-debug-log-L1373 --- plugins/domains/commands | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/domains/commands b/plugins/domains/commands index 771bebe41..c479a63f3 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -17,6 +17,11 @@ RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: f RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 +# Ensure the ip address continues to the end of the line +# Fixes using a wildcard dns service such as xip.io which allows for *..xip.io +RE_IPV4="${RE_IPV4}\$" +RE_IPV6="${RE_IPV6}\$" + case "$1" in domains) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 From c83fbad2051667d7f9766393c74eeafe9cee8223 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 19 Mar 2015 11:21:48 -0700 Subject: [PATCH 2/2] xip.io style vhosts with tests. closes #1005 --- plugins/nginx-vhosts/bind-external-ip | 6 ++++++ tests/unit/ports.bats | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/plugins/nginx-vhosts/bind-external-ip b/plugins/nginx-vhosts/bind-external-ip index 422ddc2f0..40ba4c4e8 100755 --- a/plugins/nginx-vhosts/bind-external-ip +++ b/plugins/nginx-vhosts/bind-external-ip @@ -19,6 +19,12 @@ RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: f RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 + +# Ensure the ip address continues to the end of the line +# Fixes using a wildcard dns service such as xip.io which allows for *..xip.io +RE_IPV4="${RE_IPV4}\$" +RE_IPV6="${RE_IPV6}\$" + [[ -f "$DOKKU_ROOT/VHOST" ]] && GLOBAL_VHOST=$(< "$DOKKU_ROOT/VHOST") if [[ -n "$NO_VHOST" ]]; then diff --git a/tests/unit/ports.bats b/tests/unit/ports.bats index 3612c5932..b0d3c728c 100644 --- a/tests/unit/ports.bats +++ b/tests/unit/ports.bats @@ -116,3 +116,13 @@ teardown() { echo "status: "$status assert_success } + +@test "port exposure (xip.io style hostnames)" { + echo "127.0.0.1.xip.io" > "$DOKKU_ROOT/VHOST" + deploy_app + + run bash -c "response=\"$(curl -s -S my-cool-guy-test-app.127.0.0.1.xip.io)\"; echo \$response; test \"\$response\" == \"nodejs/express\"" + echo "output: "$output + echo "status: "$status + assert_success +}