Repository navigation
fix(security): drop unnecessary Linux capabilities at container startup - #917
Conversation
Use capsh to drop dangerous capabilities (CAP_NET_RAW, CAP_DAC_OVERRIDE, CAP_SYS_CHROOT, etc.) from the bounding set at entrypoint startup. OpenShell manages the container runtime so we cannot pass --cap-drop=ALL to docker run; instead the entrypoint re-execs through capsh to strip the bounding set before any child processes launch. Keeps only the capabilities required for gosu privilege separation: cap_chown, cap_setuid, cap_setgid, cap_fowner, cap_kill. Fixes #797
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdded Linux capability dropping to container startup. The Dockerfile installs libcap2-bin, the startup script wraps execution under capsh with specific capabilities dropped (if capsh available), and a test validates that cap_net_raw is successfully dropped from the bounding set. Changes
Sequence DiagramsequenceDiagram
participant start as nemoclaw-start.sh
participant env as Environment
participant capsh as capsh
participant kernel as Kernel/Process
start->>env: Check NEMOCLAW_CAPS_DROPPED
env-->>start: Not set (first run)
start->>capsh: exec capsh --drop=[list]<br/>-c 'exec /usr/local/bin/nemoclaw-start "$@"'
capsh->>kernel: Apply capability drops<br/>(set NEMOCLAW_CAPS_DROPPED=1)
kernel->>start: Re-execute script
start->>env: Check NEMOCLAW_CAPS_DROPPED
env-->>start: Already 1 (skip capsh)
start->>start: Continue normal execution<br/>(with dropped caps)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 2
🧹 Nitpick comments (1)
scripts/nemoclaw-start.sh (1)
32-45: Consider adding a fallback message whencapshis unavailable.When
capshis not found (e.g., iflibcap2-binis removed), the script silently continues without dropping capabilities. For defense-in-depth visibility, consider logging a warning.📝 Optional: Add warning when capsh is unavailable
if [ "${NEMOCLAW_CAPS_DROPPED:-}" != "1" ] && command -v capsh >/dev/null 2>&1; then export NEMOCLAW_CAPS_DROPPED=1 exec capsh \ --drop=cap_net_raw \ --drop=cap_dac_override \ --drop=cap_sys_chroot \ --drop=cap_fsetid \ --drop=cap_setpcap \ --drop=cap_setfcap \ --drop=cap_mknod \ --drop=cap_audit_write \ --drop=cap_net_bind_service \ -- -c 'exec /usr/local/bin/nemoclaw-start "$@"' -- "$@" +elif [ "${NEMOCLAW_CAPS_DROPPED:-}" != "1" ]; then + echo "[SECURITY WARNING] capsh not available — running with default capabilities" >&2 fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/nemoclaw-start.sh` around lines 32 - 45, The script currently skips dropping capabilities silently when capsh is missing; update the block referencing NEMOCLAW_CAPS_DROPPED and the capsh presence check to emit a clear warning to stderr when command -v capsh fails (for example using echo >&2 or printf to stderr) so operators see that capability dropping did not occur; keep the existing behavior (only attempt capsh when present) and ensure the message mentions capsh and NEMOCLAW_CAPS_DROPPED so it’s easy to locate in logs.
🤖 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`:
- Around line 22-45: The capsh invocation in the startup guard (check of
NEMOCLAW_CAPS_DROPPED) uses multiple --drop= flags which is invalid; update the
exec capsh call in the block that exports NEMOCLAW_CAPS_DROPPED so it passes a
single --drop argument containing a comma-separated list of capabilities (e.g.
cap_net_raw,cap_dac_override,...cap_net_bind_service) to capsh, keeping the
trailing "-- -c 'exec /usr/local/bin/nemoclaw-start \"$@\"' -- \"$@\"" and
preserving the surrounding conditional and export of NEMOCLAW_CAPS_DROPPED.
In `@test/e2e-gateway-isolation.sh`:
- Around line 183-188: The comment incorrectly says "We read /proc/1/status"
while the code actually reads /proc/self/status; update the comment to state we
read /proc/self/status (or change the command to grep "^CapBnd:" /proc/1/status
if you prefer that behavior) so the comment matches the code that sets CAP_BND
via grep "^CapBnd:" /proc/self/status | awk "{print \$2}".
---
Nitpick comments:
In `@scripts/nemoclaw-start.sh`:
- Around line 32-45: The script currently skips dropping capabilities silently
when capsh is missing; update the block referencing NEMOCLAW_CAPS_DROPPED and
the capsh presence check to emit a clear warning to stderr when command -v capsh
fails (for example using echo >&2 or printf to stderr) so operators see that
capability dropping did not occur; keep the existing behavior (only attempt
capsh when present) and ensure the message mentions capsh and
NEMOCLAW_CAPS_DROPPED so it’s easy to locate in logs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fa820330-a75d-4afa-890f-fe58a2b8757a
📒 Files selected for processing (3)
Dockerfilescripts/nemoclaw-start.shtest/e2e-gateway-isolation.sh
- Fix package version to 1:2.66-4+deb12u2+b2 (actual bookworm version) - Use comma-separated --drop= list per capsh man page - Add warning when capsh is unavailable - Fix /proc/1/status -> /proc/self/status comment typo in test
BenediktSchackenberg
left a comment
There was a problem hiding this comment.
Solid fix — capsh bounding-set drop is the right approach for CIS 5.3 when the runtime doesn't expose --cap-drop. The re-exec guard with NEMOCLAW_CAPS_DROPPED is clean, and the fallback warning for missing capsh is a nice touch.
Two small things I noticed:
- The e2e test uses
bash -cwith nested arithmetic (\$((16#\$CAP_BND))) — might be fragile if the shell env changes.capsh --printand grepping forcap_net_rawinBounding setcould be simpler. - Worth noting in the PR description that
cap_dac_read_searchis also kept (it's not in the drop list) — intentional? Some hardening guides flag it too.
(Note: please disregard my earlier empty approval — that was submitted by automation accidentally. I'm a contributor, not a maintainer, so that approval doesn't carry merge weight anyway.)
|
@ericksoa Thank you! |
capsh --drop needs CAP_SETPCAP in the effective set to modify the bounding set. Dropping it causes "unable to raise CAP_SETPCAP for BSET changes: Operation not permitted" and prevents the sandbox from starting. Fixes install regression from #917.
…929) * fix(security): keep cap_setpcap so capsh can drop other capabilities capsh --drop needs CAP_SETPCAP in the effective set to modify the bounding set. Dropping it causes "unable to raise CAP_SETPCAP for BSET changes: Operation not permitted" and prevents the sandbox from starting. Fixes install regression from #917. * fix(security): check for CAP_SETPCAP before attempting capability drop capsh --drop requires CAP_SETPCAP in the bounding set. OpenShell's sandbox runtime strips it, so the entrypoint crashes with "unable to raise CAP_SETPCAP for BSET changes: Operation not permitted". Check with capsh --has-p first; if unavailable, skip the drop since the runtime is already restricting capabilities.
…up (NVIDIA#917) * fix(security): drop unnecessary Linux capabilities at container startup Use capsh to drop dangerous capabilities (CAP_NET_RAW, CAP_DAC_OVERRIDE, CAP_SYS_CHROOT, etc.) from the bounding set at entrypoint startup. OpenShell manages the container runtime so we cannot pass --cap-drop=ALL to docker run; instead the entrypoint re-execs through capsh to strip the bounding set before any child processes launch. Keeps only the capabilities required for gosu privilege separation: cap_chown, cap_setuid, cap_setgid, cap_fowner, cap_kill. Fixes NVIDIA#797 * fix: correct libcap2-bin version pin and capsh comma-separated syntax - Fix package version to 1:2.66-4+deb12u2+b2 (actual bookworm version) - Use comma-separated --drop= list per capsh man page - Add warning when capsh is unavailable - Fix /proc/1/status -> /proc/self/status comment typo in test
…VIDIA#929) * fix(security): keep cap_setpcap so capsh can drop other capabilities capsh --drop needs CAP_SETPCAP in the effective set to modify the bounding set. Dropping it causes "unable to raise CAP_SETPCAP for BSET changes: Operation not permitted" and prevents the sandbox from starting. Fixes install regression from NVIDIA#917. * fix(security): check for CAP_SETPCAP before attempting capability drop capsh --drop requires CAP_SETPCAP in the bounding set. OpenShell's sandbox runtime strips it, so the entrypoint crashes with "unable to raise CAP_SETPCAP for BSET changes: Operation not permitted". Check with capsh --has-p first; if unavailable, skip the drop since the runtime is already restricting capabilities.
…OVERRIDE drop (#2659) ## Summary Fix the `test/e2e/test-runtime-overrides.sh` E2E crash at baseline config capture. After PR #917 drops `CAP_DAC_OVERRIDE` via `capsh`, root can no longer write to 444-mode config files. The three runtime override functions (`apply_model_override`, `apply_cors_override`, `apply_slack_token_override`) now temporarily relax permissions to 644 before writing and re-lock to 444 afterward, using `CAP_FOWNER` which is retained by design. ## Related Issue Fixes #2653 ## Changes - **`scripts/lib/sandbox-init.sh`**: Add `relax_config_for_write()` / `lock_config_after_write()` shared helpers that `chmod 644`/`chmod 444` with symlink guards - **`scripts/nemoclaw-start.sh`**: Wrap python3 write + hash recomputation in all three override functions with the new helpers - **`scripts/nemoclaw-start.sh`**: Tighten `apply_model_override()` trigger guard — only fire when `NEMOCLAW_MODEL_OVERRIDE` or `NEMOCLAW_INFERENCE_API_OVERRIDE` is explicitly set (Dockerfile ENV defaults no longer trigger spurious override runs) - **`test/e2e/test-runtime-overrides.sh`**: Create timestamped log file matching CI artifact glob `test-runtime-overrides-*.log`, replace all `2>/dev/null` with `2>>"$LOG_FILE"` - **`test/e2e/test-runtime-overrides.sh`**: Update tests 3-5, 9-11, 14 to pair standalone parameters with `NEMOCLAW_MODEL_OVERRIDE` (matching the tightened trigger guard) ## 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 - [x] `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 - [ ] `make docs` builds without warnings (doc changes only) - [ ] Doc pages follow the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md) (doc changes only) - [ ] New doc pages include SPDX header and frontmatter (new pages only) ## 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 * **Bug Fixes** * Overrides now only apply when explicit override flags are set, preventing unintended changes. * Safer config writes: permissions are temporarily relaxed with strict safety checks (rejecting unsafe targets, skipping missing files), clear security errors on failure, recompute verification only on successful writes, and permissions are always restored; write/hash failures are surfaced. * **Tests** * Improved test logging with timestamped artifacts and preserved stderr; runtime override tests updated to cover model-override scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Julie Yaunches <[email protected]>
…OVERRIDE drop (NVIDIA#2659) ## Summary Fix the `test/e2e/test-runtime-overrides.sh` E2E crash at baseline config capture. After PR NVIDIA#917 drops `CAP_DAC_OVERRIDE` via `capsh`, root can no longer write to 444-mode config files. The three runtime override functions (`apply_model_override`, `apply_cors_override`, `apply_slack_token_override`) now temporarily relax permissions to 644 before writing and re-lock to 444 afterward, using `CAP_FOWNER` which is retained by design. ## Related Issue Fixes NVIDIA#2653 ## Changes - **`scripts/lib/sandbox-init.sh`**: Add `relax_config_for_write()` / `lock_config_after_write()` shared helpers that `chmod 644`/`chmod 444` with symlink guards - **`scripts/nemoclaw-start.sh`**: Wrap python3 write + hash recomputation in all three override functions with the new helpers - **`scripts/nemoclaw-start.sh`**: Tighten `apply_model_override()` trigger guard — only fire when `NEMOCLAW_MODEL_OVERRIDE` or `NEMOCLAW_INFERENCE_API_OVERRIDE` is explicitly set (Dockerfile ENV defaults no longer trigger spurious override runs) - **`test/e2e/test-runtime-overrides.sh`**: Create timestamped log file matching CI artifact glob `test-runtime-overrides-*.log`, replace all `2>/dev/null` with `2>>"$LOG_FILE"` - **`test/e2e/test-runtime-overrides.sh`**: Update tests 3-5, 9-11, 14 to pair standalone parameters with `NEMOCLAW_MODEL_OVERRIDE` (matching the tightened trigger guard) ## 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 - [x] `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 - [ ] `make docs` builds without warnings (doc changes only) - [ ] Doc pages follow the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md) (doc changes only) - [ ] New doc pages include SPDX header and frontmatter (new pages only) ## 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 * **Bug Fixes** * Overrides now only apply when explicit override flags are set, preventing unintended changes. * Safer config writes: permissions are temporarily relaxed with strict safety checks (rejecting unsafe targets, skipping missing files), clear security errors on failure, recompute verification only on successful writes, and permissions are always restored; write/hash failures are surfaced. * **Tests** * Improved test logging with timestamped artifacts and preserved stderr; runtime override tests updated to cover model-override scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Julie Yaunches <[email protected]>
Summary
libcap2-binto the Dockerfile (providescapsh)nemoclaw-start.sh) self-re-execs throughcapshto drop 9 dangerous capabilities from the bounding set before any child processes launch:cap_net_raw,cap_dac_override,cap_sys_chroot,cap_fsetid,cap_setpcap,cap_setfcap,cap_mknod,cap_audit_write,cap_net_bind_servicecap_chown,cap_setuid,cap_setgid,cap_fowner,cap_killcap_net_rawis absent from the bounding set after entrypoint runsSince OpenShell manages the container runtime (no
--cap-dropflag onopenshell sandbox create), the entrypoint handles capability dropping itself viacapsh. This is defense-in-depth per CIS Docker Benchmark 5.3.Thanks
Thanks to @BenediktSchackenberg for the thorough issue write-up and CIS benchmark references, and to @h-network for pushing back on docs-only approaches and keeping the bar high for a proper enforcement fix.
Fixes #797
Test plan
docker buildsucceeds with newlibcap2-binpackagetest/e2e-gateway-isolation.shtest 11 passes —cap_net_rawabsent from bounding setSummary by CodeRabbit
Security
Tests