Skip to content

The agent that grows with you

fix(profiles): a distribution can neither plant nor replace a nested credential store

John Paul Soliva8c1adb7d6dfb
diff --git a/hermes_cli/profile_distribution.py b/hermes_cli/profile_distribution.py
index 3229559e5ec..346ea93f46a 100644
--- a/hermes_cli/profile_distribution.py
+++ b/hermes_cli/profile_distribution.py
@@ -22,7 +22,9 @@ import hermes_yaml as yaml
from hermes_cli._subprocess_compat import noninteractive_git_env
from hermes_cli.archive_safe import normalize_archive_parts
-from hermes_cli.profiles import DEFAULT_EXPORT_EXCLUDE_ROOT
+from hermes_cli.profiles import (
+ DEFAULT_EXPORT_EXCLUDE_ROOT, profile_path_contains_private_store, profile_path_is_private,
+)
from utils import rmtree_readonly
@@ -343,7 +345,7 @@ def _owned_entries(staged: Path, manifest: DistributionManifest):
# Do NOT narrow to DEFAULT_DIST_OWNED — existing distributions ship arbitrary extra
# top-level paths without declaring them.
for entry in staged.iterdir():
- if entry.name not in USER_OWNED_EXCLUDE:
+ if entry.name not in USER_OWNED_EXCLUDE and not profile_path_is_private((entry.name,)):
yield entry, (entry.name,)
return
# Path-aware allowlist: copy exactly the declared paths.
@@ -352,7 +354,8 @@ def _owned_entries(staged: Path, manifest: DistributionManifest):
rel_parts = tuple(normalize_archive_parts(rel))
except ValueError:
continue
- if rel_parts[0] in USER_OWNED_EXCLUDE or _is_distribution_runtime_path(rel_parts):
+ if (rel_parts[0] in USER_OWNED_EXCLUDE or profile_path_is_private(rel_parts)
+ or _is_distribution_runtime_path(rel_parts)):
continue
src = staged.joinpath(*rel_parts)
if src.exists():
@@ -459,11 +462,11 @@ def _merge_dir(src: Path, dest: Path, rel: Tuple[str, ...]) -> None:
"""Merge authored roots while leaving runtime-owned nested state untouched."""
for child in src.iterdir():
parts = (*rel, child.name)
- if _is_distribution_runtime_path(parts):
+ if profile_path_is_private(parts) or _is_distribution_runtime_path(parts):
continue
if parts == _CRON_STORE_REL:
continue # merged up front by _copy_dist_payload
- if _is_container(child, parts):
+ if _merges_per_root(child, parts):
_merge_dir(child, _real_dir(dest, (child.name,)), parts)
else:
_replace_entry(child, dest / child.name)
@@ -472,9 +475,9 @@ def _merge_dir(src: Path, dest: Path, rel: Tuple[str, ...]) -> None:
def _refuse_symlinked_containers(src: Path, dest: Path, rel: Tuple[str, ...]) -> None:
for child in src.iterdir():
parts = (*rel, child.name)
- if _is_distribution_runtime_path(parts):
+ if profile_path_is_private(parts) or _is_distribution_runtime_path(parts):
continue
- if _is_container(child, parts):
+ if _merges_per_root(child, parts):
_refuse_symlink(dest / child.name)
_refuse_symlinked_containers(child, dest / child.name, parts)
@@ -484,8 +487,11 @@ def _merges_per_root(src: Path, rel_parts: Tuple[str, ...]) -> bool:
``_is_container``), is merged per authored root instead of replaced whole, so skills the installer
added to it (``hermes skills install`` and agent-created skills land in
``skills/<category>/``) survive. The pre-write symlink guard and the copy loop both
- use this, so the guard covers exactly what the copy merges."""
- return src.is_dir() and (len(rel_parts) == 1 or _is_container(src, rel_parts))
+ use this, so the guard covers exactly what the copy merges. An ancestor of a credential
+ store (``platforms`` of ``platforms/pairing``) is merged too, so replacing it whole can
+ neither delete the installer's store nor plant the author's."""
+ return src.is_dir() and (len(rel_parts) == 1 or _is_container(src, rel_parts)
+ or profile_path_contains_private_store(rel_parts))
def _refuse_symlinked_targets(target: Path, entries) -> None:
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index acd945330df..0a5159bf13d 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -158,6 +158,7 @@ PROFILE_CREDENTIAL_PATHS = frozenset({
".anthropic_oauth.json", # Anthropic OAuth tokens (credential_sources)
"google_token.json", "google_oauth_pending.json", "google_client_secret.json",
"google_chat_user_tokens", "google_chat_user_client_secret.json", "google_chat_user_oauth_pending.json",
+ "google_chat_user_token.json", "google_chat_user_oauth_pending", # legacy single-user layouts
"slack_tokens.json",
"webhook_subscriptions.json", # per-route HMAC secrets
"mcp-tokens", # MCP OAuth tokens
@@ -166,7 +167,22 @@ PROFILE_CREDENTIAL_PATHS = frozenset({
"pairing", "platforms/pairing", "feishu_comment_pairing.json",
"whatsapp/session", "platforms/whatsapp/session", "matrix/store", "platforms/matrix/store",
"cache/bws_cache.json", "cache/bws_cache.enc.json",
+ "workspace/meetings/node_token.json", # google_meet node RPC secret
})
+_CREDENTIAL_PATH_PARTS = tuple(tuple(p.casefold().split("/")) for p in PROFILE_CREDENTIAL_PATHS)
+
+
+def profile_path_is_private(parts: Tuple[str, ...]) -> bool:
+ """True for a PROFILE_CREDENTIAL_PATHS store or anything below one. Case-folded: on a
+ case-insensitive filesystem ``Platforms/Pairing`` IS the pairing store."""
+ folded = tuple(str(part).casefold() for part in parts)
+ return any(folded[:len(store)] == store for store in _CREDENTIAL_PATH_PARTS)
+
+
+def profile_path_contains_private_store(parts: Tuple[str, ...]) -> bool:
+ """True for a strict ancestor of a store (``platforms`` holds ``platforms/pairing``)."""
+ folded = tuple(str(part).casefold() for part in parts)
+ return any(len(store) > len(folded) and store[:len(folded)] == folded for store in _CREDENTIAL_PATH_PARTS)
# Directories/files to exclude when exporting the default (~/.hermes) profile.
# The default profile contains infrastructure (repo checkout, worktrees, DBs,
@@ -2267,8 +2283,8 @@ def export_profile(name: str, output_path: str, extra_files: Optional[Dict[str,
def _ignore_credentials(directory: str, contents: list) -> set:
ignored = _non_exportable_entries(directory, contents)
ignored.update(_EXPORT_CREDENTIAL_FILES & set(contents))
- rel = Path(directory).relative_to(profile_dir)
- ignored.update(e for e in contents if (rel / e).as_posix() in PROFILE_CREDENTIAL_PATHS)
+ rel = Path(directory).relative_to(profile_dir).parts
+ ignored.update(e for e in contents if profile_path_is_private((*rel, e)))
if Path(directory) == profile_dir:
ignored |= (PM_RUNTIME_ROOT_DIRS | _EXPORT_RECOVERY_ROOT_DIRS) & set(contents)
ignored.update(e for e in contents if e.startswith(_EXPORT_STORE_COPY_PREFIXES))
diff --git a/tests/hermes_cli/test_profile_export_credentials.py b/tests/hermes_cli/test_profile_export_credentials.py
index 7282956ad18..c0ba306ce2d 100644
--- a/tests/hermes_cli/test_profile_export_credentials.py
+++ b/tests/hermes_cli/test_profile_export_credentials.py
@@ -57,9 +57,14 @@ class TestCredentialExclusion:
def test_export_ships_no_credential_store_a_loader_reads(self, tmp_path, monkeypatch):
"""Every credential store Hermes loads from a profile home stays out of a named-profile
- export and stays user-owned on a distribution install. .op.env (env_loader) and npmrc
- (source_build) have no suffix the text scrub pass edits, so exclusion is their only guard."""
- from hermes_cli.profile_distribution import USER_OWNED_EXCLUDE
+ export and stays user-owned on a distribution install: a distribution can neither ship
+ one (nested ones included) nor opt one back in through ``distribution_owned``. .op.env
+ (env_loader) and npmrc (source_build) have no suffix the text scrub pass edits, so
+ exclusion is their only guard; the legacy Google Chat token file ships its client_secret."""
+ import shutil
+ from pathlib import Path
+
+ from hermes_cli.profile_distribution import DistributionManifest, install_distribution, write_manifest
from hermes_cli.profiles import PROFILE_CREDENTIAL_PATHS
profiles_root = tmp_path / "profiles"
@@ -67,12 +72,29 @@ class TestCredentialExclusion:
(profile_dir / "platforms").mkdir(parents=True)
(profile_dir / "config.yaml").write_text("model: gpt-4\n")
(profile_dir / "platforms" / "keep.json").write_text("{}")
- stores = {".op.env", "npmrc", *PROFILE_CREDENTIAL_PATHS}
+ stores = {".op.env", "npmrc", "google_chat_user_token.json", "google_chat_user_oauth_pending",
+ "workspace/meetings/node_token.json", *PROFILE_CREDENTIAL_PATHS}
for rel in stores:
is_dir = "." not in rel.rsplit("/", 1)[-1] and rel != "npmrc" # token dirs vs single files
target = profile_dir / rel / "store" if is_dir else profile_dir / rel
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text("fake-credential")
+
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ (tmp_path / ".hermes").mkdir()
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ tops = sorted({r.split("/")[0] for r in stores})
+ for owned in ([], sorted(stores) + tops): # legacy whole-payload, then explicit opt-in
+ staged = tmp_path / f"dist{len(owned)}"
+ shutil.copytree(profile_dir, staged)
+ write_manifest(staged, DistributionManifest(name=staged.name, version="0.1.0", distribution_owned=owned))
+ installed = install_distribution(str(staged), name=staged.name).target_dir
+ assert (installed / "platforms" / "keep.json").exists()
+ planted = sorted(r for r in stores if any(
+ f.is_file() and f.read_text() == "fake-credential"
+ for f in ((installed / r), *((installed / r).rglob("*") if (installed / r).is_dir() else ()))))
+ assert not planted, (staged.name, planted)
+
_patch_named_profile(monkeypatch, profiles_root, profile_dir)
with tarfile.open(export_profile("testprofile", str(tmp_path / "export.tar.gz")), "r:gz") as tf:
@@ -81,8 +103,6 @@ class TestCredentialExclusion:
assert {"testprofile/config.yaml", "testprofile/platforms/keep.json"} <= names
leaked = sorted(r for r in stores if any(n == f"testprofile/{r}" or n.startswith(f"testprofile/{r}/") for n in names))
assert not leaked, leaked
- root_stores = {r for r in stores if "/" not in r}
- assert root_stores <= USER_OWNED_EXCLUDE, sorted(root_stores - USER_OWNED_EXCLUDE)
def test_export_ships_no_recovery_copy_hermes_writes_of_a_store(self, tmp_path, monkeypatch):
"""Every copy Hermes' own writers leave in a profile home (pre-update zip, update snapshot,
diff --git a/website/docs/user-guide/profile-distributions.md b/website/docs/user-guide/profile-distributions.md
index aaece2f2435..2206efe82e4 100644
--- a/website/docs/user-guide/profile-distributions.md
+++ b/website/docs/user-guide/profile-distributions.md
@@ -274,7 +274,7 @@ When an installer updates to a new version, some things get replaced (author's d
|---|---|---|
| **Distribution-owned** | `SOUL.md`, `config.yaml`, `mcp.json`, `skills/`, `cron/jobs.json`, `distribution.yaml` | Files are replaced from the new clone. Skill directories are merged per entry. `cron/jobs.json` is merged by job id: shipped definitions update in place, your local jobs and each job's paused/enabled state survive, and newly shipped jobs arrive paused. Other `cron/` files and root-level hidden `skills/` metadata are runtime state and stay local. |
| **Config override** | `config.yaml` | Actually preserved by default — the installer may have tuned model or provider. Pass `--force-config` on update to reset. |
-| **User-owned** | `memories/`, `sessions/`, `state.db*`, `auth.json`, `.env` and the other credential stores, `logs/`, `workspace/`, `plans/`, `home/`, `*_cache/`, `local/` | Never touched |
+| **User-owned** | `memories/`, `sessions/`, `state.db*`, `auth.json`, `.env` and the other credential stores (including those below a distribution-owned directory, such as `platforms/pairing/` and `platforms/whatsapp/session/`), `logs/`, `workspace/`, `plans/`, `home/`, `*_cache/`, `local/` | Never touched, and `distribution_owned` cannot claim a credential store |
You can override the distribution-owned list in the manifest:
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/profile-distributions.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/profile-distributions.md
index cfe5f72a7fe..a9ea33512e0 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/profile-distributions.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/profile-distributions.md
@@ -175,7 +175,7 @@ research-bot/
|---|---|---|
| **分发所有** | `SOUL.md`、`config.yaml`、`mcp.json`、`skills/`、`cron/`、`distribution.yaml` | 从新克隆中替换 |
| **配置覆盖** | `config.yaml` | 默认实际保留——安装者可能已调整模型或 provider。更新时传入 `--force-config` 可重置。 |
-| **用户所有** | `memories/`、`sessions/`、`state.db*`、`auth.json`、`.env` 及其他凭据存储、`logs/`、`workspace/`、`plans/`、`home/`、`*_cache/`、`local/` | 永不触碰 |
+| **用户所有** | `memories/`、`sessions/`、`state.db*`、`auth.json`、`.env` 及其他凭据存储(包括位于分发所有目录之下的存储,例如 `platforms/pairing/` 和 `platforms/whatsapp/session/`)、`logs/`、`workspace/`、`plans/`、`home/`、`*_cache/`、`local/` | 永不触碰,且 `distribution_owned` 不能声明凭据存储 |
你可以在 manifest 中覆盖分发所有列表: