From d80e72dfcded1473be7bee042ef5392c6bcd4350 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 23 Oct 2015 13:42:25 +0100 Subject: [PATCH] [proxy] dynamically mount -H dirs into the proxy when launching This lets you use -H unix://*.sock outside /var/run/weave. Using a socket directly in /var/run (i.e. /var/run/foo.sock), will reintroduce the bug with namespaces not being GCed, so that is a warning. --- ...onfig_test.sh => 690_proxy_config_test.sh} | 7 ++++- weave | 29 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) rename test/{690_proxy_autoconfig_test.sh => 690_proxy_config_test.sh} (81%) diff --git a/test/690_proxy_autoconfig_test.sh b/test/690_proxy_config_test.sh similarity index 81% rename from test/690_proxy_autoconfig_test.sh rename to test/690_proxy_config_test.sh index ce6e18b2..6293a3f5 100755 --- a/test/690_proxy_autoconfig_test.sh +++ b/test/690_proxy_config_test.sh @@ -2,7 +2,7 @@ . ./config.sh -start_suite "Boot the proxy should only listen on client's interface" +start_suite "Various launch-proxy configurations" # Booting it over unix socket listens on unix socket run_on $HOST1 COVERAGE=$COVERAGE sudo -E weave launch-proxy @@ -22,6 +22,11 @@ assert_raises "run_on $HOST1 sudo docker -H unix:///var/run/weave/weave.sock ps" assert_raises "proxy docker_on $HOST1 ps" weave_on $HOST1 stop-proxy +# Booting it with -H outside /var/run/weave, still works +socket="$(mktemp -d)/weave.sock" +weave_on $HOST1 launch-proxy -H unix://$socket +assert_raises "run_on $HOST1 sudo docker -H unix:///$socket ps" 0 +weave_on $HOST1 stop-proxy # Booting it over tls errors assert_raises "DOCKER_CLIENT_ARGS='--tls' weave_on $HOST1 launch-proxy" 1 diff --git a/weave b/weave index 248d9df5..02231801 100755 --- a/weave +++ b/weave @@ -1266,17 +1266,36 @@ tls_arg() { PROXY_ARGS="$PROXY_ARGS $1 /home/weave/tls/$3.pem" } +# TODO: Handle relative paths for args +# TODO: Handle args with spaces +host_arg() { + PROXY_HOST="$1" + if [ "$PROXY_HOST" != "${PROXY_HOST#unix://}" ]; then + host=$(dirname ${PROXY_HOST#unix://}) + if [ "$host" = "${host#/}" ]; then + echo "When launching the proxy, unix sockets must be specified as an absolute path." >&2 + exit 1 + fi + if [ "$host" = "/var/run" ]; then + echo "WARNING: When launching the proxy, unix sockets directly in /var/run can lead to a bug with net namespace cleanup." >&2 + echo "For more info, see https://github.com/weaveworks/weave/issues/1455" >&2 + fi + PROXY_VOLUMES="$PROXY_VOLUMES -v $host:/host$host" + PROXY_ARGS="$PROXY_ARGS -H /host$host/$(basename ${PROXY_HOST#unix://})" + else + PROXY_ARGS="$PROXY_ARGS -H $1" + fi +} + proxy_parse_args() { while [ $# -gt 0 ]; do case "$1" in -H) - PROXY_HOST="$2" - PROXY_ARGS="$PROXY_ARGS $1 $2" + host_arg "$2" shift ;; -H=*) - PROXY_HOST="${1#*=}" - PROXY_ARGS="$PROXY_ARGS $1" + host_arg "${1#*=}" ;; -tls|--tls|-tlsverify|--tlsverify) PROXY_TLS_ENABLED=1 @@ -1333,7 +1352,7 @@ proxy_args() { PROXY_HOST="tcp://0.0.0.0:12375" ;; esac - PROXY_ARGS="$PROXY_ARGS -H $PROXY_HOST" + host_arg "$PROXY_HOST" fi }