Repository navigation
fix(security): keep cap_setpcap so capsh can drop other capabilities - #929
Conversation
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.
📝 WalkthroughWalkthroughConditionally invoke Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
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 35: Add a regression test in test/nemoclaw-start.test.js that verifies
the capability drop list behavior in scripts/nemoclaw-start.sh: read or spawn a
simple grep on the script and assert the --drop=... line contains the expected
capabilities and specifically does not include CAP_SETPCAP (or assert it
includes the fixed list shown on Line 35). Place the test alongside the existing
non-root detachment test, name it to indicate "capability drop list /
CAP_SETPCAP regression", and fail the test if the capability list changes or
reintroduces CAP_SETPCAP so future regressions are caught.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2604aaf2-24b5-4133-8990-1a1e7e2438bb
📒 Files selected for processing (1)
scripts/nemoclaw-start.sh
| export NEMOCLAW_CAPS_DROPPED=1 | ||
| exec capsh \ | ||
| --drop=cap_net_raw,cap_dac_override,cap_sys_chroot,cap_fsetid,cap_setpcap,cap_setfcap,cap_mknod,cap_audit_write,cap_net_bind_service \ | ||
| --drop=cap_net_raw,cap_dac_override,cap_sys_chroot,cap_fsetid,cap_setfcap,cap_mknod,cap_audit_write,cap_net_bind_service \ |
There was a problem hiding this comment.
Add a regression test for the capability drop list behavior.
Line 35 fixes the immediate CAP_SETPCAP issue, but there is still no guardrail test for this exact behavior. test/nemoclaw-start.test.js (Lines 1-18) currently checks only non-root log detachment, so this startup/security regression can reoccur silently.
✅ Suggested test addition
describe("nemoclaw-start non-root fallback", () => {
it("detaches gateway output from sandbox create in non-root mode", () => {
const src = fs.readFileSync(START_SCRIPT, "utf-8");
expect(src).toMatch(/if \[ "\$\(id -u\)" -ne 0 \]; then/);
expect(src).toMatch(/touch \/tmp\/gateway\.log/);
expect(src).toMatch(/nohup "\$OPENCLAW" gateway run >\/tmp\/gateway\.log 2>&1 &/);
});
+
+ it("keeps cap_setpcap out of --drop while still dropping dangerous caps", () => {
+ const src = fs.readFileSync(START_SCRIPT, "utf-8");
+ const dropLine = src.split("\n").find((line) => line.includes("--drop=")) ?? "";
+
+ expect(dropLine).toContain("cap_setfcap");
+ expect(dropLine).not.toContain("cap_setpcap");
+ });
});📝 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.
| --drop=cap_net_raw,cap_dac_override,cap_sys_chroot,cap_fsetid,cap_setfcap,cap_mknod,cap_audit_write,cap_net_bind_service \ | |
| describe("nemoclaw-start non-root fallback", () => { | |
| it("detaches gateway output from sandbox create in non-root mode", () => { | |
| const src = fs.readFileSync(START_SCRIPT, "utf-8"); | |
| expect(src).toMatch(/if \[ "\$\(id -u\)" -ne 0 \]; then/); | |
| expect(src).toMatch(/touch \/tmp\/gateway\.log/); | |
| expect(src).toMatch(/nohup "\$OPENCLAW" gateway run >\/tmp\/gateway\.log 2>&1 &/); | |
| }); | |
| it("keeps cap_setpcap out of --drop while still dropping dangerous caps", () => { | |
| const src = fs.readFileSync(START_SCRIPT, "utf-8"); | |
| const dropLine = src.split("\n").find((line) => line.includes("--drop=")) ?? ""; | |
| expect(dropLine).toContain("cap_setfcap"); | |
| expect(dropLine).not.toContain("cap_setpcap"); | |
| }); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/nemoclaw-start.sh` at line 35, Add a regression test in
test/nemoclaw-start.test.js that verifies the capability drop list behavior in
scripts/nemoclaw-start.sh: read or spawn a simple grep on the script and assert
the --drop=... line contains the expected capabilities and specifically does not
include CAP_SETPCAP (or assert it includes the fixed list shown on Line 35).
Place the test alongside the existing non-root detachment test, name it to
indicate "capability drop list / CAP_SETPCAP regression", and fail the test if
the capability list changes or reintroduces CAP_SETPCAP so future regressions
are caught.
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.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/nemoclaw-start.sh (1)
33-35: Minor: Comment refers to "bounding set" but--has-pchecks the permitted set.The comment says "CAP_SETPCAP in the bounding set" but
capsh --has-p=cap_setpcapchecks if the capability is in the permitted set. The logic is correct (capsh needs CAP_SETPCAP in the permitted set to raise it to effective for bounding set modifications), but the comment could be clarified.📝 Suggested comment fix
- # capsh --drop requires CAP_SETPCAP in the bounding set. OpenShell's - # sandbox runtime may strip it, so check before attempting the drop. + # capsh --drop requires CAP_SETPCAP in the permitted set (to raise to + # effective). OpenShell's sandbox runtime may strip it, so check first.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/nemoclaw-start.sh` around lines 33 - 35, Update the comment above the capsh check to correctly state that capsh --has-p=cap_setpcap checks for CAP_SETPCAP in the permitted set (not the bounding set), and briefly note that capsh needs the capability in the permitted set to manipulate the bounding set; adjust the comment near the capsh --has-p=cap_setpcap line to reflect this clarification.
🤖 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 40-42: The security message echo in nemoclaw-start.sh that prints
"[SECURITY] CAP_SETPCAP not available — runtime already restricts capabilities"
makes an unsupported assumption; update the logic around the CAP_SETPCAP check
to either (A) reword the echo to a neutral warning (e.g., "CAP_SETPCAP not
available — capability may be removed or runtime-restricted") referencing the
echo statement, or (B) add a verification step that reads /proc/self/status and
inspects the CapBnd field to confirm the bounding set is restricted before
emitting the "runtime restricts capabilities" message (referencing CAP_SETPCAP
and the echo). Ensure the changed message or the new check replaces the existing
echo path so we no longer assume runtime restrictions without verification.
---
Nitpick comments:
In `@scripts/nemoclaw-start.sh`:
- Around line 33-35: Update the comment above the capsh check to correctly state
that capsh --has-p=cap_setpcap checks for CAP_SETPCAP in the permitted set (not
the bounding set), and briefly note that capsh needs the capability in the
permitted set to manipulate the bounding set; adjust the comment near the capsh
--has-p=cap_setpcap line to reflect this clarification.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 31cc92d1-c005-4bdd-9d8a-f8de8b793eb6
📒 Files selected for processing (1)
scripts/nemoclaw-start.sh
| else | ||
| echo "[SECURITY] CAP_SETPCAP not available — runtime already restricts capabilities" >&2 | ||
| fi |
There was a problem hiding this comment.
Security warning assumes runtime restriction without verification.
The message "runtime already restricts capabilities" is an optimistic assumption. CAP_SETPCAP could be absent for reasons unrelated to runtime restrictions (e.g., explicit removal in a parent Dockerfile, kernel configuration). If the assumption is wrong, the container runs with full default capabilities.
Consider either:
- Rewording to avoid the assumption, or
- Adding a brief check (e.g., inspecting
/proc/self/statusCapBnd) to confirm the bounding set is actually restricted.
📝 Suggested warning reword (option 1)
else
- echo "[SECURITY] CAP_SETPCAP not available — runtime already restricts capabilities" >&2
+ echo "[SECURITY] CAP_SETPCAP not available — cannot drop capabilities; verify runtime restrictions" >&2
fi📝 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.
| else | |
| echo "[SECURITY] CAP_SETPCAP not available — runtime already restricts capabilities" >&2 | |
| fi | |
| else | |
| echo "[SECURITY] CAP_SETPCAP not available — cannot drop capabilities; verify runtime restrictions" >&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 40 - 42, The security message echo in
nemoclaw-start.sh that prints "[SECURITY] CAP_SETPCAP not available — runtime
already restricts capabilities" makes an unsupported assumption; update the
logic around the CAP_SETPCAP check to either (A) reword the echo to a neutral
warning (e.g., "CAP_SETPCAP not available — capability may be removed or
runtime-restricted") referencing the echo statement, or (B) add a verification
step that reads /proc/self/status and inspects the CapBnd field to confirm the
bounding set is restricted before emitting the "runtime restricts capabilities"
message (referencing CAP_SETPCAP and the echo). Ensure the changed message or
the new check replaces the existing echo path so we no longer assume runtime
restrictions without verification.
The e2e gateway isolation test used head -21 to source the PATH export from nemoclaw-start.sh. The capsh fix (#929) added lines, pushing PATH past line 21. Use grep to find the export line dynamically.
* fix: clean up Docker volumes after failed gateway start Closes #17. When openshell gateway start fails, it leaves behind a Docker volume (openshell-cluster-nemoclaw) in a corrupted state. Rerunning onboard hits "Corrupted cluster state" because openshell gateway destroy doesn't remove the volume. Extracts a destroyGateway() helper that removes both the gateway and its Docker volumes. Called before start (pre-cleanup), after start failure, and after health check failure. Adds the same volume cleanup to uninstall.sh and scripts/setup.sh. * test: add regression tests for gateway volume cleanup Static analysis tests that verify Docker volume cleanup exists in all three code paths (onboard.js, uninstall.sh, setup.sh) and that destroyGateway() is called on pre-start, start failure, and health check failure. Will catch regressions in CI. Refs: #17 * fix: convert assert.ok to vitest expect in policies.test.js * fix: convert node:test to vitest in gateway-cleanup.test.js * fix(test): use grep instead of hardcoded line count for PATH check The e2e gateway isolation test used head -21 to source the PATH export from nemoclaw-start.sh. The capsh fix (#929) added lines, pushing PATH past line 21. Use grep to find the export line dynamically. --------- Co-authored-by: Carlos Villela <[email protected]>
…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.
* fix: clean up Docker volumes after failed gateway start Closes NVIDIA#17. When openshell gateway start fails, it leaves behind a Docker volume (openshell-cluster-nemoclaw) in a corrupted state. Rerunning onboard hits "Corrupted cluster state" because openshell gateway destroy doesn't remove the volume. Extracts a destroyGateway() helper that removes both the gateway and its Docker volumes. Called before start (pre-cleanup), after start failure, and after health check failure. Adds the same volume cleanup to uninstall.sh and scripts/setup.sh. * test: add regression tests for gateway volume cleanup Static analysis tests that verify Docker volume cleanup exists in all three code paths (onboard.js, uninstall.sh, setup.sh) and that destroyGateway() is called on pre-start, start failure, and health check failure. Will catch regressions in CI. Refs: NVIDIA#17 * fix: convert assert.ok to vitest expect in policies.test.js * fix: convert node:test to vitest in gateway-cleanup.test.js * fix(test): use grep instead of hardcoded line count for PATH check The e2e gateway isolation test used head -21 to source the PATH export from nemoclaw-start.sh. The capsh fix (NVIDIA#929) added lines, pushing PATH past line 21. Use grep to find the export line dynamically. --------- Co-authored-by: Carlos Villela <[email protected]>
Summary
cap_setpcapfrom thecapsh --droplist in the sandbox entrypointcapsh --dropneedsCAP_SETPCAPin the effective set to modify the bounding set — dropping it causes the entrypoint to crash withunable to raise CAP_SETPCAP for BSET changes: Operation not permittedTest plan
nemoclaw onboardcompletes withoutOperation not permitteddocker run --rm <image> bash -c 'grep CapBnd /proc/self/status'confirms dangerous caps are still droppedSummary by CodeRabbit