From 8a914ddb04cdbe15034c9cb18d2daa6c8d46f313 Mon Sep 17 00:00:00 2001 From: Will Holley Date: Wed, 11 Dec 2019 12:43:41 +0000 Subject: Sanitize `ERL_FLAGS` in remsh If an environment uses `ERL_FLAGS` to configure CouchDB it can conflict with the parameters passed to `erl` in `remsh`. This was observed in a containerized CouchDB cluster, as the CouchDB Dockerfile uses `ERL_FLAGS` to set the node name and cookie, as does the Helm chart. When running `remsh` in these containers, additional `-name` and `-setcookie` parameters were silently added to the `erl` invocation, preventing the shell from connecting to the CouchDB node. This commit scrubs any `-name` or `-setcookie` flags from ERL_FLAGS before invoking erl. --- rel/overlay/bin/remsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rel/overlay/bin/remsh b/rel/overlay/bin/remsh index 963c16a10..2d28a8c85 100755 --- a/rel/overlay/bin/remsh +++ b/rel/overlay/bin/remsh @@ -71,6 +71,10 @@ if [ ! -z "$VERBOSE" ]; then set -x fi -exec "$BINDIR/erl" -boot "$ROOTDIR/releases/$APP_VSN/start_clean" \ +# If present, strip -name or -setcookie from ERL_FLAGS +# to avoid conflicts with the cli parameters +ERL_FLAGS_CLEAN=$(echo "$ERL_FLAGS" | sed 's/-setcookie \([^ ][^ ]*\)//g' | sed 's/-name \([^ ][^ ]*\)//g') + +exec env ERL_FLAGS="$ERL_FLAGS_CLEAN" "$BINDIR/erl" -boot "$ROOTDIR/releases/$APP_VSN/start_clean" \ -name remsh$$@$LHOST -remsh $NODE -hidden -setcookie $COOKIE \ "$@" -- cgit v1.2.1 From df5b31171cfafd5ac463f6786452bb0b4fa5f5e9 Mon Sep 17 00:00:00 2001 From: Will Holley Date: Wed, 11 Dec 2019 14:56:27 +0000 Subject: Remsh: attempt to auto-locate Erlang cookie Attempts to find the Erlang cookie from ERL_FLAGS or the standard vm.args location. If not present, fall back to the default (monster). --- rel/overlay/bin/remsh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rel/overlay/bin/remsh b/rel/overlay/bin/remsh index 2d28a8c85..2ac421b07 100755 --- a/rel/overlay/bin/remsh +++ b/rel/overlay/bin/remsh @@ -23,8 +23,18 @@ BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin PROGNAME=${0##*/} VERBOSE="" NODE="couchdb@127.0.0.1" -COOKIE=monster LHOST=127.0.0.1 +VM_ARGS=$COUCHDB_BIN_DIR/../etc/vm.args + +# If present, extract cookie from ERL_FLAGS +# This is used by the CouchDB Dockerfile and Helm chart +COOKIE=$(echo "$ERL_FLAGS" | sed 's/^.*setcookie \([^ ][^ ]*\).*$/\1/g') +if test -f "$VM_ARGS"; then +# else attempt to extract from vm.args + VM_ARGS_COOKIE=$(awk '$1=="-setcookie"{print $2}' "$VM_ARGS") + COOKIE="${COOKIE:-$VM_ARGS_COOKIE}" +fi +COOKIE="${COOKIE:-monster}" printHelpAndExit() { echo "Usage: ${PROGNAME} [OPTION]... [-- ]" -- cgit v1.2.1