Skip to content

Commit 9a11c2f

Browse files
feloyclaude
andcommitted
feat(sandbox,podman): chain sandbox egress through corporate HTTP proxy
In proxy-required enterprise networks the supervisor's egress proxy dialed policy-approved destinations directly, so allowed external API calls timed out behind corporate forward proxies. The supervisor now reads HTTPS_PROXY/HTTP_PROXY/ALL_PROXY/NO_PROXY from its own environment and chains approved CONNECT tunnels and plain HTTP forward requests through the corporate proxy with HTTP CONNECT, including Basic proxy authentication. NO_PROXY entries (hostnames, domain suffixes, IPs, CIDRs), loopback, and host-gateway aliases keep dialing directly. Policy evaluation, local DNS resolution, and SSRF checks are unchanged; only the final TCP dial is proxied, and the workload child's proxy variables still point at the local policy proxy. The Podman driver gains https_proxy/http_proxy/no_proxy operator config (TOML, CLI flags, and env) injected into sandbox containers as proxy environment defaults that per-sandbox environment values override. Fixes NVIDIA#1792 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Philippe Martin <[email protected]>
1 parent abe42fb commit 9a11c2f

10 files changed

Lines changed: 997 additions & 11 deletions

File tree

‎architecture/sandbox.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ handled by the inference interception path:
7878
External inference endpoints that do not use `inference.local` are treated like
7979
ordinary network traffic and must be allowed by policy.
8080

81+
In proxy-required networks, the supervisor honors `HTTPS_PROXY`/`HTTP_PROXY`/
82+
`NO_PROXY` from its own environment: after policy and SSRF checks pass, it
83+
chains the upstream dial through the corporate forward proxy with HTTP CONNECT
84+
instead of connecting directly. `NO_PROXY` destinations, loopback, and
85+
host-gateway aliases always dial directly. Only `http://` proxy URLs are
86+
supported. Local DNS resolution and SSRF validation still run before the
87+
proxied dial; the CONNECT target sent to the corporate proxy is the requested
88+
hostname. The workload child's proxy variables are unaffected — they are
89+
always rewritten to point at the local policy proxy.
90+
8191
## Credentials
8292

8393
Provider credentials are stored at the gateway and fetched by the supervisor at

‎crates/openshell-driver-podman/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ Podman resources after out-of-band container removal or label drift.
345345
| `OPENSHELL_PODMAN_TLS_CA` | `--podman-tls-ca` | unset | Host path to the CA certificate mounted for sandbox mTLS. |
346346
| `OPENSHELL_PODMAN_TLS_CERT` | `--podman-tls-cert` | unset | Host path to the client certificate mounted for sandbox mTLS. |
347347
| `OPENSHELL_PODMAN_TLS_KEY` | `--podman-tls-key` | unset | Host path to the client private key mounted for sandbox mTLS. |
348+
| `OPENSHELL_SANDBOX_HTTPS_PROXY` | `--sandbox-https-proxy` | unset | Corporate forward proxy URL injected into sandbox containers as `HTTPS_PROXY`. The in-container supervisor chains policy-approved upstream dials through it with HTTP CONNECT. Only `http://` proxy URLs are supported. |
349+
| `OPENSHELL_SANDBOX_HTTP_PROXY` | `--sandbox-http-proxy` | unset | Corporate forward proxy URL injected as `HTTP_PROXY` for plain HTTP requests. |
350+
| `OPENSHELL_SANDBOX_NO_PROXY` | `--sandbox-no-proxy` | unset | Comma-separated `NO_PROXY` list (hostnames, domain suffixes, IPs, CIDRs) dialed directly instead of through the corporate proxy. |
351+
352+
Through the gateway, the same settings are the `https_proxy`, `http_proxy`, and
353+
`no_proxy` keys under `[openshell.drivers.podman]`; see
354+
`docs/reference/gateway-config.mdx`. Per-sandbox environment values take
355+
precedence over these operator defaults.
348356

349357
## Rootless-Specific Adaptations
350358

