Skip to content

Commit 62c9e90

Browse files
authored
fix: drop cross-source socket path checks and scope the SPIRE e2e fixture
provider_spiffe_workload_api_socket_path names a CSI mount inside gateway and dedicated supervisor Pods, while the SPIRE admin socket is a node hostPath mounted only into the shared supervisor, so comparing the two paths established nothing. The driver and chart now validate only the admin socket path itself, and the docs no longer require separate directories. The e2e SPIRE fixture refuses a cluster that already has SPIRE CRDs, creates its own namespace (openshell-e2e-spire by default) before claiming ownership, installs rather than upgrades, and removes only that namespace, its CRDs, and registration entries labeled with that namespace. The SPIRE delegation harness uses uv for host Python. The configuration reference now states that gateway session JWTs must expire and what cache hits check: the session's current JWT locally, with the gateway confirming the generation only before new issuance. Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 53c3e5b commit 62c9e90

8 files changed

Lines changed: 66 additions & 101 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ fails closed.
218218
`experimental_supervisor_spiffe_delegation`, the supervisor uses them to
219219
authorize acting as the sandbox's SPIRE-delegated SPIFFE ID; the driver mounts
220220
nothing SPIFFE-related into workload Pods. The table is accepted only with the
221-
gateway topology, its admin socket must be canonical and outside the
222-
`provider_spiffe_workload_api_socket_path` directory, and the gateway ID must
223-
be a SPIFFE path segment. `provider_spiffe_workload_api_socket_path` is
221+
gateway topology, its admin socket path must be canonical, and the gateway ID
222+
must be a SPIFFE path segment. `provider_spiffe_workload_api_socket_path` is
224223
accepted with the topology only alongside delegation, for the gateway's own
225224
identity.
226225

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

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,13 @@ pub struct ExperimentalSupervisorSpiffeDelegationConfig {
269269
}
270270

