summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Mueller <dirk@dmllr.de>2013-06-18 19:37:34 +0200
committerDirk Mueller <dirk@dmllr.de>2013-06-28 08:45:27 +0200
commit233baa20f5f7c83c20c410da10861ea0fa6a0307 (patch)
tree8e03a6185ba8655944f97ecf97b4ed8d82365605
parent7b7566bac8e2df14e17631980a7fbf2df68cf116 (diff)
downloadoslo-233baa20f5f7c83c20c410da10861ea0fa6a0307.zip
oslo-233baa20f5f7c83c20c410da10861ea0fa6a0307.tar.gz
oslo-233baa20f5f7c83c20c410da10861ea0fa6a0307.tar.xz
Handle empty PATH environment variable
In locked down environments, PATH might be unavailable when running rootwrap. Change-Id: Ia55514a7d69ab26c2bcf5d1839da1d36aaf46ebc
-rw-r--r--openstack/common/rootwrap/filters.py3
-rw-r--r--openstack/common/rootwrap/wrapper.py4
-rw-r--r--tests/unit/test_rootwrap.py10
3 files changed, 13 insertions, 4 deletions
diff --git a/openstack/common/rootwrap/filters.py b/openstack/common/rootwrap/filters.py
index dfec412..b40fdfd 100644
--- a/openstack/common/rootwrap/filters.py
+++ b/openstack/common/rootwrap/filters.py
@@ -217,7 +217,8 @@ class KillFilter(CommandFilter):
return (os.path.isabs(command) and
kill_command == os.path.basename(command) and
- os.path.dirname(command) in os.environ['PATH'].split(':'))
+ os.path.dirname(command) in os.environ.get('PATH', ''
+ ).split(':'))
class ReadFileFilter(CommandFilter):
diff --git a/openstack/common/rootwrap/wrapper.py b/openstack/common/rootwrap/wrapper.py
index df1a9f4..6bd829e 100644
--- a/openstack/common/rootwrap/wrapper.py
+++ b/openstack/common/rootwrap/wrapper.py
@@ -46,8 +46,10 @@ class RootwrapConfig(object):
if config.has_option("DEFAULT", "exec_dirs"):
self.exec_dirs = config.get("DEFAULT", "exec_dirs").split(",")
else:
+ self.exec_dirs = []
# Use system PATH if exec_dirs is not specified
- self.exec_dirs = os.environ["PATH"].split(':')
+ if "PATH" in os.environ:
+ self.exec_dirs = os.environ['PATH'].split(':')
# syslog_log_facility
if config.has_option("DEFAULT", "syslog_log_facility"):
diff --git a/tests/unit/test_rootwrap.py b/tests/unit/test_rootwrap.py
index 02789ec..6e1e6e6 100644
--- a/tests/unit/test_rootwrap.py
+++ b/tests/unit/test_rootwrap.py
@@ -178,8 +178,9 @@ class RootwrapTestCase(utils.BaseTestCase):
# Filter shouldn't be able to find binary in $PATH, so fail
with fixtures.EnvironmentVariable("PATH", "/foo:/bar"):
self.assertFalse(f.match(usercmd))
- pass
-
+ # ensure that unset $PATH is not causing an exception
+ with fixtures.EnvironmentVariable("PATH"):
+ self.assertFalse(f.match(usercmd))
finally:
# Terminate the "cat" process and wait for it to finish
p.terminate()
@@ -314,6 +315,11 @@ class RootwrapTestCase(utils.BaseTestCase):
config = wrapper.RootwrapConfig(raw)
self.assertEqual(config.filters_path, ['/a', '/b'])
self.assertEqual(config.exec_dirs, os.environ["PATH"].split(':'))
+
+ with fixtures.EnvironmentVariable("PATH"):
+ c = wrapper.RootwrapConfig(raw)
+ self.assertEqual(c.exec_dirs, [])
+
self.assertFalse(config.use_syslog)
self.assertEqual(config.syslog_log_facility,
logging.handlers.SysLogHandler.LOG_SYSLOG)