Skip to content

The agent that grows with you

fix(profiles): keep .docker/.azure/.config/gh/.config/gcloud out of profile exports

kshitijk4poor404b1fec55c0
diff --git a/agent/file_safety.py b/agent/file_safety.py
index 46589df0a22..65f97f23d3d 100644
--- a/agent/file_safety.py
+++ b/agent/file_safety.py
@@ -206,12 +206,15 @@ def build_write_denied_paths(home: str) -> set[str]:
return {os.path.realpath(p) for p in paths}
+# Home-relative credential directories (POSIX paths). Also dropped from profile exports (hermes_cli.profiles).
+HOME_CREDENTIAL_DIRS = (".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", ".config/gh", ".config/gcloud")
+
+
def build_write_denied_prefixes(home: str) -> list[str]:
"""Return sensitive directory prefixes that must never be written."""
paths = [
- *(os.path.join(home, d) for d in (".ssh", ".aws", ".gnupg", ".kube")),
+ *(os.path.join(home, *d.split("/")) for d in HOME_CREDENTIAL_DIRS),
"/etc/sudoers.d", "/etc/systemd",
- *(os.path.join(home, *d) for d in ((".docker",), (".azure",), (".config", "gh"), (".config", "gcloud"))),
]
return [os.path.realpath(p) + os.sep for p in paths]
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index a12acf6bf72..77ebe934e4e 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -16,6 +16,7 @@ from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict, List, Optional, Tuple
+from agent.file_safety import HOME_CREDENTIAL_DIRS
from hermes_cli.archive_safe import archive_root_dirs, make_targz, normalize_archive_parts, safe_extract_targz
from hermes_cli.home_data_layout import PM_RUNTIME_ROOT_DIRS
from hermes_constants import (
@@ -148,8 +149,8 @@ def _clone_all_copytree_ignore(source_dir: Path):
return _ignore
-# OS credential dirs (file_safety.build_write_denied_prefixes) + direnv .envrc (_BLOCKED_PROJECT_ENV_BASENAMES).
-_OS_CREDENTIAL_STORES = (".ssh", ".aws", ".gnupg", ".kube", ".envrc")
+# OS credential dirs (file_safety.HOME_CREDENTIAL_DIRS) + direnv .envrc (_BLOCKED_PROJECT_ENV_BASENAMES).
+_OS_CREDENTIAL_STORES = (*HOME_CREDENTIAL_DIRS, ".envrc")
# Credential stores in a profile home, as paths relative to it, plus the directories where Hermes
# keeps recovery copies of them. Never shipped in a profile export, and user-owned (never
@@ -2234,7 +2235,7 @@ def _default_export_ignore(root_dir: Path):
# Universal exclusions and credential names (any depth) plus npm lockfiles that can appear at root.
ignored = _non_exportable_entries(directory, contents)
ignored.update({"package.json", "package-lock.json"} & set(contents))
- ignored.update(_EXPORT_CREDENTIAL_FILES & set(contents))
+ ignored.update(_export_credential_entries(directory, contents))
if Path(directory) == root_dir:
ignored.update(entry for entry in contents if entry not in _DEFAULT_EXPORT_INCLUDE_ROOT)
return ignored
@@ -2247,6 +2248,15 @@ def _default_export_ignore(root_dir: Path):
# its persistent Chromium profile (Cookies, Login Data — the bot's live web sessions), Xauthority, sockets.
# The OS stores are dropped wherever they sit (a skill dir copied from a home carries its ``.ssh``).
_EXPORT_CREDENTIAL_FILES = frozenset({"auth.json", ".env", "bot-desktop", *_OS_CREDENTIAL_STORES})
+_EXPORT_CREDENTIAL_PARTS = tuple(tuple(p.split("/")) for p in _EXPORT_CREDENTIAL_FILES)
+
+
+def _export_credential_entries(directory: str, contents: list) -> set:
+ """Entries of *directory* that are an _EXPORT_CREDENTIAL_FILES store: matched on trailing path
+ components, so ``.config/gh`` drops at any depth while the rest of ``.config`` ships."""
+ parts = Path(directory).parts
+ return {entry for entry in contents for store in _EXPORT_CREDENTIAL_PARTS
+ if entry == store[-1] and parts[len(parts) + 1 - len(store):] == store[:-1]}
# Text/config suffixes secret-scrubbed on export; binary DBs, images etc. are left alone.
_EXPORT_REDACT_SUFFIXES = frozenset({
@@ -2307,7 +2317,7 @@ def export_profile(name: str, output_path: str, extra_files: Optional[Dict[str,
# credential exclusion for named profiles.
def _ignore_credentials(directory: str, contents: list) -> set:
ignored = _non_exportable_entries(directory, contents)
- ignored.update(_EXPORT_CREDENTIAL_FILES & set(contents))
+ ignored.update(_export_credential_entries(directory, contents))
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:
diff --git a/tests/hermes_cli/test_profile_export_credentials.py b/tests/hermes_cli/test_profile_export_credentials.py
index 3b5f0a835d8..8c241defd8c 100644
--- a/tests/hermes_cli/test_profile_export_credentials.py
+++ b/tests/hermes_cli/test_profile_export_credentials.py
@@ -40,7 +40,7 @@ _EXTRA_STORES = {
# Single-file stores whose name has no dot; every other dotless store is a token directory.
_DOTLESS_FILES = {"npmrc"}
# Dot-named stores that are directories.
-_DOT_DIRS = {".ssh", ".aws", ".gnupg", ".kube"}
+_DOT_DIRS = {".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure"}
def _seed_stores(root):
@@ -108,8 +108,10 @@ class TestCredentialExclusion:
(profile_dir / "config.yaml.bak-my-note").write_text(f"model:\n api_key: {_LEAKED_KEY}\n")
(profile_dir / "GOOGLE_CHAT_USER_TOKENS").mkdir(exist_ok=True)
(profile_dir / "GOOGLE_CHAT_USER_TOKENS" / "upper.json").write_text("fake-credential")
- nested = [f"skills/s/{r}" for r in (".ssh/id_rsa", ".aws/credentials", ".gnupg/x", ".kube/config", ".envrc")]
- for rel in nested:
+ nested = [f"skills/s/{r}" for r in (".ssh/id_rsa", ".aws/credentials", ".gnupg/x", ".kube/config", ".envrc",
+ ".docker/config.json", ".azure/accessTokens.json",
+ ".config/gh/hosts.yml", ".config/gcloud/application_default_credentials.json")]
+ for rel in [*nested, "skills/s/.config/other/settings.json"]:
(profile_dir / rel).parent.mkdir(parents=True, exist_ok=True)
(profile_dir / rel).write_text("fake-credential")
monkeypatch.setenv("HERMES_HOME", str(profile_dir))
@@ -133,6 +135,8 @@ class TestCredentialExclusion:
assert {"testprofile/config.yaml", "testprofile/platforms/keep.json"} <= set(members)
assert "default/config.yaml" in default_members
+ assert "default/skills/s/.config/other/settings.json" in default_members
+ assert "testprofile/skills/s/.config/other/settings.json" in members
assert _LEAKED_KEY not in note
rels = {*_EXTRA_STORES, *PROFILE_CREDENTIAL_PATHS, "google_chat_user_tokens/upper.json", *nested,
*(c.relative_to(profile_dir).as_posix() for c in copies)}
diff --git a/website/docs/user-guide/profile-distributions.md b/website/docs/user-guide/profile-distributions.md
index dbf94f42f25..a041d507f13 100644
--- a/website/docs/user-guide/profile-distributions.md
+++ b/website/docs/user-guide/profile-distributions.md
@@ -87,7 +87,7 @@ Not a fit:
- **You want to hand someone your setup once, right now.** A distribution needs a repo, a manifest, and a `.gitignore`. `/export` needs none of that — see [Export and import a profile file](#export-and-import-a-profile-file). Same for backing up or moving a profile to a new machine.
- **You want to share your desktop theme and layout.** A distribution carries the agent — SOUL, config, skills, cron, MCP, plugins. An export made from the desktop app also carries the look: skin, light/dark mode, custom themes, rail color, and window layout.
-- **You want to share API keys alongside the agent.** `auth.json`, `.env` and the other credential stores Hermes reads from a profile (`.op.env`, `npmrc`, OAuth and bot token files, `honcho.json`, `mem0.json`, `teams_pipeline_store.json`, `mcp-tokens/`, `vault/`, `proxy/`, browser profiles, platform sessions, and `.ssh/`, `.aws/`, `.gnupg/`, `.kube/` and `.envrc` at the root or nested under a skill) are deliberately excluded from distributions. Each installer brings their own credentials. (Export files strip them too.)
+- **You want to share API keys alongside the agent.** `auth.json`, `.env` and the other credential stores Hermes reads from a profile (`.op.env`, `npmrc`, OAuth and bot token files, `honcho.json`, `mem0.json`, `teams_pipeline_store.json`, `mcp-tokens/`, `vault/`, `proxy/`, browser profiles, platform sessions, and `.ssh/`, `.aws/`, `.gnupg/`, `.kube/`, `.docker/`, `.azure/`, `.config/gh/`, `.config/gcloud/` and `.envrc` at the root or nested under a skill) are deliberately excluded from distributions. Each installer brings their own credentials. (Export files strip them too.)
- **You want to share memories / sessions / conversation history.** Those are user data, not distribution content. Never shipped. (Export files are different here — read [what an export contains](#what-an-export-file-contains) before sending one.)
:::caution
@@ -686,7 +686,7 @@ You cannot import as `default` — that name is the built-in root profile (`~/.h
### What an export file contains
-Always excluded, both profile types: `auth.json`, `.env` and the other credential stores Hermes reads from a profile (OAuth and bot token files such as WeChat's `weixin/accounts/`, `honcho.json`, `mcp-tokens/`, `vault/`, the iron-proxy keys in `proxy/`, browser profiles including the `/browser connect` one in `chrome-debug/`, platform sessions and pairing stores, the Teams pipeline's `teams_pipeline_store.json` with its Graph webhook `clientState`), and `.ssh/`, `.aws/`, `.gnupg/`, `.kube/` and `.envrc`, at the root or nested under a skill. Your API keys never leave the machine. `honcho.json` and `mem0.json` can hold the provider's API key next to its settings, so after an import run `hermes honcho setup` or `hermes memory setup` again.
+Always excluded, both profile types: `auth.json`, `.env` and the other credential stores Hermes reads from a profile (OAuth and bot token files such as WeChat's `weixin/accounts/`, `honcho.json`, `mcp-tokens/`, `vault/`, the iron-proxy keys in `proxy/`, browser profiles including the `/browser connect` one in `chrome-debug/`, platform sessions and pairing stores, the Teams pipeline's `teams_pipeline_store.json` with its Graph webhook `clientState`), and `.ssh/`, `.aws/`, `.gnupg/`, `.kube/`, `.docker/`, `.azure/`, `.config/gh/`, `.config/gcloud/` and `.envrc`, at the root or nested under a skill. Your API keys never leave the machine. `honcho.json` and `mem0.json` can hold the provider's API key next to its settings, so after an import run `hermes honcho setup` or `hermes memory setup` again.
**The default profile** (`~/.hermes`) is exported through an allow-list — only known Hermes artifacts, so an unrelated file sitting in your home directory can't get swept in:
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 84a88fb3920..31c02beb7eb 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
@@ -66,7 +66,7 @@ hermes profile install github.com/you/my-research-agent --alias
不适合的场景:
- **你只想在自己的机器上备份一个 profile。** 使用 [`hermes profile export` / `import`](../reference/profile-commands.md#hermes-profile-export)——那正是这两个命令的用途。
-- **你想随 agent 一起共享 API 密钥。** `auth.json`、`.env` 以及 Hermes 从 profile 读取的其他凭据存储(`.op.env`、`npmrc`、OAuth 与机器人 token 文件、`honcho.json`、`mem0.json`、`teams_pipeline_store.json`、`mcp-tokens/`、`vault/`、`proxy/`、浏览器 profile、平台会话,以及位于根目录或嵌套在技能目录下的 `.ssh/`、`.aws/`、`.gnupg/`、`.kube/` 和 `.envrc`)被刻意排除在分发之外。每个安装者使用自己的凭据。(导出文件同样会去除它们。)
+- **你想随 agent 一起共享 API 密钥。** `auth.json`、`.env` 以及 Hermes 从 profile 读取的其他凭据存储(`.op.env`、`npmrc`、OAuth 与机器人 token 文件、`honcho.json`、`mem0.json`、`teams_pipeline_store.json`、`mcp-tokens/`、`vault/`、`proxy/`、浏览器 profile、平台会话,以及位于根目录或嵌套在技能目录下的 `.ssh/`、`.aws/`、`.gnupg/`、`.kube/`、`.docker/`、`.azure/`、`.config/gh/`、`.config/gcloud/` 和 `.envrc`)被刻意排除在分发之外。每个安装者使用自己的凭据。(导出文件同样会去除它们。)
- **你想共享记忆 / 会话 / 对话历史。** 这些是用户数据,不是分发内容,永远不会被发送。
## 生命周期:从作者到安装者再到更新