bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.96k stars 397 forks source link

Spaces in cookie in vm.args makes things bad. #504

Closed cdegroot closed 5 years ago

cdegroot commented 6 years ago

Steps to reproduce

Use -setcookie something with spaces or -setcookie "something with spaces" and run describe on the resulting release - only the first word is taken, due to

https://github.com/bitwalker/distillery/blob/master/priv/libexec/config.sh#L200

Two solutions:

  1. Document this behaviour

  2. Switch to something that won't just take the first word, like:

COOKIE="$(echo "$COOKIE_ARG" | sed 's/\s*-setcookie\s*//')"

The latter solution has its own problems because vm.args requires quoting:

-setcookie "my awesome spaced out cookie"

and the above sed construct does not remove these quotes. That's simple enough to add, of course, but then you get in the hot waters of escaped double quotes inside the cookie... As I don't know enough about what Erlang does with vm.args, I've elected to open an Issue instead of a PR and let smarter people than I decide.

evadne commented 6 years ago

Distillery now requires Bash, right

#!/usr/bin/env bash

VMARGS_PATH="$1"
VM_ARGS="$(cat "$VMARGS_PATH")"
COOKIE_REGEX="^-setcookie (.+)$"

if [[ "$VM_ARGS" =~ $COOKIE_REGEX ]]; then
  echo "Cookie - ${BASH_REMATCH[1]} -"
fi
$ cat vmargs-1
-setcookie foobar

$ cat vmargs-2
-setcookie foo bar baz

./test.sh vmargs-1
Cookie - foobar -

$ ./test.sh vmargs-2
Cookie - foo bar baz -
bitwalker commented 6 years ago

Thanks @evadne! I'll have to run some experiments to see if we run into any issues with expansions down the line - setting COOKIE is the easy part, the problem is what happens when COOKIE is expanded, which with some env vars in these scripts can happen more than once - word splitting can cause some real pain in those cases.