Skip to content

policy, mcp-query: add change_impact pre-change evaluator + MCP tool - #66

Closed
fastrevmd-lab wants to merge 2 commits into
mainfrom
bors/mec-1762-change-impact-v2
Closed

fastrevmd-lab wants to merge 2 commits into
mainfrom
bors/mec-1762-change-impact-v2

Conversation

@fastrevmd-lab

@fastrevmd-lab fastrevmd-lab commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements task C of MEC-570 (pre-change impact analysis): a read-only differential first-match replay that evaluates historical flows against the current rulebase (P) and a proposed delta (P′), and reports which flows' verdict would change.

  • Three-valued (match/no_match/unknown) evaluator, respecting Junos zone-pair → global → default-deny context order and PAN-OS ordered-list + implicit defaults.
  • Delta parsing: vendor-neutral JSON op list, and (Junos only) set/delete/insert/activate/deactivate lines applied to | display set text and re-parsed with the existing parse_security_policies(). The delta never reaches a device -- this tool issues no device writes.
  • Candidate pruning restricted to the zone-pairs of the rules that actually differ between P and P', with truncation detected and reported rather than silently assumed complete.
  • Config-only pre-check: a config-only "no impact" verdict requires every changed rule in the delta to be individually accounted for -- disabled in both P and P', or part of a content-unchanged reorder pair proven equivalence-preserving -- and refuses rule names that are ambiguous across zone-pair contexts, so a mixed or ambiguous delta cannot be waved through on the strength of one benign change.
  • Per-zone-pair calibration gate: compares the evaluator's verdict against the device's own logged rule_name; below the agreement threshold (default 99%, 100-session minimum sample), that zone-pair's verdicts downgrade to unknown: model does not reproduce device behaviour with mismatch examples, instead of reporting a guess.
  • Output honesty contract: the words "safe" and "no impact" never appear in report output. A zero-result reads "no historical sessions observed in the analysable scope", or "provably no impact (config-only)" when the config-only proof applies. A deny-widening count with no logged denies in-window reports as unknown, never 0.
  • Hardens the audit path around this tool: device-output arguments that may carry secrets are hashed rather than stored verbatim in the audit trail, including on refusal/error paths, and the tool rejects caller-supplied device text that falls outside the documented scope rather than silently processing it.
  • New sovereign-only MCP tool change_impact, following the same registration/classification pattern as rule_tools/unused_rules/explain_rule, registered in the eval corpus's tool allowlist.
  • Default analysis window is 14 days against raw ssdf.events, stated in every report, until the flow_tuples_daily rollup (MEC-1639) lands.

Out of scope for v1 (always evaluate to unknown, never a guess)

App-ID filters, application-default, DAG/EDL/region (PAN-OS); identity, dynamic-application, URL-category, and scheduler-name (Junos).

Test plan

  • cd services/policy && uv run pytest -q -m "not integration" — 184 passed
  • cd services/mcp-query && uv run pytest -q -m "not integration" — 610 passed, 44 skipped
  • uvx ruff@0.12.4 check services — clean
  • uvx ruff@0.12.4 format --check services — clean
  • gitleaks protect --staged — clean

Supersedes #51.

Refs #29 (task C of this issue only; tasks A/B and the rust*mcp approval UX remain)

🤖 Generated with Claude Code

Implements task C of MEC-570 (pre-change impact analysis): a read-only
differential first-match replay that evaluates historical flows against the
current rulebase (P) and a proposed delta (P'), and reports which flows'
verdict would change.

- Three-valued (match/no_match/unknown) evaluator, respecting Junos
  zone-pair -> global -> default-deny context order and PAN-OS ordered-list
  + implicit defaults.
- Delta parsing: vendor-neutral JSON op list, and (Junos only)
  set/delete/insert/activate/deactivate lines applied to `| display set`
  text and re-parsed with the existing parse_security_policies(). The delta
  never reaches a device -- this tool issues no device writes.
- Candidate pruning restricted to the zone-pairs of the rules that actually
  differ between P and P', with truncation detected and reported rather than
  silently assumed complete.
- Config-only pre-check: a config-only "no impact" verdict requires every
  changed rule in the delta to be individually accounted for -- disabled in
  both P and P', or part of a content-unchanged reorder pair proven
  equivalence-preserving -- and refuses rule names that are ambiguous across
  zone-pair contexts, so a mixed or ambiguous delta cannot be waved through
  on the strength of one benign change.
- Per-zone-pair calibration gate: compares the evaluator's verdict against
  the device's own logged rule_name; below the agreement threshold (default
  99%, 100-session minimum sample), that zone-pair's verdicts downgrade to
  "unknown: model does not reproduce device behaviour" with mismatch
  examples, instead of reporting a guess.
- Output honesty contract: the words "safe" and "no impact" never appear in
  report output. A zero-result reads "no historical sessions observed in the
  analysable scope", or "provably no impact (config-only)" when the
  config-only proof applies. A deny-widening count with no logged denies
  in-window reports as unknown, never 0.
- Hardens the audit path around this tool: device-output arguments that may
  carry secrets are hashed rather than stored verbatim in the audit trail,
  including on refusal/error paths, and the tool rejects caller-supplied
  device text that falls outside the documented scope rather than silently
  processing it.
- New sovereign-only MCP tool change_impact, following the same
  registration/classification pattern as rule_tools/unused_rules/explain_rule,
  registered in the eval corpus's tool allowlist.
- Default analysis window is 14 days against raw ssdf.events, stated in
  every report, until the flow_tuples_daily rollup (MEC-1639) lands.

Out of scope for v1 (always evaluate to unknown, never a guess): App-ID
filters, application-default, DAG/EDL/region (PAN-OS); identity,
dynamic-application, URL-category, and scheduler-name (Junos).

Verified:
- services/policy: uv run pytest -q -m "not integration" -- 184 passed
- services/mcp-query: uv run pytest -q -m "not integration" -- 610 passed,
  44 skipped
- ruff check services / ruff format --check services -- clean
- gitleaks protect --staged -- clean

Supersedes #51.

Refs #29

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Addresses the change_impact security review on PR #66:

- apply_delta renumbers position from the resulting list order (and
  canonicalizes the caller's input list order first), so a JSON-delta
  move/add is reflected in position-based diffing and first-match
  evaluation instead of silently reading as no change.
- Junos insert accepts the fully zone-qualified form and refuses an
  ambiguous bare policy name instead of resolving to the first match.
- Junos sub-statement activate/deactivate and prefix-style
  sub-statement delete with no value are refused instead of
  mis-applying to the whole policy or silently no-op'ing.
- change_impact no longer accepts a caller-supplied deny_logging_observed
  argument; it's computed from the same candidate rows the evaluator
  scores.
- delta-line rejection errors identify the line by index only, and the
  Junos text-delta form's delta.lines is hashed before reaching
  ssdf.audit, matching junos_current_text's existing treatment.
- is_global is persisted on the policy entity and read back, instead of
  re-derived from from_zone.
- coverage.window_default_days now reflects whether the 14-day default
  was actually used.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@fastrevmd-lab

Copy link
Copy Markdown
Member Author

Superseded by #67.

@fastrevmd-lab
fastrevmd-lab deleted the bors/mec-1762-change-impact-v2 branch October 4, 2026 21:00
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