From 61953e2659d0a269ee9dc6199c1f193c9323999d Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:54:11 +0100 Subject: [PATCH] docs(design): active testing, a throwaway copy first (t83) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Proposed design for the user to decide. Active tests run by default against a copy of the customer's application, built from the repository in a short-lived sandbox (the Prüfumgebung). The code graph steers them: routes from code, and static findings confirmed against the copy. Live testing is an optional add-on with written authorisation. Covers what exists today (checked against the code), which targets qualify, build failures and charging, limits, the entitlement, cost and a Testtag price, a stage test plan, and the SKU and LB wording. Nothing is enabled. Co-Authored-By: Claude Opus 5.5 --- docs/design/active-testing-in-production.md | 367 ++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 docs/design/active-testing-in-production.md diff --git a/docs/design/active-testing-in-production.md b/docs/design/active-testing-in-production.md new file mode 100644 index 0000000..a8f2951 --- /dev/null +++ b/docs/design/active-testing-in-production.md @@ -0,0 +1,367 @@ +# Active testing: a throwaway copy first, the live system as an add-on + +**Status:** proposed design for the user to decide (t83) · 2026-11-06. Nothing is enabled +by this note. +**Not published:** `docs/design/` is excluded from the documentation site. + +## Summary + +Production runs with `PW_FEATURES=source_only`. That switches off DAST, the +LLM-driven pentest, the ICS probe and OpenPLC provision-and-test for the whole +deployment. The Leistungsbeschreibung (LB 1.0.2, §4 Abs. 3) excludes active tests. +Production can import results from a test someone else ran (#337, #349). + +**The proposal: active tests run against a throwaway copy by default.** + +1. **The Prüfumgebung (default).** We build the customer's application from the repository + Prüfwerk already has. It is started in a short-lived, isolated sandbox, with an + internal network only and no outbound traffic while testing. DAST and the automated + pentest run against that copy only. Then everything is thrown away. We never send + traffic to a customer's server. +2. **The code graph steers the test.** Routes taken from the code say what to test, + instead of a crawl guessing. A static finding that an entry point reaches is tried + against the copy. It is then reported as *confirmed exploitable* or *possible*. +3. **Live testing is an optional add-on**, off by default and switched on per tenant. + It is for what only the live system shows: TLS, headers, exposed ports, WAF, cloud + configuration. It needs written authorisation, our source IPs, rate limits and + complaint handling. +4. **Price per run**, in a Testtag unit like the Prüftag. A run costs a build plus a + sandbox, so it can't be unlimited. + +**Why the copy first:** + +| | Prüfumgebung (copy) | Live system | +| --- | --- | --- | +| Authorisation | The code is the customer's and already ours to process under the Prüfwerk contract; the copy runs on our hardware. No third party is touched. | Written authorisation, proof of ownership, a time window | +| Traffic from our IPs to the internet | none | yes: complaints, abuse reports, WAF blocks | +| Aggressive tests (writes, fuzzing, LLM-chosen URLs) | allowed: the copy is thrown away | restricted to non-destructive at a low rate | +| Logged-in tests | easy: the Prüfprofil brings test users | needs the customer's credentials (unused today, see L4) | +| What it can't show | the real deployment (TLS, WAF, reverse proxy, cloud, real data) | that is exactly what it shows | +| Hard part | **building it** (see [What qualifies](#what-qualifies-and-what-doesnt)) | legal and operations | + +## What exists today + +All of this was checked against `origin/main` (168cbe9). + +### Engines + +| Engine | What it does | Where | +| --- | --- | --- | +| DAST | Our own Rust code; there is no ZAP or Nuclei inside (those are import formats only). Steps: recon, a depth-limited crawler, then five agents in parallel: SQL injection, XSS, auth bypass, SSRF, API fuzzer. Targets: web app, REST API, GraphQL. | `compliance-dast` | +| Automated pentest | An LLM tool loop: at most 50 iterations, 30 min by default, at most 5 sessions at once. Tools: the DAST agents, plus TLS, headers, cookies, CSP, CORS, DNS/DMARC, a rate-limit tester, an OpenAPI parser and a Chrome browser over CDP. | `compliance-agent/src/pentest`, `compliance-dast/src/tools` | +| ICS probe | Read-only: Modbus/TCP function codes 0x03, 0x01 and 0x2B/0x0E; the OPC UA HEL/ACK handshake; EtherNet/IP ListIdentity; a TCP connect scan of nine OT ports; 5 s per probe. | `werkbank-exec/src/ics` | +| OpenPLC provision-and-test | Starts a throwaway OpenPLC container per scan, loads the ST program extracted from the customer's PLC project, and runs DAST and the ICS probe against it. | `werkbank-exec/src/plc` | + +### The sandbox base we already have + +`werkbank-exec/src/plc/provision.rs` (306 lines) is the nearest thing to a Prüfumgebung: + +- **Container hardening:** + - one container per scan, named uniquely; + - `--memory`, `--cpus` and `--pids-limit 512`; + - `--security-opt no-new-privileges` and `--stop-timeout 5`; + - no `-p`, so no port is ever published to the host. +- **Cleanup:** + - an owner label; + - a reaper that removes instances older than twice their maximum lifetime. +- **Tests:** the `docker` argument list comes from pure functions, so it is unit-tested + without Docker. +- **The DAST guard:** it runs DAST with `NetGuard::allow_private()`, but only against + that instance (`werkbank-exec/src/plc/mod.rs:253`). + +**What it does not do, and a Prüfumgebung needs:** + +| Gap | Today | Needed | +| --- | --- | --- | +| Network isolation | The container joins **the agent's own network** (`--network cfg.network`), so it can reach the agent, Mongo and the internet. | A fresh `docker network create --internal` per run, holding only the copy, its dependencies and the test tools. Nothing else is reachable, and nothing leaves. | +| Building | It runs a ready-made OpenPLC image. | Build the customer's image from their Dockerfile or Compose file (below). | +| Several containers | one | A Compose project: the app plus a database, cache and so on. | +| Readiness | A fixed Modbus/WebVisu port. | A health URL from the Prüfprofil, with a deadline. | +| Isolation strength | A plain Docker container, started through a Docker socket mount, which is root on the host. | Customer code is untrusted. A run needs a VM boundary (Kata/Firecracker or gVisor `runsc`), on a host that is **not** a platform node. | +| Gate | `PLC_RUNTIME_ENABLED` | The existing `PW_ALLOW_UNTRUSTED_CODE_EXEC` policy (`compliance-core/src/exec_policy.rs:83`) already says tenant code may run only "on a single-tenant or sandboxed deployment". The multi-tenant agent keeps it off. | + +**Where the Prüfumgebung runs.** It runs on a Breakpilot-hosted **Werkbank runner**: a +dedicated host outside the platform nodes, not inside the agent. The Werkbank contract +already has the right shape. The control plane queues a job, and a runner leases it, +provisions, runs and posts results (`handlers/werkbank_jobs.rs`). `JobType` already has +`Dast` and `Pentest` (`compliance-core/src/models/werkbank.rs:25-33`), but nothing creates +them yet; `enqueue` only builds PLC provision jobs. On production the Werkbank path is +off. + +The same runner design also serves a customer who wants the Prüfumgebung inside their own +network. That is the on-premises Werkbank direction already decided. + +### What the graph does today + +- **The pentest reads the graph.** `pentest/context.rs:93-140` loads up to 50 nodes + with `is_entry_point: true` and links SAST findings to them by file path. The prompt + gets a "Code Entry Points (Knowledge Graph)" section (`prompt_builder.rs:205-271`). +- **Reachability exists.** `compliance-graph/src/graph/impact.rs:30-70` searches + backwards from a finding to the entry points that reach it. It also builds call chains + of up to 10 hops, and forward blast radius. Triage puts this in its prompt + (`llm/triage.rs:317-344`). +- **Entry points are coarse.** + - Rust: `main`, `#[test]`, `#[tokio::main]` and every `pub` function. + - JavaScript: every exported function. + - Python: `main`, `__main__` and the decorators `app.route`, `app.get` and `app.post`. + - TypeScript: its own rule. + - There is no HTTP route model (method, path, parameters), and C and C# are not parsed + (that is t82). +- **No exploitability status.** Nothing marks a finding as confirmed exploitable. A + DAST finding and a SAST finding on the same weakness are not linked. + +### Tests + +| Area | Tests | In CI | +| --- | --- | --- | +| net_guard, guarded_net | 10 + 5 unit tests | yes | +| ICS probe, OpenPLC provisioning | 13 + 10 unit tests | yes | +| Pentest orchestrator, prompt builder | 7 + 20 unit tests | yes | +| DAST agents and tools | about 63 unit tests | **no**: `compliance-dast` is missing from CI's clippy and test steps (`ci.yml:128-164`) | +| DAST API | 2 integration tests | yes | +| A full run against a real target | none; there is no `pw-target` | no | + +## Proposed design + +### 1. The Prüfumgebung (default) + +**The Prüfprofil.** The customer describes how to start their application. It can be a +file in the repository (`.breakpilot/pruefprofil.yml`) or a form on the target page: + +- **compose:** the path of the Compose file, or a Dockerfile with a port. +- **service:** the container and port under test. +- **health:** a URL that answers 200 once the app is up. +- **seed:** an optional command that loads test data. +- **users:** test accounts with roles, which makes logged-in testing possible. +- **env:** configuration and **test secrets only**. The profile says so, and a check + refuses values that look like real keys, using the secret scanner we already run. + +**A run, in outline:** +- The control plane queues a Werkbank job with the target's code and Prüfprofil. +- A Breakpilot-hosted runner builds the copy, waits for its health URL, runs DAST or the + automated pentest against it, posts the findings back, and throws everything away. +- The detailed runner and isolation design is a follow-up, written and reviewed with + infra before any code. + +### What qualifies and what doesn't + +| Target | Prüfumgebung | Notes | +| --- | --- | --- | +| Web app or API with a working Dockerfile or Compose file and a Prüfprofil | **yes** | Phase 1. Linux containers only. | +| ASP.NET on .NET 6 or later | yes, with a Dockerfile | Routes from code need the C# parser (t82). | +| ASP.NET on .NET Framework (Windows only) | **no** | It would need Windows containers, which we don't offer. | +| PLC programs (ST, PLCopen) | yes, through the existing OpenPLC Werkbank path | Already built; off on production. | +| Firmware | only through emulation | Not in phase 1; a separate decision. | +| Desktop HMI, mobile apps | no | Static analysis only. | +| A repository with no Dockerfile or Compose file | no | We don't guess how to build it. The target page says what is missing. | + +**Building is the hard part, and the note says so plainly.** Most customer repositories +don't start cleanly from a fresh checkout. They depend on a database, configuration or +private packages. Phase 1 therefore takes only what the customer has made startable: a +working Dockerfile or Compose file plus a Prüfprofil. A free **Probelauf** lets the +customer find this out before paying (see the next section). + +### When the build fails + +| Cause | Example | Charged | +| --- | --- | --- | +| Ours | The runner fails, our time limit is hit through our own load, a toolchain we claim to support is missing | **no**; the run is retried or refunded | +| The customer's input | The Dockerfile doesn't build, the health URL never answers, the Prüfprofil is missing or wrong | **yes**, as with t72's "failures on the customer's input count" | +| Probelauf | Only build and start, then a health check, with no test | **never charged**, so the customer can fix their profile for free | + +The run's page shows which of these it was, with the build log, so the customer can fix +their side. + +### Limits per run + +- **Wall clock:** about 15 min to build and start, about 30 min to test, 60 min in total. + At the limit the run stops and keeps what it found. +- **Resources:** a fixed CPU, memory and disk budget per run (proposed: 4 CPUs, 8 GB, + 20 GB), sized together with infra. +- **Concurrency:** one run per tenant at a time, and a fixed number per runner. +- **Cleanup:** nothing survives a run: images, containers, networks and data are removed + every time, and a reaper removes leftovers. + +### 2. The graph steers the test + +| Step | Exists | New | +| --- | --- | --- | +| Entry points in the pentest prompt | yes (`pentest/context.rs`) | – | +| From a finding back to the entry points that reach it, with call chains | yes (`graph/impact.rs`, used in triage) | – | +| **HTTP routes from code** (method, path, parameters) | no; entry points are coarse | Route extractors per framework: ASP.NET attributes and minimal APIs (after the C# parser of t82), Express, Flask/FastAPI, axum. An OpenAPI file in the repository counts too. The test goes through exactly these routes instead of crawling. | +| **Confirm a static finding** | no | For a SAST finding whose entry point is a route, the matching DAST check runs against that route on the copy (SQL injection for CWE-89, XSS for CWE-79, SSRF for CWE-918 and so on). | +| **Exploitability status** on a finding | no | `confirmed exploitable` (the copy showed it), `possible` (reachable, not shown) or `not tested`. The finding list and the CRA view can sort by it. | + +The benefit: fewer false alarms in front of the customer, and a smaller LLM budget, +because the pentest starts from known routes and known suspects instead of exploring. + +### 3. Live testing (optional add-on) + +Live testing covers what a copy can't show: TLS, security headers, exposed ports, WAF +behaviour and cloud configuration. Off by default; switched on per tenant. + +**Conditions:** +- **Written authorisation:** the customer owns the target or is authorised in writing by + the owner. Draft clause below, for legal review. +- **Proof of ownership:** a DNS record or file token, checked before every run. +- **A time window** set by the customer, inside which runs may start. +- **Our source IPs**, published so customers can allowlist them, with reverse DNS and an + info page naming Breakpilot. +- **Rate limits:** low request rates, non-destructive checks only, a short time limit. +- **Complaint handling:** an abuse contact, a runbook, and kill switches globally, per + tenant, per target and per run. + +**What has to change in the code before live testing** (from the survey; none of it is +reachable on production today): + +| # | Gap | Size | +| --- | --- | --- | +| L1 | No ownership check exists. | M | +| L2 | Once enabled, every live-URL target would get DAST and the ICS probe every 6 hours (`change.rs:86`). Live tests must run only on request. | S | +| L3 | The target's rate limit is ignored (a fixed 100 ms in `dast.rs:172`); there is no page cap, no timeout and no overall deadline; DAST runs outside the scan concurrency limit. | M | +| L4 | `auth_config` is stored but unused, so live tests are unauthenticated. | M (later) | +| L5 | The pentest's browser and the URLs the LLM picks are not held to the target host. | M | +| L6 | `allow_destructive` is enforced only for DELETE. | S | +| L7 | The DAST and pentest routes check no role. | S | + +These also apply to the Prüfumgebung, except L1 and L2: +- `compliance-dast` has to join CI; +- the routes need a role check (L7); +- the caps in L3 keep a run inside its budget. + +**Draft clause** (live add-on only), for legal review: + +> Der Kunde versichert, dass er Inhaber des angegebenen Prüfobjekts ist oder vom Inhaber +> schriftlich ermächtigt wurde, aktive Sicherheitsprüfungen daran zu beauftragen. Er +> beauftragt Breakpilot, das Prüfobjekt im angegebenen Zeitfenster von den in der +> Leistungsbeschreibung genannten Quell-IP-Adressen aus automatisiert zu prüfen. Der +> Kunde sorgt für eine aktuelle Sicherung und informiert betroffene Dritte, etwa seinen +> Hosting-Anbieter. Er stellt Breakpilot von Ansprüchen Dritter frei, die auf einer +> fehlenden oder unzutreffenden Ermächtigung beruhen. + +### 4. Entitlement per tenant + +`PW_FEATURES=source_only` stays as the global kill switch. Below it, the tenant registry +decides per tenant, as in t72: + +- The entitlement check already takes an `addon` parameter that every caller passes as + `None` (`registry.rs:369`). +- The add-on names: `pruefumgebung` and `live_testing`. +- The dashboard reads features only from the global `/version` handshake. It needs a + tenant-scoped answer: add the add-ons to the usage response of t72 + (`GET /api/v1/metering/usage`). +- Usage events, counts only, never names: + - `testtag.booked`, key `testtag:{tenant}:{target}:{YYYY-MM-DD}`; + - `live_test.run`. +- Recommendation: an active run does **not** count against the t72 Prüfung quota. It is + metered on its own. + +### 5. Cost and price + +**Our cost per run** is an estimate, to be measured on stage: + +- **Compute:** + - building and starting the copy takes about 10–15 min on 4 CPUs; + - a test takes about 30 min, with the copy and the test tools together on about 4 CPUs; + - in total about 2.5–3 CPU-hours and up to 8 GB of memory per run. +- **On a dedicated runner host** (assumption, to confirm with infra: 16 cores and 64 GB + at about 100–150 € per month), that is about 4 runs at once: + - full use: well under 0.10 € of compute per run; + - 10 % use: about 0.30–0.60 € per run. +- **The automated pentest** adds LLM time on our own model: up to 50 rounds, roughly + 0.5–1 million tokens per session. That is GPU time, not money per token; measure it on + stage. +- **Fixed costs** are lower than for live testing (no complaints, no legal exposure to + third parties). They remain the runner host, support for failed builds, and the + Prüfprofil help. + +**Price suggestion**, set against the 9,99 € Prüftag and the 5,99 € extra target: + +| SKU | Contents | Suggestion | +| --- | --- | --- | +| `pruefwerk-testtag` | The Prüfumgebung for one target on one Berlin day, with up to 3 runs (DAST or automated pentest), so a customer can fix and test again the same day | 24,99 € per Testtag | +| `pruefwerk-probelauf` | Build and start only, no test | free | +| `pruefwerk-live` (add-on) | Live testing of verified targets, on request, including 5 runs per month | 29,00 € per month per tenant | +| `pruefwerk-live-run` | Each live run beyond the included 5 | 4,99 € per run | + +A Testtag mirrors the Prüftag that customers already know. It caps our cost per booking, +and it fits how fixes really go: test, fix, test again. + +## Test plan on stage + +1. **pw-target:** our own deliberately vulnerable web app with a Dockerfile and a + Prüfprofil. Ideally one in ASP.NET, which also tests the C# routes from t82, and one + in Node. +2. **A repository with Compose:** an open-source app with a database in its Compose + file, to prove that several containers build and start. +3. **Probelauf:** for both, it passes; with a broken Dockerfile it fails visibly, as the + customer's fault, and is not charged. +4. **Runs:** DAST and the automated pentest on both. The known vulnerabilities of + pw-target are the baseline; add a nightly fixture that compares against it. +5. **Graph steering:** the routes found in code match pw-target's real routes. A planted + SQL injection found by SAST comes back as `confirmed exploitable`, and an + unreachable one as `possible`. +6. **Limits and cleanup:** the run stops at its time limit; nothing is left behind after + a run; a second run of the same tenant waits. +7. **Entitlement and metering:** + - a tenant without the add-on is refused; + - a Testtag is booked once and allows 3 runs; + - the usage events carry counts only. +8. **Measure** minutes, CPU, memory and LLM tokens per run, for the price. +9. **Live add-on:** only after the user decides on it. It runs against pw-target under + a public stage name, reachable only from stage's own address, and covers the ownership + check, the time window, the rate limits and the kill switches. + +Production stays on `source_only` until the user gives the go. + +## Decisions for the user + +1. **The Prüfumgebung as the default** for active tests, with live testing as an + optional add-on. Recommended. +2. **Phase 1 scope:** web apps and APIs with a Dockerfile or Compose file plus a + Prüfprofil; PLC through the existing OpenPLC path; firmware later. +3. **Charging:** customer-side build failures count, ours never do, and the Probelauf is + free. +4. **Price:** the Testtag at 24,99 €; whether the live add-on is offered at all, and at + what price. +5. **Order:** + 1. `compliance-dast` into CI, the role check and the caps (L3, L7); + 2. the runner and isolation design with infra; + 3. the Prüfprofil; + 4. routes from code (after t82); + 5. the exploitability status; + 6. the stage test plan; + 7. the live add-on last, if wanted. + +## Needed from the registry, ERP and LB side + +**For the registry and ERP:** +- The add-ons `pruefumgebung` and `live_testing`. +- The SKUs `pruefwerk-testtag`, `pruefwerk-probelauf` (price 0, for counting), + `pruefwerk-live` and `pruefwerk-live-run`. +- The usage events `testtag.booked` and `live_test.run`, counts only. + +**LB wording** for the version that ships phase 1. It replaces the exclusion in §4 +Abs. 3 for tenants who booked the add-on: + +> **Prüfumgebung (Zusatzleistung).** Für gebuchte Mandanten baut Prüfwerk die Anwendung +> des Kunden aus dem bereitgestellten Quellcode in einer abgeschotteten, nur für diese +> Prüfung erzeugten Umgebung auf und prüft sie dort aktiv auf Schwachstellen, unter +> anderem SQL-Injection, Cross-Site-Scripting, Umgehung der Zugriffskontrolle und +> Server-Side Request Forgery. Systeme des Kunden oder Dritter werden dabei nicht +> angesprochen. Voraussetzung ist ein lauffähiges Dockerfile oder eine Compose-Datei +> sowie ein Prüfprofil mit Testdaten; produktive Daten oder Zugangsdaten dürfen nicht +> enthalten sein. Die Umgebung wird nach jeder Prüfung vollständig gelöscht. Ein +> Prüftag der Prüfumgebung („Testtag“) umfasst bis zu drei Prüfläufe eines Prüfobjekts +> an einem Kalendertag (Europe/Berlin). Ein Probelauf (nur Aufbau und Start) ist +> kostenfrei. Schlägt der Aufbau aus Gründen fehl, die Breakpilot zu vertreten hat, wird +> der Prüflauf nicht berechnet. Die Prüfung ist automatisiert und ersetzt keinen +> manuellen Penetrationstest. + +**For the live add-on** (only if decided), add: + +> **Live-Prüfung (Zusatzleistung).** Auf gesonderte Beauftragung prüft Prüfwerk ein vom +> Kunden benanntes, erreichbares System, dessen Inhaberschaft der Kunde nachgewiesen +> hat, im vereinbarten Zeitfenster von den unten genannten Quell-IP-Adressen aus mit +> nicht-destruktiven Prüfungen (u. a. TLS, Sicherheits-Header, offene Dienste). +> Steuerungen und industrielle Protokolle werden nicht aus dem Rechenzentrum geprüft. \ No newline at end of file