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

Quotes in sudo commands should be escaped #99

Closed
mik01aj opened this issue Aug 5, 2015 · 9 comments
Closed

Quotes in sudo commands should be escaped #99

mik01aj opened this issue Aug 5, 2015 · 9 comments
Labels

Comments

@mik01aj
Copy link

mik01aj commented Aug 5, 2015

In my flightplan, when I do:

remote.sudo('node -e \'console.log("hello")\'', {user: 'blabla'})

I get an error:

remote $ sudo -u blabla -i bash -c 'node -e 'console.log("hello")''
remote > bash: -c: line 0: syntax error near unexpected token `('
remote > bash: -c: line 0: `sudo -u blabla -i bash -c 'node -e 'console.log("hello")'''

The same command (node -e 'console.log("hello")'), when I try it in bash is valid and works fine.

@mik01aj
Copy link
Author

mik01aj commented Aug 13, 2015

This is actually surprisingly hard. Bash sucks...

http://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings

@pstadler pstadler added the bug label Aug 28, 2015
@pstadler
Copy link
Owner

This is indeed rather hard. I wrote quite a lot of shell scripts, maybe I can tackle this at some point.

@qfox
Copy link

qfox commented Aug 29, 2015

This would be enough:

function escapeShellArg (cmd) {
    return '\'' + cmd.replace(/\'/g, "'\\''") + '\'';
}

Ref: http://stackoverflow.com/questions/1779858/how-do-i-escape-a-string-for-a-shell-command-in-node

@pstadler
Copy link
Owner

pstadler commented Oct 6, 2015

@zxqfox this seems to be the correct solution indeed. Will try to get a new release ready soon.

@cmckendry
Copy link

It looks like the fix for this (specifically the removal of the -c flag) has introduced an error in a portion of our deployment process that uses the sudo functionality to run "chown" on the remote machine. Code is as follows:

remote.sudo("chown -R nobody:nobody " + rootDir + "/application/config/", {user: sudoUser});

In 0.6.4 this works as expected. In 0.6.5 it fails with a No such file or directory error. Is there a change to the format that needs to be made on our side in order to support the new sudo method?

@pstadler
Copy link
Owner

pstadler commented Oct 6, 2015

Hey @cmckendry what's rootDir? I suspect it breaks because you're using a relative path?

@pstadler
Copy link
Owner

pstadler commented Oct 6, 2015

I could verify the error, please ugprade to 0.6.6 which reverts the sudo command to the old behavior.

Thanks for reporting.

@pstadler
Copy link
Owner

pstadler commented Oct 6, 2015

@cmckendry
Copy link

Confirmed, that fixed it. Thanks!

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

No branches or pull requests

4 participants