Skip to content

fix(security): keep cap_setpcap so capsh can drop other capabilities - #929

Merged
ericksoa merged 3 commits into
mainfrom
fix-capsh-setpcap
Mar 25, 2026
Merged

ericksoa merged 3 commits into
mainfrom
fix-capsh-setpcap

Conversation

@ericksoa

@ericksoa ericksoa commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Remove cap_setpcap from the capsh --drop list in the sandbox entrypoint
  • capsh --drop needs CAP_SETPCAP in the effective set to modify the bounding set — dropping it causes the entrypoint to crash with unable to raise CAP_SETPCAP for BSET changes: Operation not permitted

Test plan

  • Fresh nemoclaw onboard completes without Operation not permitted
  • docker run --rm <image> bash -c 'grep CapBnd /proc/self/status' confirms dangerous caps are still dropped
  • CI e2e-gateway-isolation passes

Summary by CodeRabbit

  • Chores
    • Adjusted startup security behavior: capability-reduction is now performed only when supported by the system; if not available, startup proceeds and emits a security warning to stderr.

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.
@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Conditionally invoke capsh --drop=... only when capsh --has-p=cap_setpcap succeeds; otherwise emit a [SECURITY] warning and run the startup command without attempting the capability-drop replacement.

Changes

Cohort / File(s) Summary
Startup script
scripts/nemoclaw-start.sh
Make capability-drop invocation conditional: check capsh --has-p=cap_setpcap before running capsh --drop=... and setting NEMOCLAW_CAPS_DROPPED; emit [SECURITY] warning to stderr if capability check fails. Other exec flow unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I checked the caps before the leap,
A cautious hop, not into deep.
If setpcap's gone, I warn and stay—
Safe startup hops the careful way. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: keeping CAP_SETPCAP in the capability set so capsh can successfully drop other capabilities during startup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-capsh-setpcap

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b42f291 and 6e97a6f.

📒 Files selected for processing (1)
  • scripts/nemoclaw-start.sh

Comment thread scripts/nemoclaw-start.sh Outdated
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 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
--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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/nemoclaw-start.sh (1)

33-35: Minor: Comment refers to "bounding set" but --has-p checks the permitted set.

The comment says "CAP_SETPCAP in the bounding set" but capsh --has-p=cap_setpcap checks 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6e97a6f and 3e74208.

📒 Files selected for processing (1)
  • scripts/nemoclaw-start.sh

Comment thread scripts/nemoclaw-start.sh
Comment on lines +40 to +42
else
echo "[SECURITY] CAP_SETPCAP not available — runtime already restricts capabilities" >&2
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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:

  1. Rewording to avoid the assumption, or
  2. Adding a brief check (e.g., inspecting /proc/self/status CapBnd) 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.

Suggested change
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.

@ericksoa
ericksoa merged commit 4f59c57 into main Mar 25, 2026
9 checks passed
@cv
cv deleted the fix-capsh-setpcap branch March 25, 2026 22:46
ericksoa added a commit that referenced this pull request Mar 26, 2026
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.
cv added a commit that referenced this pull request Mar 26, 2026
* 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]>
lakamsani pushed a commit to lakamsani/NemoClaw that referenced this pull request Apr 4, 2026
…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.
lakamsani pushed a commit to lakamsani/NemoClaw that referenced this pull request Apr 4, 2026
* 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]>
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants