feat(demo): seed curated targets from the agent, source-only mode (#251)
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

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
This commit was merged in pull request #251.
This commit is contained in:
sharangandSharang Parnerkar committed 2026-09-14 08:24:33 +00:00
1 parent 728f3ab3bc
commit d9850bef90
25 files changed
+1215 -84

No files matched your search

+40 -2
View File
@@ -1,20 +1,29 @@
#!/usr/bin/env bash
# Seed the curated demo targets (#187) into a running compliance-agent.
#
# The agent seeds itself now: `POST /api/v1/targets/demo-seed` runs the same
# create → upload → detect → scan sequence server-side from the manifest
# compiled into its binary, which is what the dashboard's "Add demo targets"
# button and the nightly demo reset use. `--api` below calls that endpoint; the
# client-side path stays for seeding an agent whose bundled manifest is older
# than this checkout, and for --reset.
#
# Reads fixtures/demo-targets/targets.json and, for every target:
# 1. POST /api/v1/targets (name = name_prefix + name)
# 2. POST /api/v1/targets/{id}/artifacts/upload for each `upload` artifact
# 3. POST /api/v1/targets/{id}/detect (surface detected facts)
# 4. POST /api/v1/targets/{id}/scan (only with --scan)
#
# Artifact env overrides (see the manifest): DEMO_WEB_URL, DEMO_PLC_MODBUS_URL,
# Artifact env overrides (see the manifest): DEMO_PLC_MODBUS_URL,
# DEMO_PLC_FIRMWARE_IMAGE. Optional artifacts whose env var is unset are
# skipped, so the set seeds on a bare laptop; set them on comp-dev / Orca.
#
# Usage:
# scripts/seed-demo-targets.sh # seed all
# scripts/seed-demo-targets.sh --scan # seed + trigger first scan
# scripts/seed-demo-targets.sh --only web-juice-shop,git-cra-vuln-demo
# scripts/seed-demo-targets.sh --only plc-pump-station,git-cra-vuln-demo
# scripts/seed-demo-targets.sh --api # let the agent seed itself
# scripts/seed-demo-targets.sh --api --scan # … and rescan what exists
# scripts/seed-demo-targets.sh --reset # delete every "Demo · " target
# scripts/seed-demo-targets.sh --reset --scan # reset, reseed, scan
#
@@ -31,11 +40,13 @@ MANIFEST="${MANIFEST:-$ROOT/fixtures/demo-targets/targets.json}"
DO_SCAN=0
DO_RESET=0
USE_API=0
ONLY=""
while [[ $# -gt 0 ]]; do
case "$1" in
--scan) DO_SCAN=1 ;;
--reset) DO_RESET=1 ;;
--api) USE_API=1 ;;
--only) ONLY="$2"; shift ;;
-h|--help) sed -n '2,25p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
*) echo "unknown arg: $1" >&2; exit 2 ;;
@@ -72,6 +83,26 @@ api() {
PREFIX="$(jq -r '.name_prefix' "$MANIFEST")"
# --api: hand the whole job to the agent, which seeds from the manifest baked
# into its own binary. --only selects keys, --scan means rescan what exists.
seed_via_api() {
local names="[]"
if [[ -n "$ONLY" ]]; then
names=$(jq -cn --arg o "$ONLY" '$o | split(",")')
fi
local rescan="false"
[[ "$DO_SCAN" == 1 ]] && rescan="true"
local body out
body=$(jq -cn --argjson n "$names" --argjson r "$rescan" '{names: $n, rescan: $r}')
out=$(api POST "/api/v1/targets/demo-seed" -H 'Content-Type: application/json' -d "$body")
jq -r '.seeded[] | " \(.status)\t\(.name)\t\(.error // "")"' <<<"$out"
if jq -e '.seeded[] | select(.status == "failed")' <<<"$out" >/dev/null; then
echo "$(red "some targets failed")" >&2
return 1
fi
echo "$(green "seeded")"
}
reset_targets() {
echo "== reset: deleting targets named '${PREFIX}*'"
local list ids
@@ -168,6 +199,13 @@ seed_target() {
[[ "$DO_RESET" == 1 ]] && reset_targets
if [[ "$USE_API" == 1 ]]; then
echo "== seeding via the agent's own manifest → $AGENT_URL"
seed_via_api
echo "== done"
exit 0
fi
echo "== seeding from $MANIFEST → $AGENT_URL"
jq -c '.targets[]' "$MANIFEST" | while IFS= read -r t; do
key=$(jq -r '.key' <<<"$t")