diff --git a/firru/cli/edit.py b/firru/cli/edit.py index 933a34b..ae12d5f 100644 --- a/firru/cli/edit.py +++ b/firru/cli/edit.py @@ -789,7 +789,9 @@ def _emit_sh(old_path, new_path, defs_dir, result, direction=None, swaps=None, """Emit runnable firru commands that turn OLD into NEW, one per change, each naming its term so `| grep SERVICE | sh` applies a subset. Each line carries its class as a trailing comment, so `| grep narrowed | sh` takes - every safe tightening and nothing else. + every safe tightening and nothing else. A line that must not run by + accident (a widening, a change the traffic contradicts, a terminal swap) + is itself a comment, so `| sh` on the whole output never widens. A restricted diff emits restricted commands: the scope that made the finding has to travel with the command that acts on it, or running the @@ -838,6 +840,11 @@ def _emit_sh(old_path, new_path, defs_dir, result, direction=None, swaps=None, f"observed ({rec['keep_hits']} flows), left out never " f"answered: {' '.join(rec['left_out'])}") print(f"# {line} # widened: would admit {_fmt_silent(silent)}") + elif cls == "widened": + # It grants peers OLD did not. Review decides that, never a + # grep, so it is a comment like every other line that must + # not run by accident: `| sh` on the whole output is safe. + print(f"# {line} # widened REVIEW{_ev_tag(evidence, term)}") else: print(f"{line} # {cls}{_ev_tag(evidence, term)}") for term, _ in result["cosmetic"]: diff --git a/firru/cli/mass.py b/firru/cli/mass.py index 0b99698..f8c7f4a 100644 --- a/firru/cli/mass.py +++ b/firru/cli/mass.py @@ -10,7 +10,9 @@ firru diff pol.yml tightened.yml --flows w.jsonl -o sh | grep observed | firru mass firru mass out/edits/*.sh - grep -v '# widened' out/edits/host.sh | firru mass + +A widening, a change the traffic contradicts and a terminal swap are emitted +as comments, so a whole script runs only what is safe to take unreviewed. The input format is exactly the emitted script: `#` comment lines and blank lines are skipped, a trailing ` # tag` on a command is stripped, and a leading diff --git a/tests/test_diff_evidence.py b/tests/test_diff_evidence.py index a1b6d82..377ba0b 100644 --- a/tests/test_diff_evidence.py +++ b/tests/test_diff_evidence.py @@ -359,3 +359,11 @@ def test_cut_peers_are_named_by_the_inventory(tmp_path): "192.0.2.7": 3}), "silent": Counter()}} _name_peers(ev, str(d)) assert ev[1]["cut"] == Counter({"GT1": 7, "10.9.2.2 (NET_MGMT)": 1, "192.0.2.7": 3}) + + +def test_a_widening_without_evidence_is_a_comment(tmp_path, capsys): + """`| sh` on a whole script must never widen: a widening is for review.""" + out = _run(tmp_path, [_t("allow-tcp-SSH", "SSH", src="NET_MGMT")], + [_t("allow-tcp-SSH", "SSH", src="[NET_MGMT, NET_APP]")], None, capsys=capsys) + (line,) = [l for l in out.splitlines() if "set-source" in l] + assert line.startswith("# firru set-source ") and line.endswith("# widened REVIEW") diff --git a/tests/test_zero_evidence.py b/tests/test_zero_evidence.py index 613cd45..e88cf66 100644 --- a/tests/test_zero_evidence.py +++ b/tests/test_zero_evidence.py @@ -94,7 +94,7 @@ def test_review_grep_skips_it_block_early_takes_it(self, tmp_path, capsys): line = [l for l in out.splitlines() if "ISAKMP" in l][0] # review: grep 'observed (' → no match assert "observed (" not in line - # block-early: grep -v '^#' | grep -v '# widened' → runnable + # block-early: grep -v '^#' → runnable assert not line.startswith("#") and "# widened" not in line def test_a_scored_term_is_emitted_commented(self, tmp_path, capsys):