summaryrefslogtreecommitdiff
path: root/cloudinit/temp_utils.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-09-15 20:07:11 -0600
committerScott Moser <smoser@brickies.net>2017-09-18 20:37:10 -0400
commit7eb3460b0d6d3e362a246958a7ea0a9ee5d91d5e (patch)
tree8dc323976cd5ea55ebba37cf0462220dfa7c16df /cloudinit/temp_utils.py
parenteaadf52b1010cf189bde2a6abb3265b890f6d36d (diff)
downloadcloud-init-git-7eb3460b0d6d3e362a246958a7ea0a9ee5d91d5e.tar.gz
ec2: Fix maybe_perform_dhcp_discovery to use /var/tmp as a tmpdir
/run/cloud-init/tmp is on a filesystem mounted noexec, so running dchlient in Ec2Local during discovery breaks with 'Permission denied'. This branch allows us to run from a different tmp dir so we have exec rights. LP: #1717627
Diffstat (limited to 'cloudinit/temp_utils.py')
-rw-r--r--cloudinit/temp_utils.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/cloudinit/temp_utils.py b/cloudinit/temp_utils.py
index 0355f19d..5d7adf70 100644
--- a/cloudinit/temp_utils.py
+++ b/cloudinit/temp_utils.py
@@ -8,9 +8,10 @@ import tempfile
_TMPDIR = None
_ROOT_TMPDIR = "/run/cloud-init/tmp"
+_EXE_ROOT_TMPDIR = "/var/tmp/cloud-init"
-def _tempfile_dir_arg(odir=None):
+def _tempfile_dir_arg(odir=None, needs_exe=False):
"""Return the proper 'dir' argument for tempfile functions.
When root, cloud-init will use /run/cloud-init/tmp to avoid
@@ -20,8 +21,10 @@ def _tempfile_dir_arg(odir=None):
If the caller of this function (mkdtemp or mkstemp) was provided
with a 'dir' argument, then that is respected.
- @param odir: original 'dir' arg to 'mkdtemp' or other."""
-
+ @param odir: original 'dir' arg to 'mkdtemp' or other.
+ @param needs_exe: Boolean specifying whether or not exe permissions are
+ needed for tempdir. This is needed because /run is mounted noexec.
+ """
if odir is not None:
return odir
@@ -29,7 +32,9 @@ def _tempfile_dir_arg(odir=None):
if _TMPDIR:
return _TMPDIR
- if os.getuid() == 0:
+ if needs_exe:
+ tdir = _EXE_ROOT_TMPDIR
+ elif os.getuid() == 0:
tdir = _ROOT_TMPDIR
else:
tdir = os.environ.get('TMPDIR', '/tmp')
@@ -42,7 +47,8 @@ def _tempfile_dir_arg(odir=None):
def ExtendedTemporaryFile(**kwargs):
- kwargs['dir'] = _tempfile_dir_arg(kwargs.pop('dir', None))
+ kwargs['dir'] = _tempfile_dir_arg(
+ kwargs.pop('dir', None), kwargs.pop('needs_exe', False))
fh = tempfile.NamedTemporaryFile(**kwargs)
# Replace its unlink with a quiet version
# that does not raise errors when the
@@ -82,12 +88,14 @@ def tempdir(**kwargs):
def mkdtemp(**kwargs):
- kwargs['dir'] = _tempfile_dir_arg(kwargs.pop('dir', None))
+ kwargs['dir'] = _tempfile_dir_arg(
+ kwargs.pop('dir', None), kwargs.pop('needs_exe', False))
return tempfile.mkdtemp(**kwargs)
def mkstemp(**kwargs):
- kwargs['dir'] = _tempfile_dir_arg(kwargs.pop('dir', None))
+ kwargs['dir'] = _tempfile_dir_arg(
+ kwargs.pop('dir', None), kwargs.pop('needs_exe', False))
return tempfile.mkstemp(**kwargs)
# vi: ts=4 expandtab