Skip to content

feat(dir): add record metadata to evaluations - #2416

Merged
csirmazbendeguz merged 1 commit into
mainfrom
feat/record-meta
Oct 28, 2026
Merged

csirmazbendeguz merged 1 commit into
mainfrom
feat/record-meta

Conversation

@csirmazbendeguz

@csirmazbendeguz csirmazbendeguz commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2342

This PR fills RecordState.meta for evaluations.
It loads:

  • signatures
  • scan reports
  • claims

For a record, and passes the data to the CEL and OPA policies.

@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Oct 26, 2026
Base automatically changed from refactor/recordstate to main October 26, 2026 16:15
@github-actions github-actions Bot added size/L Denotes a PR that changes 1000-1999 lines and removed size/M Denotes a PR that changes 200-999 lines labels Oct 26, 2026
@github-actions github-actions Bot added size/M Denotes a PR that changes 200-999 lines and removed size/L Denotes a PR that changes 1000-1999 lines labels Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.51220% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/policy/meta.go 94.9% 6 Missing ⚠️
server/policy/facts.go 71.4% 2 Missing ⚠️
server/database/gorm/policy_facts.go 95.7% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@csirmazbendeguz
csirmazbendeguz force-pushed the feat/record-meta branch 3 times, most recently from 6792504 to 6af3d4a Compare October 27, 2026 15:08
@csirmazbendeguz
csirmazbendeguz marked this pull request as ready for review October 27, 2026 15:09
@csirmazbendeguz
csirmazbendeguz requested a review from a team as a code owner October 27, 2026 15:09

@muscariello muscariello 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.

LGTM

Comment thread server/policy/meta.go
Comment on lines +85 to +89
func scanFacts(rows []types.ScanReportObject) *policyv1.ScanFacts {
facts := &policyv1.ScanFacts{
Status: policyv1.ScanStatus_SCAN_STATUS_UNSCANNED,
MaxSeverity: securityv1.Severity_SEVERITY_UNSPECIFIED,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

meta.scan.source is never set, so an imported report is indistinguishable from a local one

scanFacts builds its ScanFacts without ever assigning Source, so meta.scan.source is FACT_SOURCE_UNSPECIFIED for every record. The field is declared in policy_input.proto and the typed CEL environment compiles it, so meta.scan.source == FactSource.FACT_SOURCE_LOCAL loads cleanly and is simply never true. A policy can't express the rule, and gets no signal that it can't.

That matters here specifically because the import path is live: autosync's syncReferrers allows ScanReportReferrerType and calls ImportReferrer, which upserts the peer's report into the same scan_reports table the local scanner writes to, with the status hardcoded to completed (server/ingest/ingest.go:147 and :174). So after a sync, meta.scan.is_safe and meta.scan.max_severity can be the publisher's own assertion about its own record, and nothing in meta says so.

This is #2342's acceptance criterion verbatim ("FactSource distinguishes an imported scan report from a local one"), and #2128 frames it as the central question for this layer — "how an evaluation policy tells an imported fact from an observed one" — with "whether FactSource is surfaced in the first increment" still listed as open.

What makes it bite now rather than before: prior to this PR state.Meta was uniformly nil and documented as a stub, so nothing in it could be trusted. After this PR everything in it can be trusted except this one field, with nothing to distinguish them.

Either resolution works, but the current in-between is the one state #2419's own reasoning rejects ("declaring them before they can be answered truthfully would compile policies that silently decide on nothing"):

  • Surface it — add a source column to scan_reports, set IMPORTED at the ingest site and LOCAL in the scan task, and project it here.
  • Defer it explicitly — if the epic's open question lands on "not this increment", then it shouldn't be reachable from a compiled expression in the meantime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yes I'm aware. We need store additional data in the database table for this, which is why I wanted to do that in a separate PR. I think it's ok to merge this and address that in a follow-up

@tkircsi

tkircsi commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Found only this issue above. Otherwise LGTM. Nice job!

@csirmazbendeguz
csirmazbendeguz added this pull request to the merge queue Oct 28, 2026
@csirmazbendeguz

Copy link
Copy Markdown
Contributor Author

Found only this issue above. Otherwise LGTM. Nice job!

I will do a follow-up PR for this. Thanks!

Merged via the queue into main with commit a39140f Oct 28, 2026
35 checks passed
@csirmazbendeguz
csirmazbendeguz deleted the feat/record-meta branch October 28, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants