Skip to content

feat(review): devops-cli's rule pack turns the recall set's network-exposure entries into tested Semgrep rules, and CI runs the pack's tests when a rule changes #1145

Closed

Description

@dan-petty

Problem

  • The one valid persona row has no rule. S11's only valid persona row (otel ipBlock 0.0.0.0/0 on port 16686, fix(k8s): deploy-stack applies the monitoring namespace perimeter #913) has no tool rule, and the loop found it in 4/10 runs, titled "Egress" each time [measured: loop §4].
  • Two of the six recall entries are this class [code: tests/fixtures/review_recall/recall_set.json].
  • A 12-line rule matched both offline, in 7.1 s [measured: d-guarantees].
  • "Tested" would mean nothing without CI. The rule tests would otherwise run only by hand, and CI's test step already takes 183 s [REST via c-feasibility].

Acceptance criteria

  • src/devops_cli/review/rules/k8s-networkpolicy-ingress-any.yaml (MIT) carries CWE and metadata.
    • Its tests hold ruleid: cases for both recall shapes, and ok: cases for a private CIDR and an egress-only policy.
  • Each recall entry names the tool and rule expected to catch it, or none (the VISION.md claim).
  • A rules manifest guards the tests.
    • devops review rules test runs semgrep --test. On a pass, it writes rules.lock with (rule sha256, test sha256, Semgrep version) per rule.
    • An offline gate test asserts that every pack rule has a matching entry.
  • A path-filtered GitHub Actions job (src/devops_cli/review/rules/**) runs semgrep --test with the pinned Semgrep, outside the pre-push gate.
  • (person-run) A path review of 38517a8 matches both network entries.
  • Tests run offline with fakes and recorded tool output: no network, no real scanner, no model; each test under 1 s.
  • changelog.d/<n>.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
  • uv run devops ci passes.

Key questions

  • Egress 0.0.0.0/0? (proposed) A separate opt-in rule.
  • How does the pack grow? (proposed) Each miss a person reports becomes a pack rule with tests. That is the learning loop that replaces the catalog.

Strategic alignment

Proposed design

Problem statement

The devops-cli review process needs to turn recall set's network-exposure entries into tested Semgrep rules and run those tests in CI when a rule changes, ensuring that security findings are validated through automated testing rather than manual verification.

Acceptance criteria

  • Criterion 1: A Semgrep rule file exists with MIT license, CWE metadata, and proper test cases for both recall shapes
    Verification: Check that src/devops_cli/review/rules/k8s-networkpolicy-ingress-any.yaml exists with MIT license, CWE metadata, and contains test cases for both recall shapes (ruleid: for matches and ok: for non-matches)
  • Criterion 2: Each recall entry in the set has a corresponding tool and rule expected to catch it
    Verification: Verify that every entry in tests/fixtures/review_recall/recall_set.json has a matching tool and rule or is marked as 'none'
  • Criterion 3: A rules manifest guards tests by running semgrep --test and writing rules.lock with rule sha256, test sha256, and Semgrep version
    Verification: Run devops review rules test and confirm that rules.lock is created with proper entries containing rule sha256, test sha256, and Semgrep version
  • Criterion 4: An offline gate test asserts that every pack rule has a matching entry in the manifest
    Verification: Run offline gate test to verify all pack rules have corresponding entries in the manifest
  • Criterion 5: A path-filtered GitHub Actions job runs semgrep --test with pinned Semgrep outside the pre-push gate
    Verification: Verify that .github/workflows/ci.yml contains a job that filters on src/devops_cli/review/rules/** and runs semgrep --test with pinned Semgrep version
  • Criterion 6: Tests run offline with fakes and recorded tool output, completing under 1 second each
    Verification: Run tests in offline mode with fakes and confirm each test completes within 1 second

Key questions

  • Egress 0.0.0.0/0? (proposed): A separate opt-in rule (proposed)
  • How does the pack grow?: Each miss a person reports becomes a pack rule with tests. That is the learning loop that replaces the catalog. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#913, #1015

Activity

  1. added
    type/feature
    scope/review
    priority/p1-high
    on Oct 3, 2026
  2. added this to the v0.2.36 milestone on Oct 11, 2026
  3. dan-petty commented on Oct 11, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 33bc45c (see proposed design in issue body).

  4. added
    status/in-progress
    on Oct 16, 2026
  5. dan-petty commented on Oct 16, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1598, merged into release/v0.2.36 as 76dd52a.

    Summary

    Closes #1145

    • Semgrep Rule Pack (src/devops_cli/review/rules/):
      • Added MIT-licensed k8s-networkpolicy-ingress-any.yaml (CWE-284) and companion k8s-networkpolicy-ingress-any.test.yaml with ruleid: cases for both recall NetworkPolicy ingress shapes (monitoring-default-perimeter and otel-default-perimeter) and ok: cases for a restricted CIDR (192.0.2.0/24) and an egress-only policy.
      • Updated src/devops_cli/security/semgrep.py to include the rule pack on default review file scans and strip directory prefixes from pack rule IDs.
    • Recall Set Tool & Rule Mapping (tests/fixtures/review_recall/recall_set.json):
      • Recorded tool and rule on every recall entry (semgrep / k8s-networkpolicy-ingress-any for Network Exposure, ruff / BLE001 for Error Handling, and none / none for docs/VISION.md).
    • Rules Lock & CLI (src/devops_cli/review/rules_pack.py, src/devops_cli/commands/review.py):
      • Added devops review rules test (--check, --rules-dir, --format, --dry-run) to run semgrep --test --metrics off and write/verify src/devops_cli/review/rules/rules.lock recording (rule_sha256, test_sha256, semgrep_version) per rule.
    • CI Workflow (.github/workflows/ci.yml):
      • Added path-filtered rule-pack (Rule Pack Tests) job for src/devops_cli/review/rules/** that installs the pinned Semgrep from tools.lock and runs semgrep --test and devops review rules test --check outside the local pre-pus…

    18 file(s) changed.

    How it was verified

    Check runs at 24f1adc:

    • Audit Defect PR Hardening: skipping
    • Prune PR DevContainer Images: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Tests & Coverage: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1145-review-rule-pack.md:

    No Acceptance Criteria section.

  6. added a commit that references this issue on Oct 17, 2026
  7. removed
    status/in-progress
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/reviewtype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions