-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(sandbox): enforce connect shell rlimits #5682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1c94c8c
fix(sandbox): enforce connect shell rlimits
ericksoa 2d0f944
fix(sandbox): keep proxy hook before rlimit hook
ericksoa 0ad89a8
Merge remote-tracking branch 'origin/main' into fix/2173-sandbox-rlimits
ericksoa 2c14b1e
fix(sandbox): prove connect shell rlimits
ericksoa 3d216d2
test(sandbox): keep rlimit hook probes linear
ericksoa cefd894
test(sandbox): prove rlimit fork denial
ericksoa 552519d
test(sandbox): keep fork storm above nproc limit
ericksoa 943615c
fix(sandbox): harden stale bashrc replay
ericksoa d30034c
test(sandbox): stabilize fork denial probe
ericksoa 43cae48
fix(sandbox): use builtin ulimit for rlimit hooks
ericksoa d1a6663
test(sandbox): add connect rlimit acceptance anchor
ericksoa 2a9fd2d
test(sandbox): keep connect rlimit acceptance linear
ericksoa 065bb7f
fix(hermes): lock path before sandbox init
ericksoa 61bb983
test(sandbox): harden fork storm rlimit probe
ericksoa e37cf26
test(sandbox): leave rlimit fixture immutable
ericksoa 139580b
Merge branch 'main' into fix/2173-sandbox-rlimits
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # shellcheck shell=bash | ||
| # | ||
| # Shared NemoClaw sandbox RLIMIT defaults. | ||
|
|
||
| NEMOCLAW_SANDBOX_NPROC_LIMIT=512 | ||
| NEMOCLAW_SANDBOX_NOFILE_LIMIT=65536 | ||
|
|
||
| _nemoclaw_set_resource_limit() { | ||
| _nemoclaw_limit_flag="$1" | ||
| _nemoclaw_limit_value="$2" | ||
| _nemoclaw_limit_label="$3" | ||
| _nemoclaw_limit_quiet="${4:-}" | ||
|
|
||
| if ! builtin ulimit "-S${_nemoclaw_limit_flag}" "$_nemoclaw_limit_value" 2>/dev/null; then | ||
| if [ "$_nemoclaw_limit_quiet" != "--quiet" ]; then | ||
| echo "[SECURITY] Could not set soft ${_nemoclaw_limit_label} limit (container runtime may restrict ulimit)" >&2 | ||
| fi | ||
| fi | ||
| if ! builtin ulimit "-H${_nemoclaw_limit_flag}" "$_nemoclaw_limit_value" 2>/dev/null; then | ||
| if [ "$_nemoclaw_limit_quiet" != "--quiet" ]; then | ||
| echo "[SECURITY] Could not set hard ${_nemoclaw_limit_label} limit (container runtime may restrict ulimit)" >&2 | ||
| fi | ||
| fi | ||
|
|
||
| unset _nemoclaw_limit_flag _nemoclaw_limit_value _nemoclaw_limit_label _nemoclaw_limit_quiet | ||
| } | ||
|
|
||
| _nemoclaw_is_decimal_limit() { | ||
| case "$1" in | ||
| "" | *[!0-9]*) | ||
| return 1 | ||
| ;; | ||
| *) | ||
| return 0 | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| _nemoclaw_verify_resource_limit() { | ||
| _nemoclaw_limit_flag="$1" | ||
| _nemoclaw_limit_value="$2" | ||
| _nemoclaw_limit_label="$3" | ||
| _nemoclaw_limit_quiet="${4:-}" | ||
| _nemoclaw_limit_status=0 | ||
|
|
||
| for _nemoclaw_limit_bound in soft hard; do | ||
| case "$_nemoclaw_limit_bound" in | ||
| soft) | ||
| _nemoclaw_limit_mode="S" | ||
| ;; | ||
| hard) | ||
| _nemoclaw_limit_mode="H" | ||
| ;; | ||
| esac | ||
| _nemoclaw_effective_limit="$(builtin ulimit "-${_nemoclaw_limit_mode}${_nemoclaw_limit_flag}" 2>/dev/null || printf '%s' unknown)" | ||
|
|
||
| if ! _nemoclaw_is_decimal_limit "$_nemoclaw_effective_limit" \ | ||
| || [ "$_nemoclaw_effective_limit" -gt "$_nemoclaw_limit_value" ]; then | ||
| if [ "$_nemoclaw_limit_quiet" != "--quiet" ]; then | ||
| echo "[SECURITY] Effective ${_nemoclaw_limit_bound} ${_nemoclaw_limit_label} limit is ${_nemoclaw_effective_limit}; expected <= ${_nemoclaw_limit_value} (container runtime may restrict ulimit)" >&2 | ||
| fi | ||
| _nemoclaw_limit_status=1 | ||
| fi | ||
| done | ||
|
|
||
| _nemoclaw_limit_return="$_nemoclaw_limit_status" | ||
| unset _nemoclaw_limit_flag _nemoclaw_limit_value _nemoclaw_limit_label _nemoclaw_limit_quiet | ||
| unset _nemoclaw_limit_status _nemoclaw_limit_bound _nemoclaw_limit_mode _nemoclaw_effective_limit | ||
| return "$_nemoclaw_limit_return" | ||
| } | ||
|
|
||
| # Harden RLIMITs at PID 1 (root) so caps are inherited by entrypoint descendants | ||
| # and cannot be raised after privilege step-down. The same function is also | ||
| # sourced by connect-shell hooks, because OpenShell connect shells are spawned | ||
| # outside the PID 1 tree and therefore do not inherit those lowered limits. | ||
| harden_resource_limits() { | ||
| _nemoclaw_rlimit_quiet="${1:-}" | ||
| _nemoclaw_set_resource_limit u "$NEMOCLAW_SANDBOX_NPROC_LIMIT" nproc "$_nemoclaw_rlimit_quiet" | ||
| _nemoclaw_set_resource_limit n "$NEMOCLAW_SANDBOX_NOFILE_LIMIT" nofile "$_nemoclaw_rlimit_quiet" | ||
| unset _nemoclaw_rlimit_quiet | ||
| } | ||
|
|
||
| verify_resource_limits() { | ||
| local _nemoclaw_rlimit_quiet="${1:-}" | ||
| local _nemoclaw_rlimit_status=0 | ||
|
|
||
| _nemoclaw_verify_resource_limit u "$NEMOCLAW_SANDBOX_NPROC_LIMIT" nproc "$_nemoclaw_rlimit_quiet" \ | ||
| || _nemoclaw_rlimit_status=1 | ||
| _nemoclaw_verify_resource_limit n "$NEMOCLAW_SANDBOX_NOFILE_LIMIT" nofile "$_nemoclaw_rlimit_quiet" \ | ||
| || _nemoclaw_rlimit_status=1 | ||
|
|
||
| return "$_nemoclaw_rlimit_status" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.