Skip to content

Commit 99956e3

Browse files
committed
fix(kubernetes): align sandbox identity annotation
Signed-off-by: Drew Newberry <[email protected]>
1 parent 4d868e1 commit 99956e3

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

‎crates/openshell-driver-docker/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,8 @@ impl ComputeDriver for DockerComputeDriver {
18771877
async fn authenticate_sandbox(
18781878
&self,
18791879
_request: Request<openshell_core::proto::compute::v1::AuthenticateSandboxRequest>,
1880-
) -> Result<Response<openshell_core::proto::compute::v1::AuthenticateSandboxResponse>, Status> {
1880+
) -> Result<Response<openshell_core::proto::compute::v1::AuthenticateSandboxResponse>, Status>
1881+
{
18811882
Err(Status::unimplemented(
18821883
"docker does not authenticate sandbox credentials",
18831884
))

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,16 +622,7 @@ impl KubernetesComputeDriver {
622622
"sandbox credential pod UID mismatch",
623623
));
624624
}
625-
let sandbox_id = pod
626-
.metadata
627-
.annotations
628-
.as_ref()
629-
.and_then(|annotations| annotations.get(LABEL_SANDBOX_ID))
630-
.filter(|value| !value.is_empty())
631-
.cloned()
632-
.ok_or_else(|| {
633-
tonic::Status::permission_denied("pod is not bound to a sandbox identity")
634-
})?;
625+
let sandbox_id = pod_sandbox_id(&pod)?;
635626
let owner = sandbox_owner_reference(&pod)?;
636627
let sandboxes = self
637628
.supported_agent_sandbox_api(self.client.clone(), &identity.namespace)
@@ -2400,6 +2391,17 @@ fn user_extra_one(user: &UserInfo, key: &str) -> Result<String, tonic::Status> {
24002391
Ok(values[0].clone())
24012392
}
24022393

2394+
#[allow(clippy::result_large_err)]
2395+
fn pod_sandbox_id(pod: &Pod) -> Result<String, tonic::Status> {
2396+
pod.metadata
2397+
.annotations
2398+
.as_ref()
2399+
.and_then(|annotations| annotations.get(LABEL_SANDBOX_ID))
2400+
.filter(|value| !value.is_empty())
2401+
.cloned()
2402+
.ok_or_else(|| tonic::Status::permission_denied("pod is not bound to a sandbox identity"))
2403+
}
2404+
24032405
#[allow(clippy::result_large_err)]
24042406
fn sandbox_owner_reference(pod: &Pod) -> Result<&OwnerReference, tonic::Status> {
24052407
let mut owners = pod
@@ -3756,7 +3758,7 @@ fn sandbox_template_to_k8s_with_validated_config(
37563758
.unwrap_or_default();
37573759
if !params.sandbox_id.is_empty() {
37583760
pod_annotations.insert(
3759-
"openshell.io/sandbox-id".to_string(),
3761+
LABEL_SANDBOX_ID.to_string(),
37603762
serde_json::Value::String(params.sandbox_id.to_string()),
37613763
);
37623764
}
@@ -7352,6 +7354,24 @@ mod tests {
73527354
);
73537355
}
73547356

7357+
#[test]
7358+
fn sandbox_template_annotation_is_accepted_by_bootstrap_authentication() {
7359+
let params = SandboxPodParams {
7360+
sandbox_id: "sandbox-a",
7361+
..Default::default()
7362+
};
7363+
let pod_template = sandbox_template_to_k8s(
7364+
&SandboxTemplate::default(),
7365+
false,
7366+
&std::collections::HashMap::new(),
7367+
true,
7368+
&params,
7369+
);
7370+
let pod: Pod = serde_json::from_value(pod_template).expect("valid pod template");
7371+
7372+
assert_eq!(pod_sandbox_id(&pod).unwrap(), "sandbox-a");
7373+
}
7374+
73557375
#[test]
73567376
fn sandbox_template_omits_empty_image_pull_secrets() {
73577377
let pod_template = sandbox_template_to_k8s(

‎deploy/helm/openshell/ci/values-spire-stack.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spire-server:
1515
clusterSPIFFEIDs:
1616
openshell-sandboxes:
1717
enabled: true
18-
spiffeIDTemplate: 'spiffe://{{ .TrustDomain }}/openshell/sandbox/{{ index .PodMeta.Annotations "openshell.io/sandbox-id" }}'
18+
spiffeIDTemplate: 'spiffe://{{ .TrustDomain }}/openshell/sandbox/{{ index .PodMeta.Annotations "openshell.ai/sandbox-id" }}'
1919
namespaceSelector:
2020
matchLabels:
2121
kubernetes.io/metadata.name: openshell

‎deploy/helm/openshell/templates/role.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rules:
3333
- watch
3434
# Per-sandbox identity: TokenReview authenticates the projected token from
3535
# the configured sandbox service account, then the gateway resolves the
36-
# returned pod name and UID to the pod's `openshell.io/sandbox-id`
36+
# returned pod name and UID to the pod's `openshell.ai/sandbox-id`
3737
# annotation. patch is intentionally NOT granted — the annotation is set
3838
# once at pod create and must remain immutable for the lifetime of the
3939
# sandbox.

‎docs/kubernetes/access-control.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Kubernetes sandbox supervisors authenticate back to the gateway as sandbox workl
2525

2626
Dynamic provider token grants can use SPIFFE without changing supervisor-to-gateway authentication. Set `server.providerTokenGrants.spiffe.enabled=true` to mount the SPIFFE CSI Workload API socket into gateway and sandbox pods while keeping the projected ServiceAccount token bootstrap and gateway-minted sandbox JWT path.
2727

28-
Provider token grants require a SPIFFE implementation such as SPIRE and identities for the gateway and sandbox pods. The repository's local SPIRE overlay assigns sandbox IDs from the pod's `openshell.io/sandbox-id` annotation, but the gateway validation path only requires the supervisor SVID to be valid and in the same SPIFFE trust domain as the gateway SVID. Provider profiles with `token_grant` metadata cause the sandbox supervisor to request JWT-SVIDs and exchange them for upstream OAuth2 access tokens. Token-exchange profiles also require a gateway SPIFFE identity because the gateway brokers the intermediate token exchange with its own JWT-SVID.
28+
Provider token grants require a SPIFFE implementation such as SPIRE and identities for the gateway and sandbox pods. The repository's local SPIRE overlay assigns sandbox IDs from the pod's `openshell.ai/sandbox-id` annotation, but the gateway validation path only requires the supervisor SVID to be valid and in the same SPIFFE trust domain as the gateway SVID. Provider profiles with `token_grant` metadata cause the sandbox supervisor to request JWT-SVIDs and exchange them for upstream OAuth2 access tokens. Token-exchange profiles also require a gateway SPIFFE identity because the gateway brokers the intermediate token exchange with its own JWT-SVID.
2929

3030
The gateway verifies supervisor JWT-SVIDs with JWT bundles fetched from the SPIFFE Workload API, so intermediate token exchange does not require gateway access to the SPIRE OIDC discovery endpoint or its TLS CA.
3131

0 commit comments

Comments
 (0)