‎crates/openshell-driver-podman/src/config.rs‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ pub struct PodmanComputeConfig {
134134
/// Set to `0` to disable health checks entirely.
135135
/// Defaults to [`DEFAULT_HEALTH_CHECK_INTERVAL_SECS`] (10 seconds).
136136
pub health_check_interval_secs: u64,
137+
/// Corporate forward proxy URL injected into sandbox containers as
138+
/// `HTTPS_PROXY`/`https_proxy` (e.g. `http://proxy.corp.com:8080`).
139+
///
140+
/// The in-container supervisor chains policy-approved TLS tunnels
141+
/// through this proxy with HTTP CONNECT instead of dialing upstream
142+
/// destinations directly. Only `http://` proxy URLs are supported.
143+
/// Per-sandbox environment values take precedence.
144+
pub https_proxy: Option<String>,
145+
/// Corporate forward proxy URL injected as `HTTP_PROXY`/`http_proxy`,
146+
/// used for plain HTTP requests. See `https_proxy`.
147+
pub http_proxy: Option<String>,
148+
/// Comma-separated `NO_PROXY` list injected alongside the proxy URLs
149+
/// (e.g. `*.svc.cluster.local,10.0.0.0/8`). Destinations matching an
150+
/// entry are dialed directly instead of through the corporate proxy.
151+
pub no_proxy: Option<String>,
137152
}
138153

139154
pub const DEFAULT_HEALTH_CHECK_INTERVAL_SECS: u64 = 10;
@@ -189,6 +204,35 @@ impl PodmanComputeConfig {
189204
Ok(())
190205
}
191206

207+
/// Validate optional corporate proxy configuration.
208+
///
209+
/// The in-container supervisor only supports `http://` forward proxies,
210+
/// so reject other schemes at config time instead of silently ignoring
211+
/// them inside every sandbox.
212+
pub fn validate_proxy_config(&self) -> Result<(), crate::client::PodmanApiError> {
213+
for (field, value) in [
214+
("https_proxy", &self.https_proxy),
215+
("http_proxy", &self.http_proxy),
216+
] {
217+
let Some(url) = value else { continue };
218+
let trimmed = url.trim();
219+
if trimmed.is_empty() {
220+
return Err(crate::client::PodmanApiError::InvalidInput(format!(
221+
"{field} must not be empty when set"
222+
)));
223+
}
224+
if let Some((scheme, _)) = trimmed.split_once("://")
225+
&& !scheme.eq_ignore_ascii_case("http")
226+
{
227+
return Err(crate::client::PodmanApiError::InvalidInput(format!(
228+
"{field} uses unsupported scheme '{scheme}': only http:// forward \
229+
proxies are supported by the sandbox supervisor"
230+
)));
231+
}
232+
}
233+
Ok(())
234+
}
235+
192236
/// Validate optional host gateway override.
193237
pub fn validate_host_gateway_ip(&self) -> Result<(), crate::client::PodmanApiError> {
194238
let trimmed = self.host_gateway_ip.trim();
@@ -262,6 +306,9 @@ impl Default for PodmanComputeConfig {
262306
sandbox_pids_limit: DEFAULT_SANDBOX_PIDS_LIMIT,
263307
enable_bind_mounts: false,
264308
health_check_interval_secs: DEFAULT_HEALTH_CHECK_INTERVAL_SECS,
309+
https_proxy: None,
310+
http_proxy: None,
311+
no_proxy: None,
265312
}
266313
}
267314
}
@@ -288,6 +335,10 @@ impl std::fmt::Debug for PodmanComputeConfig {
288335
"health_check_interval_secs",
289336
&self.health_check_interval_secs,
290337
)
338+
// Proxy URLs may embed credentials in userinfo; log presence only.
339+
.field("https_proxy", &self.https_proxy.is_some())
340+
.field("http_proxy", &self.http_proxy.is_some())
341+
.field("no_proxy", &self.no_proxy)
291342
.finish()
292343
}
293344
}
@@ -397,6 +448,49 @@ mod tests {
397448
});
398449
}
399450

