Skip to content

Commit 8a55af9

Browse files
committed
feat(supervisor): identify sandboxes to the corporate proxy by sandbox id
A corporate forward proxy sees every sandbox in a deployment as one client: the same source address, and either no credential or a single shared one. An operator who wants to attribute egress per sandbox, or to ACL it per sandbox, has nothing to key on — while the gateway's own OCSF records are already per-sandbox, so the proxy is the one place that visibility disappears. Add `--upstream-proxy-auth-sandbox-identity`, which sends the resolved sandbox id as the `Proxy-Authorization: Basic` username with an empty password. The credential parser already documents an empty password as valid (RFC 7617 splits on the first `:`), so no shared secret has to exist for this to work. The username is an identifier, not a secret, and the code and docs say so rather than implying otherwise. The supervisor constructs the header on the upstream hop, so a workload cannot forge or alter its own attribution; anything with direct network access to the proxy can, so the proxy must not treat the value as authorization on its own. Because nothing confidential is sent, the flag deliberately does not require — and in fact rejects — the cleartext-credential acknowledgement, whose text would be false here. Fail-closed in the two ways that matter. An unresolved sandbox identity is fatal rather than sending an unattributed credential, which would silently defeat a proxy ACL keyed on the username. And because one request carries a single `Proxy-Authorization` header, combining this with the auth file or credential secret is rejected at both the driver and the supervisor instead of letting one source quietly win. The id is resolved before the proxy starts, so no new plumbing is needed beyond threading it into the upstream-proxy config: `run_networking` already receives both the sandbox id and the proxy argv in the same call. Wired through both compute drivers, since a supervisor capability reachable from only one driver is not really shipped.
1 parent 9b27620 commit 8a55af9

15 files changed

Lines changed: 718 additions & 35 deletions

File tree

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

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ pub struct KubernetesComputeConfig {
407407
/// and the proxy's own ACLs become the effective egress control.
408408
#[serde(default, skip_serializing_if = "Option::is_none")]
409409
pub proxy_connect_by_hostname: Option<bool>,
410+
/// Identify each sandbox to the corporate proxy by sending its sandbox id
411+
/// as the `Proxy-Authorization: Basic` username, with an empty password.
412+
///
413+
/// This lets the proxy attribute and ACL egress per sandbox. The username
414+
/// is an identifier, not a secret: the supervisor constructs the header on
415+
/// the upstream hop, so a workload cannot forge or alter it, but anything
416+
/// with direct network access to the proxy can. The proxy must therefore
417+
/// not treat the value as authorization on its own.
418+
///
419+
/// Mutually exclusive with the credential file/secret — one request
420+
/// carries a single `Proxy-Authorization` header. Fail-closed: a sandbox
421+
/// whose identity is unresolved refuses to start rather than egressing
422+
/// unattributed.
423+
#[serde(default, skip_serializing_if = "Option::is_none")]
424+
pub proxy_auth_sandbox_identity: Option<bool>,
410425
}
411426

412427
/// Lower bound enforced by kubelet for projected SA tokens.
@@ -467,6 +482,7 @@ impl Default for KubernetesComputeConfig {
467482
proxy_auth_secret_name: None,
468483
proxy_auth_allow_insecure: None,
469484
proxy_connect_by_hostname: None,
485+
proxy_auth_sandbox_identity: None,
470486
}
471487
}
472488
}
@@ -567,7 +583,9 @@ impl KubernetesComputeConfig {
567583
.to_string(),
568584
);
569585
}
570-
} else if self.proxy_auth_allow_insecure.is_some() {
586+
} else if self.proxy_auth_sandbox_identity != Some(true)
587+
&& self.proxy_auth_allow_insecure.is_some()
588+
{
571589
// The acknowledgement without credentials means the operator
572590
// believed a credential secret was configured; surface the
573591
// mismatch.
@@ -583,6 +601,38 @@ impl KubernetesComputeConfig {
583601
);
584602
}
585603

