NousResearch/hermes-agent

Preserving file ownership and permissions on root or atomic writes

Cluster 10270 · agent · Bug. Data as of

5 open items. Fix merged in #89431 on 18 Aug 2026. Check it covers your case.

The short answer

3open issues
2open PRs
32items grouped
Known?
Yes. 32 related items grouped here, 6 issues already closed.
Fix event
A fix was merged to main in PR #89431. Check it covers your case. No release data is tracked. Fix link checked: 18 Aug 2026.
Tracker
The maintainers' tracker marks this partially resolved, deciding PRs #59130, #71009. That is separate from the fix event.

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.

Open issues3

  • Issue#14181Managed/shared Hermes runtime: atomic writes recreate SKILL.md and .bundled_manifest as 0600, causing permission-denied failures
  • Issue#22889[Bug]: Memory file writes do not preserve existing file permissions
  • Issue#29660`cron/jobs.py` forces `jobs.json` to 0600 on every save, breaking shared WebUI/gateway container deployments

Open PRs2

  • PR#22892fix(memory): preserve file permissions during atomic write
  • PR#49826fix(cron): chown jobs.json to HERMES_DIR owner on save (#17144)

Fixes on record

Merged to main. A stamp counts the issues a fix is linked to.

  • #33628 fix(docker): drop `docker exec` to hermes uid before invoking the CLI

    merged to main

    files: Dockerfile, docker/hermes-exec-shim.sh, tests/docker/test_docker_exec_privilege_drop.py

    Show the diff
    • Dockerfile
      @@ -213,13 +213,32 @@ COPY --chmod=0755 docker/cont-init.d/02-reconcile-profiles /etc/cont-init.d/02-r
       # ---------- Runtime ----------
       ENV HERMES_WEB_DIST=/opt/hermes/hermes_cli/web_dist
       ENV HERMES_HOME=/opt/data
      +
      +# `docker exec` privilege-drop shim. When operators run
      +# `docker exec <c> hermes ...` they default to root, and any file the
      +# command writes under $HERMES_HOME (auth.json, .env, config.yaml) ends
      +# up root-owned and unreadable to the supervised gateway (UID 10000).
      +# The shim lives at /opt/hermes/bin/hermes, sits earliest on PATH, and
      +# transparently re-exec's the real venv binary via `s6-setuidgid hermes`
      +# when invoked as root. Non-root callers (supervised processes,
      +# `--user hermes`, etc.) hit the short-circuit path with no overhead.
      +# Recursion is impossible because the shim exec's the venv binary by
      +# absolute path (/opt/hermes/.venv/bin/hermes). See the shim source for
      +# the opt-out env var (HERMES_DOCKER_EXEC_AS_ROOT=1).
      +COPY --chmod=0755 docker/hermes-exec-shim.sh /opt/hermes/bin/hermes
      +
       # Pre-s6 entrypoint.sh did `source .venv/bin/activate` which exported
       # the venv bin onto PATH; Architecture B's main-wrapper.sh does the
       # same for the container's main process, but `docker exec` and our
       # cont-init.d scripts don't pass through the wrapper. Expose the venv
       # bin globally so `docker exec <container> hermes ...` and any
       # subprocess that doesn't activate the venv first still find hermes.
      -ENV PATH="/opt/hermes/.venv/bin:/opt/data/.local/bin:${PATH}"
      +#
      +# /opt/hermes/bin is prepended ahead of the venv so the privilege-drop
      +# shim wins PATH resolution. The shim's last act is to exec the venv
      +# binary by absolute path, so this PATH ordering is transparent to
      +# every other consumer.
      +ENV PATH="/opt/hermes/bin:/opt/hermes/.venv/bin:/opt/data/.local/bin:${PATH}"
       RUN mkdir -p /opt/data
       VOLUME [ "/opt/data" ]
       
    • docker/hermes-exec-shim.sh
      @@ -0,0 +1,87 @@
      +#!/bin/sh
      +# shellcheck shell=sh
      +# /opt/hermes/bin/hermes — `docker exec` privilege-drop shim.
      +#
      +# Background
      +# ----------
      +# The s6 image runs the supervised gateway/main process as the unprivileged
      +# `hermes` user (UID 10000). When an operator runs `docker exec <c> hermes ...`
      +# the default UID is root (0), and any file the command writes under
      +# $HERMES_HOME — auth.json, .env, config.yaml — ends up root-owned and
      +# unreadable to the supervised gateway. The most common manifestation: the
      +# user runs `docker exec <c> hermes login`, this writes
      +# /opt/data/auth.json as root:root mode 0600, and from then on the gateway
      +# returns "Provider authentication failed: Hermes is not logged into Nous
      +# Portal" on every incoming message — even though `docker exec <c> hermes
      +# chat -q ping` (also running as root) succeeds because root happens to be
      +# able to read its own root-owned file. See systematic-debugging skill
      +# notes attached to this fix.
      +#
      +# Fix
      +# ---
      +# This shim sits at /opt/hermes/bin/hermes and is placed earliest on PATH.
      +# When invoked as root, it drops to the hermes user (via s6-setuidgid)
      +# before exec'ing the real venv binary, so anything that writes under
      +# $HERMES_HOME is uid-aligned with the supervised processes. When invoked
      +# as any non-root UID — including the supervised processes themselves,
      +# `docker exec --user hermes`, kanban subagents, etc. — it short-circuits
      +# straight to the venv binary with no privilege change. Net: one extra
      +# fork on the docker-exec-as-root path, zero behavioral change on every
      +# other path.
      +#
      +# Recursion safety: the shim exec's the venv binary by *absolute path*
      +# (/opt/hermes/.venv/bin/hermes), so the second hop cannot re-enter this
      +# shim regardless of PATH state. No sentinel env var needed.
      +#
      +# Opt-out: set HERMES_DOCKER_EXEC_AS_ROOT=1 (1/true/yes, case-insensitive)
      +# to keep running as root. Reserved for diagnostic sessions where the
      +# operator deliberately wants root semantics — e.g. inspecting root-only
      +# state via the hermes CLI. Default is to drop.
      +
      +set -e
      +
      +REAL=/opt/hermes/.venv/bin/hermes
      +
      +# Defensive: if the venv binary is missing (corrupted image, partial
      +# install), fail loudly rather than silently masking it.
      +if [ ! -x "$REAL" ]; then
      +    echo "hermes-shim: $REAL not found or not executable" >&2
      +    exit 127
      +fi
      +
      +# Already non-root? Just exec the real binary. This is the hot path for
      +# supervised processes (uid 10000) and for `docker exec --user hermes`.
      +if [ "$(id -u)" != "0" ]; then
      +    exec "$REAL" "$@"
      +fi
      +
      +# Root, with opt-out set? Honor it.
      +case "${HERMES_DOCKER_EXEC_AS_ROOT:-}" in
      +    1|true|TRUE|True|yes|YES|Yes)
      +        exec "$REAL" "$@"
      +        ;;
      +esac
      +
      +# Root, no opt-out. Drop to the hermes user.
      +#
      +# s6-setuidgid lives under /command/ which is NOT on `docker exec`'s PATH
      +# (s6-overlay only puts /command/ on PATH for supervision-tree children).
      +# Reference it by absolute path so the drop is robust against PATH
      +# manipulation.
      +S6_SUID=/command/s6-setuidgid
      +if [ ! -x "$S6_SUID" ]; then
      +    # Non-s6 image (someone stripped s6-overlay, or a hand-built variant).
      +    # Fail loud rather than silently re-execing as root and leaking the
      +    # bug this shim exists to prevent.
      +    echo "hermes-shim: $S6_SUID not found; refusing to silently run as root." >&2
      +    echo "hermes-shim: re-run with --user hermes or set HERMES_DOCKER_EXEC_AS_ROOT=1." >&2
      +    exit 126
      +fi
      +
      +# Reset HOME to the hermes user's home before dropping privileges. Without
      +# this, $HOME stays /root and any library that resolves paths off $HOME
      +# (XDG caches, lockfiles, .config writes) will try to write to /root and
      +# fail with EACCES. Mirrors main-wrapper.sh.
      +export HOME=/opt/data
      +
      +exec "$S6_SUID" hermes "$REAL" "$@"
    • tests/docker/test_docker_exec_privilege_drop.py
      @@ -0,0 +1,290 @@
      +"""Regression tests for the docker-exec privilege-drop shim.
      +
      +The shim (docker/hermes-exec-shim.sh, installed at /opt/hermes/bin/hermes)
      +exists to prevent the auth.json ownership-mismatch bug where
      +`docker exec <c> hermes login` would write /opt/data/auth.json as
      +root:root mode 0600, leaving the supervised gateway (UID 10000) unable
      +to read its own credentials and returning "Provider authentication
      +failed: Hermes is not logged into Nous Portal" on every message.
      +
      +These tests verify:
      +
      +1. ``docker exec <c> hermes …`` (defaulting to root) gets dropped to the
      +   hermes user before the real binary runs.
      +2. ``docker exec --user hermes <c> hermes …`` (already non-root) short-
      +   circuits and doesn't try to drop again.
      +3. Files written under $HERMES_HOME from a ``docker exec`` session land
      +   as hermes:hermes — the actual user-visible invariant.
      +4. The HERMES_DOCKER_EXEC_AS_ROOT opt-out lets diagnostic sessions keep
      +   running as root deliberately.
      +5. The main CMD path (``docker run <image> …``) is unaffected by the
      +   PATH-shim ordering — no recursion, no behavior change.
      +"""
      +
      +from __future__ import annotations
      +
      +import subprocess
      +import time
      +from collections.abc import Iterator
      +
      +import pytest
      +
      +
      +# How long to give a `docker run -d` container before declaring it not ready.
      +_RUN_READY_TIMEOUT_S = 20
      +
      +
      +def _wait_for_init(container: str) -> None:
      +    """Block until /init is up enough that `docker exec` is responsive."""
      +    deadline = time.time() + _RUN_READY_TIMEOUT_S
      +    while time.time() < deadline:
      +        r = subprocess.run(
      +            ["docker", "exec", container, "true"],
      +            capture_output=True, timeout=5,
      +        )
      +        if r.returncode == 0:
      +            return
      +        time.sleep(0.2)
      +    pytest.fail(f"container {container} not responsive to docker exec within {_RUN_READY_TIMEOUT_S}s")
      +
      +
      [redacted:email]
      +def sleep_container(built_image: str, container_name: str) -> Iterator[str]:
      +    """Long-lived container running `sleep infinity` so we can docker exec into it."""
      +    subprocess.run(
      +        ["docker", "rm", "-f", container_name],
      +        capture_output=True, check=False,
      +    )
      +    r = subprocess.run(
      +        ["docker", "run", "-d", "--name", container_name, built_image,
      +         "sleep", "infinity"],
      +        capture_output=True, text=True, timeout=30,
      +    )
      +    assert r.returncode == 0, f"docker run failed: {r.stderr}"
      +    try:
      +        _wait_for_init(container_name)
      +        yield container_name
      +    finally:
      +        subprocess.run(
      +            ["docker", "rm", "-f", container_name],
      +            capture_output=True, check=False,
      +        )
      +
      +
      +def test_shim_drops_root_to_hermes_uid(sleep_container: str) -> None:
      +    """docker exec defaults to root; the shim should drop to uid 10000.
      +
      +    We invoke `hermes` with a Python-style `-c` shim equivalent — there's no
      +    pure-hermes "print my uid" command, so we use the venv's python directly
      +    via the shim's PATH lookup: `python -c 'print(os.getuid())'` is resolved
      +    through the venv. But that bypasses the shim. Instead, we exploit the
      +    fact that the venv's `hermes` is a console_scripts entry — under the
      +    hood it's a tiny Python wrapper. We can't easily inject "print my uid"
      +    into it without forking subcommands. Simplest approach: have `hermes`
      +    do anything that writes to disk, then check the file's owner.
      +
      +    Use `hermes config set` which writes config.yaml under HERMES_HOME.
      +    The resulting file ownership tells us what UID the shim ended up at.
      +    """
      +    # Wipe any prior state.
      +    subprocess.run(
      +        ["docker", "exec", "--user", "root", sleep_container,
      +         "rm", "-f", "/opt/data/config.yaml"],
      +        capture_output=True, check=False,
      +    )
      +
      +    # Default docker exec (root) — should be dropped by the shim.
      +    r = subprocess.run(
      +        ["docker", "exec", sleep_container,
      +         "hermes", "config", "set", "_test.shim_marker", "1"],
      +        capture_output=True, text=True, timeout=30,
      +    )
      +    assert r.returncode == 0, f"config set failed: stdout={r.stdout!r} stderr={r.stderr!r}"
      +
      +    # The written file must be owned by hermes, not root.
      +    r = subprocess.run(
      +        ["docker", "exec", sleep_container,
      +         "stat", "-c", "%U:%G", "/opt/data/config.yaml"],
      +        capture_output=True, text=True, timeout=10,
      +    )
      +    assert r.returncode == 0, f"stat failed: {r.stderr}"
      +    assert r.stdout.strip() == "hermes:hermes", (
      +        f"config.yaml owned by {r.stdout.strip()!r}, expected hermes:hermes. "
      +        "The shim did not drop privileges before invoking hermes."
      +    )
      +
      +
      +def test_shim_short_circuits_for_non_root_exec(sleep_container: str) -> None:
      +    """docker exec --user hermes already runs as 10000; shim should be a no-op.
      +
      +    Verified indirectly: the command must still succeed end-to-end. If the
      +    shim incorrectly tried to drop privileges a second time (e.g. by
      +    invoking s6-setuidgid which requires root), it would fail with
      +    EPERM. A clean success proves the short-circuit fired.
      +    """
      +    subprocess.run(
      +        ["docker", "exec", "--user", "root", sleep_container,
      +         "rm", "-f", "/opt/data/config.yaml"],
      +        capture_output=True, check=False,
      +    )
      +
      +    r = subprocess.run(
      +        ["docker", "exec", "--user", "hermes", sleep_container,
      +         "hermes", "config", "set", "_test.shim_short_circuit", "1"],
      +        capture_output=True, text=True, timeout=30,
      +    )
      +    assert r.returncode == 0, (
      +        f"docker exec --user hermes failed: {r.stderr!r} stdout={r.stdout!r}. "
      +        "If the shim mis-handled the non-root path, this would fail with EPERM."
      +    )
      +
      +    # File still ends up hermes:hermes — orthogonally confirms uid.
      +    r = subprocess.run(
      +        ["docker", "exec", sleep_container,
      +         "stat", "-c", "%U:%G", "/opt/data/config.yaml"],
      +        capture_output=True, text=True, timeout=10,
      +    )
      +    assert r.stdout.strip() == "hermes:hermes"
      +
      +
      +def test_shim_opt_out_keeps_root(sleep_container: str) -> None:
      +    """HERMES_DOCKER_EXEC_AS_ROOT=1 should suppress the privilege drop.
      +
      +    Reserved for diagnostic sessions where the operator deliberately
      +    wants root semantics. Verified by writing a file and checking its
      +    owner.
      +    """
      +    subprocess.run(
      +        ["docker", "exec", "--user", "root", sleep_container,
      +         "rm", "-f", "/opt/data/config.yaml"],
      +        capture_output=True, check=False,
      +    )
      +
      +    r = subprocess.run(
      +        ["docker", "exec",
      +         "-e", "HERMES_DOCKER_EXEC_AS_ROOT=1",
      +         sleep_container,
      +         "hermes", "config", "set", "_test.opt_out", "1"],
      +        capture_output=True, text=True, timeout=30,
      +    )
      +    assert r.returncode == 0, f"opt-out invocation failed: {r.stderr}"
      +
      +    r = subprocess.run(
      +        ["docker", "exec", sleep_container,
      +         "stat", "-c", "%U:%G", "/opt/data/config.yaml"],
      +        capture_output=True, text=True, timeout=10,
      +    )
      +    assert r.stdout.strip() == "root:root", (
      +        f"With HERMES_DOCKER_EXEC_AS_ROOT=1, expected root:root, "
      +        f"got {r.stdout.strip()!r}"
      +    )
      +
      +
      [redacted:email]("falsy_value", ["0", "false", "no", "", "garbage", "2"])
      +def test_shim_opt_out_strict_truthiness(
      +    sleep_container: str, falsy_value: str,
      +) -> None:
      +    """Anything other than 1/true/yes (case-insensitive) does NOT opt out.
      +
      +    Strict truthiness so a typo (``HERMES_DOCKER_EXEC_AS_ROOT=0``) doesn't
      +    silently keep the user as root. Mirrors the policy used by
      +    ``HERMES_GATEWAY_NO_SUPERVISE`` in #33583.
      +    """
      +    subprocess.run(
      +        ["docker", "exec", "--user", "root", sleep_container,
      +         "rm", "-f", "/opt/data/config.yaml"],
      +        capture_output=True, check=False,
      +    )
      +
      +    r = subprocess.run(
      +        ["docker", "exec",
      +         "-e", f"HERMES_DOCKER_EXEC_AS_ROOT={falsy_value}",
      +         sleep_container,
      +         "hermes", "config", "set", "_test.falsy", "1"],
      +        capture_output=True, text=True, timeout=30,
      +    )
      +    assert r.returncode == 0, f"falsy value {falsy_value!r} caused failure: {r.stderr}"
      +
      +    r = subprocess.run(
      +        ["docker", "exec", sleep_container,
      +         "stat", "-c", "%U:%G", "/opt/data/config.yaml"],
      +        capture_output=True, text=True, timeout=10,
      +    )
      +    assert r.stdout.strip() == "hermes:hermes", (
      +        f"falsy opt-out value {falsy_value!r} unexpectedly suppressed the drop; "
      +        f"file owner is {r.stdout.strip()!r}, expected hermes:hermes"
      +    )
      +
      +
      +def test_main_cmd_path_unaffected(built_image: str) -> None:
      +    """The CMD path (docker run <image> <args>) must still work.
      +
      +    The shim sits at /opt/hermes/bin earliest on PATH; main-wrapper.sh
      +    invokes `s6-setuidgid hermes hermes <args>` which resolves `hermes`
      +    through PATH. With the shim in the way, this could regress if the
      +    shim recurses or interferes with TTY/exit-code propagation.
      +
      +    `chat --help` is cheap and exercises the full subcommand
      +    passthrough path. The duplicate of test_main_invocation's
      +    pre-existing test is intentional — that one would have passed
      +    pre-shim too; this one specifically guards against shim regressions
      +    in the CMD-as-main-program codepath.
      +    """
      +    r = subprocess.run(
      +        ["docker", "run", "--rm", built_image, "chat", "--help"],
      +        capture_output=True, text=True, timeout=60,
      +    )
      +    assert r.returncode == 0, f"CMD path broken by shim: stderr={r.stderr!r}"
      +    assert "Traceback" not in r.stderr
      +
      +
      +def test_e2e_login_then_supervised_gateway_can_read_auth(
      +    sleep_container: str,
      +) -> None:
      +    """End-to-end regression for the original bug.
      +
      +    Pre-shim: ``docker exec <c> hermes login`` (root) wrote
      +    /opt/data/auth.json as root:root 0600. The supervised gateway (UID
      +    10000) couldn't read it, _load_auth_store swallowed PermissionError
      +    as a parse failure, and resolve_nous_runtime_credentials raised
      +    "Hermes is not logged into Nous Portal" on every message.
      +
      +    We can't do a real OAuth login in a unit test, but we can stand in
      +    for it by writing the same file shape via `hermes config set`-style
      +    writes — what matters is the *file ownership invariant* downstream
      +    of `_save_auth_store`. If the shim works, every file the
      +    `docker exec` path produces is hermes-readable.
      +
      +    Specifically: pretend the operator ran `hermes login` (writes
      +    auth.json) and verify (a) the file exists and (b) it's readable by
      +    the hermes UID. We use `hermes auth list` since that touches the
      +    auth store on the read side and would fail with the same
      +    'not logged in' shape if the file was unreadable to uid 10000.
      +    """
      +    # Have the shim-protected `docker exec` write the auth store.
      +    # `hermes auth list` is read-only but still exercises _load_auth_store
      +    # under the shim's UID. We invoke `hermes config set` first to
      +    # provoke a write into HERMES_HOME so we have something concrete to
      +    # owner-check.
      +    r = subprocess.run(
      +        ["docker", "exec", sleep_container,
      +         "hermes", "config", "set", "_test.e2e_marker", "1"],
      +        capture_output=True, text=True, timeout=30,
      +    )
      +    assert r.returncode == 0, f"config set failed: {r.stderr}"
      +
      +    # The supervised UID (10000) must be able to read everything under
      +    # HERMES_HOME that docker exec just wrote.
      +    r = subprocess.run(
      +        ["docker", "exec", "--user", "hermes", sleep_container,
      +         "find", "/opt/data", "-maxdepth", "2", "-type", "f",
      +         "!", "-readable", "-print"],
      +        capture_output=True, text=True, timeout=15,
      +    )
      +    assert r.returncode == 0, f"find failed: {r.stderr}"
      +    unreadable = [ln for ln in r.stdout.splitlines() if ln.strip()]
      +    assert not unreadable, (
      +        "Files written by `docker exec` are unreadable to the hermes user "
      +        f"(supervised gateway UID): {unreadable}. The shim failed to drop "
      +        "privileges before the write."
      +    )
  • #59130 fix(docker): heal pairing-dir ownership after `docker exec` writes (#10270)

    merged to main

    files: docker/stage2-hook.sh, gateway/pairing.py, tests/gateway/test_pairing.py, website/docs/user-guide/security.md

    Show the diff
    • docker/stage2-hook.sh
      @@ -287,6 +287,23 @@ if [ -d "$HERMES_HOME/cron" ]; then
           chown_hermes_tree "$HERMES_HOME/cron"
       fi
       
      +# Always reset ownership of pairing data on every boot, same docker-exec/
      +# root-write reason as profiles/ and cron/. `docker exec <container>
      +# hermes pairing approve …` defaults to uid=0 and writes 0600 root-owned
      +# approval files that the unprivileged hermes gateway cannot read,
      +# silently leaving the approved user unauthorized (#10270). The targeted
      +# data-volume chown above only runs when the top-level $HERMES_HOME is
      +# mis-owned, so warm boots skip it — this block makes a container restart
      +# self-heal. Tiny directory (a handful of small JSON files), so the cost
      +# is negligible.
      +if [ -d "$HERMES_HOME/platforms/pairing" ]; then
      +    chown_hermes_tree "$HERMES_HOME/platforms/pairing"
      +fi
      +# Legacy location (pre-consolidated layout).
      +if [ -d "$HERMES_HOME/pairing" ]; then
      +    chown_hermes_tree "$HERMES_HOME/pairing"
      +fi
      +
       # Reset ownership of hermes-owned top-level state files on every boot.
       # The targeted data-volume chown above only covers hermes-owned
       # *subdirectories*; loose state files living directly under $HERMES_HOME
    • gateway/pairing.py
      @@ -20,6 +20,7 @@
       
       import hashlib
       import json
      +import logging
       import os
       import secrets
       import tempfile
      @@ -35,6 +36,8 @@
       from hermes_constants import get_hermes_dir
       from utils import atomic_replace
       
      +logger = logging.getLogger(__name__)
      +
       
       # Unambiguous alphabet -- excludes 0/O, 1/I to prevent confusion
       ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
      @@ -213,6 +216,30 @@ def _load_json(self, path: Path) -> dict:
               if path.exists():
                   try:
                       return json.loads(path.read_text(encoding="utf-8"))
      +            except PermissionError as e:
      +                # Surface this loudly: a 0600 file owned by a different user
      +                # (classic Docker symptom: `docker exec` runs as root and writes
      +                # the file, then the gateway process — running as `hermes` after
      +                # gosu drop — can't read it) would otherwise be swallowed by
      +                # the generic OSError branch below, silently leaving the user
      +                # marked unauthorized. See issue #10270.
      +                try:
      +                    st = path.stat()
      +                    owner_info = f"owner_uid={st.st_uid} mode={oct(st.st_mode)[-4:]}"
      +                except OSError:
      +                    owner_info = "<stat failed>"
      +                # os.geteuid doesn't exist on Windows; the Docker scenario is
      +                # POSIX-only, but the gateway (and this fallback) runs anywhere.
      +                euid = os.geteuid() if hasattr(os, "geteuid") else "n/a"
      +                logger.warning(
      +                    "Pairing file %s exists but is not readable as uid=%s (%s; %s). "
      +                    "If you ran `docker exec <container> hermes pairing approve ...` as root, "
      +                    "re-run with `docker exec -u hermes <container> ...` and "
      +                    "chown the existing file to the hermes user, or restart the "
      +                    "container so the entrypoint can fix ownership.",
      +                    path, euid, owner_info, e,
      +                )
      +                return {}
                   except (json.JSONDecodeError, OSError):
                       return {}
               return {}
    • tests/gateway/test_pairing.py
      @@ -4,6 +4,7 @@
       import os
       import sys
       import time
      +from pathlib import Path
       from unittest.mock import patch
       
       import pytest
      @@ -651,3 +652,71 @@ def test_clear_pending_all_platforms(self, tmp_path):
                   store.generate_code("discord", "user2")
                   count = store.clear_pending()
               assert count == 2
      +
      +
      +# ---------------------------------------------------------------------------
      +# Unreadable approved-list file logs a warning instead of failing silently
      +# (issue #10270: Docker `docker exec` writes root-owned 0600 files that the
      +# post-gosu gateway can't read; the previous OSError swallow turned the bug
      +# into a mystery "Unauthorized user" message)
      +# ---------------------------------------------------------------------------
      +
      +
      +class TestUnreadablePairingFile:
      +    def test_permission_error_logs_warning_and_returns_empty(self, tmp_path, caplog):
      +        import logging
      +        import builtins
      +
      +        approved_path = tmp_path / "weixin-approved.json"
      +        approved_path.write_text(
      +            '{"[redacted:email]": {"user_name": "x", "approved_at": 0}}'
      +        )
      +
      +        real_open = builtins.open
      +
      +        def fake_read_text(self, *a, **kw):
      +            # Path.read_text uses Path.open internally; raise PermissionError
      +            # to mimic a 0600 file owned by a different uid.
      +            raise PermissionError(13, "Permission denied", str(self))
      +
      +        with patch("gateway.pairing.PAIRING_DIR", tmp_path), \
      +             patch.object(Path, "read_text", fake_read_text), \
      +             caplog.at_level(logging.WARNING, logger="gateway.pairing"):
      +            store = PairingStore()
      +            result = store._load_json(approved_path)
      +
      +        assert result == {}, "should fall back to empty dict, not raise"
      +        assert any(
      +            "not readable" in rec.getMessage() and "#10270" not in rec.getMessage()
      +            or "not readable" in rec.getMessage()
      +            for rec in caplog.records
      +        ), f"expected a warning about unreadable pairing file, got {caplog.records!r}"
      +        # And the warning should include actionable advice
      +        msgs = " ".join(rec.getMessage() for rec in caplog.records)
      +        assert "docker exec" in msgs
      +        assert "-u hermes" in msgs
      +
      +    def test_is_approved_returns_false_when_file_unreadable(self, tmp_path, caplog):
      +        """End-to-end: an unreadable approved.json must not crash the gateway,
      +        and the affected user must stay unauthorized (the documented fallback
      +        behaviour) rather than triggering a 500."""
      +        import logging
      +
      +        approved_path = tmp_path / "weixin-approved.json"
      +        approved_path.write_text(
      +            '{"[redacted:email]": {"user_name": "x", "approved_at": 0}}'
      +        )
      +
      +        def fake_read_text(self, *a, **kw):
      +            raise PermissionError(13, "Permission denied", str(self))
      +
      +        with patch("gateway.pairing.PAIRING_DIR", tmp_path), \
      +             patch.object(Path, "read_text", fake_read_text), \
      +             caplog.at_level(logging.WARNING, logger="gateway.pairing"):
      +            store = PairingStore()
      +            ok = store.is_approved("weixin", "[redacted:email]")
      +
      +        assert ok is False
      +        # The warning must fire — otherwise this is the silent-failure bug.
      +        assert any(rec.levelno == logging.WARNING for rec in caplog.records), \
      +            "PermissionError on approved.json must produce a WARNING log line"
    • website/docs/user-guide/security.md
      @@ -306,6 +306,24 @@ hermes pairing revoke telegram 123456789
       hermes pairing clear-pending
       ```
       
      +:::tip Docker users: run pairing commands as the `hermes` user
      +The official Docker image runs the gateway as the unprivileged `hermes` user
      +(uid 10000) via `gosu`, but `docker exec` defaults to root. Approval files
      +created by root are written with mode `0600 root:root` and the gateway
      +cannot read them — the approval is silently ignored ([#10270][i10270]).
      +
      +Always pass `-u hermes`:
      +
      +```bash
      +docker exec -u hermes hermes-agent hermes pairing approve telegram ABC12DEF
      +```
      +
      +If you already ran the command as root and the user is still unauthorized,
      +restart the container — the entrypoint will fix ownership on the next start.
      +
      +[i10270]: https://github.com/NousResearch/hermes-agent/issues/10270
      +:::
      +
       **Storage:** Pairing data is stored in `~/.hermes/pairing/` with per-platform JSON files:
       - `{platform}-pending.json` — pending pairing requests
       - `{platform}-approved.json` — approved users
  • #71009 fix(cron): preserve jobs.json ownership when run as root + surface ticker permission errors

    merged to main

    files: cron/jobs.py, cron/scheduler_provider.py, hermes_cli/cron.py, tests/cron/test_jobs_file_ownership.py

  • #86255 fix(skills): preserve document modes during atomic writes

    merged to main

    files: tests/tools/test_skill_improvements.py, tools/skill_manager_tool.py

  • #89431 fix(skills): manifest file mode survives sync rewrites (completes #14410)

    merged to main

    files: tests/tools/test_skills_sync.py, tools/skills_sync.py

16 PRs closed without merging

From the close comments: done elsewhere 5 · superseded by another PR 4 · stale or abandoned 3 · closed without comment 1 · duplicate 1 · other 2

  • #10293 fix(gateway): chown pairing files to dir owner when CLI runs as root · closed without comment
  • #10930 fix(pairing): preserve file ownership after root approvals · duplicate → #11071
  • #11071 fix(pairing): preserve directory ownership for root writes · stale or abandoned
  • #14280 fix(skills): preserve file modes across atomic writes · stale or abandoned
  • #14410 fix(skills): preserve modes during atomic writes · done elsewhere → #86255, #89431
Show 11 more
  • #15861 fix(auth): hand auth.json to the data-dir owner when login runs as root · done elsewhere → aeb992d
  • #15993 fix(auth): chown auth.json to parent owner when written as root (#15718) · superseded by another PR → #17221, #17144, #15861, #15718
  • #16502 fix(cli): refuse-or-drop privileges when launched as root in Docker (#16480) · superseded by another PR → #33628
  • #17221 fix(utils): chown atomic-replace target to match parent when root (#17144) · done elsewhere → aeb992d, #17144
  • #23100 fix(memory): preserve existing file permissions on memory updates (#22889) · other
  • #26844 fix(docker): heal pairing-dir ownership after `docker exec` writes (#10270) · done elsewhere → de7e0a8, #59130
  • #29666 fix(cron): preserve existing jobs.json mode across writes (#29660) · done elsewhere
  • #68504 fix(cron): preserve file owner uid/gid on jobs.json atomic rewrite · other
  • #68521 fix(cron): preserve cron job ownership on root saves (#68483) · superseded by another PR → #71009
  • #70938 fix(cron): prevent root lockout when CLI writes jobs.json as root (#68483) · superseded by another PR → #71009, #68483
  • #131021 fix(cron): keep jobs.json mode across saves in containers · stale or abandoned
Closed issues · 6
  • Closed#10270[Bug]: [Docker] Pairing approval fails silently — `weixin-approved.json` created as `root` is unreadable after gateway drops privileges
  • Closed#15718hermes login writes auth.json owned by root when run via 'docker exec'; gateway running as non-root user can't read it
  • Closed#16480[Bug]: Docker-deployed Hermes can create root-owned config.yaml when CLI is run as root, causing gateway permission errors
  • Closed#17144[Bug]: Docker agent/tool memory writes create root-owned files unreadable by gateway user
  • Closed#56942Image bakes USER=root → docker exec writes root-owned shared stores, 401s the fleet
  • Closed#68483cron: CLI run as root silently locks out the uid-1000 ticker (jobs.json rewritten root:600); zombie ticker never surfaced
How this cluster was grouped
  • Link evidence (partly structural links): some members are connected by structural evidence (shared changed files, or a closing/superseded reference); the rest are joined by an automated relevance judgement over their text.
  • Members outside that structural core may belong to a different underlying problem.
  • Pairwise link density 0.06: the share of item pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. 1.00 means every pair is linked.

For your agent

The same facts, typed.