Repository navigation
feat(reconciler): evaluate records against content policies - #2229
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
2fc9c9f to
23fe646
Compare
23fe646 to
740d835
Compare
740d835 to
f24b639
Compare
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section. Signed-off-by: Luca Muscariello <[email protected]>
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section. Signed-off-by: Luca Muscariello <[email protected]>
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section. Signed-off-by: Luca Muscariello <[email protected]>
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section. Signed-off-by: Luca Muscariello <[email protected]>
…eers Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section. Signed-off-by: Luca Muscariello <[email protected]>
…cement-modes Brings in main's #2204, which rewrote the policy config this branch extends and moved its OPA directory into the reconciler's policy section, and the policy_evaluation rename from #2229. The policy config keeps main's struct, without enabled or Validate, plus this branch's enforcement settings; its test file, which main deleted, keeps only the enforcement tests. # Conflicts: # cli/cmd/daemon/daemon.config.yaml # install/charts/dir/apiserver/values.yaml # install/docker/reconciler.env # reconciler/config/config.go # reconciler/config/config_test.go # reconciler/service/service.go # server/config/config_test.go # server/database/gorm/gorm.go # server/database/gorm/policy_gate.go # server/database/gorm/policy_gate_test.go # server/policy/config/config.go # server/policy/config/config_test.go # server/server.go # server/types/database.go
…ment-backfill Brings in main's #2204, the policy_evaluation rename from #2229, and #2248's merge of both. The policy config keeps main's struct plus this branch's refresh interval and previous_version. Signed-off-by: Luca Muscariello <[email protected]>
…t-bypass Brings in main's #2204, the policy_evaluation rename from #2229, and the merges below. The runbook now names the evaluation task's Helm key, reconciler.config.policy_evaluation. Signed-off-by: Luca Muscariello <[email protected]>
|
It's important to have a job like this, but The ideal solution would be to evaluate policies on events. I'm not saying we have to evaluate them synchronously. A record's event could trigger a background job (that would evaluate that single record) Of course, we would still need this scheduled job for picking up missed records, so "evaluate on events" doesn't replace this I haven't seen this pattern in this project before, but it would be worth implementing so we can handle use-cases like this For now, the simplest solution would be to limit the number of records |
125a2b5 to
6d40c70
Compare
|
@csirmazbendeguz Paged now. I kept a run going until no record is left instead of capping it: after an edit records stay hidden until evaluated, so throttling would lengthen that. Evaluating on record events would be a good follow-up: #2270. |
6d40c70 to
07c34fb
Compare
The merge-base changed after approval.
07c34fb to
a979e8f
Compare
a979e8f to
5c27ce6
Compare
A policy reconciler task that, for each registered Evaluator, selects the records without a current verdict (never evaluated, evaluated under a superseded version, or last evaluation failed) and stores one. Records that predate a policy are selected the same way as new ones, so backfill needs no separate pass; the per-run count logged for each policy is its progress signal. Evaluator is the port concrete policy engines implement (OPA, OASF schema validation; #2135, #2157). An evaluator error is stored as a failed evaluation, which reads as non-compliant, with a fixed reason rather than the error's text, which can carry internal hosts or paths. A shutdown stores nothing: the evaluator only reports the cancellation, which is not a verdict about the record. Not registered in the reconciler service yet: no Evaluator exists to give it. Wiring lands with the first one. Refs #2207, #2205 Signed-off-by: Luca Muscariello <[email protected]>
The policy task's interval and per-record timeout existed only as the Default constants in its config package: nothing an operator controls could change them. Exposes them the way every other reconciler task's parameters are exposed: - reconciler config: a policy block, with env bindings (RECONCILER_POLICY_*) whose defaults are the task's constants, so the values live in one place; - the daemon config, the Helm reconciler config, and the docker env file, next to the other tasks. policy.enabled is off by default. With no policy evaluator implemented yet, enabling it registers the task disabled and logs why, rather than the setting being silently ignored. Refs #2207 Signed-off-by: Luca Muscariello <[email protected]>
files are loaded from, the same one the server has, and the chart fills it from config.policy. Rebased onto it, this branch declared a second Policy field and policy import for the evaluation task's settings, and the reconciler stopped compiling. The task's settings move to policy_evaluation: RECONCILER_POLICY_EVALUATION_* in the environment, reconciler.config.policy_evaluation in Helm, and reconciler.policy_evaluation in the daemon configuration. Refs #2207 Signed-off-by: Luca Muscariello <[email protected]>
A run fetched every record needing a verdict in one query, which for a first run is the whole records table, and held them all while it evaluated them one by one. The task now fetches and evaluates policy_evaluation.batch_size records at a time (default 500), each batch starting after the last record of the one before, until none is left. The batch size bounds a run's memory, not its length: after a policy changes, records stay hidden until re-evaluated, so evaluation is not throttled. A record whose evaluation failed is selected again by the next run, not by the next batch of the same run, so it cannot keep a run going. The task also registers the version of each policy it runs, at the start of every run, before evaluating any record. The server follows the policy's current version from that registry, so a policy edited on disk is picked up without anyone stating its new version. The batch size is a setting in the environment, Helm, the daemon configuration and the docker env, like the task's other parameters. Refs #2207 Signed-off-by: Luca Muscariello <[email protected]>
5c27ce6 to
bcca0ae
Compare
Closes #2207. Part of #2205. Stacked on #2226 — based on
feat/policy-evaluation-schema, so this diff shows only the task; it retargets tomainonce #2226 merges.What this adds
A
policyreconciler task. For each registeredEvaluator, it registers the version of the policy it runs, then selects the records without a current verdict — never evaluated, evaluated under a superseded policy version, or whose last evaluation failed — and stores one viaUpsertPolicyEvaluation, a batch at a time.batch_sizeat a time (default 500), each batch starting after the last record of the one before, until none is left. The batch size bounds what a run holds in memory, not how long it lasts: after a policy changes, records stay hidden until evaluated, so evaluation is not throttled. A record whose evaluation failed is selected again by the next run, not by the next batch of the same run.GetRecordsNeedingPolicyEvaluationexactly like new ones. The per-policy count logged each run is the progress signal: it falls to zero once every record has a verdict under the current version.Evaluatoris a port, not an engine:PolicyID(),PolicyVersion(),Evaluate(ctx, record). Concrete implementations (OPA, OASF schema validation) come from [Feature]: OPA-based content policy engine #2135 and [Feature]: Add validators #2157.NewTaskrejects nil evaluators, empty IDs or versions, and duplicate policy IDs, which would overwrite each other's rows.failedevaluation, which reads as non-compliant. The stored reason is a fixed string, not the error's text — evaluator errors can carry internal hosts or file paths, and the row is queryable. The detail goes to the log.Configuration
The task's parameters,
interval(default 1m),record_timeout(default 30s) andbatch_size(default 500), are exposed the way every other reconciler task's are: apolicy_evaluationblock in the reconciler config (policyis the policy directory), bound toRECONCILER_POLICY_EVALUATION_*with defaults taken from the task's own constants so the values live in one place, and entries in the daemon config, the Helm reconciler config and the docker env file.policy_evaluation.enabledis off by default. NoEvaluatoris implemented yet, so enabling it registers the task disabled and logs why, rather than the setting being silently ignored. Evaluators are passed in when the first one lands.Change to #2226
Designing the retry path surfaced a bug in #2226's query, fixed on that branch rather than here:
GetRecordsNeedingPolicyEvaluationtreated a failed row as settled, so one transient evaluator error excluded a record from reads until the policy version next changed. Only anevaluatedrow now suppresses re-selection.Not in this PR
Testing
Tests in
reconciler/tasks/policy, race-clean: evaluator validation,IsEnabled, verdict storage (including a compliant verdict's reason being dropped), fail-closed on evaluator error without persisting its text, record timeout as a failed verdict, shutdown storing nothing (also between batches), a policy's selection error not stopping the others, a store error not stopping the run, the version snapshot, the empty case, batching in record order, a failing record not keeping a run going, the default batch size, and the version being registered first (and a failed registration stopping the policy).The shutdown guard and the no-leak reason were mutation-checked: removing either makes its test fail. Plus two tests on #2226 for the retry fix, also mutation-checked.
go vetandgofmtclean; fullreconcilermodule passes under-race.