604+
if self.proxy_auth_sandbox_identity == Some(true) {
605+
if self.https_proxy.is_none() {
606+
return Err(
607+
"proxy_auth_sandbox_identity is set but no https_proxy is configured"
608+
.to_string(),
609+
);
610+
}
611+
// One request carries one Proxy-Authorization header, so the two
612+
// credential sources cannot both apply.
613+
if self.proxy_auth_secret_name.is_some() {
614+
return Err(
615+
"proxy_auth_sandbox_identity and proxy_auth_secret_name are mutually \
616+
exclusive; a request carries a single Proxy-Authorization header"
617+
.to_string(),
618+
);
619+
}
620+
// The sandbox id is an identifier, not a secret, so it needs no
621+
// cleartext acknowledgement; accepting one here would imply a
622+
// credential is being sent.
623+
if self.proxy_auth_allow_insecure.is_some() {
624+
return Err(
625+
"proxy_auth_allow_insecure does not apply to proxy_auth_sandbox_identity: \
626+
the sandbox id is an identifier, not a credential"
627+
.to_string(),
628+
);
629+
}
630+
} else if self.proxy_auth_sandbox_identity.is_some() && self.https_proxy.is_none() {
631+
return Err(
632+
"proxy_auth_sandbox_identity is set but no https_proxy is configured".to_string(),
633+
);
634+
}
635+
586636
Ok(())
587637
}
588638

@@ -1323,4 +1373,65 @@ mod tests {
13231373
assert_eq!(cfg.proxy_connect_by_hostname, Some(true));
13241374
cfg.validate_proxy_config().unwrap();
13251375
}
1376+
1377+
#[test]
1378+
fn validate_proxy_config_accepts_sandbox_identity_with_a_proxy() {
1379+
let mut cfg = proxy_cfg(Some("http://egress.openshell.svc:3128"));
1380+
cfg.proxy_auth_sandbox_identity = Some(true);
1381+
cfg.validate_proxy_config().unwrap();
1382+
}
1383+
1384+
#[test]
1385+
fn validate_proxy_config_rejects_sandbox_identity_without_a_proxy() {
1386+
for value in [Some(true), Some(false)] {
1387+
let cfg = KubernetesComputeConfig {
1388+
proxy_auth_sandbox_identity: value,
1389+
..KubernetesComputeConfig::default()
1390+
};
1391+
let err = cfg.validate_proxy_config().unwrap_err();
1392+
assert!(err.contains("proxy_auth_sandbox_identity"), "{err}");
1393+
assert!(err.contains("https_proxy"), "{err}");
1394+
}
1395+
}
1396+
1397+
/// A request carries a single `Proxy-Authorization` header, so the two
1398+
/// credential sources cannot both apply.
1399+
#[test]
1400+
fn validate_proxy_config_rejects_sandbox_identity_with_a_credential_secret() {
1401+
let mut cfg = proxy_cfg(Some("http://egress.openshell.svc:3128"));
1402+
cfg.proxy_auth_secret_name = Some("proxy-auth".to_string());
1403+
cfg.proxy_auth_allow_insecure = Some(true);
1404+
cfg.proxy_auth_sandbox_identity = Some(true);
1405+
let err = cfg.validate_proxy_config().unwrap_err();
1406+
assert!(err.contains("mutually exclusive"), "{err}");
1407+
}
1408+
1409+
/// The sandbox id is an identifier, not a secret. Accepting the
1410+
/// cleartext-credential acknowledgement alongside it would tell the
1411+
/// operator a credential is being sent when none is.
1412+
#[test]
1413+
fn validate_proxy_config_rejects_the_cleartext_acknowledgement_with_sandbox_identity() {
1414+
let mut cfg = proxy_cfg(Some("http://egress.openshell.svc:3128"));
1415+
cfg.proxy_auth_sandbox_identity = Some(true);
1416+
cfg.proxy_auth_allow_insecure = Some(true);
1417+
let err = cfg.validate_proxy_config().unwrap_err();
1418+
assert!(err.contains("identifier, not a credential"), "{err}");
1419+
}
1420+
1421+
#[test]
1422+
fn serde_reads_the_sandbox_identity_setting() {
1423+
let cfg: KubernetesComputeConfig = serde_json::from_value(serde_json::json!({
1424+
"https_proxy": "http://egress.openshell.svc:3128",
1425+
"proxy_auth_sandbox_identity": true,
1426+
}))
1427+
.unwrap();
1428+
assert_eq!(cfg.proxy_auth_sandbox_identity, Some(true));
1429+
cfg.validate_proxy_config().unwrap();
1430+
}
1431+
1432+
#[test]
1433+
fn serde_default_leaves_sandbox_identity_unset() {
1434+
let cfg: KubernetesComputeConfig = serde_json::from_value(serde_json::json!({})).unwrap();
1435+
assert_eq!(cfg.proxy_auth_sandbox_identity, None);
1436+
}
13261437
}

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

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ impl KubernetesComputeDriver {
11221122
auth_secret_name: self.config.proxy_auth_secret_name.as_deref(),
11231123
auth_allow_insecure: self.config.proxy_auth_allow_insecure == Some(true),
11241124
connect_by_hostname: self.config.proxy_connect_by_hostname == Some(true),
1125+
auth_sandbox_identity: self.config.proxy_auth_sandbox_identity == Some(true),
11251126
},
11261127
};
11271128
validate_sidecar_proxy_identity(&params)?;
@@ -2217,6 +2218,11 @@ fn upstream_proxy_cli_args(params: &SandboxPodParams<'_>) -> Vec<String> {
22172218
if params.upstream_proxy.connect_by_hostname {
22182219
args.push("--upstream-proxy-connect-by-hostname".to_string());
22192220
}
2221+
// Attribution rather than authentication: the supervisor resolves the id
2222+
// itself, so nothing sandbox-controlled reaches the header.
2223+
if params.upstream_proxy.auth_sandbox_identity {
2224+
args.push("--upstream-proxy-auth-sandbox-identity".to_string());
2225+
}
22202226
args
22212227
}
22222228

@@ -2894,6 +2900,9 @@ struct UpstreamProxyPodParams<'a> {
28942900
auth_allow_insecure: bool,
28952901
/// Send the destination hostname in CONNECT instead of a validated IP.
28962902
connect_by_hostname: bool,
2903+
/// Send the sandbox id as the Basic-auth username so the proxy can
2904+
/// attribute and ACL egress per sandbox.
2905+
auth_sandbox_identity: bool,
28972906
}
28982907

28992908
impl Default for SandboxPodParams<'_> {
@@ -6994,6 +7003,7 @@ mod tests {
69947003
auth_secret_name: Some("proxy-auth"),
69957004
auth_allow_insecure: true,
69967005
connect_by_hostname: true,
7006+
auth_sandbox_identity: false,
69977007
},
69987008
..SandboxPodParams::default()
69997009
};
@@ -7168,4 +7178,95 @@ mod tests {
71687178
assert!(!rendered.contains("--upstream-proxy"), "{topology}");
71697179
}
71707180
}
7181+
7182+
#[test]
7183+
fn sandbox_identity_flag_is_rendered_for_the_network_supervisor_only() {
7184+
let params = SandboxPodParams {
7185+
topology: SupervisorTopology::Sidecar,
7186+
supervisor_sideload_method: SupervisorSideloadMethod::InitContainer,
7187+
supervisor_image: "supervisor-image:latest",
7188+
proxy_uid: 2200,
7189+
sandbox_uid: 1500,
7190+
sandbox_gid: 1500,
7191+
upstream_proxy: UpstreamProxyPodParams {
7192+
https_proxy: Some("http://egress.openshell.svc:3128"),
7193+
auth_sandbox_identity: true,
7194+
..UpstreamProxyPodParams::default()
7195+
},
7196+
..SandboxPodParams::default()
7197+
};
7198+
let pod_template = upstream_proxy_pod_template(&params);
7199+
7200+
let sidecar = container_named(&pod_template, SUPERVISOR_NETWORK_SIDECAR_NAME);
7201+
assert_eq!(
7202+
sidecar["command"],
7203+
serde_json::json!([
7204+
SUPERVISOR_IMAGE_BINARY_PATH,
7205+
"--mode=network",
7206+
"--upstream-proxy",
7207+
"http://egress.openshell.svc:3128",
7208+
"--upstream-proxy-auth-sandbox-identity"
7209+
])
7210+
);
7211+
7212+
let agent = container_named(&pod_template, "agent");
7213+
assert_eq!(
7214+
agent["command"],
7215+
serde_json::json!([
7216+
format!("{SUPERVISOR_MOUNT_PATH}/openshell-sandbox"),
7217+
"--mode=process"
7218+
])
7219+
);
7220+
}
7221+
7222+
/// Identity mode carries no secret, so the pod must gain no credential
7223+
/// volume — nothing to mount and nothing to leak.
7224+
#[test]
7225+
fn sandbox_identity_needs_no_credential_volume() {
7226+
let params = SandboxPodParams {
7227+
topology: SupervisorTopology::Sidecar,
7228+
upstream_proxy: UpstreamProxyPodParams {
7229+
https_proxy: Some("http://egress.openshell.svc:3128"),
7230+
auth_sandbox_identity: true,
7231+
..UpstreamProxyPodParams::default()
7232+
},
7233+
..SandboxPodParams::default()
7234+
};
7235+
let pod_template = upstream_proxy_pod_template(&params);
7236+
assert!(
7237+
!volume_names(&pod_template).contains(&UPSTREAM_PROXY_AUTH_VOLUME_NAME.to_string()),
7238+
"{:?}",
7239+
volume_names(&pod_template)
7240+
);
7241+
let sidecar = container_named(&pod_template, SUPERVISOR_NETWORK_SIDECAR_NAME);
7242+
assert!(
7243+
!mount_paths(sidecar).contains(&UPSTREAM_PROXY_AUTH_MOUNT_DIR.to_string()),
7244+
"{:?}",
7245+
mount_paths(sidecar)
7246+
);
7247+
}
7248+
7249+
/// The pod spec must never carry the sandbox id as a proxy credential;
7250+
/// the supervisor resolves it in-pod after activation.
7251+
#[test]
7252+
fn sandbox_identity_argv_is_a_bare_flag_with_no_value() {
7253+
let params = SandboxPodParams {
7254+
upstream_proxy: UpstreamProxyPodParams {
7255+
https_proxy: Some("http://egress.openshell.svc:3128"),
7256+
auth_sandbox_identity: true,
7257+
..UpstreamProxyPodParams::default()
7258+
},
7259+
..SandboxPodParams::default()
7260+
};
7261+
let args = upstream_proxy_cli_args(&params);
7262+
let flag_index = args
7263+
.iter()
7264+
.position(|arg| arg == "--upstream-proxy-auth-sandbox-identity")
7265+
.expect("flag should be rendered");
7266+
assert_eq!(
7267+
flag_index,
7268+
args.len() - 1,
7269+
"the flag takes no value: {args:?}"
7270+
);
7271+
}
71717272
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ struct Args {
176176
/// SSRF/`allowed_ips` validation no longer binds the connection.
177177
#[arg(long, env = "OPENSHELL_SANDBOX_PROXY_CONNECT_BY_HOSTNAME")]
178178
sandbox_proxy_connect_by_hostname: Option<bool>,
179+
180+
/// Identify each sandbox to the corporate proxy by sending its sandbox id
181+
/// as the Proxy-Authorization Basic username. Attribution only: the value
182+
/// is an identifier, not a credential. Mutually exclusive with
183+
/// `--sandbox-proxy-auth-secret-name`.
184+
#[arg(long, env = "OPENSHELL_SANDBOX_PROXY_AUTH_SANDBOX_IDENTITY")]
185+
sandbox_proxy_auth_sandbox_identity: Option<bool>,
179186
}
180187

181188
#[tokio::main]
@@ -232,6 +239,7 @@ async fn main() -> Result<()> {
232239
proxy_auth_secret_name: args.sandbox_proxy_auth_secret_name,
233240
proxy_auth_allow_insecure: args.sandbox_proxy_auth_allow_insecure,
234241
proxy_connect_by_hostname: args.sandbox_proxy_connect_by_hostname,
242+
proxy_auth_sandbox_identity: args.sandbox_proxy_auth_sandbox_identity,
235243
})
236244
.await
237245
.into_diagnostic()?;

0 commit comments

Comments
 (0)