Repository navigation
Conversation
…lnerability (#2277) Extract common entrypoint functions from scripts/nemoclaw-start.sh and agents/hermes/start.sh into a shared shell library (scripts/lib/sandbox-init.sh). This fixes the active Hermes vulnerability where .bashrc/.profile were never locked to chmod 444 and proxy config was written inline into writable rc files. Shared primitives: - emit_sandbox_sourced_file(): write files as root:root 444 - validate_tmp_permissions(): defence-in-depth gate before service launch - drop_capabilities(): parameterized capsh cap-drop block - verify_config_integrity(): parameterized config dir argument - lock_rc_files(): chmod 444 .bashrc .profile (Hermes security fix) - cleanup_on_signal(): signal forwarding via SANDBOX_CHILD_PIDS array - validate_config_symlinks() / harden_config_symlinks(): parameterized - configure_messaging_channels(): shared channel logging Hermes security fixes: - .bashrc/.profile now locked to 444 after mutations (was wide open) - Proxy config now uses emit_sandbox_sourced_file (root:root 444) instead of inline append to writable .bashrc - validate_tmp_permissions() called before service launch Fixes #2277 Signed-off-by: Julie Yaunches <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughShared sandbox-init library added and entrypoints refactored to source it. Security primitives (tmp-file emission, tmp-perm validation, capability drop, config integrity, RC locking, symlink validation/hardening, PID/signal handling, messaging-channel config) moved to Changes
Sequence Diagram(s)sequenceDiagram
participant Entrypoint as Entrypoint (PID 1)
participant Lib as sandbox-init.sh
participant Child as Service (gateway/auto-pair)
participant Kernel as Kernel
Entrypoint->>Lib: source sandbox-init.sh
Entrypoint->>Lib: verify_config_integrity(config_dir)
Entrypoint->>Lib: emit_sandbox_sourced_file(/tmp/nemoclaw-proxy-env.sh)
Entrypoint->>Lib: validate_tmp_permissions(...)
Entrypoint->>Child: start gateway / auto-pair (capture PIDs)
Entrypoint->>Entrypoint: set SANDBOX_CHILD_PIDS, SANDBOX_WAIT_PID
Entrypoint->>Lib: trap cleanup_on_signal SIGTERM SIGINT
Kernel->>Entrypoint: SIGTERM
Entrypoint->>Lib: cleanup_on_signal -> forward SIGTERM to SANDBOX_CHILD_PIDS
Child-->>Entrypoint: exit status
Entrypoint->>Kernel: exit with child's status
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/lib/sandbox-init.sh`:
- Around line 219-221: The loop that iterates over the SANDBOX_CHILD_PIDS array
in cleanup_on_signal is erroring under set -u when the array is empty/unset;
update both loops that iterate over SANDBOX_CHILD_PIDS (the for pid in
"${SANDBOX_CHILD_PIDS[@]}" loops) to guard against an unset/empty array by using
the ${SANDBOX_CHILD_PIDS[@]+"${SANDBOX_CHILD_PIDS[@]}"} expansion so the loop
safely expands to nothing when the array is empty while preserving normal
iteration when it has elements.
In `@test/sandbox-init.test.ts`:
- Around line 83-84: The test uses a macOS/BSD-specific stat invocation; add a
cross-platform helper function getFilePerms(filePath: string) that calls
execFileSync("stat", ["-f", "%Lp", filePath], ...) and falls back in a catch to
execFileSync("stat", ["-c", "%a", filePath], ...), trimming the result, then
replace direct calls to execFileSync("stat", ...) in the permission assertions
(e.g. the check that expects "444") to use getFilePerms(target) instead so the
test passes on both macOS and Linux.
In `@test/service-env.test.ts`:
- Around line 364-368: The test currently runs execFileSync("stat", ["-f",
"%Lp", join(fakeDataDir, "proxy-env.sh")]) which only works on macOS/BSD; update
the test to try the BSD form first and fall back to the Linux form by catching
the error and re-running execFileSync with ["-c", "%a"] (same encoding and trim)
so the perms variable still yields "444"; reference the existing execFileSync
call, perms variable, fakeDataDir, and the "proxy-env.sh" filename when making
the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 82520056-8c41-40a1-849f-255448f753a7
📒 Files selected for processing (6)
agents/hermes/start.shscripts/lib/sandbox-init.shscripts/nemoclaw-start.shtest/nemoclaw-start.test.tstest/sandbox-init.test.tstest/service-env.test.ts
- Fix cross-platform stat: use stat -c '%a' (Linux) with stat -f '%Lp'
(macOS) fallback for permission assertions in tests
- Fix SANDBOX_CHILD_PIDS[@] unbound variable under set -u by using
${arr[@]+...} guard pattern in cleanup_on_signal
- Add COPY for sandbox-init.sh in both Dockerfiles (OpenClaw + Hermes)
to /usr/local/lib/nemoclaw/ with dev fallback to relative path
- Update e2e-gateway-isolation test 14 to grep --drop= from
sandbox-init.sh instead of the entrypoint (function moved)
Signed-off-by: Julie Yaunches <[email protected]>
The stageOptimizedSandboxBuildContext function selectively copies files into a temp build context — it was copying scripts/nemoclaw-start.sh but not the new scripts/lib/sandbox-init.sh that the entrypoint sources. This would cause the Docker COPY to fail during nemoclaw onboard. Signed-off-by: Julie Yaunches <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/nemoclaw-start.sh`:
- Line 220: The local assignment local model_override="$NEMOCLAW_MODEL_OVERRIDE"
can trigger an "unbound variable" under set -u when NEMOCLAW_MODEL_OVERRIDE is
unset but other overrides exist; change the assignment to use a safe parameter
expansion that defaults to empty (e.g. ${NEMOCLAW_MODEL_OVERRIDE-}) so
model_override is always defined, and apply the same guarded expansion pattern
to any similar local override variables in that function to avoid
unbound-variable errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 18d1acf3-8419-4c44-af3c-b8c245c63c00
📒 Files selected for processing (8)
Dockerfileagents/hermes/Dockerfileagents/hermes/start.shscripts/lib/sandbox-init.shscripts/nemoclaw-start.shtest/e2e-gateway-isolation.shtest/sandbox-init.test.tstest/service-env.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- test/service-env.test.ts
| fi | ||
|
|
||
| local model_override="${NEMOCLAW_MODEL_OVERRIDE:-}" | ||
| local model_override="$NEMOCLAW_MODEL_OVERRIDE" |
There was a problem hiding this comment.
Fix unbound variable error when only non-model overrides are set.
Under set -u, line 220 will fail with "unbound variable" if NEMOCLAW_MODEL_OVERRIDE is unset but another override like NEMOCLAW_CONTEXT_WINDOW is set. The early-return check (lines 196-201) allows entering this function when any override is set, not just NEMOCLAW_MODEL_OVERRIDE.
🐛 Proposed fix: Guard against unset variable
- local model_override="$NEMOCLAW_MODEL_OVERRIDE"
+ local model_override="${NEMOCLAW_MODEL_OVERRIDE:-}"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| local model_override="$NEMOCLAW_MODEL_OVERRIDE" | |
| local model_override="${NEMOCLAW_MODEL_OVERRIDE:-}" |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/nemoclaw-start.sh` at line 220, The local assignment local
model_override="$NEMOCLAW_MODEL_OVERRIDE" can trigger an "unbound variable"
under set -u when NEMOCLAW_MODEL_OVERRIDE is unset but other overrides exist;
change the assignment to use a safe parameter expansion that defaults to empty
(e.g. ${NEMOCLAW_MODEL_OVERRIDE-}) so model_override is always defined, and
apply the same guarded expansion pattern to any similar local override variables
in that function to avoid unbound-variable errors.
…brary Signed-off-by: Julie Yaunches <[email protected]>
The snapshot rollback test fails 100% on linux-amd64-cpu4 self-hosted runners but passes on GitHub-hosted ubuntu-latest. Temporarily switch the runner to isolate whether the failure is runner-specific. Revert once root cause is identified. Signed-off-by: Julie Yaunches <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/pr-self-hosted.yaml:
- Around line 82-85: Revert the change that set runs-on: ubuntu-latest for the
test-e2e-sandbox job and restore runs-on: linux-amd64-cpu4 (keep the job name
test-e2e-sandbox and its required gate intact), then add a new separate
diagnostic job (e.g., test-e2e-sandbox-ubuntu-diagnostic) that copies the same
steps but uses runs-on: ubuntu-latest so you can reproduce the issue on
GitHub-hosted runners without removing validation on the self-hosted
linux-amd64-cpu4 environment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 0c723b82-81cc-4235-896e-608d8a04a410
📒 Files selected for processing (1)
.github/workflows/pr-self-hosted.yaml
| # TEMP: switched from linux-amd64-cpu4 to ubuntu-latest to diagnose | ||
| # snapshot rollback failure (100% repro on self-hosted, 0% on GitHub-hosted). | ||
| # Revert once root cause is identified. See PR #2288 discussion. | ||
| runs-on: ubuntu-latest |
There was a problem hiding this comment.
Keep self-hosted sandbox E2E as a required gate.
Line 85 moves test-e2e-sandbox to ubuntu-latest, which drops validation in the environment where this failure is reported as 100% reproducible. That can hide self-hosted-only regressions. Please keep this job on linux-amd64-cpu4 and add a separate temporary GitHub-hosted diagnostic job instead.
Suggested direction
- # TEMP: switched from linux-amd64-cpu4 to ubuntu-latest to diagnose
+ # Keep self-hosted as the gate for environment-faithful validation.
+ # Add a separate temporary GitHub-hosted diagnostic job if needed.
...
- runs-on: ubuntu-latest
+ runs-on: linux-amd64-cpu4🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/pr-self-hosted.yaml around lines 82 - 85, Revert the
change that set runs-on: ubuntu-latest for the test-e2e-sandbox job and restore
runs-on: linux-amd64-cpu4 (keep the job name test-e2e-sandbox and its required
gate intact), then add a new separate diagnostic job (e.g.,
test-e2e-sandbox-ubuntu-diagnostic) that copies the same steps but uses runs-on:
ubuntu-latest so you can reproduce the issue on GitHub-hosted runners without
removing validation on the self-hosted linux-amd64-cpu4 environment.
…agnosis" This reverts commit 80ff40d.
…flow (#2294) ## Summary Switch `test-e2e-sandbox` from `linux-amd64-cpu4` (NVIDIA self-hosted) to `ubuntu-latest` (GitHub-hosted) in the `pr-self-hosted` workflow. The snapshot rollback test fails 100% on the self-hosted runner but passes reliably on GitHub-hosted runners. ## Related Issue Unblocks all PRs gated on `pr-self-hosted` — the workflow has never had a passing run since it was added in #2121. ## Changes - **`.github/workflows/pr-self-hosted.yaml`**: Change `test-e2e-sandbox` `runs-on` from `linux-amd64-cpu4` to `ubuntu-latest` - Other E2E jobs (`build-sandbox-images`, `test-e2e-gateway-isolation`) remain on `linux-amd64-cpu4` since they pass there ### Diagnosis The `rollbackFromSnapshot()` function in `nemoclaw/src/blueprint/snapshot.ts` does `renameSync` + `cpSync` on `/sandbox/.openclaw` (which contains symlinks to `.openclaw-data`). On the self-hosted runner's Docker environment, one of these operations throws — but the bare `catch {}` swallows the error and returns `false`, producing the "Rollback returned false" failure with no diagnostic output. Confirmed in PR #2288 by temporarily switching the runner — `test-e2e-sandbox` passed immediately on `ubuntu-latest`. ## Type of Change - [x] Code change (feature, bug fix, or refactor) - [ ] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Verification - [ ] `npx prek run --all-files` passes - [ ] `npm test` passes - [x] Tests added or updated for new or changed behavior - [x] No secrets, API keys, or credentials committed - [ ] Docs updated for user-facing behavior changes ## AI Disclosure - [x] AI-assisted — tool: Claude Code (pi agent) --- Signed-off-by: Julie Yaunches <[email protected]> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated test environment configuration for improved compatibility and reliability of end-to-end snapshot tests. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Julie Yaunches <[email protected]>
Summary
Extract common entrypoint functions from
scripts/nemoclaw-start.sh(OpenClaw) andagents/hermes/start.sh(Hermes) into a shared shell library (scripts/lib/sandbox-init.sh). This fixes an active Hermes vulnerability (same class as #2181), prevents the two entrypoints from drifting further apart, and establishes reusable primitives for future agent types.Related Issue
Fixes #2277
Changes
scripts/lib/sandbox-init.sh(new): Shared library with security primitives —emit_sandbox_sourced_file(),validate_tmp_permissions(),drop_capabilities(),verify_config_integrity(),lock_rc_files(),cleanup_on_signal(),validate_config_symlinks(),harden_config_symlinks(),configure_messaging_channels()agents/hermes/start.sh: Sources shared library. Security fix:.bashrc/.profilenow locked to 444 vialock_rc_files()(was wide open). Proxy config now usesemit_sandbox_sourced_file(root:root 444) instead of inline append to writable.bashrc.validate_tmp_permissions()gate added before service launch.scripts/nemoclaw-start.sh: Sources shared library. Replaced inline capsh block,verify_config_integrity(), symlink validation, messaging channels, cleanup, and proxy-env writing with shared versions. Proxy-env.sh now written viaemit_sandbox_sourced_file(444 instead of 644).test/sandbox-init.test.ts(new): 28 tests covering all shared library functions independentlytest/nemoclaw-start.test.ts: Updated tests for sharedcleanup_on_signalpattern (replaces inlinecleanup())test/service-env.test.ts: Updated sed extraction anchors foremit_sandbox_sourced_filepattern; added 444 permission assertionHermes vulnerability fix summary
.bashrc/.profilelocked?lock_rc_filesemit_sandbox_sourced_file/tmppermission validationvalidate_tmp_permissionsbefore service launchType of Change
Verification
npx prek run --all-filespasses (shellcheck, shfmt, eslint, prettier, gitleaks all pass; test runner has pre-existing Docker-dependent failures on main)npm testpasses (sandbox-init 28/28, service-env 34/34, nemoclaw-start 68/68; pre-existing install-preflight failures unrelated to this PR)make docsbuilds without warnings (doc changes only)AI Disclosure
Signed-off-by: Julie Yaunches [email protected]
Summary by CodeRabbit
Security Improvements
Chores
Tests