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

consul-template crashes because it assumes sh is installed and added to the command before running it #1508

Closed
bbourbie opened this issue Aug 20, 2021 · 4 comments · Fixed by #1509

Comments

@bbourbie
Copy link

Hello,

We are running consul-template in a docker image named google distroless and for security reasons, there are no shell installed.

Last version of consule-template that was working well was 0.25.2, when I install consule-template 0.27.0, we now have the crash

2021-08-20T19:03:03.260Z [DEBUG] (runner) all templates rendered
2021-08-20T19:03:03.260Z [INFO] (child) spawning: sh -c /app/monitor -listen :8443 -metrics.path /metrics
2021-08-20T19:03:03.261Z [ERR] (cli) child: exec: "sh": executable file not found in $PATH

the command line is

 consul-template  -config /home/splunk/config.hcl  -exec /app/monitor -listen :8443 -metrics.path /metrics

A quick look at the source code shows me a prepCommand in runner.go and nothing to change that preCommand.

I don't think it's correct to assume there's a sh installed, I don't want to add sh to my docker image for security reasons

@eikenb

@eikenb
Copy link
Contributor

eikenb commented Aug 20, 2021

Hey @bbourbie, sorry for your troubles. I know the problem and have an idea for a pretty quick fix.

The problem is that earlier versions used a shell parsing library that was a constant source of bugs and, after a review, was found to mishandle quoting at a base level requiring a large rewrite to fix. I decided to skip trying to parse shell command lines and call the system shell with the configured command passed to it, leaving the shell parsing to the shell. I made this the only way code was executed on *nix systems.

For Windows I had it only accept single argument commands as it doesn't have a shell. I could make the change pretty easily to expand that to all environments, that is that if the configured command is a single command (no spaces/tabs/etc) then it would be run directly w/o the underlying shell call.

This is a small change that shouldn't impact anyone's use, but would fix your case. What do you think? I think I could add this pretty speedily and I'm already looking to do a release soon due to a security issue...

@eikenb eikenb added the bug label Aug 20, 2021
@eikenb eikenb added this to the 0.27.1 milestone Aug 20, 2021
eikenb added a commit that referenced this issue Aug 20, 2021
Instead of always using `sh -c` to run command lines on *nix check if it
is a single command (no spaces) and, if so, run that command directly.

This will give users on systems without 'sh' a way to run their commands.

Fixes #1508
@eikenb
Copy link
Contributor

eikenb commented Aug 20, 2021

Hey @bbourbie .. I just posted the PR to make this change. I think it is probably a good general fix for cases like this but I'd like to hear back that it does address your case before going forward with it.

Thanks.

@bbourbie
Copy link
Author

Thank you for your fast responses!! Let me review the PR.

eikenb added a commit that referenced this issue Aug 24, 2021
Instead of always using `sh -c` to run command lines on *nix check if it
is a single command (no spaces) and, if so, run that command directly.

This will give users on systems without 'sh' a way to run their commands.

Fixes #1508
eikenb added a commit that referenced this issue Aug 30, 2021
Instead of always using `sh -c` to run command lines on *nix check if it
is a single command (no spaces) and, if so, run that command directly.

This will give users on systems without 'sh' a way to run their commands.

Fixes #1508
@eikenb
Copy link
Contributor

eikenb commented Aug 30, 2021

Hey @bbourbie,

I've made a few updates to the PR and it has gone through internal review. I'm ready to merge and release 0.27.1 with the fixes but wanted to let you have a chance to review it and verify that it would address your needs.

Thanks.

eikenb added a commit that referenced this issue Sep 7, 2021
Instead of always using `sh -c` to run command lines on *nix check if it
is a single command (no spaces) and, if so, run that command directly.

This will give users on systems without 'sh' a way to run their commands.

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

Successfully merging a pull request may close this issue.

2 participants