Repository navigation
feat(dir): try a candidate content policy before deploying it - #2275
Conversation
Under strict enforcement a policy that rejects too much hides those records until it is fixed. DryRun evaluates an Evaluator against every indexed record and reports how many the policy would exclude and, for the first of them in CID order, why. It reads through DryRunDB, which has no method that writes, so a dry run cannot store a verdict or register a version, and so cannot change what a read returns. It selects the records under an ID no verdict is ever stored under, so every record is evaluated, including those the deployed policy of the same ID already has a verdict for. It evaluates with the policy task's batch size and per-record timeout, so a record that takes too long fails here as it would there. A record the evaluator cannot judge counts as excluded, since it would stay hidden, and is told apart in the report. When the context ends the report so far is returned with the error, and the record in hand is not counted. Refs #2264, #2205 Signed-off-by: Luca Muscariello <[email protected]>
The dry run needs a way to be run. The candidate is a file with a validators list, as in the configuration, whose entries have op evaluate, so a policy that proves good can be pasted into the configuration unchanged. It is read and checked before the node is touched, and the policies are built as the reconciler builds them. dirctl daemon policy dry-run runs it against the daemon, and reconciler dry-run in the reconciler's own image, which has the database and the registry a Helm deployment keeps. Both read the node's records from its database and its registry, so the node has to be running; they refuse to start, and say so, when nothing answers, since a record that cannot be read is not a record the policy rejects. The report lists the count, a sample and the reasons, as text or JSON (-o human|json, as the other dirctl commands), and says that nothing was stored. The runbook and the CLI reference describe it, including how to run it in a pod with the candidate on standard input. Refs #2264, #2205 Signed-off-by: Luca Muscariello <[email protected]>
…nd changes nothing Runs dirctl daemon policy dry-run against the policy suite's daemon. A candidate that rejects what the node serves reports that record, and not the one the node withholds; the policy the node already enforces reports the record the node withholds and not the one it serves, so the report can be checked against what a read does; and after both, the served record is still served, the withheld one still withheld, and search still finds the first. Running it caught that a dry run must read through the daemon's registry and not open the store directory itself, which the embedded registry owns. Closes #2264. Refs #2205 Signed-off-by: Luca Muscariello <[email protected]>
…in the dry-run tests wsl_v5 wants a blank line between a declaration and the loop that fills it, and modernize's embedlit objects to naming the embedded AuthConfig type in a struct literal, so the field is set after the literal instead. Fixes the Lint job failure on #2275. Signed-off-by: Luca Muscariello <[email protected]>
…literal modernize's embedlit objects both to naming the embedded AuthConfig type in a struct literal and to assigning its field after the literal: with Go 1.27 the promoted field is set in the literal itself. Fixes the Lint job failure on #2275. Signed-off-by: Luca Muscariello <[email protected]>
tagalign wants the mapstructure tags of consecutive fields in one column. Fixes the Lint job failure on #2275. Signed-off-by: Luca Muscariello <[email protected]>
Error assertions use require, and a cleanup that restores a variable is separated from the declaration by a blank line. Fixes the Lint job failure on #2275. Signed-off-by: Luca Muscariello <[email protected]>
…eads The dry-run suite waited until the node served the record the policy passes and took that to mean both records had their verdicts. Until the policy is enforced the node serves every record, so when this suite ran before the enforcement suite the wait returned at once and the read of the rejected record succeeded. Wait for the rejected record to be refused first. Signed-off-by: Luca Muscariello <[email protected]>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
The reconciler binary's dry-run entry point had no unit test: only the dirctl wrapper was exercised, by the E2E suite. Cover the bad-input paths, which must fail before the node is opened, the unreachable store, and a report on an empty node. Signed-off-by: Luca Muscariello <[email protected]>
|
Do we have to nest this under |
|
Kubernetes has its own command, so you don't need kubectl exec -i deploy/<reconciler> -- /reconciler dry-run --candidate /dev/stdin < candidate.yamlIt's the same dry run, started inside the reconciler pod, which already has the database and the registry. I haven't run the Kubernetes command on a real cluster yet. It uses the same code as the daemon command, which is tested end to end. |
|
It would be better to have a single command, we can add a dry-run RPC for this, that would be best IMO |
|
Agreed, a single command through a dry-run RPC is the better end state. That RPC is a new service with its own authorization and limits, so I'd rather do it in a separate PR. This PR already gives operators a working dry run now, on a local daemon and on Kubernetes. I'll open a follow-up issue for the RPC and link it here. OK to merge this one first? |
|
Follow-up filed: #2290, the dry-run RPC and a single |
|
@csirmazbendeguz I think merging the commands is a bad idea. If we do that we have to create an RPC in the server which brings only bad performance to the overall system. Offloading to clients it's the right approach as the load becomes pull based. |
|
I see. We can proceed with this for now, and do some refactoring later when we can evaluate policies efficiently... The real issue is that evaluating policies is slow. We'll need to address that later. OPA policies can be translated to SQL, which would make evaluation as simple as a SQL query. There are also SQL translators for CEL. |
Closes #2264. Part of #2205.
What this adds
Under strict enforcement, editing a policy hides every record until it is evaluated under the new rule, and a policy that wrongly rejects records hides them until it is fixed. A dry run tries a candidate policy on the node's real records before it is deployed and reports how many it would exclude, a sample of them, and why.
policy.DryRunreads throughDryRunDB, an interface with no method that writes: it cannot store a verdict or register a version, so it cannot change what a read returns. It selects records under an ID no verdict is stored under, so every record is evaluated, including those the deployed policy of the same ID already has a verdict for.ValidatorEvaluator(feat(reconciler): evaluate records against OPA and CEL policies #2266) and the policy task's batch size and per-record timeout, so a record that takes too long fails here as it would there. A record the evaluator cannot judge, or that cannot be read, counts as excluded and is marked as such, since it would stay hidden.validatorslist as in the configuration, entries withop: ["evaluate"], so a good policy can be pasted into the configuration unchanged. It is read and checked before the node is touched.reconciler/dryrun):dirctl daemon policy dry-run, andreconciler dry-runin the reconciler's own image, which has the database and the registry a Helm deployment keeps (the candidate can come on standard input withkubectl exec -i). Flags:--candidate,--policy-dir(default: the node's),--policy(one policy of the file),--samples,-o human|json.Testing
policy.DryRun: counts and the sample (in CID order, with reasons); a failure counts as excluded; nothing is stored or registered; records are selected under the dry-run ID; paging; the sample size; an empty node; the per-record timeout; interruption returns the report so far without counting the record in hand; selection errors.daemon policy,--candidateis required, an unreachable registry is refused with where it looked, a bad file is refused without touching the node.evaluateentries, accepting an empty candidate, droppingwould_excludefrom the JSON, and dropping the "nothing was stored" line each make a test fail.reconciler,cli,testsandservervet clean;reconcilerandclitests pass.Not covered
The Kubernetes path (
kubectl exec -i … /reconciler dry-run) is documented but was not run on a cluster; it shares the runner with the daemon command, which is tested end to end.