fix(nri-image-policy): observe the launch environment the runtime execs #697
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 630 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #697"
general
weight: 0.35
joaosa
Fixes the admission half of #693.
What breaks
A CDI container edit that sets an environment name the image config or pod spec already set leaves the OCI spec carrying that name twice. containerd applies CDI edits through runtime-tools' generator:
whose cache is keyed on the whole
NAME=VALUEstring while the lookup uses the name alone:Reproduced directly against the version containerd v2.3.4 vendors (
runtime-tools v0.9.1-0.20251114084447):runc hides it —
prepareEnvdrops duplicates keeping the last value (libcontainer/env.go) — so the container runs with the CDI value and nothing looks wrong. We do not hide it:ObserveEnvrejects duplicate names,containerEnvswallows the error, and the launch environment reads as unknown evidence, which onlyenv: anyadmits.Every CUDA base image sets
NVIDIA_VISIBLE_DEVICESand the NVIDIA CDI spec rewrites it tovoid, so in practice every GPU workload built on one is forced ontoenv: any— environment completely unconstrained, the opposite of what the operator asked for.The change
Observe those containers with the rule the runtime itself applies — keep the last value per name — then validate strictly as before.
The tolerance is scoped to containers carrying CDI evidence: the CRI
CDIDevicesfield, or thecdi.k8s.ioannotations thecdi-annotationsdevice-list strategy uses. That is the one case where the ambiguity is not real. Everywhere else a duplicate still makes the environment unobservable, because nothing tells us which value the runtime would keep and the ambiguity must not collapse into a map and then satisfy a constrained grant — the existingTestEnvAdmissionUsesFinalStartSpec/duplicatecase keeps passing unchanged.ObserveEnvitself is untouched, so every other caller keeps the strict reading.This restores exactness rather than relaxing it: for GPU workloads the fingerprint now describes the environment the process receives, where before they had no environment policy at all.
Tests
internal/cmds/nri-image-policy/cdi_env_693_test.go:CDIDevicesfieldLD_PRELOADon top of the duplicate is still denied=, empty name) stay unobservable even under CDIpkg/allowlist/env_test.gocoversObserveLaunchEnvdirectly: duplicates resolve to the runtime's value, malformed entries are still rejected, and duplicate-free input observes identically toObserveEnv.Validation status
Measured on the candidate cluster (rke2 v1.36.4+rke2r1, containerd 2.3.4-k3s1.36, device plugin v0.19.3 with
cdi-annotations), busybox + 1 GPU,mounts: any:| pod spec | pinned value | result |
|---|---|---|
| — |
NVIDIA_VISIBLE_DEVICES=void| admit ||
VIS=void|void| deny ||
VIS=all|all| deny ||
VIS=all|void| deny ||
VIS=all| omitted | deny |The three middle rows exhaust the possible single-value views, so the evidence is unusable rather than mismatched. Controls: the same collisions on a pod with no GPU admit normally, and a plain image-vs-pod-spec
PATHcollision behaves correctly, since containerd's own env merge deduplicates.What I could not do is verify the patched binary on that hardware: on
cvmMode=bare-metalthe plugin comes from the measured node image (/opt/nri/plugins/10-nri-image-policy, read-only erofs), so a chart-level image swap replaces the installer, not the enforcer — correct behaviour, but it means end-to-end confirmation needs a node-image build, or a gke/aks-mode cluster wherenriImagePolicy.baked=false.Also worth doing
Upstream
createEnvCacheMapshould key by name. That stops CDI emitting duplicates at the source for everyone; this change does not depend on it, and is still wanted regardless, since the plugin should describe the environment the runtime produces rather than refuse to look at it.Not included
mounts: exactfor GPU workloads additionally needs #642 to reach the deployed components; with both in place a GPU entry can pin env and mounts exactly, leaving only attested GPU identity free to vary. The derived values for the DeepSeek worker (109 env values, 15 CDI mount rules) are ready to apply.