Skip to content

fix(temp_utils): create scratch dir ancestors with mode 0700#6928

Open
abidedavana wants to merge 1 commit into
canonical:mainfrom
abidedavana:fix/temp-dir-mode-4189
Open

fix(temp_utils): create scratch dir ancestors with mode 0700#6928
abidedavana wants to merge 1 commit into
canonical:mainfrom
abidedavana:fix/temp-dir-mode-4189

Conversation

@abidedavana

Copy link
Copy Markdown

The exec-capable fallback scratch directories (/var/tmp/cloud-init and the /usr/lib/cloud-init/clouddir fallback used when /var/tmp is noexec) were created world-writable (0o1777) and left behind after cloud-init ran. All consumers run as root and the per-run mkdtemp children are already 0o700, so the ancestor need not be world-writable. Create it 0o700 instead, which also satisfies STIG UBTU-20-010427.

Fixes GH-4189

The exec-capable fallback scratch directories (/var/tmp/cloud-init and
the /usr/lib/cloud-init/clouddir fallback used when /var/tmp is noexec)
were created world-writable (0o1777) and left behind after cloud-init
ran. All consumers run as root and the per-run mkdtemp children are
already 0o700, so the ancestor need not be world-writable. Create it
0o700 instead, which also satisfies STIG UBTU-20-010427.

Fixes canonicalGH-4189
Comment thread cloudinit/temp_utils.py
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.

@abidedavana
abidedavana requested a review from holmanb July 18, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

World writable /usr/lib/cloud-init/clouddir should not be left behind

2 participants