Skip to content

Create rust implementation of the scan result enrichment with library and cli #28

Closed

Description

@daniel-grnbn

Implement the enrichment of scan-results with the data from vt-metadata.json and notus metadata in rust:

Implemented status

Implemented and merged in PR #36:

  • Rust crate/workspace plus scan-enrich-results CLI
  • Python integration with engine selection (auto, python, rust)
  • Rust as the default path when the binary is available
  • Python retained as an explicit reference/fallback path
  • VT metadata enrichment, Notus advisory/product merge behavior, and optional SCAP/NVD CVE enrichment
  • Existing e2e path updated to use the Rust engine under the hood
  • Rust/Python parity fixtures and tests

Remaining gap vs original issue wording

Not yet implemented:

  • a fully streaming / full-result memory-conscious pipeline for very large raw scan-results payloads
  • a dedicated large-input benchmark or scale-validation path

Current implementation selectively loads feed metadata by OID/CVE, but still loads the scan-results JSON payload into memory before enrichment.

Activity

  1. clawosiris commented on May 14, 2026

    @clawosiris
    Owner

    I reviewed this and I think the right plan is to optimize for streaming + selective lookup first, then add a persistent cache only if benchmarks show repeated feed scans are still too expensive.

    Recommended implementation plan

    1) Rust library first, CLI on top, Python calls the CLI as a subprocess

    I would make the Rust crate the source of truth and keep the Python integration thin at first:

    • scan_enrichment_core (library)
    • scan-enrich-results (CLI)
    • optional Python bindings later if subprocess overhead actually matters

    That keeps the boundary simple and avoids dragging PyO3/maturin complexity into the first version.

    2) Use a two-pass streaming pipeline for very large result sets

    For 500k+ results, we should avoid loading the full scan-results JSON into memory.

    Recommended CLI flow:

    1. Pass 1: stream the input results JSON and collect only the unique OIDs into a HashSet<String>
    2. scan vt-metadata.json and Notus .notus files and build a matched-only in-memory map for just those OIDs
    3. Pass 2: stream the results again and write enriched JSON incrementally

    Why this is a good default:

    • memory scales with unique OIDs, not total result count
    • output can be written incrementally with a buffered writer
    • we avoid holding 500k enriched result objects in RAM
    • for many real scans, repeated OIDs should be far smaller than result count

    Metadata mapping strategy

    Default path: selective in-memory map

    For one-shot runs, I would not build a full in-memory index of all metadata by default.
    Instead:

    • parse the result set once to find the required OIDs
    • scan vt-metadata.json sequentially and keep only entries whose OIDs are in the requested set
    • scan Notus advisory files and keep only advisory entries whose OIDs are in the requested set

    This should drastically reduce memory usage versus loading all NASL metadata and all Notus metadata up front.

    Persistent cache path: add an embedded DB only for repeated runs

    If we expect repeated enrichment runs against the same feed data, then a persistent local cache makes sense.

    My recommendation would be:

    • SQLite first, not RocksDB/sled/LMDB on day 1

    Reasoning:

    • embedded, no service to run
    • mature and boring in the good way
    • simple key/value access by OID is easy
    • straightforward cache invalidation and feed-version tracking
    • easier to inspect/debug than a custom binary index format

    Suggested schema idea:

    • metadata(oid TEXT, source TEXT, feed_version TEXT, payload_json BLOB, PRIMARY KEY (oid, source, feed_version))
    • source = 'vt' | 'notus'
    • feed_version derived from feed fingerprint / sha256sums / mtime+size digest

    Then the enrichment flow becomes:

    1. collect unique OIDs from results
    2. look up only those OIDs in SQLite
    3. if cache missing/stale, rebuild or refill from the feed files
    4. stream output

    Memory usage guidance

    Things to avoid

    • loading all scan results into a Vec<Value>
    • loading the whole vt-metadata.json into a giant HashMap unless we actually need most of it
    • building a full Notus global index in RAM by default
    • cloning large JSON blobs unnecessarily

    Things to do

    • use serde_json::Deserializer for streaming input
    • stream output with BufWriter
    • keep only:
      • unique OID set
      • matched metadata entries for those OIDs
      • tiny counters / summary state
    • store metadata payloads in compact structs, not generic Value, where practical
    • if we do persistent caching, store raw JSON payloads or compact normalized structs keyed by OID

    Practical phased plan

    Phase 1: working Rust CLI + library

    Phase 2: benchmark and profile

    Measure:

    • wall-clock time for 10k / 100k / 500k results
    • peak RSS
    • time spent in:
      • result parsing
      • VT metadata scan
      • Notus advisory scan
      • JSON output writing

    Phase 3: add optional persistent cache if needed

    If feed rescans dominate repeated runs:

    • add --cache-dir / default cache path
    • build SQLite-backed OID cache keyed by feed fingerprint
    • warm cache from feed files once, reuse across runs

    My bias on the DB question

    I would not start with embedded NoSQL.

    For this use case, the priority is:

    1. predictable memory usage
    2. simple deployment
    3. easy debugging
    4. good enough lookup performance

    That usually points to:

    • first: streaming + selective in-memory matching
    • second: SQLite cache if repeated runs need it
    • later only if proven necessary: RocksDB/LMDB/custom binary index

    Acceptance criteria I’d add

    • can process 500k+ results without loading the entire result set into memory
    • supports both NASL vt-metadata.json and Notus .notus advisory enrichment
    • produces the same output shape described in Restructure enriched json to maintain structure of scan results #22
    • has benchmarks or at least documented measurements for large result sets
    • optional persistent cache is keyed to feed version/fingerprint so stale metadata is not reused

    If helpful, I can turn this into a concrete task breakdown (crate layout, interfaces, benchmark harness, cache schema, and CLI contract).

  2. clawosiris commented on May 14, 2026

    @clawosiris
    Owner

    Updated the issue description to reflect what PR #36 actually implemented: Rust library/CLI + Python subprocess integration + default Rust path + parity tests. Also documented the remaining gap: selective feed lookup landed, but full streaming / large-input benchmarking did not.

  3. clawosiris commented on May 14, 2026

    @clawosiris
    Owner

    Reviewed again after the follow-up workflow/doc merges (including PR #40).

    Conclusion: leave this issue open.

    The Rust library/CLI, Python subprocess integration, default Rust path, Notus support, SCAP expansion, parity tests, and CI coverage are all in place.

    However, the remaining gap documented in the issue still stands:

    • the implementation still loads the raw scan-results JSON payload into memory before enrichment
    • there is still no dedicated large-input benchmark / scale-validation path for the 500k+ result target from the original issue wording

    So this is substantially implemented, but not fully done relative to the original large-scale streaming requirement.

  4. added a commit that references this issue on May 16, 2026
    ba59178
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions