fix(plc): a repository holding only a CODESYS archive is a PLC project #528

Merged
sharang merged 2 commits from fix/a5-projectarchive-plc into main 2026-10-08 21:38:24 +00:00
Owner

What was wrong

A managed git repository (auto-created target) whose tree is only a CODESYS .projectarchive was classified Backend / API:

  • the heuristic classifier knew only .st files as PLC evidence, so the tree gave no verdict and the classification fell back to the default type the managed target was created with;
  • the CODESYS library/runtime SBOM (plc::sbom::collect_sbom, then the NVD runtime match and CSAF matching) ran only inside the PLC path (run_plc_scan), which is entered only when the scan plan, built from the target type, contains the control-logic scan. So the target got no CODESYS components and no runtime CVEs.

What changed

  • Classifier (classify/language.rs): a committed *.projectarchive or CODESYS *.project counts as PLC evidence (0.85, above the backend manifests' 0.55-0.6), and so does an uploaded source archive named *.projectarchive (kind prior, which also makes the lightweight /detect right). A managed target that no person typed is retyped to SPS/PLC by the existing detected_type, with the CRA + IEC 62443 profile, so later scans take the full PLC path. PLCopen XML is not added: the classifier did not know it before, and detecting it reliably means reading file contents.
  • Code pipeline (orchestrator.rs, scan_tree): this mirrors the firmware approach, where the code decides and not only the chosen type. Every scanned tree's .projectarchive files, plus an uploaded *.projectarchive that ingest unpacked (plc::sbom::uploaded_archive), add their CODESYS components to the SBOM. The runtime is matched in NVD (scan_codesys) in the same timed NVD step as the embedded libraries, so the alerts go through the same CSAF matching, enrichment, resolve_gone and CVE-issue sync as the rest of the target's alerts. I did not call persist_control_app_sbom from the code path on purpose: its resolve_gone would have resolved the code pipeline's alerts, and the reverse would also have happened.
  • The code pipeline's SBOM replacement no longer protects codesys entries: a PLC-planned target returns before the code pipeline, so on this path they are always the code pipeline's own entries (and a target retyped away from PLC loses its stale ones).
  • Targets whose type is PLC are unchanged: they still return early on the PLC path, which collects the SBOM as before.
  • Docs: docs/guide/plc.md explains the detection and the SBOM for non-PLC targets.

Nightly baselines

None change. Every plc-* nightly target is plc_sps with a plc_project upload (the plan already has PLC, so the PLC path is unchanged). No other nightly tree contains a .projectarchive or .project (find fixtures -iname '*.projectarchive' -o -iname '*.project' only finds the two PLC upload fixtures). I did not add a "projectarchive onboarded as service" nightly target, because it needs a blessed baseline from a real nightly run (NIGHTLY_BLESS=1) and I cannot produce one locally. That is a possible follow-up.

Tests

  • classify::tests::a_managed_repo_holding_only_a_codesys_archive_is_typed_plc: a git tree with only fixtures/nightly/plc/line_control.projectarchive classifies as PlcSps, and detected_type flips a managed BackendService target to PlcSps.
  • classify::language::tests::a_committed_codesys_archive_is_plc_even_beside_a_backend_manifest, an_uploaded_codesys_archive_prior_is_plc.
  • plc::sbom::tests::the_nightly_codesys_fixture_alone_in_a_tree_yields_its_components (6 codesys components incl. the runtime), only_an_uploaded_projectarchive_is_read_as_one.
  • cargo test -p compliance-agent --lib filtered to classify and plc::sbom: 38 passed. cargo fmt --all --check and cargo clippy -p compliance-agent --all-targets -- -D warnings are clean.
  • Not run: the orchestrator end to end (it has no Mongo-backed run test). The scan_tree wiring is covered by review only.

Stage re-test

  1. Push a repository that contains only line_control.projectarchive (from fixtures/nightly/plc/) to the managed git source, so the Prüfobjekt is auto-created.
  2. Let the first scan finish. Under Stückliste (SBOM) the CODESYS components show (Standard, Util, SysSocket, CmpCodeMeter, 3SLicense, CODESYS Control for Linux SL 3.5.16.0), and Schwachstellen lists the runtime CVEs (e.g. CVE-2022-4046).
  3. The Prüfobjekt's type is now SPS / PLC. Click Prüfung starten again: the run shows the SPS-Analyse phase and the same components.
  4. Edit an existing PLC Prüfobjekt (type chosen as SPS/PLC, .projectarchive upload) and scan it. Its components and CVEs are unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

## What was wrong A managed git repository (auto-created target) whose tree is only a CODESYS `.projectarchive` was classified **Backend / API**: - the heuristic classifier knew only `.st` files as PLC evidence, so the tree gave no verdict and the classification fell back to the default type the managed target was created with; - the CODESYS library/runtime SBOM (`plc::sbom::collect_sbom`, then the NVD runtime match and CSAF matching) ran only inside the PLC path (`run_plc_scan`), which is entered only when the scan plan, built from the target type, contains the control-logic scan. So the target got no CODESYS components and no runtime CVEs. ## What changed - **Classifier** (`classify/language.rs`): a committed `*.projectarchive` or CODESYS `*.project` counts as PLC evidence (0.85, above the backend manifests' 0.55-0.6), and so does an uploaded source archive named `*.projectarchive` (kind prior, which also makes the lightweight `/detect` right). A managed target that no person typed is retyped to SPS/PLC by the existing `detected_type`, with the CRA + IEC 62443 profile, so later scans take the full PLC path. PLCopen XML is not added: the classifier did not know it before, and detecting it reliably means reading file contents. - **Code pipeline** (`orchestrator.rs`, `scan_tree`): this mirrors the firmware approach, where the code decides and not only the chosen type. Every scanned tree's `.projectarchive` files, plus an uploaded `*.projectarchive` that ingest unpacked (`plc::sbom::uploaded_archive`), add their CODESYS components to the SBOM. The runtime is matched in NVD (`scan_codesys`) in the same timed NVD step as the embedded libraries, so the alerts go through the same CSAF matching, enrichment, `resolve_gone` and CVE-issue sync as the rest of the target's alerts. I did not call `persist_control_app_sbom` from the code path on purpose: its `resolve_gone` would have resolved the code pipeline's alerts, and the reverse would also have happened. - The code pipeline's SBOM replacement no longer protects `codesys` entries: a PLC-planned target returns before the code pipeline, so on this path they are always the code pipeline's own entries (and a target retyped away from PLC loses its stale ones). - Targets whose type is PLC are unchanged: they still return early on the PLC path, which collects the SBOM as before. - Docs: `docs/guide/plc.md` explains the detection and the SBOM for non-PLC targets. ## Nightly baselines None change. Every `plc-*` nightly target is `plc_sps` with a `plc_project` upload (the plan already has PLC, so the PLC path is unchanged). No other nightly tree contains a `.projectarchive` or `.project` (`find fixtures -iname '*.projectarchive' -o -iname '*.project'` only finds the two PLC upload fixtures). I did not add a "projectarchive onboarded as service" nightly target, because it needs a blessed baseline from a real nightly run (`NIGHTLY_BLESS=1`) and I cannot produce one locally. That is a possible follow-up. ## Tests - `classify::tests::a_managed_repo_holding_only_a_codesys_archive_is_typed_plc`: a git tree with only `fixtures/nightly/plc/line_control.projectarchive` classifies as PlcSps, and `detected_type` flips a managed BackendService target to PlcSps. - `classify::language::tests::a_committed_codesys_archive_is_plc_even_beside_a_backend_manifest`, `an_uploaded_codesys_archive_prior_is_plc`. - `plc::sbom::tests::the_nightly_codesys_fixture_alone_in_a_tree_yields_its_components` (6 codesys components incl. the runtime), `only_an_uploaded_projectarchive_is_read_as_one`. - `cargo test -p compliance-agent --lib` filtered to `classify` and `plc::sbom`: 38 passed. `cargo fmt --all --check` and `cargo clippy -p compliance-agent --all-targets -- -D warnings` are clean. - Not run: the orchestrator end to end (it has no Mongo-backed run test). The scan_tree wiring is covered by review only. ## Stage re-test 1. Push a repository that contains only `line_control.projectarchive` (from `fixtures/nightly/plc/`) to the managed git source, so the Prüfobjekt is auto-created. 2. Let the first scan finish. Under **Stückliste (SBOM)** the CODESYS components show (Standard, Util, SysSocket, CmpCodeMeter, 3SLicense, *CODESYS Control for Linux SL 3.5.16.0*), and **Schwachstellen** lists the runtime CVEs (e.g. CVE-2022-4046). 3. The Prüfobjekt's type is now **SPS / PLC**. Click **Prüfung starten** again: the run shows the **SPS-Analyse** phase and the same components. 4. Edit an existing PLC Prüfobjekt (type chosen as SPS/PLC, `.projectarchive` upload) and scan it. Its components and CVEs are unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-08 21:06:01 +00:00
fix(plc): a repository holding only a CODESYS archive is a PLC project
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 11m20s
c3f9e53806
A managed git target whose tree is just a .projectarchive was classified
"Backend / API" (the classifier knew only .st as PLC evidence), and the
CODESYS library/runtime SBOM was collected only on the PLC path, so it
got no CODESYS components and no runtime CVEs.

- classifier: a committed .projectarchive or CODESYS .project, and an
  uploaded source archive named *.projectarchive, are PLC evidence
  (0.85), so a managed target is typed SPS/PLC by its code
- code pipeline: every scan tree's .projectarchive files (and an
  uploaded one, which ingest unpacks) add their CODESYS components to
  the SBOM and the runtime is matched in NVD with the other NVD lookups,
  whatever the target type; the code pipeline now owns those entries
  (a PLC-planned target never reaches it)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-08 21:26:04 +00:00
fix(plc): a committed CODESYS project types a repository PLC only on its own
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 11m10s
90bcb6e4f8
A code repository that also keeps a CODESYS project (a package.json,
pom.xml or Cargo.toml beside it) stays a code target and keeps its code
scans; its CODESYS components and runtime CVEs are collected by the code
pipeline either way. The committed-files verdict drops below the backend
manifests; a repository with nothing but the archive is still PLC.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 90c19b5a94 into main 2026-10-08 21:38:24 +00:00
Sign in to join this conversation.