← Back to Pull requests

nri-image-policy: recover running member pods on a plugin restart #1096

Closed
unknown closed this pull request without merging on Oct 29, 2026 14:17 UTC
View on GitHub
unknown unknown commented on Oct 26, 2026 14:41 UTC
Author

What this does

When the nri-image-policy enforcer reconnects to a node with member pods
already running — a plugin restart, or containerd restarting under it — it
takes each pod back under the mesh gate from what the sandbox itself shows:
the proven network namespace, the live ruleset in it, and the containers the
runtime lists. A pod it cannot take back is refused for its life.

Rebase and the two recovery fixes it surfaced

Rebased onto main, which now carries declared egress ("exits") per workload
entry. Verifying a recovered pod's ruleset now has to account for the exits it
was granted, and wiring that up surfaced two ways a member pod was refused for
life across an enforcer restart:

  • Exits were read from the wrong source, at the wrong time. The exits a

  • recovered pod holds were taken from the admission inventory, which a restarted
    process has not repopulated when recovery runs; and recovery ran at connect,
    before the served allowlist that declares egress had applied. Now a recovered
    pod's exits are decided from the launches the enforcer reads back from the
    runtime, and recovery is deferred alongside the startup check so it runs once
    a served allowlist is present. A pod whose exits cannot be decided (no served
    allowlist yet) or whose match is refused is granted none and verified against
    the base mesh ruleset: a pod whose live ruleset is exactly that recovers, and
    only one still holding exits is refused, with the cause named. A
    created-but-never-run container is left out of the match, as admission never
    counted it.

  • A recovered container's network namespace was matched by path string. The

  • runtime labels the same namespace differently at different times — the
    sandbox's CNI path at creation, a /proc/<pid>/ns/net handle in a Synchronize
    replay — so a string comparison read the relabelling as a move and refused the
    container, and with it the pod. Now the reported namespace is resolved to its
    kernel identity (device and inode) and compared to the sandbox's, as the
    namespace proof already does. A container not running, or one reported running
    whose /proc handle is already gone, moves no packets and is not checked.

    Behaviour changes

  • Recovery is deferred with the startup check regardless of enforce_existing

  • and whether an inventory is configured, so it runs on a restart however the
    check is configured; RunDeferredCheck consumes the deferred batch
    unconditionally.
  • Between NRI registration and the deferred check, a pre-existing member pod is

  • briefly not on the gate's record. A token request for it, and a container
    create that reaches the mesh gate, are refused transiently and retried, not
    for the pod's life: the gate distinguishes a sandbox recovery has not yet
    reached (transient) from one still unknown after recovery (refused for life).
  • A mesh endpoint that starts in that window is recovered as a started member:

  • recovery reads a container's liveness from the running set, not only the
    registration snapshot, which does not see a container that started after it
    was taken.

    Known limitations

  • If the enforcer restarts while every initial allowlist fetch fails (the node

  • serves only its base allowlist), a pod that was granted exits cannot have them
    decided and is refused until an allowlist applies; ordinary member pods, whose
    ruleset is the base mesh ruleset, are unaffected.
  • Recovery reads container liveness from the running set, but the network

  • namespace handle comes from the Synchronize snapshot: a container that exits
    in the deferral window, or pid reuse within it, can leave that handle stale
    until the stop event lands.
  • A workload container that both starts and stops inside the deferral window is

  • not counted toward the recovered pod's exit decision: it is gone from the
    running set and was created, not running, in the snapshot. Narrow, and its
    mesh membership is unaffected.
  • A member pod that holds an allowlist entry's declared exits is recovered by

  • re-deciding those exits against the node's current served allowlist. If the
    served allowlist changed after the pod started so that it no longer resolves
    the same exits, recovery does not re-admit that pod, because its live firewall
    ruleset no longer matches what the current allowlist would grant. A running
    pod's exits are otherwise fixed for its life, so this only affects a pod caught
    by an allowlist change across a plugin restart.

    Verification

  • Rebased onto main at 788e4fdb; the branch is four commits on top of it,

  • all signed, working tree clean.
  • go vet passes on the package for both GOOS=linux and GOOS=darwin; the

  • //go:build linux recovery tests compile under GOOS=linux. The full
    package go test passes except for the health/attestation unix-socket tests,
    which fail only on macOS because the temp socket path exceeds the platform's
    sun_path limit — an environment limit, not a regression, and they pass in
    CI.
  • The recovery paths — deferred recovery, deciding a recovered pod's exits from

  • the launches read back, and matching a recovered container's namespace by
    kernel identity — are exercised on a real network namespace under the
    nftables-required suite, which runs in CI (Build & Test and Coverage gate
    both green on the rebased tip).
  • Conformance/metal verification is deferred to after merge. The metal lanes

  • boot a node CVM from the published node image for the commit under test, and
    those images are built only for main commits (about 40 minutes after a
    merge), never for a branch tip — so this branch cannot be run on the metal
    lanes. Once this merges, the post-merge main commit's lanes verify the
    mesh-recovery behaviour; the regression this fixes was a running pod refused
    on the old string-based namespace comparison, so the check is that a mesh
    member's leaf renews across a mid-run containerd restart.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: joaosa Review duration: 4296m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1096"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%