Fix running complex command lines via bootstrap_host_exec

This currently uses eval $* which doesn't correctly handle complex args
e.g with complex quoting, subshells etc..

exec "$@" is the correct command to run.

"$@" is special in bash and expands to "$1" "$2" "$3" etc... to pass through
command line args verbatim.  Also exec accepts a list of args while eval
accepts a string.

However fixing it may break command strings that happened to work previously.
So this change deprecates bootstrap_host_exec, replacing it with
bootstrap_host_only_eval and bootstrap_host_only_exec.

Change-Id: I993c3354a3d9fd392fa4fa2e3b5b8ed421487a88
Closes-bug: 1718914
This commit is contained in:
Oliver Walsh 2017-09-22 11:56:17 +01:00
parent 6b3d6b94fb
commit 69265fcebb
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
SERVICE_NAME=$1
if [ -z "$SERVICE_NAME" ]; then
echo "Please supply a valid service name."
exit 1
fi
shift
if [ -z "$*" ]; then
echo "Please supply a valid 'command' to run as an argument."
exit 1
fi
HOSTNAME=$(/bin/hostname -s)
SERVICE_NODEID=$(/bin/hiera -c /etc/puppet/hiera.yaml "${SERVICE_NAME}_short_bootstrap_node_name")
if [[ "$HOSTNAME" == "$SERVICE_NODEID" ]]; then
eval $*
else
echo "Skipping execution since this is not the bootstrap node for this service."
fi

View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
SERVICE_NAME=$1
if [ -z "$SERVICE_NAME" ]; then
echo "Please supply a valid service name."
exit 1
fi
shift
if [ -z "$*" ]; then
echo "Please supply a valid 'command' to run as an argument."
exit 1
fi
HOSTNAME=$(/bin/hostname -s)
SERVICE_NODEID=$(/bin/hiera -c /etc/puppet/hiera.yaml "${SERVICE_NAME}_short_bootstrap_node_name")
if [[ "$HOSTNAME" == "$SERVICE_NODEID" ]]; then
exec "$@"
else
echo "Skipping execution since this is not the bootstrap node for this service."
fi

View File

@ -24,6 +24,8 @@ packages =
scripts =
scripts/bootstrap_host_exec
scripts/bootstrap_host_only_eval
scripts/bootstrap_host_only_exec
scripts/create_freeipa_enroll_envfile.py
scripts/pull-puppet-modules
scripts/run-validation