Skip to content

fix(sandboxpolicy): close the classify follow-ups and guard gadget pins - #1230

Draft
matthyx wants to merge 6 commits into
omx/nri-s5b-followupsfrom
omx/nri-fu-classify
Draft

matthyx wants to merge 6 commits into
omx/nri-s5b-followupsfrom
omx/nri-fu-classify

Conversation

@matthyx

@matthyx matthyx commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-ups from the reviews of #1163 (S4) and the stack re-merge review, plus a CI guard for gadget pins. Stacked on #1178.

  • Override record: a rejected spec's override record stays the strict union while the spec is stale, and shrinks to the spec's own overrides once it compiles again at the same identity.
  • Deep copies: ClassifyPod and PodPlansAt return typed deep copies instead of a JSON round trip (about 7x faster), so callers cannot alias the snapshot or the last-good plans (CodeRabbit feat(sandboxpolicy): lock-free pod classification for the start gate #1163 4805356433). A reflection test fails if any field is shared or missed.
  • Identity (owner decision): the dead s.Identity == nil check is removed. An enforce policy with identity, alone or with http, stays gate-Strict and is refused at start.
  • Comments: prev.pod, PodClassification.Strict.
  • Gadget pin guard: section_images.go records a source digest per section (the gadget's files, the headers its sources transitively include, the IG version; CRLF read as LF; unreadable directives and unlisted angle headers fail). TestSectionSourcesMatchPins fails a gadget change made without a pin rotation, in the existing go test jobs. check-product-images -sections and make check-section-images verify built images, and the unit-test job now runs make check-section-images right after building the gadgets.

Validation:

  • vet; go test ./pkg/sandboxpolicy/... in default, -tags startgate_vmtest and -race: all pass.
  • Mutations for every logic change fail a test.
  • The pins were anchored on a local VM build (Debian 13, IG v0.57.0): make gadgets built from these sources matched the recorded pins, and a negative control (an edited enforce_network/gadget.yaml) was refused with a manifest digest mismatch.
  • NOT-RUN: VM qualification. The new CI step runs for the first time on this PR.

AI Review

Written with Claude Code (Claude Opus 5.5). One independent adversarial review: APPROVE with LOW findings (CRLF, unused headers, the build baseline, then an over-broad header rule), all fixed and re-checked (APPROVE).

🤖 Generated with Claude Code

matthyx and others added 2 commits December 5, 2026 16:24
…get pins

Follow-ups from the reviews of #1163 and the re-merge review.

- A rejected spec's override record stays the strict union while the
  spec is stale and shrinks to the spec's own overrides once it
  compiles again at the same identity.
- ClassifyPod and PodPlansAt return typed deep copies (about 7x faster
  than the JSON round trip); a reflection test fails if a field is
  shared or missed (CodeRabbit #1163 4805356433).
- R1: the dead s.Identity check is removed; an enforce policy with
  identity, alone or with http, stays gate-Strict and is refused at
  start (owner batch 18).
- Comments: prev.pod, PodClassification.Strict.
- Pin guard: section_images.go records a source digest per section
  (gadget files, transitively included headers, VERSION; CRLF read as
  LF; unreadable directives and unlisted angle headers fail).
  TestSectionSourcesMatchPins fails a gadget change made without a pin
  rotation. check-product-images -sections and make
  check-section-images verify built images; anchored on a local VM
  build (IG v0.57.0), with a negative control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Docs-exempt: internal fixes, tests and a CI guard in the unreleased NRI start gate stack
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Run make check-section-images after the unit-test job builds the
gadgets, so a gadget source change without a pin rotation fails CI.
Anchored on a local VM build with IG v0.57.0 (the job's ig version),
including a negative control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Docs-exempt: CI step only, no behavior change
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An active critical issue can drop GateStrict while retained documents still enforce, and a separate digest issue misses valid includes preceded by comments and subsequent nested-header changes.

2 open issues
What changed in this PR

This PR follows up on sandbox-policy start-gate classification and adds checks linking gadget sources to pinned enforcement images.

Changes:

  • Refines override retention and replaces JSON cloning with typed deep copies.
  • Clarifies identity-policy classification and adds regression tests.
  • Adds source-digest guards and section-only image verification.
File Description
pkg/​sandboxpolicy/​igbackend/​section_sources_test.go Adds source-digest and include-scanning checks.
pkg/​sandboxpolicy/​igbackend/​section_images.go Records source digests alongside image pins.
pkg/​sandboxpolicy/​controller.go Tracks stale overrides and copies returned plans.
pkg/​sandboxpolicy/​classify.go Adds typed copies and clarifies classification semantics.
pkg/​sandboxpolicy/​classify_fu3_test.go Tests overrides, copy isolation, and identity classification.
Makefile Adds check-section-images.
cmd/​check-product-images/​main.go Adds section-only verification mode.

Review effort: Balanced

Comment thread pkg/sandboxpolicy/controller.go Resolved
…rved

Copilot on #1230 (e36d8eb).

- gateStrictSections also counts a section whose served network or
  file document enforces (policy mode, default, rule or per-access
  default), so a same-identity Audit replacement during a binding
  failure cannot drop GateStrict while the old enforcing document is
  still served (4811715164).
- The pin guard's include scan strips comments (literal-aware) before
  reading directives, refuses an include after other text on its line,
  refuses a builder header name that a repo file could shadow, and its
  completeness cross-check walks nested headers (4811715182).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Docs-exempt: internal fix and test guard in the unreleased NRI start gate stack
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx
matthyx requested a balanced review from Copilot December 5, 2026 15:52
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Peak CPU p95 (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A valid continued %:include directive is silently skipped, so edits to its header leave the source digest unchanged and bypass the no-build pin guard.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot 4811837908 on #1230: a %:include digraph behind a backslash
continuation was silently skipped by the pin guard's include scan.

The scan now refuses any trigraph, joins continued lines (LF or CRLF,
trailing blanks allowed), blanks comments on the joined text and reads
%: as #, before detecting directives; %:%: and an include after code
are errors. The completeness cross-check reads the joined text, so a
header name split across a continuation is seen whole. The real
tree's digests are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Docs-exempt: test-only pin guard change
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx
matthyx requested a balanced review from Copilot December 5, 2026 16:05
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Peak CPU p95 (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The include scanner incorrectly rewrites %: in quoted header names, potentially hashing the wrong file and missing changes to the actual dependency.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot 4811937127 on #1230: the include scan mapped every %: to #, so
a header named extra%:dep.h was hashed as extra#dep.h. Only a %: that
starts a logical line now reads as #; a %: in a header name, string or
char literal stays as written. %:%: and an include after code are still
errors, and the cross-check sees names containing %: or # whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Docs-exempt: test-only pin guard change
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx
matthyx requested a balanced review from Copilot December 5, 2026 16:26
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Peak CPU p95 (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the digest guard can miss changes to absolute includes and configured nested inputs, allowing pin checks to pass despite changed sources.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.035 0.033 -6.6%
Peak CPU (cores) 0.040 0.038 -4.8%
Peak CPU p95 (cores) 0.038 0.036 -6.2%
Avg Memory (MiB) 219.959 202.163 -8.1%
Peak Memory (MiB) 228.551 207.684 -9.1%
Dedup Effectiveness

No data available.

This branch has not been deployed

No deployments
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.

2 participants