451+
// ── Proxy config validation ───────────────────────────────────────
452+
453+
#[test]
454+
fn validate_proxy_config_accepts_unset_and_http() {
455+
assert!(
456+
PodmanComputeConfig::default()
457+
.validate_proxy_config()
458+
.is_ok()
459+
);
460+
let cfg = PodmanComputeConfig {
461+
https_proxy: Some("http://proxy.corp.com:8080".to_string()),
462+
http_proxy: Some("proxy.corp.com:3128".to_string()),
463+
no_proxy: Some("*.svc.cluster.local".to_string()),
464+
..PodmanComputeConfig::default()
465+
};
466+
assert!(cfg.validate_proxy_config().is_ok());
467+
}
468+
469+
#[test]
470+
fn validate_proxy_config_rejects_non_http_schemes() {
471+
for url in ["https://proxy:443", "socks5://proxy:1080"] {
472+
let cfg = PodmanComputeConfig {
473+
https_proxy: Some(url.to_string()),
474+
..PodmanComputeConfig::default()
475+
};
476+
let err = cfg.validate_proxy_config().unwrap_err();
477+
assert!(
478+
err.to_string().contains("unsupported scheme"),
479+
"{url}: {err}"
480+
);
481+
}
482+
}
483+
484+
#[test]
485+
fn validate_proxy_config_rejects_empty_value() {
486+
let cfg = PodmanComputeConfig {
487+
http_proxy: Some(" ".to_string()),
488+
..PodmanComputeConfig::default()
489+
};
490+
let err = cfg.validate_proxy_config().unwrap_err();
491+
assert!(err.to_string().contains("http_proxy"), "{err}");
492+
}
493+
400494
// ── TLS config validation ─────────────────────────────────────────
401495

402496
#[test]

‎crates/openshell-driver-podman/src/container.rs‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,25 @@ fn build_env(
384384
env.insert(openshell_core::sandbox_env::USER_ENVIRONMENT.into(), json);
385385
}
386386

387+
// 1.5. Operator-configured corporate egress proxy. The in-container
388+
// supervisor reads these from its own environment and chains approved
389+
// upstream dials through the corporate proxy; the workload child's proxy
390+
// variables are rewritten separately to point at the local policy proxy.
391+
// Inserted as defaults so per-sandbox user env wins. Both cases are set
392+
// because proxy-aware tooling disagrees on which one it reads.
393+
for (name, value) in [
394+
("HTTPS_PROXY", &config.https_proxy),
395+
("https_proxy", &config.https_proxy),
396+
("HTTP_PROXY", &config.http_proxy),
397+
("http_proxy", &config.http_proxy),
398+
("NO_PROXY", &config.no_proxy),
399+
("no_proxy", &config.no_proxy),
400+
] {
401+
if let Some(value) = value {
402+
env.entry(name.into()).or_insert_with(|| value.clone());
403+
}
404+
}
405+
387406
// 2. Required driver vars (highest priority -- always overwrite).
388407
env.insert(
389408
openshell_core::sandbox_env::SANDBOX.into(),
@@ -1675,6 +1694,85 @@ mod tests {
16751694
);
16761695
}
16771696

1697+
#[test]
1698+
fn container_spec_injects_operator_proxy_env() {
1699+
let sandbox = test_sandbox("test-id", "test-name");
1700+
let mut config = test_config();
1701+
config.https_proxy = Some("http://proxy.corp.com:8080".to_string());
1702+
config.http_proxy = Some("http://proxy.corp.com:3128".to_string());
1703+
config.no_proxy = Some("*.svc.cluster.local,10.0.0.0/8".to_string());
1704+
1705+
let spec = build_container_spec(&sandbox, &config);
1706+
let env_map = spec["env"].as_object().expect("env should be an object");
1707+
1708+
for key in ["HTTPS_PROXY", "https_proxy"] {
1709+
assert_eq!(
1710+
env_map.get(key).and_then(|v| v.as_str()),
1711+
Some("http://proxy.corp.com:8080"),
1712+
"{key} should carry the operator proxy URL"
1713+
);
1714+
}
1715+
for key in ["HTTP_PROXY", "http_proxy"] {
1716+
assert_eq!(
1717+
env_map.get(key).and_then(|v| v.as_str()),
1718+
Some("http://proxy.corp.com:3128"),
1719+
"{key} should carry the operator proxy URL"
1720+
);
1721+
}
1722+
for key in ["NO_PROXY", "no_proxy"] {
1723+
assert_eq!(
1724+
env_map.get(key).and_then(|v| v.as_str()),
1725+
Some("*.svc.cluster.local,10.0.0.0/8"),
1726+
"{key} should carry the operator NO_PROXY list"
1727+
);
1728+
}
1729+
}
1730+
1731+
#[test]
1732+
fn container_spec_omits_proxy_env_when_unconfigured() {
1733+
let sandbox = test_sandbox("test-id", "test-name");
1734+
let spec = build_container_spec(&sandbox, &test_config());
1735+
let env_map = spec["env"].as_object().expect("env should be an object");
1736+
1737+
for key in ["HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY"] {
1738+
assert!(
1739+
!env_map.contains_key(key),
1740+
"{key} should be absent without operator proxy config"
1741+
);
1742+
}
1743+
}
1744+
1745+
#[test]
1746+
fn container_spec_user_env_overrides_operator_proxy() {
1747+
use openshell_core::proto::compute::v1::{DriverSandboxSpec, DriverSandboxTemplate};
1748+
1749+
let mut sandbox = test_sandbox("test-id", "test-name");
1750+
sandbox.spec = Some(DriverSandboxSpec {
1751+
environment: std::collections::HashMap::from([(
1752+
"HTTPS_PROXY".to_string(),
1753+
"http://sandbox-specific:9999".to_string(),
1754+
)]),
1755+
template: Some(DriverSandboxTemplate::default()),
1756+
..Default::default()
1757+
});
1758+
let mut config = test_config();
1759+
config.https_proxy = Some("http://proxy.corp.com:8080".to_string());
1760+
1761+
let spec = build_container_spec(&sandbox, &config);
1762+
let env_map = spec["env"].as_object().expect("env should be an object");
1763+
1764+
assert_eq!(
1765+
env_map.get("HTTPS_PROXY").and_then(|v| v.as_str()),
1766+
Some("http://sandbox-specific:9999"),
1767+
"per-sandbox HTTPS_PROXY should win over operator config"
1768+
);
1769+
assert_eq!(
1770+
env_map.get("https_proxy").and_then(|v| v.as_str()),
1771+
Some("http://proxy.corp.com:8080"),
1772+
"unset lowercase variant still falls back to operator config"
1773+
);
1774+
}
1775+
16781776
#[test]
16791777
fn container_spec_required_labels_cannot_be_overridden() {
16801778
use openshell_core::proto::compute::v1::{DriverSandboxSpec, DriverSandboxTemplate};

‎crates/openshell-driver-podman/src/driver.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ impl PodmanComputeDriver {
185185
config.validate_tls_config()?;
186186
config.validate_runtime_limits()?;
187187
config.validate_host_gateway_ip()?;
188+
config.validate_proxy_config()?;
188189

189190
let client = PodmanClient::new(config.socket_path.clone());
190191

‎crates/openshell-driver-podman/src/main.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ struct Args {
103103
/// Host path to the client private key for sandbox mTLS.
104104
#[arg(long, env = "OPENSHELL_PODMAN_TLS_KEY")]
105105
podman_tls_key: Option<PathBuf>,
106+
107+
/// Corporate forward proxy URL injected into sandbox containers as
108+
/// `HTTPS_PROXY` for the supervisor's upstream dials (http:// only).
109+
#[arg(long, env = "OPENSHELL_SANDBOX_HTTPS_PROXY")]
110+
sandbox_https_proxy: Option<String>,
111+
112+
/// Corporate forward proxy URL injected as `HTTP_PROXY` (http:// only).
113+
#[arg(long, env = "OPENSHELL_SANDBOX_HTTP_PROXY")]
114+
sandbox_http_proxy: Option<String>,
115+
116+
/// Comma-separated `NO_PROXY` list injected alongside the proxy URLs.
117+
#[arg(long, env = "OPENSHELL_SANDBOX_NO_PROXY")]
118+
sandbox_no_proxy: Option<String>,
106119
}
107120

108121
#[tokio::main]
@@ -135,6 +148,9 @@ async fn main() -> Result<()> {
135148
guest_tls_cert: args.podman_tls_cert,
136149
guest_tls_key: args.podman_tls_key,
137150
sandbox_pids_limit: args.sandbox_pids_limit,
151+
https_proxy: args.sandbox_https_proxy,
152+
http_proxy: args.sandbox_http_proxy,
153+
no_proxy: args.sandbox_no_proxy,
138154
..PodmanComputeConfig::default()
139155
})
140156
.await

‎crates/openshell-supervisor-network/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pub mod run;
1919
pub mod sigv4;
2020
mod spiffe_endpoint;
2121
mod token_grant;
22+
pub mod upstream_proxy;

0 commit comments

Comments
 (0)