Skip to content

refactor(server): add OperationInput for operation policies - #2419

Merged
tkircsi merged 3 commits into
mainfrom
feat/operation-input
Oct 27, 2026
Merged

tkircsi merged 3 commits into
mainfrom
feat/operation-input

Conversation

@tkircsi

@tkircsi tkircsi commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

The counterpart of #2400. An operation policy received only the record's struct, so it could ask nothing about the operation it was deciding, and both layers compiled against the same CEL environment, so an operation policy could name meta and read it as empty rather than be told it cannot have it.

ValidateOperation now takes an OperationInput. Decide builds it once per decision, so every policy deciding one operation reads the same now, which is what the field is for.

CEL compiles against one of two environments, chosen by the block the policy was configured in. An evaluation keeps record, record_cid, indexed_at and meta; an operation gets record, record_cid, context and now. Because the environment is chosen when the policy is loaded, an operation policy naming meta or indexed_at fails at startup rather than deciding on an empty value once per record. That is why the layer travels from the config block down to the provider.

OPA is given the same values as a nested input document, so input.record.name means the same thing in both layers. This replaces the flat document an operation policy got before, where the record's fields sat at the document root. No .rego file ships in the repo or the charts, so no policy needed migrating. Two differences follow from the document being JSON: an enum arrives as its name, so the comparison is input.context.operation == "OPERATION_PUSH", and an unset source_peer_id is absent rather than empty.

verdicts and indexed_at are declared in neither the operation environment nor its Rego document, because reaching either needs a database read that Decide does not have, and declaring them before they can be answered truthfully would compile policies that silently decide on nothing. They arrive with the verdict read in #2344, which is also what populates context.source_peer_id: the proto reserves it for autosync, nothing sets it yet, so a policy reads it as absent at every operation.

Existing CEL policies are unaffected: record and record_cid read as they did, and the e2e policy suite's expressions are evaluation policies. The records validation documentation gains a section on what a policy can read, and the Helm values, daemon configuration and server README no longer say the record is the only thing bound.

Refs #2341

@tkircsi tkircsi self-assigned this Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped⏩ skipped✅ passedOct 27, 2026, 2:01 PM

@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Oct 27, 2026
@tkircsi tkircsi added kind/refactor Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed size/M Denotes a PR that changes 200-999 lines labels Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.75000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/policy/opa.go 94.1% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Oct 27, 2026
@tkircsi
tkircsi marked this pull request as ready for review October 27, 2026 14:01
@tkircsi
tkircsi requested a review from a team as a code owner October 27, 2026 14:01
@tkircsi
tkircsi added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 8b72770 Oct 27, 2026
38 checks passed
@tkircsi
tkircsi deleted the feat/operation-input branch October 27, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dir/server kind/refactor Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants