{"repo":"NousResearch/hermes-agent","public_id":"10270","display_label":"Preserving file ownership and permissions on root or atomic writes","summary":"Most members concern files in Hermes data directories (auth.json, jobs.json, config.yaml, pairing files, memory, skills) ending up root-owned or with altered modes after root/docker exec writes or atomic rewrites, which can leave the gateway user without access. The group includes both bug reports and proposed fixes across several components.","subsystem":"agent","kind":"bug","counts":{"members":32,"open_issues":3,"open_issues_distinct":3,"open_prs":2,"closed_issues":6,"merged_prs":5,"attempt_prs":18},"landed_fix":{"status":"merged_to_main","basis":"structural","pr":89431,"merged_at":"2026-08-18T20:18:56+00:00"},"resolution":{"state":"partially_resolved","by":"pr-59130,pr-71009"},"freshness":{"state":"verified","last_verified_at":"2026-08-18T20:18:56+00:00","is_stale":false},"grouping":{"backbone":"STRUCTURAL_PARTIAL","link_density":0.05580645161290323},"fix_edges":[{"issue_number":10270,"pr_number":59130,"tier":"verified","basis":"closing_ref","confidence":0.95,"recoverable_from_timeline":true,"pr_merged_at":"2026-07-05T21:48:50+00:00"},{"issue_number":14181,"pr_number":86255,"tier":"verified","basis":"superseded_ref","confidence":0.9,"recoverable_from_timeline":false,"pr_merged_at":"2026-08-18T19:52:54+00:00"},{"issue_number":14181,"pr_number":89431,"tier":"verified","basis":"superseded_ref","confidence":0.9,"recoverable_from_timeline":false,"pr_merged_at":"2026-08-18T20:18:56+00:00"},{"issue_number":16480,"pr_number":33628,"tier":"verified","basis":"superseded_ref","confidence":0.9,"recoverable_from_timeline":false,"pr_merged_at":"2026-05-28T03:30:37+00:00"},{"issue_number":68483,"pr_number":71009,"tier":"verified","basis":"closing_ref","confidence":0.95,"recoverable_from_timeline":true,"pr_merged_at":"2026-07-24T22:52:13+00:00"}],"members":[{"kind":"issue","number":10270,"title":"[Bug]: [Docker] Pairing approval fails silently — `weixin-approved.json` created as `root` is unreadable after gateway drops privileges","url":null,"state":"closed"},{"kind":"issue","number":14181,"title":"Managed/shared Hermes runtime: atomic writes recreate SKILL.md and .bundled_manifest as 0600, causing permission-denied failures","url":null,"state":"open"},{"kind":"issue","number":15718,"title":"hermes login writes auth.json owned by root when run via 'docker exec'; gateway running as non-root user can't read it","url":null,"state":"closed"},{"kind":"issue","number":16480,"title":"[Bug]: Docker-deployed Hermes can create root-owned config.yaml when CLI is run as root, causing gateway permission errors","url":null,"state":"closed"},{"kind":"issue","number":17144,"title":"[Bug]: Docker agent/tool memory writes create root-owned files unreadable by gateway user","url":null,"state":"closed"},{"kind":"issue","number":22889,"title":"[Bug]: Memory file writes do not preserve existing file permissions","url":null,"state":"open"},{"kind":"issue","number":29660,"title":"`cron/jobs.py` forces `jobs.json` to 0600 on every save, breaking shared WebUI/gateway container deployments","url":null,"state":"open"},{"kind":"issue","number":56942,"title":"Image bakes USER=root → docker exec writes root-owned shared stores, 401s the fleet","url":null,"state":"closed"},{"kind":"issue","number":68483,"title":"cron: CLI run as root silently locks out the uid-1000 ticker (jobs.json rewritten root:600); zombie ticker never surfaced","url":null,"state":"closed"},{"kind":"pr","number":10293,"title":"fix(gateway): chown pairing files to dir owner when CLI runs as root","url":null,"state":"closed","close_reason":{"category":"silent_close","implication":"active"},"merged":false},{"kind":"pr","number":10930,"title":"fix(pairing): preserve file ownership after root approvals","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#11071","number":11071}],"category":"duplicate_of","implication":"duplicate"},"merged":false},{"kind":"pr","number":11071,"title":"fix(pairing): preserve directory ownership for root writes","url":null,"state":"closed","close_reason":{"category":"stale_abandoned","implication":"active"},"merged":false},{"kind":"pr","number":14280,"title":"fix(skills): preserve file modes across atomic writes","url":null,"state":"closed","close_reason":{"category":"stale_abandoned","implication":"active"},"merged":false},{"kind":"pr","number":14410,"title":"fix(skills): preserve modes during atomic writes","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#86255","number":86255},{"kind":"pr","value":"#89431","number":89431}],"category":"implemented_elsewhere","implication":"superseded"},"merged":false},{"kind":"pr","number":15861,"title":"fix(auth): hand auth.json to the data-dir owner when login runs as root","url":null,"state":"closed","close_reason":{"refs":[{"kind":"commit","value":"aeb992d34374bf07f34811a3e8a11e623d1cc16b","number":0}],"category":"implemented_elsewhere","implication":"superseded"},"merged":false},{"kind":"pr","number":15993,"title":"fix(auth): chown auth.json to parent owner when written as root (#15718)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#17221","number":17221},{"kind":"pr","value":"#17144","number":17144},{"kind":"pr","value":"#15861","number":15861},{"kind":"pr","value":"#15718","number":15718}],"category":"superseded_by_pr","implication":"superseded"},"merged":false},{"kind":"pr","number":16502,"title":"fix(cli): refuse-or-drop privileges when launched as root in Docker (#16480)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#33628","number":33628}],"category":"superseded_by_pr","implication":"superseded"},"merged":false},{"kind":"pr","number":17221,"title":"fix(utils): chown atomic-replace target to match parent when root (#17144)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"commit","value":"aeb992d34","number":0},{"kind":"pr","value":"#17144","number":17144}],"category":"implemented_elsewhere","implication":"superseded"},"merged":false},{"kind":"pr","number":22892,"title":"fix(memory): preserve file permissions during atomic write","url":null,"state":"open","close_reason":{"refs":[{"kind":"commit","value":"551e5af50dc6597069e57af047213f61e40246d6","number":0}],"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":23100,"title":"fix(memory): preserve existing file permissions on memory updates (#22889)","url":null,"state":"closed","close_reason":{"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":26844,"title":"fix(docker): heal pairing-dir ownership after `docker exec` writes (#10270)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"commit","value":"de7e0a887","number":0},{"kind":"pr","value":"#59130","number":59130}],"category":"implemented_elsewhere","implication":"superseded"},"merged":false},{"kind":"pr","number":29666,"title":"fix(cron): preserve existing jobs.json mode across writes (#29660)","url":null,"state":"closed","close_reason":{"category":"implemented_elsewhere","implication":"superseded"},"merged":false,"is_fix_pr":true,"fix_tier":"suggested","fix_detail_withheld":true},{"kind":"pr","number":33628,"title":"fix(docker): drop `docker exec` to hermes uid before invoking the CLI","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["Dockerfile","docker/hermes-exec-shim.sh","tests/docker/test_docker_exec_privilege_drop.py"],"fix_hunks":[{"file":"Dockerfile","hunks":["@@ -213,13 +213,32 @@ COPY --chmod=0755 docker/cont-init.d/02-reconcile-profiles /etc/cont-init.d/02-r\n # ---------- Runtime ----------\n ENV HERMES_WEB_DIST=/opt/hermes/hermes_cli/web_dist\n ENV HERMES_HOME=/opt/data\n+\n+# `docker exec` privilege-drop shim. When operators run\n+# `docker exec <c> hermes ...` they default to root, and any file the\n+# command writes under $HERMES_HOME (auth.json, .env, config.yaml) ends\n+# up root-owned and unreadable to the supervised gateway (UID 10000).\n+# The shim lives at /opt/hermes/bin/hermes, sits earliest on PATH, and\n+# transparently re-exec's the real venv binary via `s6-setuidgid hermes`\n+# when invoked as root. Non-root callers (supervised processes,\n+# `--user hermes`, etc.) hit the short-circuit path with no overhead.\n+# Recursion is impossible because the shim exec's the venv binary by\n+# absolute path (/opt/hermes/.venv/bin/hermes). See the shim source for\n+# the opt-out env var (HERMES_DOCKER_EXEC_AS_ROOT=1).\n+COPY --chmod=0755 docker/hermes-exec-shim.sh /opt/hermes/bin/hermes\n+\n # Pre-s6 entrypoint.sh did `source .venv/bin/activate` which exported\n # the venv bin onto PATH; Architecture B's main-wrapper.sh does the\n # same for the container's main process, but `docker exec` and our\n # cont-init.d scripts don't pass through the wrapper. Expose the venv\n # bin globally so `docker exec <container> hermes ...` and any\n # subprocess that doesn't activate the venv first still find hermes.\n-ENV PATH=\"/opt/hermes/.venv/bin:/opt/data/.local/bin:${PATH}\"\n+#\n+# /opt/hermes/bin is prepended ahead of the venv so the privilege-drop\n+# shim wins PATH resolution. The shim's last act is to exec the venv\n+# binary by absolute path, so this PATH ordering is transparent to\n+# every other consumer.\n+ENV PATH=\"/opt/hermes/bin:/opt/hermes/.venv/bin:/opt/data/.local/bin:${PATH}\"\n RUN mkdir -p /opt/data\n VOLUME [ \"/opt/data\" ]\n "]},{"file":"docker/hermes-exec-shim.sh","hunks":["@@ -0,0 +1,87 @@\n+#!/bin/sh\n+# shellcheck shell=sh\n+# /opt/hermes/bin/hermes — `docker exec` privilege-drop shim.\n+#\n+# Background\n+# ----------\n+# The s6 image runs the supervised gateway/main process as the unprivileged\n+# `hermes` user (UID 10000). When an operator runs `docker exec <c> hermes ...`\n+# the default UID is root (0), and any file the command writes under\n+# $HERMES_HOME — auth.json, .env, config.yaml — ends up root-owned and\n+# unreadable to the supervised gateway. The most common manifestation: the\n+# user runs `docker exec <c> hermes login`, this writes\n+# /opt/data/auth.json as root:root mode 0600, and from then on the gateway\n+# returns \"Provider authentication failed: Hermes is not logged into Nous\n+# Portal\" on every incoming message — even though `docker exec <c> hermes\n+# chat -q ping` (also running as root) succeeds because root happens to be\n+# able to read its own root-owned file. See systematic-debugging skill\n+# notes attached to this fix.\n+#\n+# Fix\n+# ---\n+# This shim sits at /opt/hermes/bin/hermes and is placed earliest on PATH.\n+# When invoked as root, it drops to the hermes user (via s6-setuidgid)\n+# before exec'ing the real venv binary, so anything that writes under\n+# $HERMES_HOME is uid-aligned with the supervised processes. When invoked\n+# as any non-root UID — including the supervised processes themselves,\n+# `docker exec --user hermes`, kanban subagents, etc. — it short-circuits\n+# straight to the venv binary with no privilege change. Net: one extra\n+# fork on the docker-exec-as-root path, zero behavioral change on every\n+# other path.\n+#\n+# Recursion safety: the shim exec's the venv binary by *absolute path*\n+# (/opt/hermes/.venv/bin/hermes), so the second hop cannot re-enter this\n+# shim regardless of PATH state. No sentinel env var needed.\n+#\n+# Opt-out: set HERMES_DOCKER_EXEC_AS_ROOT=1 (1/true/yes, case-insensitive)\n+# to keep running as root. Reserved for diagnostic sessions where the\n+# operator deliberately wants root semantics — e.g. inspecting root-only\n+# state via the hermes CLI. Default is to drop.\n+\n+set -e\n+\n+REAL=/opt/hermes/.venv/bin/hermes\n+\n+# Defensive: if the venv binary is missing (corrupted image, partial\n+# install), fail loudly rather than silently masking it.\n+if [ ! -x \"$REAL\" ]; then\n+    echo \"hermes-shim: $REAL not found or not executable\" >&2\n+    exit 127\n+fi\n+\n+# Already non-root? Just exec the real binary. This is the hot path for\n+# supervised processes (uid 10000) and for `docker exec --user hermes`.\n+if [ \"$(id -u)\" != \"0\" ]; then\n+    exec \"$REAL\" \"$@\"\n+fi\n+\n+# Root, with opt-out set? Honor it.\n+case \"${HERMES_DOCKER_EXEC_AS_ROOT:-}\" in\n+    1|true|TRUE|True|yes|YES|Yes)\n+        exec \"$REAL\" \"$@\"\n+        ;;\n+esac\n+\n+# Root, no opt-out. Drop to the hermes user.\n+#\n+# s6-setuidgid lives under /command/ which is NOT on `docker exec`'s PATH\n+# (s6-overlay only puts /command/ on PATH for supervision-tree children).\n+# Reference it by absolute path so the drop is robust against PATH\n+# manipulation.\n+S6_SUID=/command/s6-setuidgid\n+if [ ! -x \"$S6_SUID\" ]; then\n+    # Non-s6 image (someone stripped s6-overlay, or a hand-built variant).\n+    # Fail loud rather than silently re-execing as root and leaking the\n+    # bug this shim exists to prevent.\n+    echo \"hermes-shim: $S6_SUID not found; refusing to silently run as root.\" >&2\n+    echo \"hermes-shim: re-run with --user hermes or set HERMES_DOCKER_EXEC_AS_ROOT=1.\" >&2\n+    exit 126\n+fi\n+\n+# Reset HOME to the hermes user's home before dropping privileges. Without\n+# this, $HOME stays /root and any library that resolves paths off $HOME\n+# (XDG caches, lockfiles, .config writes) will try to write to /root and\n+# fail with EACCES. Mirrors main-wrapper.sh.\n+export HOME=/opt/data\n+\n+exec \"$S6_SUID\" hermes \"$REAL\" \"$@\""]},{"file":"tests/docker/test_docker_exec_privilege_drop.py","hunks":["@@ -0,0 +1,290 @@\n+\"\"\"Regression tests for the docker-exec privilege-drop shim.\n+\n+The shim (docker/hermes-exec-shim.sh, installed at /opt/hermes/bin/hermes)\n+exists to prevent the auth.json ownership-mismatch bug where\n+`docker exec <c> hermes login` would write /opt/data/auth.json as\n+root:root mode 0600, leaving the supervised gateway (UID 10000) unable\n+to read its own credentials and returning \"Provider authentication\n+failed: Hermes is not logged into Nous Portal\" on every message.\n+\n+These tests verify:\n+\n+1. ``docker exec <c> hermes …`` (defaulting to root) gets dropped to the\n+   hermes user before the real binary runs.\n+2. ``docker exec --user hermes <c> hermes …`` (already non-root) short-\n+   circuits and doesn't try to drop again.\n+3. Files written under $HERMES_HOME from a ``docker exec`` session land\n+   as hermes:hermes — the actual user-visible invariant.\n+4. The HERMES_DOCKER_EXEC_AS_ROOT opt-out lets diagnostic sessions keep\n+   running as root deliberately.\n+5. The main CMD path (``docker run <image> …``) is unaffected by the\n+   PATH-shim ordering — no recursion, no behavior change.\n+\"\"\"\n+\n+from __future__ import annotations\n+\n+import subprocess\n+import time\n+from collections.abc import Iterator\n+\n+import pytest\n+\n+\n+# How long to give a `docker run -d` container before declaring it not ready.\n+_RUN_READY_TIMEOUT_S = 20\n+\n+\n+def _wait_for_init(container: str) -> None:\n+    \"\"\"Block until /init is up enough that `docker exec` is responsive.\"\"\"\n+    deadline = time.time() + _RUN_READY_TIMEOUT_S\n+    while time.time() < deadline:\n+        r = subprocess.run(\n+            [\"docker\", \"exec\", container, \"true\"],\n+            capture_output=True, timeout=5,\n+        )\n+        if r.returncode == 0:\n+            return\n+        time.sleep(0.2)\n+    pytest.fail(f\"container {container} not responsive to docker exec within {_RUN_READY_TIMEOUT_S}s\")\n+\n+\n[redacted:email]\n+def sleep_container(built_image: str, container_name: str) -> Iterator[str]:\n+    \"\"\"Long-lived container running `sleep infinity` so we can docker exec into it.\"\"\"\n+    subprocess.run(\n+        [\"docker\", \"rm\", \"-f\", container_name],\n+        capture_output=True, check=False,\n+    )\n+    r = subprocess.run(\n+        [\"docker\", \"run\", \"-d\", \"--name\", container_name, built_image,\n+         \"sleep\", \"infinity\"],\n+        capture_output=True, text=True, timeout=30,\n+    )\n+    assert r.returncode == 0, f\"docker run failed: {r.stderr}\"\n+    try:\n+        _wait_for_init(container_name)\n+        yield container_name\n+    finally:\n+        subprocess.run(\n+            [\"docker\", \"rm\", \"-f\", container_name],\n+            capture_output=True, check=False,\n+        )\n+\n+\n+def test_shim_drops_root_to_hermes_uid(sleep_container: str) -> None:\n+    \"\"\"docker exec defaults to root; the shim should drop to uid 10000.\n+\n+    We invoke `hermes` with a Python-style `-c` shim equivalent — there's no\n+    pure-hermes \"print my uid\" command, so we use the venv's python directly\n+    via the shim's PATH lookup: `python -c 'print(os.getuid())'` is resolved\n+    through the venv. But that bypasses the shim. Instead, we exploit the\n+    fact that the venv's `hermes` is a console_scripts entry — under the\n+    hood it's a tiny Python wrapper. We can't easily inject \"print my uid\"\n+    into it without forking subcommands. Simplest approach: have `hermes`\n+    do anything that writes to disk, then check the file's owner.\n+\n+    Use `hermes config set` which writes config.yaml under HERMES_HOME.\n+    The resulting file ownership tells us what UID the shim ended up at.\n+    \"\"\"\n+    # Wipe any prior state.\n+    subprocess.run(\n+        [\"docker\", \"exec\", \"--user\", \"root\", sleep_container,\n+         \"rm\", \"-f\", \"/opt/data/config.yaml\"],\n+        capture_output=True, check=False,\n+    )\n+\n+    # Default docker exec (root) — should be dropped by the shim.\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", sleep_container,\n+         \"hermes\", \"config\", \"set\", \"_test.shim_marker\", \"1\"],\n+        capture_output=True, text=True, timeout=30,\n+    )\n+    assert r.returncode == 0, f\"config set failed: stdout={r.stdout!r} stderr={r.stderr!r}\"\n+\n+    # The written file must be owned by hermes, not root.\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", sleep_container,\n+         \"stat\", \"-c\", \"%U:%G\", \"/opt/data/config.yaml\"],\n+        capture_output=True, text=True, timeout=10,\n+    )\n+    assert r.returncode == 0, f\"stat failed: {r.stderr}\"\n+    assert r.stdout.strip() == \"hermes:hermes\", (\n+        f\"config.yaml owned by {r.stdout.strip()!r}, expected hermes:hermes. \"\n+        \"The shim did not drop privileges before invoking hermes.\"\n+    )\n+\n+\n+def test_shim_short_circuits_for_non_root_exec(sleep_container: str) -> None:\n+    \"\"\"docker exec --user hermes already runs as 10000; shim should be a no-op.\n+\n+    Verified indirectly: the command must still succeed end-to-end. If the\n+    shim incorrectly tried to drop privileges a second time (e.g. by\n+    invoking s6-setuidgid which requires root), it would fail with\n+    EPERM. A clean success proves the short-circuit fired.\n+    \"\"\"\n+    subprocess.run(\n+        [\"docker\", \"exec\", \"--user\", \"root\", sleep_container,\n+         \"rm\", \"-f\", \"/opt/data/config.yaml\"],\n+        capture_output=True, check=False,\n+    )\n+\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", \"--user\", \"hermes\", sleep_container,\n+         \"hermes\", \"config\", \"set\", \"_test.shim_short_circuit\", \"1\"],\n+        capture_output=True, text=True, timeout=30,\n+    )\n+    assert r.returncode == 0, (\n+        f\"docker exec --user hermes failed: {r.stderr!r} stdout={r.stdout!r}. \"\n+        \"If the shim mis-handled the non-root path, this would fail with EPERM.\"\n+    )\n+\n+    # File still ends up hermes:hermes — orthogonally confirms uid.\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", sleep_container,\n+         \"stat\", \"-c\", \"%U:%G\", \"/opt/data/config.yaml\"],\n+        capture_output=True, text=True, timeout=10,\n+    )\n+    assert r.stdout.strip() == \"hermes:hermes\"\n+\n+\n+def test_shim_opt_out_keeps_root(sleep_container: str) -> None:\n+    \"\"\"HERMES_DOCKER_EXEC_AS_ROOT=1 should suppress the privilege drop.\n+\n+    Reserved for diagnostic sessions where the operator deliberately\n+    wants root semantics. Verified by writing a file and checking its\n+    owner.\n+    \"\"\"\n+    subprocess.run(\n+        [\"docker\", \"exec\", \"--user\", \"root\", sleep_container,\n+         \"rm\", \"-f\", \"/opt/data/config.yaml\"],\n+        capture_output=True, check=False,\n+    )\n+\n+    r = subprocess.run(\n+        [\"docker\", \"exec\",\n+         \"-e\", \"HERMES_DOCKER_EXEC_AS_ROOT=1\",\n+         sleep_container,\n+         \"hermes\", \"config\", \"set\", \"_test.opt_out\", \"1\"],\n+        capture_output=True, text=True, timeout=30,\n+    )\n+    assert r.returncode == 0, f\"opt-out invocation failed: {r.stderr}\"\n+\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", sleep_container,\n+         \"stat\", \"-c\", \"%U:%G\", \"/opt/data/config.yaml\"],\n+        capture_output=True, text=True, timeout=10,\n+    )\n+    assert r.stdout.strip() == \"root:root\", (\n+        f\"With HERMES_DOCKER_EXEC_AS_ROOT=1, expected root:root, \"\n+        f\"got {r.stdout.strip()!r}\"\n+    )\n+\n+\n[redacted:email](\"falsy_value\", [\"0\", \"false\", \"no\", \"\", \"garbage\", \"2\"])\n+def test_shim_opt_out_strict_truthiness(\n+    sleep_container: str, falsy_value: str,\n+) -> None:\n+    \"\"\"Anything other than 1/true/yes (case-insensitive) does NOT opt out.\n+\n+    Strict truthiness so a typo (``HERMES_DOCKER_EXEC_AS_ROOT=0``) doesn't\n+    silently keep the user as root. Mirrors the policy used by\n+    ``HERMES_GATEWAY_NO_SUPERVISE`` in #33583.\n+    \"\"\"\n+    subprocess.run(\n+        [\"docker\", \"exec\", \"--user\", \"root\", sleep_container,\n+         \"rm\", \"-f\", \"/opt/data/config.yaml\"],\n+        capture_output=True, check=False,\n+    )\n+\n+    r = subprocess.run(\n+        [\"docker\", \"exec\",\n+         \"-e\", f\"HERMES_DOCKER_EXEC_AS_ROOT={falsy_value}\",\n+         sleep_container,\n+         \"hermes\", \"config\", \"set\", \"_test.falsy\", \"1\"],\n+        capture_output=True, text=True, timeout=30,\n+    )\n+    assert r.returncode == 0, f\"falsy value {falsy_value!r} caused failure: {r.stderr}\"\n+\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", sleep_container,\n+         \"stat\", \"-c\", \"%U:%G\", \"/opt/data/config.yaml\"],\n+        capture_output=True, text=True, timeout=10,\n+    )\n+    assert r.stdout.strip() == \"hermes:hermes\", (\n+        f\"falsy opt-out value {falsy_value!r} unexpectedly suppressed the drop; \"\n+        f\"file owner is {r.stdout.strip()!r}, expected hermes:hermes\"\n+    )\n+\n+\n+def test_main_cmd_path_unaffected(built_image: str) -> None:\n+    \"\"\"The CMD path (docker run <image> <args>) must still work.\n+\n+    The shim sits at /opt/hermes/bin earliest on PATH; main-wrapper.sh\n+    invokes `s6-setuidgid hermes hermes <args>` which resolves `hermes`\n+    through PATH. With the shim in the way, this could regress if the\n+    shim recurses or interferes with TTY/exit-code propagation.\n+\n+    `chat --help` is cheap and exercises the full subcommand\n+    passthrough path. The duplicate of test_main_invocation's\n+    pre-existing test is intentional — that one would have passed\n+    pre-shim too; this one specifically guards against shim regressions\n+    in the CMD-as-main-program codepath.\n+    \"\"\"\n+    r = subprocess.run(\n+        [\"docker\", \"run\", \"--rm\", built_image, \"chat\", \"--help\"],\n+        capture_output=True, text=True, timeout=60,\n+    )\n+    assert r.returncode == 0, f\"CMD path broken by shim: stderr={r.stderr!r}\"\n+    assert \"Traceback\" not in r.stderr\n+\n+\n+def test_e2e_login_then_supervised_gateway_can_read_auth(\n+    sleep_container: str,\n+) -> None:\n+    \"\"\"End-to-end regression for the original bug.\n+\n+    Pre-shim: ``docker exec <c> hermes login`` (root) wrote\n+    /opt/data/auth.json as root:root 0600. The supervised gateway (UID\n+    10000) couldn't read it, _load_auth_store swallowed PermissionError\n+    as a parse failure, and resolve_nous_runtime_credentials raised\n+    \"Hermes is not logged into Nous Portal\" on every message.\n+\n+    We can't do a real OAuth login in a unit test, but we can stand in\n+    for it by writing the same file shape via `hermes config set`-style\n+    writes — what matters is the *file ownership invariant* downstream\n+    of `_save_auth_store`. If the shim works, every file the\n+    `docker exec` path produces is hermes-readable.\n+\n+    Specifically: pretend the operator ran `hermes login` (writes\n+    auth.json) and verify (a) the file exists and (b) it's readable by\n+    the hermes UID. We use `hermes auth list` since that touches the\n+    auth store on the read side and would fail with the same\n+    'not logged in' shape if the file was unreadable to uid 10000.\n+    \"\"\"\n+    # Have the shim-protected `docker exec` write the auth store.\n+    # `hermes auth list` is read-only but still exercises _load_auth_store\n+    # under the shim's UID. We invoke `hermes config set` first to\n+    # provoke a write into HERMES_HOME so we have something concrete to\n+    # owner-check.\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", sleep_container,\n+         \"hermes\", \"config\", \"set\", \"_test.e2e_marker\", \"1\"],\n+        capture_output=True, text=True, timeout=30,\n+    )\n+    assert r.returncode == 0, f\"config set failed: {r.stderr}\"\n+\n+    # The supervised UID (10000) must be able to read everything under\n+    # HERMES_HOME that docker exec just wrote.\n+    r = subprocess.run(\n+        [\"docker\", \"exec\", \"--user\", \"hermes\", sleep_container,\n+         \"find\", \"/opt/data\", \"-maxdepth\", \"2\", \"-type\", \"f\",\n+         \"!\", \"-readable\", \"-print\"],\n+        capture_output=True, text=True, timeout=15,\n+    )\n+    assert r.returncode == 0, f\"find failed: {r.stderr}\"\n+    unreadable = [ln for ln in r.stdout.splitlines() if ln.strip()]\n+    assert not unreadable, (\n+        \"Files written by `docker exec` are unreadable to the hermes user \"\n+        f\"(supervised gateway UID): {unreadable}. The shim failed to drop \"\n+        \"privileges before the write.\"\n+    )\n"]}]},{"kind":"pr","number":49826,"title":"fix(cron): chown jobs.json to HERMES_DIR owner on save (#17144)","url":null,"state":"open","close_reason":{"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":59130,"title":"fix(docker): heal pairing-dir ownership after `docker exec` writes (#10270)","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["docker/stage2-hook.sh","gateway/pairing.py","tests/gateway/test_pairing.py","website/docs/user-guide/security.md"],"fix_hunks":[{"file":"docker/stage2-hook.sh","hunks":["@@ -287,6 +287,23 @@ if [ -d \"$HERMES_HOME/cron\" ]; then\n     chown_hermes_tree \"$HERMES_HOME/cron\"\n fi\n \n+# Always reset ownership of pairing data on every boot, same docker-exec/\n+# root-write reason as profiles/ and cron/. `docker exec <container>\n+# hermes pairing approve …` defaults to uid=0 and writes 0600 root-owned\n+# approval files that the unprivileged hermes gateway cannot read,\n+# silently leaving the approved user unauthorized (#10270). The targeted\n+# data-volume chown above only runs when the top-level $HERMES_HOME is\n+# mis-owned, so warm boots skip it — this block makes a container restart\n+# self-heal. Tiny directory (a handful of small JSON files), so the cost\n+# is negligible.\n+if [ -d \"$HERMES_HOME/platforms/pairing\" ]; then\n+    chown_hermes_tree \"$HERMES_HOME/platforms/pairing\"\n+fi\n+# Legacy location (pre-consolidated layout).\n+if [ -d \"$HERMES_HOME/pairing\" ]; then\n+    chown_hermes_tree \"$HERMES_HOME/pairing\"\n+fi\n+\n # Reset ownership of hermes-owned top-level state files on every boot.\n # The targeted data-volume chown above only covers hermes-owned\n # *subdirectories*; loose state files living directly under $HERMES_HOME"]},{"file":"gateway/pairing.py","hunks":["@@ -20,6 +20,7 @@\n \n import hashlib\n import json\n+import logging\n import os\n import secrets\n import tempfile","@@ -35,6 +36,8 @@\n from hermes_constants import get_hermes_dir\n from utils import atomic_replace\n \n+logger = logging.getLogger(__name__)\n+\n \n # Unambiguous alphabet -- excludes 0/O, 1/I to prevent confusion\n ALPHABET = \"ABCDEFGHJKLMNPQRSTUVWXYZ23456789\"","@@ -213,6 +216,30 @@ def _load_json(self, path: Path) -> dict:\n         if path.exists():\n             try:\n                 return json.loads(path.read_text(encoding=\"utf-8\"))\n+            except PermissionError as e:\n+                # Surface this loudly: a 0600 file owned by a different user\n+                # (classic Docker symptom: `docker exec` runs as root and writes\n+                # the file, then the gateway process — running as `hermes` after\n+                # gosu drop — can't read it) would otherwise be swallowed by\n+                # the generic OSError branch below, silently leaving the user\n+                # marked unauthorized. See issue #10270.\n+                try:\n+                    st = path.stat()\n+                    owner_info = f\"owner_uid={st.st_uid} mode={oct(st.st_mode)[-4:]}\"\n+                except OSError:\n+                    owner_info = \"<stat failed>\"\n+                # os.geteuid doesn't exist on Windows; the Docker scenario is\n+                # POSIX-only, but the gateway (and this fallback) runs anywhere.\n+                euid = os.geteuid() if hasattr(os, \"geteuid\") else \"n/a\"\n+                logger.warning(\n+                    \"Pairing file %s exists but is not readable as uid=%s (%s; %s). \"\n+                    \"If you ran `docker exec <container> hermes pairing approve ...` as root, \"\n+                    \"re-run with `docker exec -u hermes <container> ...` and \"\n+                    \"chown the existing file to the hermes user, or restart the \"\n+                    \"container so the entrypoint can fix ownership.\",\n+                    path, euid, owner_info, e,\n+                )\n+                return {}\n             except (json.JSONDecodeError, OSError):\n                 return {}\n         return {}"]},{"file":"tests/gateway/test_pairing.py","hunks":["@@ -4,6 +4,7 @@\n import os\n import sys\n import time\n+from pathlib import Path\n from unittest.mock import patch\n \n import pytest","@@ -651,3 +652,71 @@ def test_clear_pending_all_platforms(self, tmp_path):\n             store.generate_code(\"discord\", \"user2\")\n             count = store.clear_pending()\n         assert count == 2\n+\n+\n+# ---------------------------------------------------------------------------\n+# Unreadable approved-list file logs a warning instead of failing silently\n+# (issue #10270: Docker `docker exec` writes root-owned 0600 files that the\n+# post-gosu gateway can't read; the previous OSError swallow turned the bug\n+# into a mystery \"Unauthorized user\" message)\n+# ---------------------------------------------------------------------------\n+\n+\n+class TestUnreadablePairingFile:\n+    def test_permission_error_logs_warning_and_returns_empty(self, tmp_path, caplog):\n+        import logging\n+        import builtins\n+\n+        approved_path = tmp_path / \"weixin-approved.json\"\n+        approved_path.write_text(\n+            '{\"[redacted:email]\": {\"user_name\": \"x\", \"approved_at\": 0}}'\n+        )\n+\n+        real_open = builtins.open\n+\n+        def fake_read_text(self, *a, **kw):\n+            # Path.read_text uses Path.open internally; raise PermissionError\n+            # to mimic a 0600 file owned by a different uid.\n+            raise PermissionError(13, \"Permission denied\", str(self))\n+\n+        with patch(\"gateway.pairing.PAIRING_DIR\", tmp_path), \\\n+             patch.object(Path, \"read_text\", fake_read_text), \\\n+             caplog.at_level(logging.WARNING, logger=\"gateway.pairing\"):\n+            store = PairingStore()\n+            result = store._load_json(approved_path)\n+\n+        assert result == {}, \"should fall back to empty dict, not raise\"\n+        assert any(\n+            \"not readable\" in rec.getMessage() and \"#10270\" not in rec.getMessage()\n+            or \"not readable\" in rec.getMessage()\n+            for rec in caplog.records\n+        ), f\"expected a warning about unreadable pairing file, got {caplog.records!r}\"\n+        # And the warning should include actionable advice\n+        msgs = \" \".join(rec.getMessage() for rec in caplog.records)\n+        assert \"docker exec\" in msgs\n+        assert \"-u hermes\" in msgs\n+\n+    def test_is_approved_returns_false_when_file_unreadable(self, tmp_path, caplog):\n+        \"\"\"End-to-end: an unreadable approved.json must not crash the gateway,\n+        and the affected user must stay unauthorized (the documented fallback\n+        behaviour) rather than triggering a 500.\"\"\"\n+        import logging\n+\n+        approved_path = tmp_path / \"weixin-approved.json\"\n+        approved_path.write_text(\n+            '{\"[redacted:email]\": {\"user_name\": \"x\", \"approved_at\": 0}}'\n+        )\n+\n+        def fake_read_text(self, *a, **kw):\n+            raise PermissionError(13, \"Permission denied\", str(self))\n+\n+        with patch(\"gateway.pairing.PAIRING_DIR\", tmp_path), \\\n+             patch.object(Path, \"read_text\", fake_read_text), \\\n+             caplog.at_level(logging.WARNING, logger=\"gateway.pairing\"):\n+            store = PairingStore()\n+            ok = store.is_approved(\"weixin\", \"[redacted:email]\")\n+\n+        assert ok is False\n+        # The warning must fire — otherwise this is the silent-failure bug.\n+        assert any(rec.levelno == logging.WARNING for rec in caplog.records), \\\n+            \"PermissionError on approved.json must produce a WARNING log line\""]},{"file":"website/docs/user-guide/security.md","hunks":["@@ -306,6 +306,24 @@ hermes pairing revoke telegram 123456789\n hermes pairing clear-pending\n ```\n \n+:::tip Docker users: run pairing commands as the `hermes` user\n+The official Docker image runs the gateway as the unprivileged `hermes` user\n+(uid 10000) via `gosu`, but `docker exec` defaults to root. Approval files\n+created by root are written with mode `0600 root:root` and the gateway\n+cannot read them — the approval is silently ignored ([#10270][i10270]).\n+\n+Always pass `-u hermes`:\n+\n+```bash\n+docker exec -u hermes hermes-agent hermes pairing approve telegram ABC12DEF\n+```\n+\n+If you already ran the command as root and the user is still unauthorized,\n+restart the container — the entrypoint will fix ownership on the next start.\n+\n+[i10270]: https://github.com/NousResearch/hermes-agent/issues/10270\n+:::\n+\n **Storage:** Pairing data is stored in `~/.hermes/pairing/` with per-platform JSON files:\n - `{platform}-pending.json` — pending pairing requests\n - `{platform}-approved.json` — approved users\n"]}]},{"kind":"pr","number":68504,"title":"fix(cron): preserve file owner uid/gid on jobs.json atomic rewrite","url":null,"state":"closed","close_reason":{"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":68521,"title":"fix(cron): preserve cron job ownership on root saves (#68483)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#71009","number":71009}],"category":"superseded_by_pr","implication":"superseded"},"merged":false},{"kind":"pr","number":70938,"title":"fix(cron): prevent root lockout when CLI writes jobs.json as root (#68483)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#71009","number":71009},{"kind":"pr","value":"#68483","number":68483}],"category":"superseded_by_pr","implication":"superseded"},"merged":false},{"kind":"pr","number":71009,"title":"fix(cron): preserve jobs.json ownership when run as root + surface ticker permission errors","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["cron/jobs.py","cron/scheduler_provider.py","hermes_cli/cron.py","tests/cron/test_jobs_file_ownership.py"]},{"kind":"pr","number":86255,"title":"fix(skills): preserve document modes during atomic writes","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["tests/tools/test_skill_improvements.py","tools/skill_manager_tool.py"]},{"kind":"pr","number":89431,"title":"fix(skills): manifest file mode survives sync rewrites (completes #14410)","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["tests/tools/test_skills_sync.py","tools/skills_sync.py"]},{"kind":"pr","number":131021,"title":"fix(cron): keep jobs.json mode across saves in containers","url":null,"state":"closed","close_reason":{"category":"stale_abandoned","implication":"active"},"merged":false}],"trust":{"default_tier":"verified","includes_suggested":false}}