Repository navigation
Commit 5db9432
fix(sandbox): add opt-in fail-closed cap-drop enforcement (#4707)
## Summary
On hosts without CAP_SETPCAP (GitHub runners, Brev shadecloud, Colossus
Ubuntu
24.04, Docker Desktop, WSL), `drop_capabilities` cannot run `capsh
--drop`, so
dangerous bounding-set caps survive and the agent boots with a weaker
posture
than the security model assumes. This adds an opt-in fail-closed guard
(`NEMOCLAW_REQUIRE_CAP_DROP=1`) that verifies the agent process tree's
actual
bounding set and refuses to start if dangerous capabilities remain.
## Related Issue
Refs #3280
<!-- Refs (not Closes): this hardens the agent process tree only. The
`nemoclaw connect` shell inherits the container's OCI bounding set and
is not
affected; tightening that needs cap_drop at sandbox-create, tracked
upstream in
NVIDIA/OpenShell#1452. #3280 should stay open pending that. -->
## Changes
- `scripts/lib/sandbox-init.sh`:
- `enforce_cap_drop_if_required` runs on **every** path out of
`drop_capabilities` and verifies the **actual** `CapBnd` rather than
trusting
the `NEMOCLAW_CAPS_DROPPED` sentinel (closes a strict-mode bypass).
- A single `DANGEROUS_CAPS` list feeds both the `capsh --drop` arguments
and
the verifier, so the drop-set and the verify-set (all 10 caps) cannot
drift.
- A non-empty but unparseable `CapBnd` is treated as unverifiable:
refuse in
strict mode, warn in default mode — never a raw bash arithmetic error.
- `setpriv`-based privilege step-down strips the remaining load-bearing
caps
atomically with the setuid transition (falls back to `gosu` when
`setpriv`/`CAP_SETPCAP` are unavailable).
- Default stays **warn-and-continue** (zero regression — the inverse of
the
reverted #4266); operators set `NEMOCLAW_REQUIRE_CAP_DROP=1` to
refuse-to-start.
- `test/sandbox-init.test.ts`: repro + strict-mode + sentinel-bypass +
malformed-`CapBnd` coverage, seam-driven (`NEMOCLAW_PROC_STATUS`) and
deterministic.
- `docs/security/best-practices.mdx`,
`docs/deployment/sandbox-hardening.mdx`:
document `NEMOCLAW_REQUIRE_CAP_DROP` and the verified scope.
## Type of Change
- [ ] Code change (feature, bug fix, or refactor)
- [x] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)
## Verification
- [x] `npx prek run --all-files` passes
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [x] Docs updated for user-facing behavior changes
<!-- test/sandbox-init.test.ts 37/37 (vitest). pre-commit + pre-push
hooks
(shellcheck, shfmt, TypeScript CLI, Test CLI, commitlint, DCO, gitleaks)
pass on
each push; full PR CI green incl. test-e2e-sandbox /
test-non-root-sandbox-smoke. -->
---
Signed-off-by: Dongni Yang <[email protected]>
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Opt-in strict verification via NEMOCLAW_REQUIRE_CAP_DROP=1: agent can
refuse to start if dangerous Linux capabilities remain.
* **Behavior**
* More accurate detection and clearer diagnostics of residual
bounding-set capabilities; improved sandbox step-down argument handling.
* **Tests**
* Added deterministic tests covering warn-and-continue, strict-mode
refusal, and various verification edge cases.
* **Documentation**
* Updated docs explaining capability-drop behavior and the strict
verification option.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: Dongni Yang <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>1 parent fcacd5e commit 5db9432
4 files changed
Lines changed: 376 additions & 27 deletions
File tree
- docs
- deployment
- security
- scripts/lib
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
296 | 302 | | |
297 | 303 | | |
298 | 304 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
| 223 | + | |
219 | 224 | | |
220 | 225 | | |
221 | 226 | | |
222 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
223 | 255 | | |
224 | 256 | | |
225 | 257 | | |
| |||
232 | 264 | | |
233 | 265 | | |
234 | 266 | | |
235 | | - | |
| 267 | + | |
236 | 268 | | |
237 | | - | |
238 | | - | |
239 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
240 | 273 | | |
241 | 274 | | |
242 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
243 | 363 | | |
244 | 364 | | |
245 | 365 | | |
| |||
249 | 369 | | |
250 | 370 | | |
251 | 371 | | |
252 | | - | |
253 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
254 | 375 | | |
255 | | - | |
| 376 | + | |
256 | 377 | | |
257 | 378 | | |
258 | 379 | | |
259 | 380 | | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
277 | 385 | | |
278 | 386 | | |
279 | 387 | | |
| |||
331 | 439 | | |
332 | 440 | | |
333 | 441 | | |
334 | | - | |
335 | | - | |
| 442 | + | |
| 443 | + | |
336 | 444 | | |
337 | 445 | | |
338 | 446 | | |
339 | | - | |
340 | | - | |
| 447 | + | |
| 448 | + | |
341 | 449 | | |
342 | 450 | | |
343 | 451 | | |
| |||
0 commit comments