Files
pruefwerk/docs/design/derive-checks-from-controls.md
T
sharangandClaude Opus 5.5 a66b7a5991
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m11s
CI / Deploy Agent (push) Successful in 4m35s
fix(sast): run only our own semgrep rules, no registry rules or metrics (#441)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-10-05 13:03:43 +00:00

174 lines
10 KiB
Markdown

# Deriving checks from breakpilot-compliance controls
**Status:** draft for agreement with the breakpilot-compliance side (#383) · 2026-09-25
**Not published:** `docs/design/` is excluded from the documentation site.
## Why
Prüfwerk tells a manufacturer where its product stands against the CRA. The controls
come from breakpilot-compliance ("dsms"); the checks come from us. Today the two meet
late: our tools find things, and our hand-written map says afterwards which control a
finding belongs to. Nothing we check is derived from a control. This note proposes how
dsms controls should drive what Prüfwerk checks, without ever letting an LLM decide
coverage.
## How it works today
1. **Detectors run on their own:** semgrep (our CRA rule pack; registry rules are not licensed for a service),
cppcheck, gitleaks, syft/osv and the PLC linter.
2. **Our control map** (`control-map/data/cra_control_map.json`, written and reviewed by
us) binds each of the 40 CRA Annex I controls to the tools, rule ids, CWEs and
languages that check it: 21 covered, 19 not checkable in code.
3. **Triage.** A finding is matched to its controls through the map. The LLM judge
confirms each match against the code, reading the binding's own check text (#381),
and every confirmation has to quote the code verbatim (the grounding gate). The judge
never removes a finding (#367).
4. **Grounded surface checks** cover the eight controls violated by an absence: no
update signature, no security logging, and so on. A hand-written keyword list per
control finds the code, and the judge decides (#376).
5. **Status.** The CRA status says "no violation found" only where a rule covered the
scanned languages and every tool it relies on completed (#368, #387).
**Where the dsms controls come in:**
| Source | What it is | Used for | Live on staging and production |
| --- | --- | --- | --- |
| CRA catalog (`oscal-catalog-cra.json`) | 40 controls, with severity, evidence type and Annex anchor | judge prose, ratings on the CRA status | yes, as a baked snapshot |
| Master controls (`?framework=master-controls`) | about 2,900 code-checkable controls, clustered | semantic mapping (5c) | **no**: not shipped (#382) |
**Gaps this note addresses:**
- The binding between a check and a control is ours alone; dsms never sees it.
- The surface keywords are hard-coded in Rust (`controls/surface.rs`) rather than derived from control text.
- No new check can come out of a control.
- dsms has two ways to take our results:
- it pulls our pre-computed OSCAL verdicts over MCP (`POST /v1/cra/oscal-from-scanner`);
- it also re-maps raw findings by CWE (`/assess-from-scanner`, `cra_finding_mapper.py`, `_CWE_TO_REQ`).
The second can disagree with the first.
## Principles (unchanged)
- **Tools detect, the LLM judges.** Every finding comes from a deterministic detector
or a grounded surface check. The LLM confirms or refutes a mapping, quoting code.
- **Coverage is decided by people.** Which control is checked by which rule is
reviewed and versioned, never inferred at scan time.
- **A claim needs a check that ran.** No "no violation found" without a rule for the
language and a tool that completed.
## Proposal
### 1. Gate: which controls Prüfwerk checks at all
dsms knows how each control is evidenced:
- **master controls:** `mc_verification`: `source_code`, `network`, `it_process`, `document`, `manual`, `hybrid`;
- **CRA:** `evidence-type`: `code`, `process`, `hybrid`, `document`.
We use that as the gate:
| dsms method | Lane |
| --- | --- |
| `source_code`, `code` | Prüfwerk static analysis |
| `network` | Prüfwerk dynamic tests (DAST, TLS, ports; the Werkbank runner) |
| `hybrid` | both: the code part here, the process part in dsms |
| `it_process`, `process`, `document`, `manual` | dsms (process evidence) |
Controls outside our lane stay "not checkable in code" on our side and are evidenced in
dsms.
**Already in place:**
- The master-controls export (breakpilot PR #129) contains only `source_code` and `network` controls, so dsms already applies the gate.
- Every master control carries its method as a `verification-method` prop, and the export also groups by it. The snapshot shipped in #382 has 2,143 `network` and 739 `source_code` controls.
- CRA controls carry `evidence-type`.
**The gap is ours:** `OscalDocument::to_controls()` reads `evidence-type` but drops `verification-method`. We keep it per control (story 1). **Ask A1 is met**; nothing to ask.
### 2. What each control asks, in terms a check can use
A control's statement is written for auditors ("SAST … in der CI/CD-Pipeline"), not for
code. The more concrete material differs by catalog:
- **CRA (the pilot's 40):** already there. Each control links dsms measures, exported as
24 back-matter resources, for example M600 "Nicht benötigte Dienste, Ports und
Protokolle standardmäßig deaktivieren". We read those links today but do not use them.
They are the first source. No ask.
- **Master controls:** the canonical controls behind them have `test_procedure[]` and
`requirements[]`, which the export does not carry. **Ask A2:** export them as raw
catalog parts. The OSCAL *assessment objectives* stay on our side, as agreed on
2026-07-20: catalog content is dsms's, the assessment layer is ours.
From that material we derive, once per control and version, reviewed by a person:
- **check texts per binding** (today written by hand, #381);
- **surface terms per language** for the grounded check (today hard-coded in `surface.rs`), with C/C++, ST/SCL and the web languages as separate lists.
Derived data lives in the control map, keyed by the control id and the catalog's
content hash. A catalog change shows up as a failing parity test (#381), not as a silent
drift.
### 3. New rules from controls (candidates, never automatic)
For a code-checkable control that no rule covers:
1. From the control's objectives, an LLM drafts a semgrep rule, plus positive and
negative examples.
2. The rule must parse, fire on every positive example and on none of the negative
ones. That gate is deterministic, as in Prose2Policy's compile-and-test step.
3. A person reviews it into `rules/cra_semgrep.yaml`, together with its binding and a
nightly fixture.
dsms's Payment Compliance Pack (25 semgrep and 5 CodeQL rules tied to control ids) is the
precedent. The difference: candidates are proposed per control, and nothing reaches a
scan without review.
### 4. Retrieval at scale
For the master controls (about 2,900 in our lane), a finding cannot be matched through a
hand-written map. The semantic pass (5c) embeds control text and retrieves the nearest
controls per finding.
Two improvements, from prior art:
- a **deterministic pre-filter** before the judge: the control's derived terms must occur in the region, as in IRIS;
- a judge answer with **counter-evidence spans and a failure mode**, as in VulnAgent-R2, to cut false confirmations.
The unused `ControlsProvider::controls()` query API becomes the entry point.
**Needs #382** (ship the master-controls snapshot) and **ask A6** (access to the export).
### 5. One mapping, not two
dsms already pulls our per-control verdicts as OSCAL (`POST /v1/cra/oscal-from-scanner`
calling our `oscal_assessment` MCP tool). But `/assess-from-scanner` still re-maps raw
findings by CWE (`_CWE_TO_REQ`), and two mappings of the same finding will drift. Instead:
- **Ask A5:** for Prüfwerk findings, the OSCAL path is the only one. The CWE table stays as a fallback for other scanners.
- **Coverage:** Prüfwerk adds its per-control coverage (which controls it checks, with which tools, for which languages, and whether the last run completed), so dsms can mark those controls as machine-checked and ask for process evidence only for the rest. `get_control_mapping` already exposes the static part.
## Asks to breakpilot-compliance
| # | Ask | Why |
| --- | --- | --- |
| A1 | ~~Verification method per master control~~: **met**, each control carries `verification-method` | the gate (1) |
| A2 | `test_procedure` / `requirements` of master controls as raw catalog parts (objectives stay ours) | check texts and surface terms (2), rule candidates (3) |
| A3 | Keep control ids stable and the content hash per catalog | our map is keyed on them |
| A4 | Umlauts in the catalog's titles and prose ("Passwörter", not "Passwoerter") | shown to customers verbatim |
| A5 | For Prüfwerk findings, use only the OSCAL verdicts (not `_CWE_TO_REQ`), plus our coverage | one mapping (5) |
| A6 | A service token for the master-controls export | #382, retrieval (4) |
| A7 | Reclassify the catalog route from `TENANT_REQUIRED` (human principals only) to `GLOBAL_AUTHENTICATED` or `INTERNAL_SERVICE_ONLY`, with a Prüfwerk client in realm `breakpilot-dev` | automatic snapshot refresh; until then a one-off snapshot with a user's token (#382) |
## What we build (stories, once agreed)
1. **Gate by method:** keep each master control's `verification-method` and each CRA control's evidence type; controls outside our lane are "evidenced in dsms" on the CRA status.
2. **Derived check texts and surface terms:** for CRA, from the linked measures (available now); for master controls, from A2's material. Reviewed and versioned in the control map; `surface.rs` reads its terms from there.
3. **Rule-candidate pipeline:** LLM draft, deterministic test gate, review; one candidate per uncovered control; nightly fixture per accepted rule.
4. **Judge answer and pre-filter:** counter-evidence spans and failure mode; deterministic term pre-filter in 5c.
5. **Coverage export:** per-control coverage (tools, languages, last run) over MCP and in the evidence pack.
**Order.**
- Stories 1 and 5 need nothing new from dsms except A5, and give the biggest win: one mapping, and an honest split between machine and process evidence.
- Story 2 can start now for the 40 CRA controls (from the measures); master controls need A2.
- Story 3 follows story 2. Story 4 needs #382.
## Open questions
- **Who reviews rule candidates and derived terms?** Proposal: Prüfwerk engineering, with a dsms reviewer for the control semantics.
- **Versioning:** how often does the CRA catalog change, and do we re-derive on every change or on request?
- **IEC 62443:** the same approach once dsms exports that catalog (#241, #236).
- **Languages:** which ones first for derived surface terms? Proposal: C/C++ (the pilot), then ST/SCL, then the web stack.