271271
impl ExperimentalSupervisorSpiffeDelegationConfig {
272-
fn validate(&self, gateway_id: &str, workload_api_socket_path: &str) -> Result<(), String> {
273-
// Mounts expose whole directories, so both socket directories must be
274-
// canonical for the comparison below to mean what it says.
272+
fn validate(&self, gateway_id: &str) -> Result<(), String> {
275273
if self.admin_socket_group == Some(0) {
276274
return Err("experimental_supervisor_spiffe_delegation.admin_socket_group must not be the root group".into());
277275
}
278-
let admin_dir = canonical_socket_dir(&self.admin_socket_path).ok_or("experimental_supervisor_spiffe_delegation.admin_socket_path must be a canonical absolute UNIX socket path below a dedicated directory")?;
279-
// The admin API authorizes delegation. Its directory is mounted into
280-
// the shared supervisor only, and the Workload API directory into
281-
// gateway Pods, so neither directory may contain the other.
282-
if !workload_api_socket_path.trim().is_empty() {
283-
let workload_dir = canonical_socket_dir(workload_api_socket_path).ok_or("provider_spiffe_workload_api_socket_path must be a canonical absolute UNIX socket path when experimental_supervisor_spiffe_delegation is set")?;
284-
if admin_dir.starts_with(workload_dir) || workload_dir.starts_with(admin_dir) {
285-
return Err("experimental_supervisor_spiffe_delegation.admin_socket_path and provider_spiffe_workload_api_socket_path must be in separate, non-nested directories".into());
286-
}
287-
}
276+
// The socket's directory is mounted from the node, so the path must be
277+
// canonical for the mount to be exactly the directory it names.
278+
canonical_socket_dir(&self.admin_socket_path).ok_or("experimental_supervisor_spiffe_delegation.admin_socket_path must be a canonical absolute UNIX socket path below a dedicated directory")?;
288279
let prefix = openshell_core::spiffe::SandboxSpiffeIdPrefix::parse(&self.spiffe_id_prefix)
289280
.map_err(|error| {
290281
format!("experimental_supervisor_spiffe_delegation.spiffe_id_prefix: {error}")
@@ -616,10 +607,7 @@ impl KubernetesComputeConfig {
616607
})?;
617608
shared.validate()?;
618609
match &self.experimental_supervisor_spiffe_delegation {
619-
Some(delegation) => delegation.validate(
620-
&self.gateway_id,
621-
&self.provider_spiffe_workload_api_socket_path,
622-
)?,
610+
Some(delegation) => delegation.validate(&self.gateway_id)?,
623611
// Without delegation the shared supervisor has only its
624612
// own identity, which must not stand in for a sandbox.
625613
None if self.provider_spiffe_enabled() => {
@@ -1264,7 +1252,7 @@ mod tests {
12641252
}
12651253

12661254
#[test]
1267-
fn spiffe_delegation_is_gateway_topology_only_and_never_reuses_the_workload_api() {
1255+
fn spiffe_delegation_is_gateway_topology_only() {
12681256
let delegation = || ExperimentalSupervisorSpiffeDelegationConfig {
12691257
admin_socket_path: "/run/spire/admin/admin.sock".to_string(),
12701258
spiffe_id_prefix: "spiffe://example.org/openshell".to_string(),
@@ -1294,34 +1282,6 @@ mod tests {
12941282
let invalid = [
12951283
// The supervisor's own Workload API identity never stands in for a sandbox.
12961284
gateway(None, workload_api),
1297-
gateway(
1298-
Some(ExperimentalSupervisorSpiffeDelegationConfig {
1299-
admin_socket_path: "/spiffe-workload-api/admin.sock".to_string(),
1300-
..delegation()
1301-
}),
1302-
workload_api,
1303-
),
1304-
gateway(
1305-
Some(ExperimentalSupervisorSpiffeDelegationConfig {
1306-
admin_socket_path: "/spiffe-workload-api/private/admin.sock".to_string(),
1307-
..delegation()
1308-
}),
1309-
workload_api,
1310-
),
1311-
gateway(
1312-
Some(ExperimentalSupervisorSpiffeDelegationConfig {
1313-
admin_socket_path: "/run/admin.sock".to_string(),
1314-
..delegation()
1315-
}),
1316-
"/run/spire/workload/api.sock",
1317-
),
1318-
gateway(
1319-
Some(ExperimentalSupervisorSpiffeDelegationConfig {
1320-
admin_socket_path: "/run/spire/private/admin.sock".to_string(),
1321-
..delegation()
1322-
}),
1323-
"/run/x/../spire/api.sock",
1324-
),
13251285
];
13261286
let invalid = invalid.into_iter().chain(
13271287
[

‎deploy/helm/openshell/templates/_helpers.tpl‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ fullname, so the name never collapses into another release resource's name.
380380

381381
{{/*
382382
SPIRE delegation of sandbox identities to the shared supervisor. The admin
383-
socket directory is mounted into the shared supervisor only and the Workload
384-
API directory into gateway Pods, so the two must be canonical, separate, and
385-
non-nested. The gateway compute driver repeats these checks at startup.
383+
socket's directory is mounted from the node into the shared supervisor only,
384+
so its path must be canonical. The gateway compute driver repeats these checks
385+
at startup.
386386
*/}}
387387
{{- define "openshell.validateSpiffeDelegation" -}}
388388
{{- $delegation := .delegation -}}
@@ -398,14 +398,6 @@ non-nested. The gateway compute driver repeats these checks at startup.
398398
{{- if not (regexMatch "^spiffe://[a-z0-9._-]+(/[A-Za-z0-9._-]+)*$" $prefix) -}}
399399
{{- fail "experimental_supervisor_spiffe_delegation.spiffe_id_prefix must be spiffe://<trust-domain>[/<segment>...]" -}}
400400
{{- end -}}
401-
{{- $workload := get .kubernetes "provider_spiffe_workload_api_socket_path" | default "" -}}
402-
{{- if $workload -}}
403-
{{- $adminDir := printf "%s/" (dir $admin) -}}
404-
{{- $workloadDir := printf "%s/" (dir $workload) -}}
405-
{{- if or (not (regexMatch $canonical $workload)) (regexMatch "/\\.\\.?(/|$)" $workload) (hasPrefix $workloadDir $adminDir) (hasPrefix $adminDir $workloadDir) -}}
406-
{{- fail "experimental_supervisor_spiffe_delegation.admin_socket_path and provider_spiffe_workload_api_socket_path must be canonical paths in separate, non-nested directories" -}}
407-
{{- end -}}
408-
{{- end -}}
409401
{{- end }}
410402

411403
{{/*
@@ -676,7 +668,7 @@ Validate chart values that Helm would otherwise accept silently.
676668
{{- fail "experimental_supervisor_topology=gateway does not support upstream proxy settings, or provider SPIFFE identity without experimental_supervisor_spiffe_delegation" -}}
677669
{{- end -}}
678670
{{- if $delegation -}}
679-
{{- include "openshell.validateSpiffeDelegation" (dict "delegation" $delegation "kubernetes" $kubernetes) -}}
671+
{{- include "openshell.validateSpiffeDelegation" (dict "delegation" $delegation) -}}
680672
{{- end -}}
681673
{{- if and (eq (get $kubernetes "workspace_mode" | default "shared") "operator") (not (regexMatch "^[A-Za-z0-9][-A-Za-z0-9_./]*==?[-A-Za-z0-9_.]*$" (get $kubernetes "operator_namespace_label" | default ""))) -}}
682674
{{- fail "experimental_supervisor_topology=gateway in operator workspace mode requires operator_namespace_label of the form key=value" -}}

‎deploy/helm/openshell/tests/experimental_supervisor_test.yaml‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,6 @@ tests:
328328
asserts:
329329
- failedTemplate:
330330
errorMessage: experimental_supervisor_spiffe_delegation requires experimental_supervisor_topology=gateway
331-
- it: rejects an admin socket the gateway's Workload API mount would expose
332-
template: templates/experimental-supervisor.yaml
333-
set:
334-
gatewayConfig:
335-
openshell.drivers.kubernetes:
336-
experimental_supervisor_topology: gateway
337-
provider_spiffe_workload_api_socket_path: /run/spire/api.sock
338-
experimental_supervisor_spiffe_delegation:
339-
admin_socket_path: /run/spire/private/admin.sock
340-
spiffe_id_prefix: spiffe://example.org/openshell
341-
asserts:
342-
- failedTemplate:
343-
errorMessage: experimental_supervisor_spiffe_delegation.admin_socket_path and provider_spiffe_workload_api_socket_path must be canonical paths in separate, non-nested directories
344331
- it: never adds the root group for the admin socket
345332
template: templates/experimental-supervisor.yaml
346333
set:

‎docs/how-it-works/gateways/configuration.mdx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,11 @@ A sandbox's SPIFFE ID is
15951595
from the immutable sandbox ID, so it stays the same when the sandbox stops and
15961596
starts, and a sandbox recreated with the same name gets a new sandbox ID and
15971597
SPIFFE ID. The chart mounts the directory of `admin_socket_path` from the node
1598-
into the shared supervisor Pod only, adds `admin_socket_group` (the group that owns the
1599-
admin socket, never `0`) to its supplemental groups, and gives it a dedicated
1600-
service account. The admin socket and the Workload API socket must be in
1601-
separate, non-nested directories.
1598+
into the shared supervisor Pod only, adds `admin_socket_group` (the group that
1599+
owns the admin socket, never `0`) to its supplemental groups, and gives it a
1600+
dedicated service account. Gateway session JWTs must expire: the supervisor
1601+
rejects non-expiring tokens, so keep a positive
1602+
`[openshell.gateway.gateway_jwt].ttl_secs` (the Helm default is 3600).
16021603

16031604
You provision SPIRE:
16041605

@@ -1631,7 +1632,10 @@ sandbox and runtime generation, and confirms with the gateway that the
16311632
generation is still current. It accepts exactly one SVID with the expected
16321633
SPIFFE ID; a missing, duplicate, or mismatched entry fails the grant and never
16331634
falls back to the supervisor's own identity. Cached provider tokens belong to
1634-
one generation's session and are discarded when it ends. SVIDs and provider
1635-
tokens already issued stay valid until they expire. The gateway session signing
1635+
one generation's session. Each cache hit re-verifies the session's current
1636+
gateway JWT locally, so a removed session's tokens are not served; the gateway
1637+
confirmation runs only before new issuance, so a gateway-side revocation stops
1638+
cache hits only once the session is removed or its JWT expires. SVIDs and
1639+
provider tokens already issued stay valid until they expire. The gateway session signing
16361640
key that verifies a session is fixed when the session starts; after rotating it,
16371641
stop and start the affected sandboxes.

‎e2e/rust/tests/kubernetes_shared_supervisor_spiffe.rs‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ const SPIRE_CLUSTER: &str = "openshell-e2e";
3636
const SPIRE_CLASS: &str = "spire-spire";
3737
/// Matches `ci/values-experimental-supervisor-spiffe.yaml`.
3838
const ID_PREFIX: &str = "spiffe://openshell.local/openshell";
39-
const ENTRY_LABEL: &str = "app.kubernetes.io/managed-by=openshell-e2e";
39+
/// Label on the registration entries this run creates, naming its SPIRE
40+
/// fixture so cleanup never touches another run's entries.
41+
const ENTRY_LABEL: &str = "openshell.ai/e2e-spire-fixture";
4042
const STS_SERVICE: &str = "openshell-e2e-sts";
4143
const CLIENT_ASSERTION_TYPE: &str = "urn:ietf:params:oauth:client-assertion-type:jwt-spiffe";
4244
const TOKEN_TYPE_ACCESS_TOKEN: &str = "urn:ietf:params:oauth:token-type:access_token";
@@ -584,15 +586,23 @@ async fn supervisor_agent_id() -> String {
584586
)
585587
}
586588

589+
fn spire_fixture() -> String {
590+
std::env::var("OPENSHELL_E2E_SPIRE_NAMESPACE")
591+
.ok()
592+
.filter(|namespace| !namespace.is_empty())
593+
.expect("OPENSHELL_E2E_SPIRE_NAMESPACE is set by with-kube-gateway.sh")
594+
}
595+
587596
/// Register `sandbox_id`'s SPIFFE ID for delegation, scoped to `agent_id`.
588597
async fn register(gateway_id: &str, sandbox_id: &str, agent_id: &str) {
598+
let fixture = spire_fixture();
589599
let manifest = format!(
590600
r"apiVersion: spire.spiffe.io/v1alpha1
591601
kind: ClusterStaticEntry
592602
metadata:
593603
name: openshell-sandbox-{sandbox_id}
594604
labels:
595-
app.kubernetes.io/managed-by: openshell-e2e
605+
{ENTRY_LABEL}: {fixture}
596606
spec:
597607
className: {SPIRE_CLASS}
598608
spiffeID: {}
@@ -611,7 +621,7 @@ async fn unregister_all() {
611621
"delete",
612622
"clusterstaticentries.spire.spiffe.io",
613623
"-l",
614-
ENTRY_LABEL,
624+
&format!("{ENTRY_LABEL}={}", spire_fixture()),
615625
"--ignore-not-found",
616626
])
617627
.output()

‎e2e/with-kube-gateway.sh‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@
5757
# SPIRE delegation fixture:
5858
# Set OPENSHELL_E2E_KUBE_SPIRE_DELEGATION=1 to install pinned SPIRE hardened
5959
# charts (ci/values-spire-delegation-stack.yaml) before OpenShell, with the
60-
# agent admin socket exposed for the shared supervisor. The release is
61-
# removed again on exit. Tests create sandbox registration entries.
60+
# agent admin socket exposed for the shared supervisor. The fixture needs a
61+
# cluster without SPIRE CRDs and creates a fresh namespace
62+
# (OPENSHELL_E2E_SPIRE_NAMESPACE, default openshell-e2e-spire); it removes
63+
# both, and the registration entries tests label with that namespace, on exit.
6264
#
6365
# Credential-driver fixture:
6466
# Set OPENSHELL_E2E_CREDENTIAL_DRIVERS=1 to enable one credential storage
@@ -121,7 +123,8 @@ VAULT_CA_CONFIG_MAP="openbao-ca"
121123
VAULT_DNS_ALIAS="${VAULT_RELEASE_NAME}-0"
122124
VAULT_CA_FILE="${WORKDIR}/openbao-ca.crt"
123125
SPIRE_FIXTURE_DEPLOYED=0
124-
SPIRE_NAMESPACE="${OPENSHELL_E2E_SPIRE_NAMESPACE:-spire}"
126+
SPIRE_NAMESPACE="${OPENSHELL_E2E_SPIRE_NAMESPACE:-openshell-e2e-spire}"
127+
SPIRE_CRDS=(clusterspiffeids.spire.spiffe.io clusterstaticentries.spire.spiffe.io clusterfederatedtrustdomains.spire.spiffe.io)
125128
SPIRE_CHART_REPO="https://spiffe.github.io/helm-charts-hardened/"
126129
SPIRE_CHART_VERSION="${OPENSHELL_E2E_SPIRE_CHART_VERSION:-0.30.3}"
127130
SPIRE_CRDS_CHART_VERSION="${OPENSHELL_E2E_SPIRE_CRDS_CHART_VERSION:-0.6.1}"
@@ -494,37 +497,47 @@ provision_vault_auth() {
494497
}
495498

496499
deploy_spire_fixture() {
497-
echo "Installing SPIRE ${SPIRE_CHART_VERSION} fixture in namespace ${SPIRE_NAMESPACE}..."
500+
# The fixture owns only what it creates: refuse a cluster that already has
501+
# the namespace or SPIRE CRDs, so cleanup can never remove another install.
502+
local crd
503+
for crd in "${SPIRE_CRDS[@]}"; do
504+
if kctl get crd "${crd}" >/dev/null 2>&1; then
505+
echo "ERROR: CRD ${crd} already exists; the SPIRE fixture needs a cluster without SPIRE." >&2
506+
exit 2
507+
fi
508+
done
509+
if ! kctl create namespace "${SPIRE_NAMESPACE}" >/dev/null; then
510+
echo "ERROR: could not create a fresh SPIRE fixture namespace ${SPIRE_NAMESPACE}; set OPENSHELL_E2E_SPIRE_NAMESPACE to an unused name." >&2
511+
exit 2
512+
fi
498513
SPIRE_FIXTURE_DEPLOYED=1
499-
helmctl upgrade --install spire-crds spire-crds --repo "${SPIRE_CHART_REPO}" \
514+
echo "Installing SPIRE ${SPIRE_CHART_VERSION} fixture in namespace ${SPIRE_NAMESPACE}..."
515+
helmctl install spire-crds spire-crds --repo "${SPIRE_CHART_REPO}" \
500516
--version "${SPIRE_CRDS_CHART_VERSION}" \
501-
--namespace "${SPIRE_NAMESPACE}" --create-namespace --wait
502-
helmctl upgrade --install spire spire --repo "${SPIRE_CHART_REPO}" \
517+
--namespace "${SPIRE_NAMESPACE}" --wait
518+
helmctl install spire spire --repo "${SPIRE_CHART_REPO}" \
503519
--version "${SPIRE_CHART_VERSION}" \
504520
--namespace "${SPIRE_NAMESPACE}" \
505521
--values "${ROOT}/deploy/helm/openshell/ci/values-spire-delegation-stack.yaml" \
506522
--wait --timeout 5m
507523
kctl -n "${SPIRE_NAMESPACE}" rollout status daemonset/spire-agent --timeout=180s
524+
# Tests label the registration entries they create with this namespace.
508525
export OPENSHELL_E2E_SPIRE_NAMESPACE="${SPIRE_NAMESPACE}"
509526
}
510527

511528
cleanup_spire_fixture() {
512529
[ "${SPIRE_FIXTURE_DEPLOYED}" = "1" ] || return 0
513530
kctl delete clusterstaticentries.spire.spiffe.io \
514-
-l app.kubernetes.io/managed-by=openshell-e2e --ignore-not-found \
531+
-l "openshell.ai/e2e-spire-fixture=${SPIRE_NAMESPACE}" --ignore-not-found \
515532
>/dev/null 2>&1 || true
516533
helmctl uninstall spire --namespace "${SPIRE_NAMESPACE}" --wait --timeout 120s \
517534
>/dev/null 2>&1 || true
518535
helmctl uninstall spire-crds --namespace "${SPIRE_NAMESPACE}" --wait --timeout 60s \
519536
>/dev/null 2>&1 || true
520-
# The CRD chart keeps its CRDs on uninstall; remove only the ones it owned.
521-
local crd
522-
for crd in clusterspiffeids clusterstaticentries clusterfederatedtrustdomains; do
523-
crd="${crd}.spire.spiffe.io"
524-
if [ "$(kctl get crd "${crd}" -o jsonpath='{.metadata.annotations.meta\.helm\.sh/release-namespace}' 2>/dev/null)" = "${SPIRE_NAMESPACE}" ]; then
525-
kctl delete crd "${crd}" --wait=false >/dev/null 2>&1 || true
526-
fi
527-
done
537+
# The CRD chart keeps its CRDs on uninstall. None existed before the
538+
# fixture, so these are the fixture's own.
539+
kctl delete crd "${SPIRE_CRDS[@]}" --ignore-not-found --wait=false \
540+
>/dev/null 2>&1 || true
528541
kctl delete namespace "${SPIRE_NAMESPACE}" --wait=true --timeout=120s \
529542
--ignore-not-found >/dev/null 2>&1 || true
530543
SPIRE_FIXTURE_DEPLOYED=0

‎tasks/scripts/test-spire-delegation.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ DELEGATE_ID="spiffe://${TRUST_DOMAIN}/openshell/shared-supervisor"
6464
NODE_ID="spiffe://${TRUST_DOMAIN}/node/test"
6565
SERVER_SOCKET="${WORK}/server/api.sock"
6666
ADMIN_SOCKET="${WORK}/agent/private/admin.sock"
67-
SERVER_PORT="$(python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')"
67+
SERVER_PORT="$(uv run --no-project python -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')"
6868
mkdir -p "${WORK}/server" "${WORK}/agent/public" "${WORK}/agent/private"
6969

7070
cat >"${WORK}/server.conf" <<EOF
@@ -147,7 +147,7 @@ entry() {
147147
server entry create -parentID "${NODE_ID}" -spiffeID "$1" -selector "$2" >/dev/null
148148
}
149149
sandbox_id() {
150-
python3 -c 'import uuid; print(uuid.uuid4())'
150+
cat /proc/sys/kernel/random/uuid
151151
}
152152
sandbox_entry() {
153153
entry "${ID_PREFIX}/gateway/${GATEWAY_ID}/sandbox/$2" "openshell:sandbox:${GATEWAY_ID}:$1"

0 commit comments

Comments
 (0)