Skip to content

feat(ocsf): validate OCSF events against exported JSON Schemas - #5019

Merged
krishicks merged 2 commits into
mainfrom
feat/4596-ocsf-json-schema-validation/krishicks
Oct 29, 2026
Merged

krishicks merged 2 commits into
mainfrom
feat/4596-ocsf-json-schema-validation/krishicks

Conversation

@krishicks

Copy link
Copy Markdown
Collaborator

Summary

Replace the hand-written OCSF schema walker with validation against the JSON Schemas the OCSF schema server exports. The exports already encode required attributes, at_least_one constraints, undefined attributes, types, and enum values, so the new openshell-ocsf-validate crate only picks the schema and delegates to the jsonschema crate. This adds the enum, type, and class identifier checks #4596 asks for.

Related Issue

Closes #4596

Changes

  • New openshell-ocsf-validate crate (test-only; consumers take it as a dev-dependency). validate_event selects the schema from the event's metadata.version, class_uid, and declared metadata.profiles, and returns every violation with its JSON pointer path.
  • An exported schema covers one fixed set of profiles, so the crate vendors one export per class and profile combination OpenShell emits: schemas/v<version>/<class>@<profiles>.json (18 files for 1.8.0). An event with no vendored schema fails with the schemas/update.sh command that vendors it.
  • Keying on metadata.version lets a new OCSF version's schemas land before the emitters switch to it, then the old version's directory is deleted.
  • Top-level container is accepted unvalidated, as before (bug(ocsf): top-level container is undefined in OCSF 1.8.0 event classes #4915).
  • Builder, producer, gateway audit, and Podman e2e tests call validate_event; openshell-ocsf's validation module and its vendored per-object schemas are removed.
  • Adds jsonschema 0.58.6 (default features off). It raises num-bigint, regex-automata, and zmij in the root lockfile, so the nested testkit and conformance lockfiles are aligned.

Reviewing commit by commit separates the new crate from the switch to it.

Testing

  • openshell-ocsf-validate unit tests (written red first), openshell-ocsf, and the producer tests in openshell-supervisor-network, openshell-supervisor-process, and openshell-server pass
  • mise run pre-commit passes
  • Podman e2e ocsf_jsonl_conformance passes: real supervisor Network, HTTP, and SSH records validate against the exported schemas (run with the follow-ups from the fix(ocsf): emit schema-conformant OCSF 1.8 events #4288 review on top)
  • Unit tests added/updated
  • E2E tests added/updated

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)

Comment thread crates/openshell-ocsf-validate/src/lib.rs
@krishicks krishicks added the test:e2e Requires end-to-end coverage label Oct 28, 2026
@github-actions

Copy link
Copy Markdown

Label test:e2e applied for 16f91f1. Open the existing run and click Re-run all jobs to execute with the label set. The run will execute the standard E2E suite after building the required gateway, sandbox, and supervisor images once. The matching required CI gate status on this PR will flip green automatically once the run finishes.

@matthewgrossman matthewgrossman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary: no correctness bugs found in the new crate. Two non-blocking concerns inline.

Comment thread crates/openshell-ocsf-validate/README.md
Comment thread crates/openshell-ocsf-validate/src/lib.rs
Add openshell-ocsf-validate, which validates an OCSF event against the
JSON Schema the OCSF schema server exports for the event's version,
class, and declared profiles. The exports encode required attributes,
at_least_one constraints, undefined attributes, types, and enum values,
so the crate delegates to the jsonschema crate and only selects the
schema. The exports type type_uid only as an integer, so the crate also
checks that it equals class_uid * 100 + activity_id.

An exported schema covers one fixed set of profiles, so the crate vendors
one export per class and profile combination that OpenShell emits, under
schemas/v<version>/<class>@<profiles>.json. An event whose version or
combination has no vendored schema fails with the schemas/update.sh
command that vendors it. Keying on the event's version lets a new OCSF
version's schemas land before the emitters switch to it. The build
embeds every vendored file.

Top-level container is accepted unvalidated, as OCSF does not define it
at the event level (#4915).

Signed-off-by: Kris Hicks <khicks@nvidia.com>
Replace openshell-ocsf's hand-written schema walker with
openshell-ocsf-validate in the builder, producer, gateway audit and
Podman e2e tests. One validate_event call now covers what the
per-object validate_required_fields, validate_known_fields and
validate_enum_value calls checked, and adds type checks and enum
checks for every attribute.

Remove the validation module and the vendored OCSF object and class
schemas from openshell-ocsf. The e2e suite no longer depends on
openshell-ocsf directly.

Signed-off-by: Kris Hicks <khicks@nvidia.com>
@krishicks
krishicks force-pushed the feat/4596-ocsf-json-schema-validation/krishicks branch from 16f91f1 to a711f9a Compare October 28, 2026 23:09
@krishicks
krishicks enabled auto-merge October 28, 2026 23:15
@krishicks
krishicks added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit af6604a Oct 29, 2026
127 of 129 checks passed
@krishicks
krishicks deleted the feat/4596-ocsf-json-schema-validation/krishicks branch October 29, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:e2e Requires end-to-end coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(ocsf): validate enum ranges, scalar types, and class identifiers in schema tests

3 participants