Skip to content

Commit cc0405c

Browse files
committed
feat(sandbox,gateway): route sandbox egress through corporate HTTP proxy
- Chain sandbox egress through a corporate HTTP proxy so outbound traffic from within the sandbox respects the host proxy settings - Forward sandbox proxy environment variables to the generated Podman config so the proxy is applied consistently to Podman-managed workloads Signed-off-by: Philippe Martin <[email protected]>
1 parent 8cf2673 commit cc0405c

11 files changed

Lines changed: 989 additions & 5 deletions

File tree

‎architecture/sandbox.md‎

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

106+
In proxy-required networks, the supervisor honors `HTTPS_PROXY`/`HTTP_PROXY`/
107+
`NO_PROXY` from its own environment: after policy and SSRF checks pass, it
108+
chains the upstream dial through the corporate forward proxy with HTTP CONNECT
109+
instead of connecting directly. `NO_PROXY` destinations, loopback, and
110+
host-gateway aliases always dial directly. Only `http://` proxy URLs are
111+
supported. Local DNS resolution and SSRF validation still run before the
112+
proxied dial; the CONNECT target sent to the corporate proxy is the requested
113+
hostname. The workload child's proxy variables are unaffected — they are
114+
always rewritten to point at the local policy proxy.
115+
106116
## Credentials
107117

108118
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
@@ -385,6 +385,25 @@ fn build_env(
385385
env.insert(openshell_core::sandbox_env::USER_ENVIRONMENT.into(), json);
386386
}
387387

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

1668+
#[test]
1669+
fn container_spec_injects_operator_proxy_env() {
1670+
let sandbox = test_sandbox("test-id", "test-name");
1671+
let mut config = test_config();
1672+
config.https_proxy = Some("http://proxy.corp.com:8080".to_string());
1673+
config.http_proxy = Some("http://proxy.corp.com:3128".to_string());
1674+
config.no_proxy = Some("*.svc.cluster.local,10.0.0.0/8".to_string());
1675+
1676+
let spec = build_container_spec(&sandbox, &config);
1677+
let env_map = spec["env"].as_object().expect("env should be an object");
1678+
1679+
for key in ["HTTPS_PROXY", "https_proxy"] {
1680+
assert_eq!(
1681+
env_map.get(key).and_then(|v| v.as_str()),
1682+
Some("http://proxy.corp.com:8080"),
1683+
"{key} should carry the operator proxy URL"
1684+
);
1685+
}
1686+
for key in ["HTTP_PROXY", "http_proxy"] {
1687+
assert_eq!(
1688+
env_map.get(key).and_then(|v| v.as_str()),
1689+
Some("http://proxy.corp.com:3128"),
1690+
"{key} should carry the operator proxy URL"
1691+
);
1692+
}
1693+
for key in ["NO_PROXY", "no_proxy"] {
1694+
assert_eq!(
1695+
env_map.get(key).and_then(|v| v.as_str()),
1696+
Some("*.svc.cluster.local,10.0.0.0/8"),
1697+
"{key} should carry the operator NO_PROXY list"
1698+
);
1699+
}
1700+
}
1701+
1702+
#[test]
1703+
fn container_spec_omits_proxy_env_when_unconfigured() {
1704+
let sandbox = test_sandbox("test-id", "test-name");
1705+
let spec = build_container_spec(&sandbox, &test_config());
1706+
let env_map = spec["env"].as_object().expect("env should be an object");
1707+
1708+
for key in ["HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY"] {
1709+
assert!(
1710+
!env_map.contains_key(key),
1711+
"{key} should be absent without operator proxy config"
1712+
);
1713+
}
1714+
}
1715+
1716+
#[test]
1717+
fn container_spec_user_env_overrides_operator_proxy() {
1718+
use openshell_core::proto::compute::v1::{DriverSandboxSpec, DriverSandboxTemplate};
1719+
1720+
let mut sandbox = test_sandbox("test-id", "test-name");
1721+
sandbox.spec = Some(DriverSandboxSpec {
1722+
environment: std::collections::HashMap::from([(
1723+
"HTTPS_PROXY".to_string(),
1724+
"http://sandbox-specific:9999".to_string(),
1725+
)]),
1726+
template: Some(DriverSandboxTemplate::default()),
1727+
..Default::default()
1728+
});
1729+
let mut config = test_config();
1730+
config.https_proxy = Some("http://proxy.corp.com:8080".to_string());
1731+
1732+
let spec = build_container_spec(&sandbox, &config);
1733+
let env_map = spec["env"].as_object().expect("env should be an object");
1734+
1735+
assert_eq!(
1736+
env_map.get("HTTPS_PROXY").and_then(|v| v.as_str()),
1737+
Some("http://sandbox-specific:9999"),
1738+
"per-sandbox HTTPS_PROXY should win over operator config"
1739+
);
1740+
assert_eq!(
1741+
env_map.get("https_proxy").and_then(|v| v.as_str()),
1742+
Some("http://proxy.corp.com:8080"),
1743+
"unset lowercase variant still falls back to operator config"
1744+
);
1745+
}
1746+
16491747
#[test]
16501748
fn container_spec_required_labels_cannot_be_overridden() {
16511749
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]
@@ -137,6 +150,9 @@ async fn main() -> Result<()> {
137150
guest_tls_cert: args.podman_tls_cert,
138151
guest_tls_key: args.podman_tls_key,
139152
sandbox_pids_limit: args.sandbox_pids_limit,
153+
https_proxy: args.sandbox_https_proxy,
154+
http_proxy: args.sandbox_http_proxy,
155+
no_proxy: args.sandbox_no_proxy,
140156
..PodmanComputeConfig::default()
141157
})
142158
.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)