Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion agents/hermes-01x/Dockerfile.tools
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ RUN set -eu; \
'export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --no-sandbox --no-zygote --disable-gpu"' \
>/etc/chromium.d/nemoclaw-openshell; \
chmod 0644 /etc/chromium.d/nemoclaw-openshell; \
# Hermes' ensure_hermes_home() chmods HERMES_HOME and cron/ to 0700 unless
# it detects a container, and a build step does not match its markers.
# The root Hermes process that reads /sandbox/.hermes therefore sets
# HERMES_CONTAINER=1, as the base image's cron probes do. Without it,
# cron/ became 0700 gateway:sandbox, and the Hermes gateway, which runs as
# user sandbox, could not use cron (#90). Record every directory under
# /sandbox/.hermes before the first Hermes process and compare after the
# last one, so a changed owner or mode fails the build.
hermes_dirs() { \
find /sandbox/.hermes -xdev -type d -printf '%p %u:%g %m\n' >"$1.raw"; \
LC_ALL=C sort "$1.raw" >"$1"; \
rm "$1.raw"; \
}; \
test "$(stat -c '%U:%G %a' /sandbox/.hermes)" = "sandbox:sandbox 3770"; \
test "$(stat -c '%U:%G %a' /sandbox/.hermes/cron)" = "gateway:sandbox 2770"; \
hermes_dirs /tmp/nemoclaw-tools/hermes-dirs.before; \
# Keep Hermes on its built-in browser tools instead of the Browser Use CLI
# that `uvx browser-use` fetches from PyPI (configure-tools-browser.py
# explains why). The managed policy gets the same value, or the dashboard
Expand Down Expand Up @@ -258,7 +274,7 @@ RUN set -eu; \
# does not compile them on every start.
/opt/hermes/.venv/bin/python -I -m py_compile \
/opt/hermes/tools/browser_use_cli.py /opt/hermes/hermes_cli/config_defaults.py; \
( cd /opt/hermes && HERMES_HOME=/sandbox/.hermes /opt/hermes/.venv/bin/python -I -c \
( cd /opt/hermes && HERMES_CONTAINER=1 HERMES_HOME=/sandbox/.hermes /opt/hermes/.venv/bin/python -I -c \
'import sys; sys.path.insert(0, "/opt/hermes"); from tools.browser_use_cli import get_browser_backend, is_browser_use_cli_mode; assert get_browser_backend() == "off" and not is_browser_use_cli_mode()' ); \
mcp_digest="$(/opt/hermes/.venv/bin/python -I /usr/local/lib/nemoclaw/build-hermes-mcp-digest.py --guard /usr/local/lib/nemoclaw/hermes-runtime-config-guard.py --config "$config")"; \
test "$mcp_line" = "# nemoclaw-hermes-mcp-state-v1 intended=$mcp_digest applied=$mcp_digest"; \
Expand Down Expand Up @@ -295,6 +311,10 @@ RUN set -eu; \
( cd /opt/hermes && HOME="$profile_root" HERMES_HOME="$profile_home" /opt/hermes/.venv/bin/python -I -c \
'import sys; sys.path.insert(0, "/opt/hermes"); from tools.browser_use_cli import get_browser_backend, is_browser_use_cli_mode; assert get_browser_backend() == "off" and not is_browser_use_cli_mode()' ); \
rm -rf "$profile_root"; \
test "$(stat -c '%U:%G %a' /sandbox/.hermes)" = "sandbox:sandbox 3770"; \
test "$(stat -c '%U:%G %a' /sandbox/.hermes/cron)" = "gateway:sandbox 2770"; \
hermes_dirs /tmp/nemoclaw-tools/hermes-dirs.after; \
diff -u /tmp/nemoclaw-tools/hermes-dirs.before /tmp/nemoclaw-tools/hermes-dirs.after; \
rm -rf /tmp/nemoclaw-tools /root/.npm /root/.cache /root/.local/share/pnpm

# Same user name as the base image configuration.
Expand Down
10 changes: 10 additions & 0 deletions ci/source-shape-test-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@
"test": "is the manifest the 0.1.x transaction and image load",
"category": "security"
},
{
"file": "test/hermes-01x-image.test.ts",
"test": "sets HERMES_CONTAINER=1 on every line that sets HERMES_HOME=/sandbox/.hermes",
"category": "security"
},
{
"file": "test/hermes-01x-image.test.ts",
"test": "checks cron/ and every Hermes home directory after the last Hermes process",
"category": "security"
},
{
"file": "test/hermes-final-image-layout.test.ts",
"test": "keeps security entrypoint hashes synchronized with the copied files",
Expand Down
10 changes: 9 additions & 1 deletion docs/modification/2026-11-17-hermes-tools-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ Dashboard 使用自己的 profile `dashboard-home`。sandbox 每次啟動時,`st

建置步驟在執行腳本前以 `sha256sum -c` 比對這兩個檔案與 `Dockerfile.tools` 記錄的 hash(`BASE_IMAGE` 中這兩個檔案的 hash),不符時建置失敗;執行後以 `py_compile` 重新產生這兩個 module 的 bytecode。Dashboard policy 檢查之後,建置步驟建立具名 profile `nemoclaw-policy-probe`,確認它沒有 `config.yaml`,接著執行 base 映像的 `profile-policy` 檢查(每個受管路徑,包含 `browser.backend`),並確認 `get_browser_backend()` 為 `off`、不是 Browser Use CLI 模式。

建置步驟以 root 執行 Hermes 程序時,Hermes 的 `ensure_hermes_home()` 會把 `HERMES_HOME` 與 `cron/` 改成 `0700`,除非它判斷自己在容器內。建置步驟不符合它的判斷條件,所以讀 `/sandbox/.hermes` 的步驟設定 `HERMES_CONTAINER=1`,與 base 映像的 cron 檢查相同。`openshell01x-hermes-0.21.3-2026.11.25-tools.1` 沒有這項設定:`cron/` 變成 `0700 gateway:sandbox`,以 sandbox 使用者執行的 Hermes gateway 無法使用 cron(#90)。建置步驟檢查:

- 第一個 Hermes 程序之前與最後一個之後,`/sandbox/.hermes` 下每個目錄的 owner、group 與 mode 相同。
- `/sandbox/.hermes` 是 `sandbox:sandbox 3770`。
- `cron/` 是 `gateway:sandbox 2770`。

任一項不符時建置失敗。

Hermes Agent v0.21.3 以本機 Chromium 執行時不做私有位址檢查(`tools/browser_tool.py` 的 `_url_policy_error`),所以 OpenShell policy DNS 回傳的 `198.18.0.0/15` 合成 IP 不會被擋;雲端 metadata 位址(例如 `169.254.169.254`)仍一律拒絕。這點與 OpenClaw 不同,不需要設定 SSRF 例外。

要讓瀏覽器開網站,sandbox 的 network policy(由 ClawShell 管理)需要一條規則:
Expand All @@ -110,7 +118,7 @@ Hermes Agent v0.21.3 以本機 Chromium 執行時不做私有位址檢查(`tools

| 步驟 | 內容 |
|------|------|
| `check-image.sh ... hermes` | 執行設定、`hermes --version` 與 base 相同;新增的 setuid、setgid 或 file capability 檔案必須列在 `tools/openclaw-tools-image/privileged-files-added.txt` |
| `check-image.sh ... hermes` | 執行設定、`hermes --version` 與 base 相同;新增的 setuid、setgid 或 file capability 檔案必須列在 `tools/openclaw-tools-image/privileged-files-added.txt`;`/sandbox/.hermes` 下每個目錄的 owner、group 與 mode 與 base 相同,tools layer 也不新增目錄 |
| `check-tools-start.sh` | base 與 tools 映像以相同限制啟動(無網路、`--cap-drop ALL`、`no-new-privileges`),容器狀態、啟動輸出、`/tmp/nemoclaw-start.log` 與 process 清單必須相同 |
| `run-fixtures.sh ... hermes` | 以 sandbox 使用者、唯讀 root、無 capability、無網路執行共用 fixture;OpenClaw 專屬的 `himalaya_skill_override` 與 `browser_config` 記為 `SKIP`,`himalaya_journey` 略過 skill 檢查。`hermes_browser_backend` 確認 `browser.backend` 為 `off`、設定 hash 相符、Hermes 提供內建 browser 工具;`hermes_dashboard_seed` 以映像內的 policy 與 `config.yaml` 執行 Dashboard 設定同步,產生的設定要有模型,`browser.backend` 為 `off`;`agent_browser` 不帶任何 agent-browser 設定開頁,並確認 Chromium 帶著 `/etc/chromium.d` 的參數執行;`hermes_profile_browser` 建立沒有 `config.yaml` 的具名 profile,並把記錄呼叫的 `uvx` 放在 `PATH` 最前面,確認 `browser.backend` 為 `off`、不是 Browser Use CLI 模式、browser 工具組有 `browser_navigate` 與 `browser_snapshot` 而沒有 `browser_exec`,再以 `browser_navigate` 開啟本機檔案頁面並檢查 snapshot;`uvx` 被呼叫時失敗 |
| Trivy | tools layer 不得新增可修正的 CRITICAL 或 HIGH 弱點 |
Expand Down
134 changes: 134 additions & 0 deletions test/hermes-01x-image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,137 @@ describe("patch-agent-home-state-symlink.py", () => {
expect(changed.result.stderr).toContain("source shape changed");
});
});

