Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudinit/temp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _tempfile_dir_arg(odir=None, needs_exe: bool = False):
tdir = get_tmp_ancestor(odir, needs_exe)
if not os.path.isdir(tdir):
os.makedirs(tdir)
os.chmod(tdir, 0o1777)
os.chmod(tdir, 0o700)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the sticky bit removed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sticky bit only matters when multiple users can write to a dir , it stops them deleting/renaming each other's files, like in /tmp. with 0700 root is the only writer, so there's nothing left for it to protect. happy to keep it (0o1700) if you'd prefer, but on a root-only dir it'd be a no-op.


if needs_exe:
if util.has_mount_opt(tdir, "noexec"):
Expand Down
20 changes: 20 additions & 0 deletions tests/unittests/test_temp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Tests for cloudinit.temp_utils"""

import os
import stat
from tempfile import gettempdir

import pytest
Expand Down Expand Up @@ -120,6 +121,25 @@ def fake_mkstemp(*args, **kwargs):
assert "/fake/return/path" == retval
assert [{"dir": "/run/cloud-init/tmp"}] == calls

def test_mkdtemp_creates_missing_ancestor_not_world_writable(
self, tmp_path
):
"""mkdtemp creates missing ancestor dirs with mode 0o700 (GH-4189)."""
ancestor = str(tmp_path / "scratch")
retval = mkdtemp(dir=ancestor)
assert os.path.isdir(retval)
assert 0o700 == stat.S_IMODE(os.stat(ancestor).st_mode)

def test_mkstemp_creates_missing_ancestor_not_world_writable(
self, tmp_path
):
"""mkstemp creates missing ancestor dirs with mode 0o700 (GH-4189)."""
ancestor = str(tmp_path / "scratch")
fd, retval = mkstemp(dir=ancestor)
os.close(fd)
assert os.path.isfile(retval)
assert 0o700 == stat.S_IMODE(os.stat(ancestor).st_mode)

def test_tempdir_error_suppression(self):
"""test tempdir suppresses errors during directory removal."""

Expand Down
Loading