On Feb 15, 9:14 am, Peter Valdemar Mørch <[email protected]> wrote:
> Thanks, John, for your reply also on this matter!
>
> On Feb 15, 3:16 pm, jcbollinger <[email protected]> wrote:
>
> > It seems like this should do the trick:
> > puppet -e '$v="xyz" exec { f: command => "/bin/echo v is \'$v\'",
> > logoutput => true }'
>
> :-) Yeah, that would take care of these particular instances.
>
> Now imagine this (in a proper manifest file, so we take shell escaping
> out of the picture):
>
> # This is identical to your proposal, right? :
> exec { f:
>     command => "/bin/echo v is '$v'",
>     logoutput => true
>
> }
>
> Now, how about:
> # double-quote, single-quote, double-quote: This causes an error
> $v = "'"
>
> or
>
> # This causes an error too
> $v = "x'y'z\n@$\"{"
>
> or
>
> # This does _bad_ stuff
> $v = "';rm -rf /etc";
>
> My point is, that unless there is some support in puppet for escaping
> $v, there is *no* way to use $v reliably in an exec command string,
> given an arbitrary $v. For any quoting suggestion you come up with, I
> would always be able to come up with a counter-example of $v so that /
> etc/passwd gets sent to hackers-r-us.dk.


Fair enough.  You are correct.


> Unless puppet supports escaping somehow. Which it looks like it
> doesn't. Which means, that I have to check all facts and input to
> puppet outside of puppet, or my custom facts have to be sanitised or
> pre-escaped before puppet sees them, which is a shame! :-(


You are welcome to write such a function, of course, either for
private use or to contribute to the project.  Given that Ruby already
has support for what you want, it should be dead simple to wrap it
into a Puppet function.


> I'm surprised I can't find an equivalent of Perl's quotemeta or Ruby's
> Shellwords.escape. Invaluable for _safe_ shell stuff...


Pretty much anything you can do with Ruby you can do in Puppet via
templates.  Some such things would be pretty nasty hacks, but not so
much something like this:

$v = $::some_unsafe_value
$v_safe = inline_template("<% require 'shellwords' %><%=
shellwords.escape(v) %>")

Overall, however, I suspect that you are probing a rather uncommon use
case.  It is rare that one would want to use a fact value to construct
an Exec command, especially given that Execs serve as a last resort
anyway.  Even if we stipulate that an Exec will be used to perform
some otherwise-unsupported task, it is a symptom of questionable
manifest design if the the command needs to rely on node facts.

Above all, if an adversary has managed to subvert the Puppet agent on
some node, so as to be able to control the fact values submitted to
the Puppetmaster, then the battle is already lost.  Rather than craft
troublesome fact values, such an adversary could more easily just
directly make the agent do whatever dirty deed he wanted.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to