Remove env changing support in daemon mode

It introduced a security issue since these env vars are not filtered by
either sudo or rootwrap. This change reverts changes in common code from
Iace26738f910a18a5d1d3479fad949027e5a3816 (most of them)
and purges ability to specify env in arguments for daemon.

Environment should be provided to callee process using EnvFilter and
/usr/bin/env.

Change-Id: Iafbc493d6158f3ea85b3d74cb37c29e161a1099f
This commit is contained in:
Yuriy Taraday 2015-03-04 14:50:25 +03:00
parent 8472c5e363
commit f485b93f47
7 changed files with 10 additions and 33 deletions

View File

@ -338,8 +338,6 @@ The class provides one method ``execute`` with following arguments:
* ``userargs`` - list of command line arguments that are to be used to run the * ``userargs`` - list of command line arguments that are to be used to run the
command; command;
* ``env`` - dict of environment variables to be set for it (by default it's an
empty dict, so all environment variables are stripped);
* ``stdin`` - string to be passed to standard input of child process. * ``stdin`` - string to be passed to standard input of child process.
The method returns 3-tuple containing: The method returns 3-tuple containing:

View File

@ -127,12 +127,12 @@ class Client(object):
self._initialize() self._initialize()
return self._proxy return self._proxy
def execute(self, cmd, env=None, stdin=None): def execute(self, cmd, stdin=None):
self._ensure_initialized() self._ensure_initialized()
proxy = self._proxy proxy = self._proxy
retry = False retry = False
try: try:
res = proxy.run_one_command(cmd, env, stdin) res = proxy.run_one_command(cmd, stdin)
except (EOFError, IOError): except (EOFError, IOError):
retry = True retry = True
# res can be None if we received final None sent by dying server thread # res can be None if we received final None sent by dying server thread
@ -140,5 +140,5 @@ class Client(object):
# at this point. # at this point.
if retry or res is None: if retry or res is None:
proxy = self._restart(proxy) proxy = self._restart(proxy)
res = proxy.run_one_command(cmd, env, stdin) res = proxy.run_one_command(cmd, stdin)
return res return res

View File

@ -43,16 +43,12 @@ class RootwrapClass(object):
self.config = config self.config = config
self.filters = filters self.filters = filters
def run_one_command(self, userargs, env=None, stdin=None): def run_one_command(self, userargs, stdin=None):
if env is None:
env = {}
obj = wrapper.start_subprocess( obj = wrapper.start_subprocess(
self.filters, userargs, self.filters, userargs,
exec_dirs=self.config.exec_dirs, exec_dirs=self.config.exec_dirs,
log=self.config.use_syslog, log=self.config.use_syslog,
close_fds=True, close_fds=True,
env=env,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)

View File

@ -57,9 +57,9 @@ class CommandFilter(object):
return ['sudo', '-u', self.run_as, to_exec] + userargs[1:] return ['sudo', '-u', self.run_as, to_exec] + userargs[1:]
return [to_exec] + userargs[1:] return [to_exec] + userargs[1:]
def get_environment(self, userargs, env=None): def get_environment(self, userargs):
"""Returns specific environment to set, None if none.""" """Returns specific environment to set, None if none."""
return env return None
class RegExpFilter(CommandFilter): class RegExpFilter(CommandFilter):
@ -277,10 +277,8 @@ class EnvFilter(CommandFilter):
to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path
return [to_exec] + self.exec_args(userargs)[1:] return [to_exec] + self.exec_args(userargs)[1:]
def get_environment(self, userargs, env=None): def get_environment(self, userargs):
if env is None: env = os.environ.copy()
env = os.environ
env = env.copy()
# ignore leading 'env' # ignore leading 'env'
if userargs[0] == 'env': if userargs[0] == 'env':

View File

@ -162,13 +162,6 @@ class RootwrapDaemonTest(_FunctionalBase, testtools.TestCase):
# Expect client to succesfully restart daemon and run simple request # Expect client to succesfully restart daemon and run simple request
self.test_run_once() self.test_run_once()
def test_env_setting(self):
code, out, err = self.execute(['sh', '-c', 'echo $SOMEVAR'],
env={'SOMEVAR': 'teststr'})
self.assertEqual(0, code)
self.assertEqual(b'teststr\n', out)
self.assertEqual(b'', err)
def _exec_thread(self, fifo_path): def _exec_thread(self, fifo_path):
try: try:
# Run a shell script that signals calling process through FIFO and # Run a shell script that signals calling process through FIFO and

View File

@ -190,8 +190,7 @@ def _getlogin():
os.getenv('LOGNAME')) os.getenv('LOGNAME'))
def start_subprocess(filter_list, userargs, exec_dirs=[], log=False, def start_subprocess(filter_list, userargs, exec_dirs=[], log=False, **kwargs):
env=None, **kwargs):
filtermatch = match_filter(filter_list, userargs, exec_dirs) filtermatch = match_filter(filter_list, userargs, exec_dirs)
command = filtermatch.get_command(userargs, exec_dirs) command = filtermatch.get_command(userargs, exec_dirs)
@ -202,6 +201,6 @@ def start_subprocess(filter_list, userargs, exec_dirs=[], log=False,
obj = subprocess.Popen(command, obj = subprocess.Popen(command,
preexec_fn=_subprocess_setup, preexec_fn=_subprocess_setup,
env=filtermatch.get_environment(userargs, env=env), env=filtermatch.get_environment(userargs),
**kwargs) **kwargs)
return obj return obj

View File

@ -166,13 +166,6 @@ class RootwrapDaemonTest(_FunctionalBase, testtools.TestCase):
# Expect client to succesfully restart daemon and run simple request # Expect client to succesfully restart daemon and run simple request
self.test_run_once() self.test_run_once()
def test_env_setting(self):
code, out, err = self.execute(['sh', '-c', 'echo $SOMEVAR'],
env={'SOMEVAR': 'teststr'})
self.assertEqual(0, code)
self.assertEqual(b'teststr\n', out)
self.assertEqual(b'', err)
def _exec_thread(self, fifo_path): def _exec_thread(self, fifo_path):
try: try:
# Run a shell script that signals calling process through FIFO and # Run a shell script that signals calling process through FIFO and