mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-27 13:28:01 +00:00
fix(cli): create role markers and the placement lock owner-only
py/overly-permissive-file on PR #625 (marker.py:60, placement.py:182): both files were created 0o644; only the owning user's pull, clean and list read them. The new tests set umask 0 and fail at 0o644. 🎯 Fix: 95 % 💥 Break: 3 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: ~100 % 🏆 Score: 92 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9c278ce46
commit
8c199a915d
4 files changed
+18
-2
No files matched your search
@@ -58,7 +58,7 @@ def write_marker(role: Path, group: str, provenance: str) -> None:
|
||||
elif mode is not None:
|
||||
marker.unlink()
|
||||
descriptor = os.open(
|
||||
marker, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o644
|
||||
marker, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o600
|
||||
)
|
||||
with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
|
||||
handle.write(marker_text(role.name, group, provenance))
|
||||
|
||||
@@ -179,7 +179,7 @@ def _check_role(group: str, staged: Path) -> None:
|
||||
def _locked(work_dir: Path) -> Iterator[None]:
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
lock = work_dir / LOCK_FILE
|
||||
descriptor = os.open(lock, os.O_RDONLY | os.O_CREAT | os.O_NOFOLLOW, 0o644)
|
||||
descriptor = os.open(lock, os.O_RDONLY | os.O_CREAT | os.O_NOFOLLOW, 0o600)
|
||||
try:
|
||||
try:
|
||||
fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -109,6 +110,13 @@ class TestWriteMarker(unittest.TestCase):
|
||||
self.assertTrue((self.role / MARKER_FILE).is_file())
|
||||
self.assertTrue(is_placed(self.role))
|
||||
|
||||
def test_the_marker_is_readable_by_its_owner_only_whatever_the_umask(self):
|
||||
self.addCleanup(os.umask, os.umask(0))
|
||||
write_marker(self.role, PLACED, ORIGIN)
|
||||
mode = (self.role / MARKER_FILE).stat().st_mode
|
||||
self.assertEqual(0o600, stat.S_IMODE(mode))
|
||||
self.assertTrue(is_placed(self.role))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
@@ -484,6 +486,12 @@ class TestClean(_PullFixture, unittest.TestCase):
|
||||
self.assertTrue((target / "keep.yml").is_file())
|
||||
self.assertEqual([], self.leftovers())
|
||||
|
||||
def test_the_lock_is_open_to_its_owner_only_whatever_the_umask(self):
|
||||
self.addCleanup(os.umask, os.umask(0))
|
||||
clean(self.roles, self.work)
|
||||
mode = (self.work / placement.LOCK_FILE).stat().st_mode
|
||||
self.assertEqual(0o600, stat.S_IMODE(mode))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user