Skip to content

fix(agent): resolve sandbox PID for SVID subscription after CNI ADD - #72

Merged
bpalermo merged 1 commit into
mainfrom
fix/agent-deferred-svid-pid
Jun 7, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/agent-deferred-svid-pid

Conversation

@bpalermo

@bpalermo bpalermo commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Problem

Workload inbound mTLS never came up: the server certificate (SVID) secret stayed warming in Envoy. The agent logged skipping SVID subscription: PID not available for every managed pod.

Root cause is the containerd CNI lifecycle, not a bug in resolvePID:

  • containerd creates the pod network namespace without a long-lived process in it, calls CNI ADD, and starts the sandbox (pause) container only after ADD returns.
  • So at ADD time the netns inode scan finds no /proc/<pid>/ns/net to match, and the CRI fallback calls ContainerStatus(<sandbox-id>) (a sandbox isn't a container) and fails.
  • Pid is nil → SubscribePod is skipped → no delegated SVID → cert warms forever.

Fix

Resolve the PID agent-side, after ADD, retrying until the sandbox process exists, then subscribe:

  • The agent runs in the host PID namespace (hostPID: true) so a /proc/<pid>/ns/net scan sees container processes. The host netns dir is already mounted with HostToContainer propagation.
  • subscribePodWhenPIDResolves polls the pod's netns and inode-matches it against /proc/<pid>/ns/net to find the sandbox PID, then calls the SPIRE Delegated Identity API. Bounded (15s, 200ms poll), runs in the background so CNI ADD isn't blocked.
  • CNIServerConfig.HostMountPrefix (default /host) locates the host netns file from inside the container.

The sandbox PID attests to the same Kubernetes selectors (namespace, service account) as the app container — confirmed against SPIRE's delegated-identity handler, which derives selectors via delegateWorkloadAttestor.Attest(ctx, pid) — so it yields the correct spiffe://<td>/ns/<ns>/sa/<sa> SVID.

Tests

  • pidFromProcNetnsPath parsing.
  • resolvePIDFromNetns inode-match against the test process's own /proc/self/ns/net.
  • resolvePIDWithRetry success-after-retries and context-timeout paths.
  • agent chart lint/template pass with hostPID.

Note

Completes the inbound-SDS path together with #70 (validation-context naming). Full live pod→pod mTLS traffic e2e (with #70, #71, this) will be run once they're available together on the agent image.

The CNI plugin could not supply a container PID at ADD time — containerd creates
the pod network namespace without a process in it and starts the sandbox
container only after CNI ADD returns, so neither the netns inode scan nor a CRI
ContainerStatus(sandbox-id) yields a PID. The agent therefore logged
"skipping SVID subscription: PID not available" and never fetched the workload's
X.509 SVID, leaving its inbound mTLS server certificate stuck warming in Envoy.

Resolve the PID agent-side instead: after AddPod, poll the pod's network
namespace and inode-match it against /proc/<pid>/ns/net to find the sandbox
process once it starts, then subscribe via the SPIRE Delegated Identity API. The
sandbox PID attests to the same Kubernetes selectors (namespace, service
account) as the app container, so it yields the correct SPIFFE ID.

- agent runs in the host PID namespace (hostPID: true) so the /proc scan sees
  container processes; the host netns dir is already mounted (HostToContainer).
- CNIServerConfig.HostMountPrefix (default /host) locates the host netns file.
- resolution is bounded (15s, 200ms poll) and runs in the background so it does
  not block CNI ADD.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bpalermo
bpalermo merged commit 670959b into main Jun 7, 2026
10 checks passed
@bpalermo
bpalermo deleted the fix/agent-deferred-svid-pid branch June 7, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant