Repository navigation
fix(agent): resolve sandbox PID for SVID subscription after CNI ADD - #72
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Workload inbound mTLS never came up: the server certificate (SVID) secret stayed warming in Envoy. The agent logged
skipping SVID subscription: PID not availablefor every managed pod.Root cause is the containerd CNI lifecycle, not a bug in
resolvePID:/proc/<pid>/ns/netto match, and the CRI fallback callsContainerStatus(<sandbox-id>)(a sandbox isn't a container) and fails.Pidis nil →SubscribePodis skipped → no delegated SVID → cert warms forever.Fix
Resolve the PID agent-side, after ADD, retrying until the sandbox process exists, then subscribe:
hostPID: true) so a/proc/<pid>/ns/netscan sees container processes. The host netns dir is already mounted withHostToContainerpropagation.subscribePodWhenPIDResolvespolls the pod's netns and inode-matches it against/proc/<pid>/ns/netto 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 correctspiffe://<td>/ns/<ns>/sa/<sa>SVID.Tests
pidFromProcNetnsPathparsing.resolvePIDFromNetnsinode-match against the test process's own/proc/self/ns/net.resolvePIDWithRetrysuccess-after-retries and context-timeout paths.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.