Skip to content

Commit b3b3c75

Browse files
committed
fix(kubernetes): strip provider SPIFFE socket from proxy-pod agent pod
The base pod template mounts the provider SPIFFE Workload API socket (CSI volume, container mount, and OPENSHELL_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET env) into the agent pod when provider SPIFFE is enabled. The sidecar transform strips these from the agent container, but the proxy-pod transform did not, leaving the socket exposed to the agent pod. That socket belongs only in the supervisor (proxy) pod, which mints provider credentials. The proxy-pod agent pod holds a scoped process-kind credential that is denied provider-secret RPCs, so it must not receive an SVID. Strip the env and the container mount, and drop the CSI volume from the agent pod spec entirely (no container in the agent pod mounts it). The supervisor pod continues to mount it. Reported in review by grs. Signed-off-by: Russell Bryant <[email protected]>
1 parent e4f9466 commit b3b3c75

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

  • crates/openshell-driver-kubernetes/src

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,6 +4561,15 @@ fn apply_supervisor_proxy_pod_topology(
45614561
.or_insert_with(|| serde_json::json!([]))
45624562
.as_array_mut();
45634563
if let Some(volumes) = volumes {
4564+
// The provider SPIFFE Workload API socket belongs only in the supervisor
4565+
// (proxy) pod, which mints provider credentials. The agent pod holds a
4566+
// scoped process-kind credential that cannot access provider secrets, so
4567+
// it must not carry an SVID: drop the CSI volume entirely (no container
4568+
// in the agent pod mounts it after the cleanup below).
4569+
volumes.retain(|v| {
4570+
v.get("name").and_then(serde_json::Value::as_str)
4571+
!= Some(SPIFFE_WORKLOAD_API_VOLUME_NAME)
4572+
});
45644573
volumes.push(serde_json::json!({
45654574
"name": "openshell-proxy-pod-ca-source",
45664575
"secret": {
@@ -4673,6 +4682,9 @@ fn apply_supervisor_proxy_pod_topology(
46734682
.or_insert_with(|| serde_json::json!([]))
46744683
.as_array_mut();
46754684
if let Some(volume_mounts) = volume_mounts {
4685+
// Drop the provider SPIFFE Workload API mount from the agent
4686+
// container; it belongs only in the supervisor (proxy) pod.
4687+
remove_volume_mount(volume_mounts, SPIFFE_WORKLOAD_API_VOLUME_NAME);
46764688
volume_mounts.push(supervisor_volume_mount());
46774689
volume_mounts.push(proxy_pod_ca_tls_volume_mount(true));
46784690
}
@@ -4682,6 +4694,14 @@ fn apply_supervisor_proxy_pod_topology(
46824694
.or_insert_with(|| serde_json::json!([]))
46834695
.as_array_mut();
46844696
if let Some(env) = env {
4697+
// The provider SPIFFE Workload API socket lives only in the proxy
4698+
// pod; strip its env so the agent never advertises a socket it no
4699+
// longer mounts.
4700+
remove_env(
4701+
env,
4702+
openshell_core::sandbox_env::PROVIDER_SPIFFE_WORKLOAD_API_SOCKET,
4703+
);
4704+
46854705
// Select the process-supervisor + remote-proxy runtime path: own
46864706
// gateway session (no sidecar control socket), NetworkOnly
46874707
// enforcement, and the proxy CA read from the mounted TLS dir.
@@ -9600,6 +9620,99 @@ mod tests {
96009620
);
96019621
}
96029622

9623+
/// The provider SPIFFE Workload API socket must live only in the supervisor
9624+
/// (proxy) pod, which mints provider credentials. The agent pod holds a
9625+
/// scoped process-kind credential that cannot access provider secrets, so it
9626+
/// must not carry an SVID: no CSI volume, no container mount, no env.
9627+
#[test]
9628+
fn proxy_pod_strips_provider_spiffe_from_agent_but_keeps_it_on_supervisor() {
9629+
let names = proxy_pod_resource_names("example-sandbox", "sandbox-123");
9630+
let params = SandboxPodParams {
9631+
topology: SupervisorTopology::ProxyPod,
9632+
supervisor_image: "supervisor-image:latest",
9633+
namespace: "agents",
9634+
sandbox_id: "sandbox-123",
9635+
sandbox_name: "example-sandbox",
9636+
cr_name: "example-sandbox",
9637+
proxy_uid: 2200,
9638+
sandbox_uid: 1500,
9639+
sandbox_gid: 1500,
9640+
provider_spiffe_enabled: true,
9641+
provider_spiffe_workload_api_socket_path: "/spiffe-workload-api/spire-agent.sock",
9642+
..SandboxPodParams::default()
9643+
};
9644+
9645+
// Agent pod: SPIFFE stripped everywhere.
9646+
let pod_template = sandbox_template_to_k8s(
9647+
&SandboxTemplate {
9648+
image: "agent-image:latest".to_string(),
9649+
..SandboxTemplate::default()
9650+
},
9651+
false,
9652+
&std::collections::HashMap::new(),
9653+
false,
9654+
&params,
9655+
);
9656+
let agent = &pod_template["spec"]["containers"][0];
9657+
assert!(
9658+
rendered_env(
9659+
agent,
9660+
openshell_core::sandbox_env::PROVIDER_SPIFFE_WORKLOAD_API_SOCKET
9661+
)
9662+
.is_none(),
9663+
"agent must not advertise the provider SPIFFE socket"
9664+
);
9665+
let agent_mounts = agent["volumeMounts"]
9666+
.as_array()
9667+
.expect("agent volumeMounts");
9668+
assert!(
9669+
!agent_mounts
9670+
.iter()
9671+
.any(|m| m["name"] == SPIFFE_WORKLOAD_API_VOLUME_NAME),
9672+
"agent container must not mount the SPIFFE workload API socket"
9673+
);
9674+
let pod_volumes = pod_template["spec"]["volumes"]
9675+
.as_array()
9676+
.expect("pod volumes");
9677+
assert!(
9678+
!pod_volumes
9679+
.iter()
9680+
.any(|v| v["name"] == SPIFFE_WORKLOAD_API_VOLUME_NAME),
9681+
"agent pod must not carry the SPIFFE CSI volume"
9682+
);
9683+
9684+
// Supervisor (proxy) pod: SPIFFE retained (it mints provider credentials).
9685+
let dep = serde_json::to_value(proxy_pod_supervisor_deployment(
9686+
&names,
9687+
&std::collections::HashMap::new(),
9688+
&std::collections::HashMap::new(),
9689+
&params,
9690+
&KubernetesPodDriverConfig::default(),
9691+
&ProxyPodPlacement::default(),
9692+
1,
9693+
serde_json::json!({}),
9694+
))
9695+
.unwrap();
9696+
let sup_spec = &dep["spec"]["template"]["spec"];
9697+
let sup_mounts = sup_spec["containers"][0]["volumeMounts"]
9698+
.as_array()
9699+
.expect("supervisor volumeMounts");
9700+
assert!(
9701+
sup_mounts
9702+
.iter()
9703+
.any(|m| m["name"] == SPIFFE_WORKLOAD_API_VOLUME_NAME),
9704+
"supervisor container must mount the SPIFFE workload API socket"
9705+
);
9706+
let sup_volumes = sup_spec["volumes"].as_array().expect("supervisor volumes");
9707+
assert!(
9708+
sup_volumes
9709+
.iter()
9710+
.any(|v| v["name"] == SPIFFE_WORKLOAD_API_VOLUME_NAME
9711+
&& v["csi"]["driver"] == "csi.spiffe.io"),
9712+
"supervisor pod must carry the SPIFFE CSI volume"
9713+
);
9714+
}
9715+
96039716
/// The supervisor must also honor the public `platform_config` placement the
96049717
/// workload pod reads (runtime class, node selector, tolerations). Otherwise
96059718
/// the workload can land under Kata (or a required node) while the supervisor

0 commit comments

Comments
 (0)