// ── Hermes home permissions in the tools image (#90) ────────────────────
// Hermes' ensure_hermes_home() chmods HERMES_HOME and cron/ to 0700 unless it
// detects a container. A root build step that ran Hermes on /sandbox/.hermes
// without HERMES_CONTAINER=1 left cron/ 0700 gateway:sandbox, so the Hermes
// gateway, which runs as user sandbox, could not use cron.
describe("Hermes tools image keeps the base image's Hermes home permissions (#90)", () => {
const TOOLS_DOCKERFILE = path.join(AGENT, "Dockerfile.tools");
const CHECK_IMAGE = path.resolve(
import.meta.dirname,
"../tools/openclaw-tools-image/fixtures/check-image.sh",
);
const HERMES_HOME_RUN = "HERMES_HOME=/sandbox/.hermes";

// source-shape-contract: security -- Hermes chmods its home and cron/ to 0700 outside a container, which locks the sandbox-run gateway out of cron
it("sets HERMES_CONTAINER=1 on every line that sets HERMES_HOME=/sandbox/.hermes", () => {
const tools = fs.readFileSync(TOOLS_DOCKERFILE, "utf8");
const lines = tools.split("\n").filter((line) => line.includes(HERMES_HOME_RUN));
expect(lines.length).toBeGreaterThan(0);
for (const line of lines) expect(line, line.trim()).toContain("HERMES_CONTAINER=1");
});

// source-shape-contract: security -- The build must fail when the tools layer changes the owner or mode the base image gives cron/ and the other Hermes home directories
it("checks cron/ and every Hermes home directory after the last Hermes process", () => {
const tools = fs.readFileSync(TOOLS_DOCKERFILE, "utf8");
const base = fs.readFileSync(path.join(AGENT, "Dockerfile"), "utf8");
const baseCron = base.match(/check_metadata \/sandbox\/\.hermes\/cron '([^']+)'/);
expect(baseCron, "base image cron/ metadata check").not.toBeNull();
const lastHermes = tools.lastIndexOf(HERMES_HOME_RUN);
const cronCheck = tools.lastIndexOf(
`test "$(stat -c '%U:%G %a' /sandbox/.hermes/cron)" = "${baseCron![1]}"`,
);
const dirsCheck = tools.lastIndexOf(
"diff -u /tmp/nemoclaw-tools/hermes-dirs.before /tmp/nemoclaw-tools/hermes-dirs.after",
);
expect(cronCheck).toBeGreaterThan(lastHermes);
expect(dirsCheck).toBeGreaterThan(lastHermes);
expect(tools.indexOf("hermes_dirs /tmp/nemoclaw-tools/hermes-dirs.before")).toBeLessThan(
tools.indexOf(HERMES_HOME_RUN),
);
});

describe("check-image.sh", () => {
const BASE = "registry.example/hermes@sha256:" + "a".repeat(64);
const TOOLS = "nemoclaw-hermes-tools:ci";
const HERMES_DIRS = [
"/sandbox/.hermes sandbox:sandbox 3770",
"/sandbox/.hermes/cron gateway:sandbox 2770",
"/sandbox/.hermes/sessions sandbox:sandbox 770",
];
// Answers only the docker commands check-image.sh runs.
const FAKE_DOCKER = `#!/usr/bin/env bash
set -euo pipefail
image_after_entrypoint() {
while [ "$#" -gt 0 ]; do
if [ "$1" = --entrypoint ]; then echo "$3"; return; fi
shift
done
}
case "$1" in
buildx) echo '{"manifests":[{"platform":{"os":"linux","architecture":"amd64"}},{"platform":{"os":"linux","architecture":"arm64"}}]}' ;;
pull) ;;
image)
if [ "$2" = inspect ] && [ "$3" = -f ]; then echo 100; else echo '[{"Config":{"User":"sandbox"}}]'; fi ;;
run)
image=$(image_after_entrypoint "$@")
case "$*" in
*"--entrypoint hermes"*) echo "Hermes Agent v0.21.3" ;;
*"--entrypoint /usr/bin/find"*)
if [ "$image" = "$FAKE_TOOLS" ] && [ -n "\${FAKE_TOOLS_HERMES_DIRS:-}" ]; then
printf '%s\\n' "$FAKE_TOOLS_HERMES_DIRS"
else
printf '%s\\n' "$FAKE_BASE_HERMES_DIRS"
fi ;;
*"--entrypoint dpkg-query"*) printf 'bash\\t5.2\\n' ;;
*) ;;
esac ;;
*) echo "unexpected docker command: $*" >&2; exit 64 ;;
esac
`;
let dir: string;
beforeEach(() => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), "check-image-"));
fs.mkdirSync(path.join(dir, "bin"));
fs.writeFileSync(path.join(dir, "bin", "docker"), FAKE_DOCKER, { mode: 0o755 });
});
afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));

