Repository navigation
feat(dir): serve only records that comply with every enforced policy - #2235
Conversation
65f5bb6 to
d310adf
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
d310adf to
09a7d28
Compare
09a7d28 to
c0874fe
Compare
c0874fe to
3e7009c
Compare
It's a good default, but admins should be able to see which records are "quarantined" somehow. Same way you can also view quarantined files in Windows Defender. I was thinking of a search flag, but we may want to have a separate command for this instead e.g.
I'm not sure this is acceptable, this is quite disruptive. We could ignore the policy version here, check if the record has a positive verdict (latest policy version or not). If a policy is updated, it would take a couple minutes for it to apply but that's expected. As an admin / user, that's how I would expect it to work |
db58072 to
6b8f23d
Compare
|
@csirmazbendeguz Quarantined records: the audit API in #2253 is the view; a |
6b8f23d to
0af7426
Compare
The merge-base changed after approval.
0af7426 to
482e206
Compare
482e206 to
ddf40ac
Compare
A policy gate in the shared record query builder: for each enforced policy, a record needs an evaluated, compliant verdict at the version in force. It fails closed, requiring a positive verdict rather than excluding negative ones, so a record never evaluated, whose evaluation failed, or compliant only under a superseded version is excluded too. Applied in handleFilterOptions, which every search, catalog and resolve query passes through, so no caller-supplied filter can lift it; and in the distinct-value listings behind ListFilterValues and ListCatalogTags, which would otherwise list skills, domains and authors that only excluded records carry. The reconciler's selector of records to evaluate has its own query and stays ungated. The enforced set is supplied at construction (WithEnforcedPolicies) and read per query. Nothing supplies it yet, so behaviour is unchanged until a policy engine does. Refs #2208, #2205 Signed-off-by: Luca Muscariello <[email protected]>
ddf40ac to
68be496
Compare
Part of #2208 (first of two PRs), part of #2205. Stacked on #2229, which is stacked on #2226:
main← #2226 ← #2229 ← this. Based onfeat/policy-evaluation-task; each PR retargets tomainas the one below it merges.What this adds
A policy gate in the database read path. For each enforced policy, a record needs an evaluated, compliant verdict at the version in force to be returned.
statusandcompliant, astypes.EvaluatedPolicyStatusesrequires of every read-path filter, rather than relying onUpsertPolicyEvaluationclearingcomplianton failed rows.handleFilterOptions, which every search, catalog and resolve query passes through (GetRecords,GetRecordCIDs,CountRecords,GetCatalogEntries,CountCatalogEntries), so no caller can forget it and no caller-supplied filter can lift it — asking for an excluded record by CID or by name returns nothing.ListFilterValuesandListCatalogTagsread the skill, domain, module and author values directly; they're gated as well, or they'd list values that only excluded records carry.GetRecordsNeedingPolicyEvaluationhas its own query and stays ungated. If it were gated, a record with no verdict would never be evaluated, and so never served.The enforced set is supplied at construction with
WithEnforcedPolicies(func() []types.EnforcedPolicy)and read per query. Nothing supplies it yet, so behaviour is unchanged until a policy engine does — the same source should build both the reconciler's evaluators (#2229) and this set, so the two can't disagree about which policies exist.Deviation from the issue text
#2208 suggests a
NOT EXISTSagainst the verdict table, shaped likeapplyExcludedScanSeverities. That excludes records with a non-compliant row and lets records with no row through — fail-open, contradicting #2205's rule that "no verdict yet" must mean excluded. This usesEXISTSof a compliant row per enforced policy instead. The mutation check below confirms theNOT EXISTSshape fails the fail-closed tests.Consequences worth knowing
Not in this PR
Pull,LookupandPullReferrer. They read the OCI store by CID, not the database, so they need their own per-record check. That's the second Make exclusion of non-compliant records unconditional on every read path #2208 PR.Testing
8 tests in
policy_gate_test.go: nothing enforced changes nothing (no gate, and an empty set); only a current compliant verdict is served (non-compliant, no verdict, failed-but-marked-compliant, and stale-version records excluded); every enforced policy must pass; verdicts of unenforced policies don't count; no filter can lift the gate; the enforced set is read per query; the reconciler's selector still sees unevaluated records; and every read — records, count, catalog entries, catalog count, filter values (skills and authors), catalog tags — is gated, with an ungated pass first so the gated counts are provably not vacuous.Mutation-checked, each mutant compiling: the issue's
NOT EXISTSshape, a vacuous status check, a vacuous version check, and removing the gate fromhandleFilterOptions,distinctColumnordistinctAuthorseach make at least one test fail. Fullserversuite passes;go vetandgofmtclean.