Skip to content

The agent that grows with you

fix: align profile reservations with bootstrap permissions

Teknium87ba34fdf90f
diff --git a/gateway/runtime_ownership.py b/gateway/runtime_ownership.py
index 72105b54370..be100516c72 100644
--- a/gateway/runtime_ownership.py
+++ b/gateway/runtime_ownership.py
@@ -38,7 +38,7 @@ class ProfileOwnership:
for home in sorted({canonical_home(p) for p in homes}):
if home in self._handles:
continue
- home.mkdir(parents=True, exist_ok=True)
+ home.mkdir(mode=0o700, parents=True, exist_ok=True)
path = home / 'gateway.lock'
flags = os.O_RDWR | os.O_CREAT | getattr(os, 'O_NOFOLLOW', 0)
fd = os.open(path, flags, 0o600)
diff --git a/hermes_cli/gateway_runtime_discovery.py b/hermes_cli/gateway_runtime_discovery.py
index 12735b3f5d3..3d82590aed9 100644
--- a/hermes_cli/gateway_runtime_discovery.py
+++ b/hermes_cli/gateway_runtime_discovery.py
@@ -22,8 +22,7 @@ def _private_node(path: Path, *, kind: str) -> os.stat_result:
predicates = {"socket": stat.S_ISSOCK, "file": stat.S_ISREG, "directory": stat.S_ISDIR}
if not predicates[kind](node.st_mode) or node.st_uid != os.getuid(): # windows-footgun: ok — POSIX socket path only
raise DiscoveryError("unsafe_control_path")
- forbidden = 0o022 if kind == "directory" else 0o077
- if stat.S_IMODE(node.st_mode) & forbidden:
+ if stat.S_IMODE(node.st_mode) & 0o077:
raise DiscoveryError("unsafe_control_permissions")
return node
diff --git a/tests/gateway/test_runtime_ownership.py b/tests/gateway/test_runtime_ownership.py
index cfe826f4f4d..a6580fc44eb 100644
--- a/tests/gateway/test_runtime_ownership.py
+++ b/tests/gateway/test_runtime_ownership.py
@@ -39,6 +39,58 @@ print('CLAIMED', result)
release_gateway_runtime_lock()
+async def test_reserved_home_is_eligible_for_same_user_bootstrap(tmp_path):
+ import asyncio
+ import json
+
+ from gateway.control_socket import GatewayControlServer
+ from gateway.runtime_bootstrap import TicketStore
+ from gateway.runtime_ownership import ProfileOwnership
+ from hermes_cli.gateway_runtime import discover_gateway_endpoint
+
+ home = tmp_path / 'new-private-home'
+ owner = ProfileOwnership()
+ old_umask = os.umask(0o022)
+ try:
+ owner.reserve([home])
+ finally:
+ os.umask(old_umask)
+ server = GatewayControlServer(home)
+ server.ticket_store = TicketStore('fixture-owner', frozenset({str(home)}))
+ try:
+ assert await server.start()
+ pointer = home / 'gateway.sock.path'
+ socket_path = pointer.read_text().strip() if pointer.exists() else str(home / 'gateway.sock')
+ reader, writer = await asyncio.open_unix_connection(socket_path)
+ try:
+ writer.write(json.dumps({'protocol': 1, 'verb': 'session-ticket', 'id': 1,
+ 'params': {'profile_id': str(home), 'instance_id': 'fixture-owner',
+ 'purpose': 'interactive'}}).encode() + b'\n')
+ await writer.drain()
+ reply = json.loads(await asyncio.wait_for(reader.readline(), 2))
+ assert reply.get('ok') is True, reply.get('error')
+ finally:
+ writer.close()
+ await writer.wait_closed()
+ finally:
+ await server.stop()
+ owner.close()
+
+ # Pre-existing readable homes are refused, not silently chmodded.
+ existing = tmp_path / 'existing-readable-home'
+ existing.mkdir(mode=0o755)
+ existing.chmod(0o755)
+ owner.reserve([existing])
+ try:
+ observed = await asyncio.to_thread(discover_gateway_endpoint, existing)
+ assert (observed.state, observed.reason_code) == ('inaccessible', 'unsafe_control_permissions')
+ assert existing.stat().st_mode & 0o777 == 0o755
+ finally:
+ owner.close()
+
+
@pytest.mark.linux_only
def test_profile_reservations_unwind_without_releasing_another_owner(tmp_path):
from gateway import runtime_ownership
diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.md
index e85e4224374..b8c6925c9d4 100644
--- a/website/docs/reference/cli-commands.md
+++ b/website/docs/reference/cli-commands.md
@@ -296,6 +296,12 @@ requested only when no service is found. This command never installs or rewrites
service definitions, enables linger, elevates privileges, or clears update fences.
Ambiguous or inaccessible ownership fails closed.
+On POSIX, local bootstrap requires an owner-only profile directory. Newly reserved
+homes are created with mode `0700`; existing permissions are never changed by
+`ensure`. An existing home readable by other users returns
+`inaccessible / unsafe_control_permissions`. Review the directory's intended
+sharing policy and explicitly make it private before retrying local attachment.
+
| Exit code | Meaning |
|-----------|---------|
| `0` | Compatible session runtime ready. |