From bbce5eac4e2c7c65c377ac65e68841f4be7e1c98 Mon Sep 17 00:00:00 2001 From: Derek Hsu Date: Thu, 3 Dec 2026 13:34:23 +0800 Subject: [PATCH] fix(images): install libexpat 2.9.0 in the Hermes 0.1.x base LibreOffice 4:26.8.3.1-0+deb13u1 in Debian trixie-security depends on libexpat1 (>= 2.9.0). The Hermes 0.1.x base held libexpat1 2.8.3-1, so the Hermes tools image could not install it (#92). - agents/hermes-01x/Dockerfile.base installs libexpat1 2.9.0-1~deb13u1 from the snapshot.debian.org URL and with the SHA-256 values that the OpenClaw base already uses, and checks pyexpat for expat 2.9.0. - A new controlled package profile, hermes-01x, is the shared inventory with libexpat1=2.9.0-1~deb13u1. The Hermes 0.1.x base writes and probes it, and the final Hermes 0.1.x image probes it instead of hermes-compatible and checks expat 2.9.0. - The shared, openclaw, and hermes-compatible profiles do not change, so the OpenShell 0.0.x Hermes and Deep Agents Code bases and the CLI inventory checks keep their behavior. - The base security package test covers the Hermes 0.1.x base and final image, including a final image on a base that still has libexpat 2.8.3, which must fail. No image is published here. After merge, the Hermes 0.1.x image must be published and agents/hermes-01x/Dockerfile.tools must move to its digest before the tools image can be released. Refs #95, #92 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Hsu --- agents/hermes-01x/Dockerfile | 4 +- agents/hermes-01x/Dockerfile.base | 14 ++-- .../2026-11-17-hermes-tools-image.md | 11 ++- .../security/security-package-inventory.mts | 9 ++- .../standalone-security-package-inventory.mts | 17 +++-- .../security-package-specs.ts | 9 ++- test/helpers/base-apt-security-functions.ts | 12 +++- test/helpers/dockerfile-run-shell.test.ts | 26 ++++++- test/helpers/dockerfile-run-shell.ts | 28 ++++++++ .../sandbox-base-security-packages.test.ts | 68 ++++++++++++++++++- 10 files changed, 173 insertions(+), 25 deletions(-) diff --git a/agents/hermes-01x/Dockerfile b/agents/hermes-01x/Dockerfile index 4cbf6a0cf6e..911017e1872 100644 --- a/agents/hermes-01x/Dockerfile +++ b/agents/hermes-01x/Dockerfile @@ -1365,13 +1365,13 @@ RUN ( set -eu; \ && check_metadata /sandbox/.venvs/sandbox-mcp-server/bin/sandbox-mcp-server 'root:root 755' ) \ # Verify the immutable security package inventory in the completed image. && ( set -eu; \ - security_probe="$(node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON /opt/nemoclaw-security/scripts/security/security-package-inventory.mts probe hermes-compatible)"; \ + security_probe="$(node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON /opt/nemoclaw-security/scripts/security/security-package-inventory.mts probe hermes-01x)"; \ sh -ec "$security_probe"; \ test "$(perl -e 'print $^V')" = "v5.44.0"; \ ldd /usr/bin/jq | grep -Eq 'libonig[.]so[.]5'; \ test "$(jq --version)" = "jq-1.8.2"; \ printf '%s\n' '{"sandbox":"healthy"}' | jq -e '.sandbox == "healthy"' >/dev/null; \ - python3 -c "import pyexpat; assert pyexpat.EXPAT_VERSION == 'expat_2.8.3', pyexpat.EXPAT_VERSION"; \ + python3 -c "import pyexpat; assert pyexpat.EXPAT_VERSION == 'expat_2.9.0', pyexpat.EXPAT_VERSION"; \ printf '%s %s\n' \ "4ff43a8578bda2f14686c67911b64c18e869841973722b1c623b5727491bdaf7" \ /usr/lib/python3.13/html/parser.py \ diff --git a/agents/hermes-01x/Dockerfile.base b/agents/hermes-01x/Dockerfile.base index df5184f181d..3723e5e8f8f 100644 --- a/agents/hermes-01x/Dockerfile.base +++ b/agents/hermes-01x/Dockerfile.base @@ -135,14 +135,14 @@ RUN --mount=type=bind,source=scripts/security/security-package-inventory.mts,tar && arch="$(dpkg --print-architecture)" \ && case "$arch" in \ amd64) \ - libexpat_sha256="978e9d30b84893a4c8191d8dae4d1b93c9b7ecaa772ada2fdb892ae3765cab4e"; \ + libexpat_sha256="feff874772cae904ae4d24e917b35664952bec4b4ae9100a4edda5a7fa746832"; \ libonig_sha256="3abee130696244050500bcc7870e3b4cb82ddd87149ece3fd55010c3d4e1d18c"; \ libjq_sha256="9a5bf964cef39ed8f0f162e20d856e31961d28a57772b5313989b42a8be7e941"; \ jq_sha256="b973a5d304f666845e8ccefab492e3850d4bc2e7aa2a1e7450862095125f2cc0"; \ vim_tiny_sha256="df2d037d405f1376d1d8025d022dba81fbfed8695f68a131b788d16d3b68cf83" \ ;; \ arm64) \ - libexpat_sha256="660f5f598a06aa56613a2fbf1ffbd408708175f1a6c2fac833842148f0228176"; \ + libexpat_sha256="d9e1c50fcdad079fe16d77f1578adcc763be1bf7f2da7fa8adca7010b0c84c83"; \ libonig_sha256="137e708575c0622d347815d19cb471a107546b16e9602805ee27afad7bba107f"; \ libjq_sha256="eae4a828df2eb53d728f88109d9f9549e0983a90b573cf0c7fa1e4bbc7533a7e"; \ jq_sha256="c25086443abd04d1457cbb322a0837f9ba986f82b28f44670467c8dc9be1f696"; \ @@ -152,14 +152,14 @@ RUN --mount=type=bind,source=scripts/security/security-package-inventory.mts,tar esac \ && security_deb_dir="/tmp/nemoclaw-debian-security" \ && snapshot_url="https://snapshot.debian.org/archive/debian/20260724T000000Z/pool/main" \ - && expat_snapshot_url="https://snapshot.debian.org/archive/debian/20260811T082421Z/pool/main" \ + && expat_snapshot_url="https://snapshot.debian.org/archive/debian/20261017T204620Z/pool/main" \ && vim_snapshot_url="https://snapshot.debian.org/archive/debian/20260727T143429Z/pool/main" \ && vim_common_sha256="c21aad77632ef790d2352f1c38e688069980bbd530034248dd5e1158da9c9fe3" \ && mkdir -p "$security_deb_dir" \ && curl --proto '=https' --tlsv1.2 -fsSL \ --retry 5 --retry-all-errors --retry-delay 2 --connect-timeout 15 --max-time 120 \ -o "$security_deb_dir/libexpat1.deb" \ - "$expat_snapshot_url/e/expat/libexpat1_2.8.3-1_${arch}.deb" \ + "$expat_snapshot_url/e/expat/libexpat1_2.9.0-1~deb13u1_${arch}.deb" \ && curl --proto '=https' --tlsv1.2 -fsSL \ --retry 5 --retry-all-errors --retry-delay 2 --connect-timeout 15 --max-time 120 \ -o "$security_deb_dir/libonig5.deb" \ @@ -204,7 +204,7 @@ RUN --mount=type=bind,source=scripts/security/security-package-inventory.mts,tar && test "$(jq --version)" = "jq-1.8.2" \ && ldd /usr/bin/jq | grep -Eq 'libonig[.]so[.]5' \ && printf '%s\n' '{"sandbox":"healthy"}' | jq -e '.sandbox == "healthy"' >/dev/null \ - && python3 -c "import pyexpat; assert pyexpat.EXPAT_VERSION == 'expat_2.8.3', pyexpat.EXPAT_VERSION" \ + && python3 -c "import pyexpat; assert pyexpat.EXPAT_VERSION == 'expat_2.9.0', pyexpat.EXPAT_VERSION" \ && printf '%s %s\n' \ "4ff43a8578bda2f14686c67911b64c18e869841973722b1c623b5727491bdaf7" \ /usr/lib/python3.13/html/parser.py \ @@ -226,11 +226,11 @@ RUN --mount=type=bind,source=scripts/security/security-package-inventory.mts,tar && perl -e \ 'my $x = join "|", "aaa".."mzz"; my $y = join "|", "naa".."zzz"; use re "Debug"; "fnord" =~ m/(?:$x)|(?:$y)/' \ && install -d -o root -g root -m 0755 /usr/local/share/nemoclaw \ - && node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON /tmp/nemoclaw-security/scripts/security/security-package-inventory.mts inventory shared "$(dpkg --print-architecture)" \ + && node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON /tmp/nemoclaw-security/scripts/security/security-package-inventory.mts inventory hermes-01x "$(dpkg --print-architecture)" \ > /usr/local/share/nemoclaw/security-packages.txt \ && chown root:root /usr/local/share/nemoclaw/security-packages.txt \ && chmod 0444 /usr/local/share/nemoclaw/security-packages.txt \ - && security_probe="$(node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON /tmp/nemoclaw-security/scripts/security/security-package-inventory.mts probe shared)" \ + && security_probe="$(node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON /tmp/nemoclaw-security/scripts/security/security-package-inventory.mts probe hermes-01x)" \ && sh -ec "$security_probe" \ && rm -rf /tmp/nemoclaw-native-security \ && rm -rf "$security_deb_dir" \ diff --git a/docs/modification/2026-11-17-hermes-tools-image.md b/docs/modification/2026-11-17-hermes-tools-image.md index 9d201f8edd6..263934be58b 100644 --- a/docs/modification/2026-11-17-hermes-tools-image.md +++ b/docs/modification/2026-11-17-hermes-tools-image.md @@ -26,6 +26,15 @@ agent 在 sandbox 內處理這些工作時,不需要在執行期間下載套件 index digest 為 `sha256:89aad1dc08c0c8d7fafc49089f7351b44ed4dec6b5027df6b8d8b193af04a577`。 `agents/hermes-01x/Dockerfile.tools` 的 `BASE_IMAGE` 同時寫出 tag 與 digest;建置以 digest 為準,tag 用來產生發布 tag。 +`2026.11.25` base 不能安裝 Debian trixie-security 目前提供的 LibreOffice `4:26.8.3.1-0+deb13u1`:它需要 `libexpat1 (>= 2.9.0)`,但這個 base 的受控套件是 `libexpat1 2.8.3-1`,tools 映像的 apt 步驟因此失敗(#92)。 +Issue #95 讓 Hermes 0.1.x base(`agents/hermes-01x/Dockerfile.base`)改裝 `libexpat1 2.9.0-1~deb13u1`,也就是 OpenClaw base 已審過的同一個檔案,並使用 Hermes 0.1.x 專用的受控套件 profile `hermes-01x`。 +OpenShell 0.0.x 的 Hermes 與 Deep Agents Code base 仍是 `2.8.3-1`。 +這項修改不發布映像;合併後依序執行: + +1. 以 `Images / Hermes OpenShell 0.1.x` 發布新的 Hermes 映像。 +2. 把新的 tag 與 index digest 寫進 `Dockerfile.tools` 的 `BASE_IMAGE`(見第 5 節的「更新 base」)。 +3. 發布 tools 映像。 + 只提供 OpenShell 0.1.x 版本。OpenShell 0.0.x 的 Hermes 映像(`agents/hermes/`)預定淘汰,不提供 tools 映像。 這是本 fork 的功能,不是 NVIDIA 官方支援的產品。 @@ -144,5 +153,5 @@ gateway 與 API runtime 由 OpenShell 啟動,要在 OpenShell 0.1.7 sandbox 中 - **新增的特權檔案**:LibreOffice 的相依套件帶入 `dbus-daemon-launch-helper`(setuid)與 `gst-ptp-helper`(file capability)。process 設定 `no_new_privs` 時兩者都不會取得額外權限;fixture 與啟動比對都在這個條件下執行,OpenShell sandbox 內的 process 也實測為 `NoNewPrivs: 1`(見下方實機驗收)。其他新增的特權檔案會讓 `check-image.sh` 失敗。 - **API profile 不受影響**:API profile 的政策拒絕 terminal 與 browser 工具,Landlock 也只開放部分路徑,新工具只在預設 profile 使用。API profile 的 `config.yaml` 由 managed policy 的受管區段產生,`tools.3` 起 `browser` 區段也帶有 `backend: "off"`,但 browser 工具仍被拒絕。 - **沒有 `config.yaml` 的具名 profile**:`tools.2` 與 `tools.3` 中,這類 profile 的 `browser.backend` 是未設定,Hermes 改用 Browser Use CLI;base 映像的 `profile-policy` 檢查若在這兩版重跑,會因此不通過。`tools.4` 起,Hermes 原始碼的預設值是 `off`(見 3.3 節),建置步驟在 tools 映像重跑 `profile-policy` 檢查,fixture 的 `hermes_profile_browser` 也確認不會呼叫 `uvx`。profile 自己設定的 `browser.backend` 仍然優先,設成 `""` 或 `browser-use` 時 Hermes 仍會改用 Browser Use CLI。base 映像(`openshell-hermes`)沒有這項修改。 -- **base 的安全檢查**:Hermes base 沒有 tmux,受控的 expat 版本(`libexpat1=2.8.3-1`)也與 OpenClaw base(2.9.0)不同,所以 `base_security_checks` 只對 OpenClaw 檢查這兩項;Hermes 的 expat 版本由 `controlled_packages` 依 base 的 `security-packages.txt` 檢查。 +- **base 的安全檢查**:Hermes base 沒有 tmux,`2026.11.25` base 的受控 expat 版本(`libexpat1=2.8.3-1`)也與 OpenClaw base(2.9.0)不同,所以 `base_security_checks` 只對 OpenClaw 檢查這兩項;Hermes 的 expat 版本由 `controlled_packages` 依 base 的 `security-packages.txt` 檢查。#95 之後的 Hermes base 改用 `2.9.0-1~deb13u1`。 - **實機驗收**(`tools.1`,OpenShell 0.1.7、Podman、arm64,經 ClawShell 建立):sandbox 到 `running`,API 對話與 `upload_file` 上傳下載正常;`nemoclaw-start`、Hermes gateway、API runtime 與 MCP supervisor 的 `NoNewPrivs` 皆為 1;4 個 LibreOffice 同時轉檔時 sandbox 內 process 峰值 31(#32 的上限 512)。 diff --git a/scripts/security/security-package-inventory.mts b/scripts/security/security-package-inventory.mts index f4a458f13eb..839baf541ba 100644 --- a/scripts/security/security-package-inventory.mts +++ b/scripts/security/security-package-inventory.mts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { + HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, OPENCLAW_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, PINNED_HERMES_BASE_SECURITY_PACKAGE_INVENTORY, SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, @@ -9,13 +10,15 @@ import { } from "../../src/lib/sandbox-base-image/security-package-specs.ts"; const [operation, profile, architecture] = process.argv.slice(2); -if (!["shared", "openclaw", "hermes-compatible"].includes(profile ?? "")) { - throw new Error("Expected shared, openclaw, or hermes-compatible package profile"); +if (!["shared", "openclaw", "hermes-compatible", "hermes-01x"].includes(profile ?? "")) { + throw new Error("Expected shared, openclaw, hermes-compatible, or hermes-01x package profile"); } const inventory = profile === "openclaw" ? OPENCLAW_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY - : SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY; + : profile === "hermes-01x" + ? HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY + : SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY; switch (operation) { case "inventory": if (architecture !== "amd64" && architecture !== "arm64") { diff --git a/scripts/security/standalone-security-package-inventory.mts b/scripts/security/standalone-security-package-inventory.mts index c08923519d8..695d037bac9 100644 --- a/scripts/security/standalone-security-package-inventory.mts +++ b/scripts/security/standalone-security-package-inventory.mts @@ -12,7 +12,8 @@ const PINNED_HERMES_BASE_SECURITY_PACKAGE_OVERRIDES: ReadonlyMap ["libc-bin=2.41-12+deb13u5", "libc-bin=2.41-12+deb13u4"], ]); const SHARED_LIBEXPAT_PACKAGE = "libexpat1=2.8.3-1"; -// Only the OpenClaw base installs the Debian security update (#19). +// The OpenClaw (#19) and Hermes 0.1.x base images install the Debian security +// update. LibreOffice 26.8 in the Hermes tools image needs it (#95). const OPENCLAW_LIBEXPAT_PACKAGE = "libexpat1=2.9.0-1~deb13u1"; const SHARED_ZLIB_PACKAGE = "zlib1g=1:1.3.dfsg+really1.3.1-1+b1+nemoclaw1"; // The OpenClaw base installs Debian's zlib and apt security updates, which @@ -66,6 +67,12 @@ const OPENCLAW_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY = [ "libapt-pkg7.0=3.0.4", ] as const; +/** Hermes 0.1.x base: the shared inventory with the Debian expat update (#95). */ +const HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY = + SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY.map((packageSpec) => + packageSpec === SHARED_LIBEXPAT_PACKAGE ? OPENCLAW_LIBEXPAT_PACKAGE : packageSpec, + ); + const SECURITY_INVENTORY_PROBE_OK = "nemoclaw-security-inventory-ok"; const SANDBOX_BASE_NODE_VERSION = "24.22.1"; @@ -107,13 +114,15 @@ function securityInventoryProbe( } const [operation, profile, architecture] = process.argv.slice(2); -if (!["shared", "openclaw", "hermes-compatible"].includes(profile ?? "")) { - throw new Error("Expected shared, openclaw, or hermes-compatible package profile"); +if (!["shared", "openclaw", "hermes-compatible", "hermes-01x"].includes(profile ?? "")) { + throw new Error("Expected shared, openclaw, hermes-compatible, or hermes-01x package profile"); } const inventory = profile === "openclaw" ? OPENCLAW_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY - : SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY; + : profile === "hermes-01x" + ? HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY + : SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY; switch (operation) { case "inventory": if (architecture !== "amd64" && architecture !== "arm64") { diff --git a/src/lib/sandbox-base-image/security-package-specs.ts b/src/lib/sandbox-base-image/security-package-specs.ts index a17973471cd..fdd0ce060ac 100644 --- a/src/lib/sandbox-base-image/security-package-specs.ts +++ b/src/lib/sandbox-base-image/security-package-specs.ts @@ -12,7 +12,8 @@ const PINNED_HERMES_BASE_SECURITY_PACKAGE_OVERRIDES: ReadonlyMap ["libc-bin=2.41-12+deb13u5", "libc-bin=2.41-12+deb13u4"], ]); const SHARED_LIBEXPAT_PACKAGE = "libexpat1=2.8.3-1"; -// Only the OpenClaw base installs the Debian security update (#19). +// The OpenClaw (#19) and Hermes 0.1.x base images install the Debian security +// update. LibreOffice 26.8 in the Hermes tools image needs it (#95). const OPENCLAW_LIBEXPAT_PACKAGE = "libexpat1=2.9.0-1~deb13u1"; const SHARED_ZLIB_PACKAGE = "zlib1g=1:1.3.dfsg+really1.3.1-1+b1+nemoclaw1"; // The OpenClaw base installs Debian's zlib and apt security updates, which @@ -67,6 +68,12 @@ export const OPENCLAW_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY = [ "libapt-pkg7.0=3.0.4", ] as const; +/** Hermes 0.1.x base: the shared inventory with the Debian expat update (#95). */ +export const HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY = + SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY.map((packageSpec) => + packageSpec === SHARED_LIBEXPAT_PACKAGE ? OPENCLAW_LIBEXPAT_PACKAGE : packageSpec, + ); + export const SECURITY_INVENTORY_PROBE_OK = "nemoclaw-security-inventory-ok"; export const SANDBOX_BASE_NODE_VERSION = "24.22.1"; diff --git a/test/helpers/base-apt-security-functions.ts b/test/helpers/base-apt-security-functions.ts index a9cf9f439c2..8a0be8fa6b5 100644 --- a/test/helpers/base-apt-security-functions.ts +++ b/test/helpers/base-apt-security-functions.ts @@ -9,7 +9,7 @@ export type BaseAptLibexpatPackage = Readonly<{ sha256: Readonly>; }>; -/** Expat package that the Hermes and Deep Agents Code base images install. */ +/** Expat package that the Hermes (OpenShell 0.0.x) and Deep Agents Code base images install. */ export const SHARED_LIBEXPAT_PACKAGE: BaseAptLibexpatPackage = { debianVersion: "2.8.3-1", expatVersion: "2.8.3", @@ -19,7 +19,7 @@ export const SHARED_LIBEXPAT_PACKAGE: BaseAptLibexpatPackage = { }, }; -/** Expat security update that only the OpenClaw base image installs (#19). */ +/** Expat security update that the OpenClaw (#19) and Hermes 0.1.x base images install. */ export const OPENCLAW_LIBEXPAT_PACKAGE: BaseAptLibexpatPackage = { debianVersion: "2.9.0-1~deb13u1", expatVersion: "2.9.0", @@ -61,12 +61,18 @@ export type BaseAptImagePackages = Readonly<{ zlib1gVersion: string; }>; -/** Hermes and Deep Agents Code: NemoClaw zlib backport. */ +/** Hermes (OpenShell 0.0.x) and Deep Agents Code: NemoClaw zlib backport. */ export const SHARED_BASE_APT_PACKAGES: BaseAptImagePackages = { libexpat: SHARED_LIBEXPAT_PACKAGE, zlib1gVersion: "1:1.3.dfsg+really1.3.1-1+b1+nemoclaw1", }; +/** Hermes 0.1.x: Debian expat security update and the NemoClaw zlib backport. */ +export const HERMES_01X_BASE_APT_PACKAGES: BaseAptImagePackages = { + libexpat: OPENCLAW_LIBEXPAT_PACKAGE, + zlib1gVersion: SHARED_BASE_APT_PACKAGES.zlib1gVersion, +}; + /** OpenClaw: Debian expat, zlib, and apt security updates. */ export const OPENCLAW_BASE_APT_PACKAGES: BaseAptImagePackages = { libexpat: OPENCLAW_LIBEXPAT_PACKAGE, diff --git a/test/helpers/dockerfile-run-shell.test.ts b/test/helpers/dockerfile-run-shell.test.ts index 7a95ab962a3..4906a59f972 100644 --- a/test/helpers/dockerfile-run-shell.test.ts +++ b/test/helpers/dockerfile-run-shell.test.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, expect, it } from "vitest"; -import { dockerRunCommandBetween } from "./dockerfile-run-shell"; +import { dockerRunCommandBetween, dockerSubshellBetween } from "./dockerfile-run-shell"; describe("Dockerfile RUN shell extraction", () => { it("removes Docker instruction options before returning the shell command", () => { @@ -32,4 +32,28 @@ describe("Dockerfile RUN shell extraction", () => { "if true; then printf 'ready\\n'; fi", ); }); + + it("returns the commands of a subshell inside a merged RUN instruction", () => { + const dockerfile = [ + "RUN true \\", + " # start", + " && ( set -eu; \\", + " printf 'ready\\n'; \\", + " test -n ready ) \\", + " # end", + " && true", + ].join("\n"); + + expect(dockerSubshellBetween(dockerfile, "# start", "# end")).toBe( + "set -eu; printf 'ready\\n'; test -n ready", + ); + }); + + it("rejects a block that is not one subshell", () => { + const dockerfile = ["# start", "RUN printf 'ready\\n'", "# end"].join("\n"); + + expect(() => dockerSubshellBetween(dockerfile, "# start", "# end")).toThrow( + "Expected one && ( ... ) subshell after # start", + ); + }); }); diff --git a/test/helpers/dockerfile-run-shell.ts b/test/helpers/dockerfile-run-shell.ts index 6d8430bd788..959951d43c8 100644 --- a/test/helpers/dockerfile-run-shell.ts +++ b/test/helpers/dockerfile-run-shell.ts @@ -50,6 +50,34 @@ export function dockerRunCommandBetween( .replace(/^(?:--[a-z-]+=[^\s]+\s+)+/u, ""); } +/** + * Return the commands of a `&& ( ... )` subshell that a merged RUN instruction + * holds between two comment markers. + */ +export function dockerSubshellBetween( + dockerfile: string, + startMarker: string, + endMarker: string, +): string { + const start = dockerfile.indexOf(startMarker); + const end = dockerfile.indexOf(endMarker, start); + if (start === -1 || end === -1 || end <= start) { + throw new Error(`Expected Dockerfile block between ${startMarker} and ${endMarker}`); + } + const block = dockerfile + .slice(start, end) + .split("\n") + .filter((line) => !line.trimStart().startsWith("#")) + .join("\n") + .trim() + .replace(/\\\n\s*/g, " "); + const match = block.match(/^&& \( ([\s\S]*) \) \\$/u); + if (!match) { + throw new Error(`Expected one && ( ... ) subshell after ${startMarker}`); + } + return match[1]; +} + export function shellCommandSegmentBetween( command: string, startMarker: string, diff --git a/test/runtime/sandbox/sandbox-base-security-packages.test.ts b/test/runtime/sandbox/sandbox-base-security-packages.test.ts index b0459e196de..5c561eb2429 100644 --- a/test/runtime/sandbox/sandbox-base-security-packages.test.ts +++ b/test/runtime/sandbox/sandbox-base-security-packages.test.ts @@ -11,6 +11,7 @@ import { SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, } from "../../../src/lib/sandbox-base-image/security-inventory"; import { + HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, PINNED_HERMES_BASE_SECURITY_PACKAGE_INVENTORY, SANDBOX_BASE_NODE_VERSION, securityInventoryProbe, @@ -19,10 +20,15 @@ import { BASE_APT_SECURITY_HASHES, type BaseAptImagePackages, baseAptSecurityFunctions, + HERMES_01X_BASE_APT_PACKAGES, OPENCLAW_BASE_APT_PACKAGES, SHARED_BASE_APT_PACKAGES, } from "../../helpers/base-apt-security-functions"; -import { dockerRunCommandBetween, runLoggedDockerShell } from "../../helpers/dockerfile-run-shell"; +import { + dockerRunCommandBetween, + dockerSubshellBetween, + runLoggedDockerShell, +} from "../../helpers/dockerfile-run-shell"; import { stageFixedParser, useRealPatchedParser, @@ -53,6 +59,19 @@ const SECURITY_IMAGES = [ aptPackages: SHARED_BASE_APT_PACKAGES, libexpatSnapshot: "20260811T082421Z", }, + { + name: "Hermes 0.1.x", + dockerfile: path.join(ROOT, "agents", "hermes-01x", "Dockerfile.base"), + finalDockerfile: path.join(ROOT, "agents", "hermes-01x", "Dockerfile"), + startMarker: "# Install the reviewed libexpat, jq, and Vim packages", + additionalStartMarker: null, + endMarker: "COPY scripts/lib/reviewed-npm-archive.mts", + expectedInventory: HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, + aptPackages: HERMES_01X_BASE_APT_PACKAGES, + libexpatSnapshot: "20261017T204620Z", + // The completed-image check is a subshell of a merged RUN (#70). + completedImageCheck: "subshell", + }, { name: "Deep Agents Code", dockerfile: path.join(ROOT, "agents", "langchain-deepagents-code", "Dockerfile.base"), @@ -106,6 +125,10 @@ const EXPECTED_OPENCLAW_SECURITY_PACKAGE_INVENTORY = [ "apt=3.0.4", "libapt-pkg7.0=3.0.4", ] as const; +// Hermes 0.1.x installs the Debian expat update that LibreOffice 26.8 needs. +const EXPECTED_HERMES_01X_SECURITY_PACKAGE_INVENTORY = EXPECTED_SECURITY_PACKAGE_INVENTORY.map( + (entry) => (entry === "libexpat1=2.8.3-1" ? "libexpat1=2.9.0-1~deb13u1" : entry), +); const PUBLISHED_HERMES_SECURITY_PACKAGE_OVERRIDES = new Map([ [ "nemoclaw-python3.13-htmlparser-fix=3.13.5-2+deb13u5+nemoclaw1", @@ -130,6 +153,7 @@ const REDUCED_CONTEXT_PROFILES = [ SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, PINNED_HERMES_BASE_SECURITY_PACKAGE_INVENTORY, ], + ["hermes-01x", HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, undefined], ] as const; function runReducedContextRenderer(...args: string[]) { @@ -179,7 +203,7 @@ function stageInventoryRenderer( // Execute the real renderer with the fixture's simulated installed packages. // A child shell preserves errexit when the Dockerfile invokes the probe in &&. const staged = command.replace( - /\$\(node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON \/(?:tmp|opt)\/nemoclaw-security\/scripts\/security\/security-package-inventory\.mts probe ([a-z-]+)\)/g, + /\$\(node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON \/(?:tmp|opt)\/nemoclaw-security\/scripts\/security\/security-package-inventory\.mts probe ([a-z0-9-]+)\)/g, (_match, profile: string) => { const rendered = spawnSync(process.execPath, [renderer, "probe", profile], { encoding: "utf8", @@ -320,7 +344,8 @@ function completedImageSecurityCommand( mode: 0o444, }); const dockerfile = fs.readFileSync(image.finalDockerfile, "utf-8"); - const command = dockerRunCommandBetween( + const extract = "completedImageCheck" in image ? dockerSubshellBetween : dockerRunCommandBetween; + const command = extract( dockerfile, "# Verify the immutable security package inventory in the completed image.", "# End completed-image security package verification.", @@ -428,6 +453,9 @@ describe("sandbox base security packages", () => { expect(OPENCLAW_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY).toEqual( EXPECTED_OPENCLAW_SECURITY_PACKAGE_INVENTORY, ); + expect(HERMES_01X_SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY).toEqual( + EXPECTED_HERMES_01X_SECURITY_PACKAGE_INVENTORY, + ); }); it.each( @@ -605,6 +633,40 @@ describe("sandbox base security packages", () => { } }); + it.each( + ARCHITECTURES, + )("rejects a Hermes 0.1.x base that still installs libexpat 2.8.3 on %s (#95)", (architecture) => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-hermes-01x-old-expat-")); + const hermes01x = SECURITY_IMAGES.find((image) => image.name === "Hermes 0.1.x")!; + const prepared = completedImageSecurityCommand( + hermes01x, + tmp, + architecture, + SANDBOX_BASE_SECURITY_PACKAGE_INVENTORY, + ); + + try { + const { result } = runLoggedDockerShell( + prepared.command, + tmp, + [ + "perl_base_installed=1", + "perl_installed=1", + 'stat() { printf "0:0:444\\n"; }', + ...useRealPatchedParser( + baseAptSecurityFunctions(architecture, SHARED_BASE_APT_PACKAGES), + prepared.pythonShim, + ), + ], + { timeoutMs: 15_000 }, + ); + expect(result.status).not.toBe(0); + expect(result.stdout).not.toContain("nemoclaw-security-inventory-ok"); + } finally { + fs.rmSync(tmp, { recursive: true, force: true }); + } + }); + it.each( ARCHITECTURES, )("accepts the exact published Hermes Python package on %s", (architecture) => {