function checkImage(toolsDirs?: string[]) {
const env: Record<string, string | undefined> = {
...process.env,
PATH: `${path.join(dir, "bin")}:${process.env.PATH}`,
FAKE_TOOLS: TOOLS,
FAKE_BASE_HERMES_DIRS: [...HERMES_DIRS].reverse().join("\n"),
FAKE_TOOLS_HERMES_DIRS: toolsDirs?.join("\n"),
};
return spawnSync("bash", [CHECK_IMAGE, BASE, TOOLS, path.join(dir, "out"), "hermes"], {
encoding: "utf8",
env,
});
}

it("passes when the tools image keeps every Hermes home directory", () => {
const result = checkImage(HERMES_DIRS);
expect(result.status, result.stderr).toBe(0);
expect(fs.readFileSync(path.join(dir, "out", "tools-hermes-dirs.txt"), "utf8")).toBe(
`${HERMES_DIRS.join("\n")}\n`,
);
});

it("fails when the tools image makes cron/ 0700", () => {
const result = checkImage(
HERMES_DIRS.map((line) =>
line.startsWith("/sandbox/.hermes/cron ")
? "/sandbox/.hermes/cron gateway:sandbox 700"
: line,
),
);
expect(result.status).not.toBe(0);
expect(result.stdout).toContain("+/sandbox/.hermes/cron gateway:sandbox 700");
expect(result.stderr).toContain(
"FAIL: tools layer changes directories under /sandbox/.hermes",
);
});

it("fails when the tools image adds a directory under /sandbox/.hermes", () => {
const result = checkImage([...HERMES_DIRS, "/sandbox/.hermes/backups root:root 755"]);
expect(result.status).not.toBe(0);
expect(result.stderr).toContain(
"FAIL: tools layer changes directories under /sandbox/.hermes",
);
});
});
});
16 changes: 16 additions & 0 deletions tools/openclaw-tools-image/fixtures/check-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ unexpected=$(LC_ALL=C comm -23 "$out/added-privileged.txt" "$out/allowed-privile
test -z "$unexpected" || fail "tools layer adds privileged files not in privileged-files-added.txt:
$unexpected"

# The Hermes gateway runs as sandbox and reaches cron/ and other state through
# group sandbox. Every directory under /sandbox/.hermes must keep the base
# image's owner, group, and mode, and the tools layer adds none (#90).
if [ "$agent" = hermes ]; then
hermes_dirs() {
docker run --rm --network none --user root --entrypoint /usr/bin/find "$1" \
/sandbox/.hermes -xdev -type d -printf '%p %u:%g %m\n' >"$2.raw"
LC_ALL=C sort "$2.raw" >"$2"
rm "$2.raw"
}
hermes_dirs "$base" "$out/base-hermes-dirs.txt"
hermes_dirs "$tools" "$out/tools-hermes-dirs.txt"
diff -u "$out/base-hermes-dirs.txt" "$out/tools-hermes-dirs.txt" \
|| fail "tools layer changes directories under /sandbox/.hermes"
fi

base_size=$(docker image inspect -f '{{.Size}}' "$base")
tools_size=$(docker image inspect -f '{{.Size}}' "$tools")
jq -n --argjson base "$base_size" --argjson tools "$tools_size" \
Expand Down
Loading