Skip to content

The agent that grows with you

Revert "fix(gateway): refuse a hardlinked gateway.lock whatever its mode"

Teknium416c7705f32a
diff --git a/gateway/runtime_ownership.py b/gateway/runtime_ownership.py
index 723171a64f5..cebb3962124 100644
--- a/gateway/runtime_ownership.py
+++ b/gateway/runtime_ownership.py
@@ -31,11 +31,15 @@ def tighten_lock_mode(fd: int) -> None:
chmodded, through the already-open NOFOLLOW descriptor (no path race); anything else is refused.
"""
info = os.fstat(fd)
- if not stat.S_ISREG(info.st_mode) or (os.name != 'nt' and info.st_uid != os.getuid()): # windows-footgun: ok — POSIX only
+ if os.name == 'nt':
+ if not stat.S_ISREG(info.st_mode):
+ raise PermissionError('unsafe gateway lock owner or type')
+ return
+ if not stat.S_ISREG(info.st_mode) or info.st_uid != os.getuid(): # windows-footgun: ok — POSIX branch
raise PermissionError('unsafe gateway lock owner or type')
- if info.st_nlink != 1: # a second name (cp -al / rsync --link-dest clone) shares the record
- raise PermissionError('unsafe gateway lock link count')
- if os.name != 'nt' and stat.S_IMODE(info.st_mode) & 0o077:
+ if stat.S_IMODE(info.st_mode) & 0o077:
+ if info.st_nlink != 1:
+ raise PermissionError('unsafe gateway lock link count')
os.fchmod(fd, 0o600) # windows-footgun: ok — POSIX branch
diff --git a/tests/gateway/test_gateway_lock_hardlink.py b/tests/gateway/test_gateway_lock_hardlink.py
deleted file mode 100644
index 63d427668f4..00000000000
--- a/tests/gateway/test_gateway_lock_hardlink.py
+++ /dev/null
@@ -1,19 +0,0 @@
-"""A hardlinked gateway.lock (a cp -al / rsync --link-dest profile clone) is never written."""
-import os
-
-import pytest
-
-
-def test_private_hardlinked_gateway_lock_is_refused_unwritten(tmp_path):
- from gateway import runtime_ownership
- clone, home = tmp_path / 'clone', tmp_path / 'home'
- for path in (clone, home):
- path.mkdir(mode=0o700)
- sentinel = clone / 'gateway.lock'
- sentinel.write_text('sentinel', encoding='utf-8')
- sentinel.chmod(0o600) # already private: the chmod branch never runs
- os.link(sentinel, home / 'gateway.lock')
- with pytest.raises(PermissionError, match='link count'):
- runtime_ownership.ProfileOwnership().reserve([home])
- assert sentinel.read_text(encoding='utf-8') == 'sentinel'