Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extended_bin does not account for cookie being set in an extended vm.args #904

Open
artman41 opened this issue Jan 28, 2022 · 2 comments
Open

Comments

@artman41
Copy link

If I have 2 vm.args files where 1 of the files inherits the cookie from a different file:

file1.vm.args

-cookie test_cookie

file2.vm.args

-args_file file1.vm.args

Then the following line in extended_bin will not work and will instead use the cookie in ~/.erlang.cookie

# Extract the target cookie
# Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie
if [ -n "$RELX_COOKIE" ]; then
COOKIE="$RELX_COOKIE"
else
COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)"
DEFAULT_COOKIE_FILE="$HOME/.erlang.cookie"
if [ -z "$COOKIE_ARG" ]; then
if [ -f "$DEFAULT_COOKIE_FILE" ]; then
COOKIE="$(cat "$DEFAULT_COOKIE_FILE")"
else
echo "No cookie is set or found. This limits the scripts functionality, installing, upgrading, rpc and getting a list of versions will not work."
fi
else
# Extract cookie name from COOKIE_ARG
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
fi
fi

Even though the recursion is validated a few lines prior

# Check vm.args and other files referenced via -args_file parameters for:
# - nonexisting -args_files
# - circular dependencies of -args_files
# - relative paths in -args_file parameters
# - multiple/mixed occurrences of -name and -sname parameters
# - missing -name or -sname parameters
# If all checks pass, extract the target node name
set +e
TMP_NAME_ARG=$(awk 'function check_name(file)
{
# if file exists, then it should be readable
if (system("test -f "file) == 0 && system("test -r "file) != 0) {
print file" not readable"
exit 3
}
while ((getline line<file)>0) {
if (line~/^-args_file +/) {
gsub(/^-args_file +| *$/, "", line)
if (line in files) {
print "circular reference to "line" encountered in "file
exit 5
}
files[line]=line
check_name(line)
}
else if (line~/^-s?name +/) {
if (name!="") {
print "\""line"\" parameter found in "file" but already specified as \""name"\""
exit 2
}
name=line
}
}
}
BEGIN {
split("", files)
name=""
}
{
files[FILENAME]=FILENAME
check_name(FILENAME)
if (name=="") {
print "need to have exactly one of either -name or -sname parameters but none found"
exit 1
}
print name
exit 0
}' "$VMARGS_PATH")

@tsloughter
Copy link
Member

Thanks, yea, I guess we need to utilize the files array to check all of them for everything (not just COOKIE, but dist args too).

@artman41
Copy link
Author

artman41 commented Jan 28, 2022

@tsloughter just wrote this function which I'm going to put copy into our extended_bin after relx creates it, I'm thinking it can replace the call on line 728, any use?

function get_cookie() {
    local vm_args_file="$1";
    if [[ -z "$vm_args_file" ]]; then
        echo 'vm_args_file was empty!' >&2;
        exit 1;
    fi;
    local cookie="$(grep '^-setcookie' $vm_args_file)";
    for args_file in $(grep '^-args_file' $vm_args_file | awk  '{print $2}'); do
        local new_cookie="$(get_cookie $args_file)";
        if [[ -n "$new_cookie" ]]; then
            cookie=$new_cookie;
        fi;
    done;
    echo $cookie;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants