Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sync-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
path: docs-website

- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "0.10.12"

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 68 additions & 1 deletion architecture/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ paths, such as proxy support files or GPU device paths when a GPU is present.

All ordinary agent egress is routed through the sandbox proxy. The proxy
identifies the calling binary, checks trust-on-first-use binary identity, rejects
unsafe internal destinations, and evaluates the active policy.
unsafe internal destinations, and evaluates the active policy. On Linux, it
maps an accepted proxy connection back to the workload socket by matching the
complete local-to-remote TCP tuple before resolving every process that owns the
socket inode.
For inspected HTTP traffic, the proxy can enforce REST method/path rules,
WebSocket upgrade and text-message rules, GraphQL operation rules, and
MCP method, tool, and supported params rules or generic JSON-RPC method rules
Expand Down Expand Up @@ -103,6 +106,70 @@ handled by the inference interception path:
External inference endpoints that do not use `inference.local` are treated like
ordinary network traffic and must be allowed by policy.

In proxy-required networks, the supervisor chains upstream TLS tunnels through
a corporate forward proxy with HTTP CONNECT instead of connecting directly,
once policy and SSRF checks pass. Only TLS (CONNECT) egress is chained:
plain-HTTP requests always dial the destination directly, because forwarding
plain HTTP through a proxy requires absolute-form request forwarding rather
than CONNECT tunneling and is out of scope. The proxy configuration is an
operator-owned boundary delivered on the supervisor's command line
(`--upstream-proxy` and friends) by the compute driver; sandbox and template
environment — and `ENV` values baked into the sandbox image — cannot
influence it, since none of these can alter the argv the driver sets. The
conventional `HTTPS_PROXY`/`HTTP_PROXY`/`NO_PROXY` variables a sandbox
controls are ignored on this path. Operator `NO_PROXY` destinations and
loopback always dial directly; add driver-injected host aliases (e.g.
`host.containers.internal`) to the operator `NO_PROXY` list when the corporate
proxy cannot reach the container host. `NO_PROXY` matching is port-aware and
resolution-aware: an entry with a `:port` qualifier only bypasses that port,
and IP/CIDR entries also match hostnames through their validated resolved
addresses, with the direct dial limited to the addresses the entry contains. Only `http://` proxy URLs in explicit
`http://host:port` form are supported — the scheme and port are both
required, and a path, query, or fragment is rejected. Local DNS resolution
and SSRF validation still run before the proxied dial, and the CONNECT
target sent to the corporate proxy is a validated resolved address, so the
proxy performs no DNS resolution of its own and the tunnel stays bound to
the answer that passed SSRF and `allowed_ips` validation. The hostname still
travels inside the tunnel (TLS SNI, application `Host`). In split-horizon
networks, point the gateway host at the corporate resolver so internal names
validate to their internal addresses; the `proxy_connect_by_hostname`
opt-in exists as a
last resort for proxies whose ACLs filter on hostnames and reject IP CONNECT
targets — with it, the proxy resolves the name itself and its ACLs become
the effective egress control for proxied TLS. (Resolving through the proxy's
own DNS view, e.g. DoH tunneled via CONNECT, is a possible future
enhancement and out of scope.) The workload child's proxy variables are
unaffected — they are always rewritten to point at the local policy proxy.

The configuration is fail-closed: a setting that is present but invalid — an
empty value, an unsupported or malformed proxy URL, an unreadable auth file,
a malformed credential, or an auth file or `NO_PROXY` list set while no proxy
URL is configured — is fatal to supervisor startup instead of being treated
as unset, so a misconfiguration can never silently degrade to direct dialing
or unauthenticated proxy access. Only an omitted argument means "no proxy".
The driver validates the same rules at sandbox-create time through
validators shared with the supervisor
(`openshell_core::driver_utils::parse_upstream_proxy_url` and
`parse_upstream_proxy_credential`).

Proxy credentials are never embedded in the URL: an inline `user:pass@` is
rejected because it would be stored in `gateway.toml` and exposed in container
metadata. Operators supply credentials via `proxy_auth_file`; the driver
stages them as a root-only secret mounted at a fixed path and passes only
that path on the supervisor's command line. The supervisor reads the
file and builds the `Proxy-Authorization: Basic` header; a credential that is
empty, contains control characters, or is not in `user:pass` form is fatal on
both sides.

The Basic header travels over the plain-TCP connection to the `http://` proxy,
so it is readable on the network path between sandbox host and proxy.
Configuring `proxy_auth_file` therefore requires the explicit opt-in
`proxy_auth_allow_insecure = true`. Both the
driver (at sandbox-create time) and the supervisor (at startup) reject an
auth file without the acknowledgement, and the acknowledgement without an
auth file, so credentials are never sent in cleartext without an explicit
operator decision.

