Files
pruefwerk/docs/guide/demo-targets.md
T
sharangandSharang Parnerkar d9850bef90
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Docs (push) Successful in 1m8s
CI / Deploy MCP (push) Successful in 3m53s
CI / Deploy Dashboard (push) Successful in 5m34s
CI / Deploy Agent (push) Successful in 6m58s
feat(demo): seed curated targets from the agent, source-only mode (#251)
Demonstration plan, phase D3 (agent side). Two things blocked a self-serve demo: a fresh trial tenant landed on an empty targets page, and staging tried to run DAST, pentest, the ICS probe and the soft-PLC runtime that are not deployed there, so those stages surfaced as tool errors.

## Seeding

| Request | Meaning |
|---|---|
| `GET /api/v1/targets/demo-seed` | what would be created: `key`, display `name`, `kind`, `description`, `source_only` |
| `POST /api/v1/targets/demo-seed` | body `{"names":[…],"rescan":false}`, empty `names` seeds all; `202` with one row per target, `status` = `queued` \| `exists` \| `failed` |
| `POST /api/v1/platform/tenants/demo/reset` | now takes `{"seed": true}` and reseeds with a service token, for the nightly sales-demo reset |

Seeding runs through a new shared target lifecycle (`compliance-agent/src/targets.rs`: create → store upload → attach → detect), which the onboarding handlers now call as well — so a seeded target is an ordinary target with the same records and the same `target.added` usage events, and there is no HTTP self-call. It is idempotent by display name: the seeder owns the `Demo · ` prefix, so a second call finds its own targets. `scan_id` is always `null` in the response because the scan run is created inside the background pipeline.

## Source-only set

The manifest is now source-only: `plc-pump-station`, `plc-conveyor-line`, `git-cra-vuln-demo`, `firmware-zephyr-example`. The Juice Shop target needed a running instance for DAST and pentest and is removed, along with `DEMO_WEB_URL`. Everything ships inside the agent binary (manifest plus the PLC upload fixtures), so a deployed agent seeds without the repo.

## `PW_FEATURES=source_only`

A static-analysis-only deployment: DAST, the ICS probe and the ephemeral PLC runtime record a `skipped_stages` entry on the scan run (`{stage, status:"skipped", reason:"feature disabled"}`) instead of failing; starting a DAST run or a pentest session answers `409`; the flag list is published on the public `/api/v1/platform/version` handshake so the dashboard reads the set the agent enforces rather than its own copy of the env. Unknown flags are kept and reported, so a dashboard-only flag needs no agent release.

Docs and the ops script are updated: `scripts/seed-demo-targets.sh --api` hands the job to the agent, the client-side path stays for `--reset` and for agents older than the checkout.

Verified locally: `cargo fmt --all --check`, `cargo clippy -p compliance-agent -- -D warnings`, `cargo clippy -p compliance-core -- -D warnings`, `cargo test -p compliance-core -p compliance-agent -p werkbank-exec -p control-map --lib` (414 tests). `compliance-agent/tests/demo_seed.rs` needs Mongo and runs outside CI like the other integration tests.

Pairs with the dashboard's "Add demo targets" button and with orca-platform setting `PW_FEATURES=source_only` on the staging agent.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #251
2026-09-14 08:24:33 +00:00

5.6 KiB

Demo Targets

Prüfwerk ships a small, versioned set of demo targets — representative inputs that exercise every scan path repeatably. They double as the fixture set for the nightly regression and as a ready-made walkthrough for demos.

The set lives in fixtures/demo-targets/targets.json and is compiled into the agent binary, so a deployed agent can seed itself.

The shipped set is source-only: every required artifact is a file or a git repository, so the whole set scans in an environment with no browser, no soft-PLC and no reachable devices (PW_FEATURES=source_only). The web-app target, which needed a running Juice Shop for DAST and pentest, is not part of it any more.

What is in the set

Key Target type Artifacts What it exercises
plc-pump-station PLC / SPS (composite) pump_station.st, pump_fbd.xml, optional Modbus live URL, optional firmware image PLC control-logic SAST (ST and FBD-as-XML), ICS probe, semantic CRA/master-control mapping
plc-conveyor-line PLC / SPS conveyor.xml, traffic_light.st Pure control-logic SAST on a PLCopen-XML program plus a realistic OpenPLC-style sample with three planted defects
git-cra-vuln-demo Backend service git sharang/cra-vuln-demo Plain git SAST: Semgrep → CWE → CRA control refs (cra-ai-8/13/20)
firmware-zephyr-example Firmware (RTOS) git zephyrproject-rtos/example-application Tramiton detect handoff (build_system = zephyr), firmware source SBOM

The PLC files are the same ones under examples/plc-demo/ that the PLC rule tests already run against, so their expected rule ids are enforced offline on every CI run (compliance-agent::fixtures tests).

Reproducibility

  • Git artifacts carry a pin (commit SHA, plus pin_tag where a release tag exists). The agent clones branch; the pin records which commit the baseline was recorded against. When a baseline drifts, re-pin and update expect in the same change.
  • Uploaded artifacts are checked into this repository.
  • Anything that needs infrastructure is optional and env-driven, so the set seeds cleanly on a laptop and gains the dynamic pieces on comp-dev:
Env var Used by Meaning
DEMO_PLC_MODBUS_URL plc-pump-station Modbus endpoint for the ICS probe (in-cluster default modbus://plc-sim:502). Skipped when unset.
DEMO_PLC_FIRMWARE_IMAGE plc-pump-station Absolute path to a device firmware image to attach. Skipped when unset.

Seeding the targets

From the dashboard (what a trial user does)

A fresh tenant's empty targets page offers Add demo targets. It calls the agent, which creates each target from its bundled manifest, attaches the artifacts, runs detection and starts a scan — the same code path as the onboarding wizard, so the result is ordinary targets, findings and usage events. Seeding twice is harmless: a target that is already there is reported as exists and nothing is re-run unless a rescan is asked for.

The endpoints behind the button:

Request Meaning
GET /api/v1/targets/demo-seed What would be created: key, display name, kind, description, source_only.
POST /api/v1/targets/demo-seed Seed them. Body {"names": ["…"], "rescan": false}; empty names seeds all. Answers 202 with one row per target: status = queued | exists | failed.

The nightly reset of the sales demo tenant uses the same seeding code through POST /api/v1/platform/tenants/demo/reset {"tenant_id": "…", "seed": true} with a service token, so it needs no user session.

From the command line (ops)

# let the agent seed itself from its own manifest
scripts/seed-demo-targets.sh --api


# against a local dev agent (no Keycloak → dev tenant)
scripts/seed-demo-targets.sh

# seed and trigger the first scan of each
scripts/seed-demo-targets.sh --scan

# only some targets
scripts/seed-demo-targets.sh --only plc-pump-station,git-cra-vuln-demo

# wipe every "Demo · " target and reseed
scripts/seed-demo-targets.sh --reset --scan

# a deployed agent
AGENT_URL=https://comp-dev.breakpilot.com AGENT_TOKEN=$TOKEN \
DEMO_PLC_MODBUS_URL=modbus://plc-sim:502 scripts/seed-demo-targets.sh --scan

The script uses only curl + jq and the public onboarding API: POST /api/v1/targets, POST /api/v1/targets/{id}/artifacts/upload, POST /api/v1/targets/{id}/detect, POST /api/v1/targets/{id}/scan. Every seeded target is named Demo · <name>; --reset deletes exactly that prefix and nothing else.

Manual (re)onboarding

Each target can also be created through the onboarding wizard:

  1. PLC targets — pick PLC / SPS, upload the .st / .xml files from examples/plc-demo/, optionally add a modbus:// live URL. See PLC / SPS (CODESYS).
  2. Git targets — pick the type, add the git URL and branch from the manifest. Public repos need no credentials.
  3. Web app — not part of the shipped set: add the git repo and a live URL yourself, then enable DAST and, if wanted, pentest on the scan-selection step. Both are unavailable while PW_FEATURES=source_only.

Golden baselines

Each target's expect block states what a healthy scan must produce (min_findings, required sast_rule_ids, cwes, control_refs, min_sbom_components, scans_offered, pentest_supported, detected_facts). The PLC baselines are asserted in unit tests today; the nightly regression story (#188) runs the full set against a live agent and alerts on drift.