## Credentials

Provider credentials are stored at the gateway and fetched by the supervisor at
Expand Down
73 changes: 65 additions & 8 deletions crates/openshell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,11 @@ enum Commands {

/// Show gateway status and information.
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
Status,
Status {
/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
output: OutputFormat,
},

/// Manage inference configuration.
#[command(after_help = INFERENCE_EXAMPLES, help_template = SUBCOMMAND_HELP_TEMPLATE)]
Expand Down Expand Up @@ -1434,6 +1438,10 @@ enum SandboxCommands {
#[arg(long, value_parser = ["manual", "auto"], default_value = "manual")]
approval_mode: String,

/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table, conflicts_with_all = ["editor", "command", "no_keep", "forward"])]
output: OutputFormat,

/// Command to run after "--" (defaults to an interactive shell).
#[arg(last = true, allow_hyphen_values = true)]
command: Vec<String>,
Expand All @@ -1447,8 +1455,12 @@ enum SandboxCommands {
name: Option<String>,

/// Print only the active policy YAML (same policy as the default view; stdout only).
#[arg(long)]
#[arg(long, conflicts_with = "output")]
policy_only: bool,

/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
output: OutputFormat,
},

/// List sandboxes.
Expand Down Expand Up @@ -2270,11 +2282,24 @@ async fn main() -> Result<()> {
// -----------------------------------------------------------
// Top-level status
// -----------------------------------------------------------
Some(Commands::Status) => {
Some(Commands::Status { output }) => {
if let Ok(ctx) = resolve_gateway(&cli.gateway, &cli.gateway_endpoint) {
let mut tls = tls.with_gateway_name(&ctx.name);
let auth_error = apply_auth_with_status(&mut tls, &ctx.name);
run::gateway_status(&ctx.name, &ctx.endpoint, &tls, auth_error.as_deref()).await?;
run::gateway_status(
&ctx.name,
&ctx.endpoint,
output.as_str(),
&tls,
auth_error.as_deref(),
)
.await?;
} else if openshell_cli::output::print_output_single(
output.as_str(),
&(),
|()| serde_json::json!({"status": "not_configured"}),
)? {
// Structured output handled.
} else {
println!("{}", "Gateway Status".cyan().bold());
println!();
Expand Down Expand Up @@ -2885,6 +2910,7 @@ async fn main() -> Result<()> {
labels,
envs,
approval_mode,
output,
command,
} => {
// Resolve --tty / --no-tty into an Option<bool> override.
Expand Down Expand Up @@ -2971,6 +2997,7 @@ async fn main() -> Result<()> {
labels: labels_map,
environment: env_map,
approval_mode: &approval_mode,
output: output.as_str(),
},
&cli.workspace,
&tls,
Expand Down Expand Up @@ -3030,10 +3057,21 @@ async fn main() -> Result<()> {
| SandboxCommands::Download { .. } => {
unreachable!()
}
SandboxCommands::Get { name, policy_only } => {
SandboxCommands::Get {
name,
policy_only,
output,
} => {
let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?;
run::sandbox_get(endpoint, &name, policy_only, &cli.workspace, &tls)
.await?;
run::sandbox_get(
endpoint,
&name,
policy_only,
output.as_str(),
&cli.workspace,
&tls,
)
.await?;
}
SandboxCommands::List {
limit,
Expand Down Expand Up @@ -3883,7 +3921,7 @@ mod tests {
.expect("global gateway flag should parse with subcommands");

assert_eq!(cli.gateway.as_deref(), Some("demo"));
assert!(matches!(cli.command, Some(Commands::Status)));
assert!(matches!(cli.command, Some(Commands::Status { .. })));
}

#[test]
Expand Down Expand Up @@ -5025,6 +5063,25 @@ mod tests {
);
}

#[test]
fn sandbox_create_output_conflicts_with_side_effect_args() {
for (label, extra_args) in [
("--editor", &["--editor", "code"][..]),
("trailing command", &["--", "claude"][..]),
("--no-keep", &["--no-keep"][..]),
("--forward", &["--forward", "8080"][..]),
] {
let args = ["openshell", "sandbox", "create", "--output", "json"]
.into_iter()
.chain(extra_args.iter().copied());
let result = Cli::try_parse_from(args);
assert!(
result.is_err(),
"structured output should conflict with {label}"
);
}
}

#[test]
fn sandbox_create_resource_flags_parse() {
let cli = Cli::try_parse_from([
Expand Down
Loading
Loading