Repository navigation
feat(dir): enforce content policies per kind of read, with a shadow mode - #2248
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…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]>
|
If I understand correctly the issue is that updating a policy may accidentally hide everything. So before updating a policy, admins can switch to shadow mode, update the policy, check the logs, and if everything is ok, switch back? I wonder if there's a better way to add a safety rail or if a safety rail is really necessary here at all... How about having a command for checking what records a policy would effect? That way users can check pre-emptively before applying any policies |
b1aec6d to
eb43adf
Compare
|
@csirmazbendeguz Shadow mode works but lifts enforcement for the whole edit. Edits are enforced at once instead, so the safeguard is review and a trial on a node that doesn't serve users. |
eb43adf to
cc24c4e
Compare
|
I'm not sure "shadow mode" is necessary to be honest Personally I wouldn't use this feature as an admin just to test out some policy changes If I was a node admin I would rather have some kind of way to check that the policy I'm about to deploy will affect anything - a dry run, to make sure it behaves correctly in advance That was just my opinion as I was thinking about how I would use this. I'm not super against it though and so if you think it would be useful to you then we can merge it |
|
@csirmazbendeguz Shadow mode is stage 1 of the rollout in #2209 (a metric telling "would exclude" from "excluded"), so I'd keep it. A dry run of a candidate policy before it's deployed is a good addition, and a better answer for edits. It needs an evaluator to run against the records, so I'd track it as a follow-up: #2264. |
cc24c4e to
dc9b211
Compare
dc9b211 to
cc8660f
Compare
The merge-base changed after approval.
cc8660f to
7831e98
Compare
7831e98 to
bb29989
Compare
Nothing supplied the enforced policies to the read gate, so it could not be turned on. policy.enforcement now lists them, each at the version in force, and gives each kind of read its own mode, so enforcement can be rolled out one kind at a time: - search: search, the catalog, filter values, publication by query; - fetch: pull, lookup, referrers, export, the peer RPC, publication of explicit CIDs, verification lookups. A mode is off, shadow or enforce. Shadow checks each fetch but serves every record, even when the check itself fails; searches in shadow mode are not filtered. Both modes default to off. The server's APIs read through a view of the database that applies the enforcement. The database itself applies none: ingestion and the reconciler, which in daemon mode shares the server's database, read through it and must see every record. A database that cannot enforce the policies stops the server from starting rather than serving unchecked records, and enforcing without authz logs a warning, since registry credentials then let any caller read excluded records. Refs #2209 Signed-off-by: Luca Muscariello <[email protected]>
Shadow mode is only useful if it tells what enforcing would hide. With a metrics server, the gate now reports: - dir_policy_gate_search_records_excluded, a gauge of the indexed records searches exclude, counted at each scrape; - dir_policy_gate_fetches_excluded_total, a counter of reads by CID the policies refused. Both carry outcome="would_exclude" in shadow mode and outcome="excluded" when enforcing. The gauge is absent while searches check nothing, and when it cannot be counted, rather than failing the whole scrape. Refs #2209 Signed-off-by: Luca Muscariello <[email protected]>
Adding the served view pushed server.New's maintainability index to 19, below maintidx's floor of 20. Opening the database and building the view the APIs read through now happen in openDatabase, leaving New with one branch where it had two. Refs #2209 Signed-off-by: Luca Muscariello <[email protected]>
openDatabase is the path every deployed server takes: nothing hands it a database, so it opens the configured one. The tests only ever handed one in. They now open a configured SQLite database and check that the APIs get a separate gated view, that a database handed in is used as is, and that an unknown database type fails. Refs #2209 Signed-off-by: Luca Muscariello <[email protected]>
Enforced policies were listed with a version, which an admin had to copy from the evaluator into the server's config after every change to a policy. A version derived from a policy's content cannot be kept up by hand, and getting the order wrong hides records one by one as they are re-evaluated. policy.enforcement.policies now lists policy IDs only. The server follows the version the reconciler registers for each, rechecking every policy.enforcement.refresh_interval (default 30s), and enforces it strictly: a verdict under any other version does not count. After a policy is edited, a record stays hidden until it has been evaluated under the new rule, so nothing the new rule rejects is served while that happens. A policy no evaluator has registered is not enforced yet and is logged once. The IDs can be set from the environment as a comma-separated list. Refs #2209 Signed-off-by: Luca Muscariello <[email protected]>
bb29989 to
1a1fcdf
Compare
Part of #2209 (first PR: stages 1 and 3, and the metric). Part of #2205. Stacked on #2246:
main← #2226 ← #2229 ← #2235 ← #2237 ← #2238 ← #2241 ← #2246 ← this.Why
The read gate from #2208 had no way to be turned on: nothing supplied the enforced policies. #2209 asks for a staged rollout, so turning it on starts with seeing what it would hide.
What this adds
policy.enforcementconfig. Lists the enforced policy IDs and gives each kind of read its own mode,off(default),shadoworenforce:search: search, the catalog, filter values, publication by query or of every record.fetch: pull, lookup, referrers, export, the peer RPC, publication of explicit CIDs, identity status lookups.refresh_interval(default 30s) and enforces the current version strictly: a verdict under any other version does not count. After a policy is edited, a record stays hidden until it has been evaluated under the new rule, so nothing the new rule rejects is served meanwhile; content already delivered cannot be recalled. A policy no evaluator has registered is not enforced and is logged once.outcome="would_exclude"in shadow mode andoutcome="excluded"when enforcing:dir_policy_gate_search_records_excluded: a gauge of indexed records searches exclude, counted at each scrape. It is left out, not failed, if the count errors.dir_policy_gate_fetches_excluded_total: a counter of reads by CID the policies refused.Rest of #2209
Testing
CountRecordsExcludedcounts non-compliant and unevaluated records.server,reconciler,cliandtestsvet clean. The affected server packages andcli/cmd/daemonpass withCGO_ENABLED=0, which avoids the local SDK link failure. The first commit builds and passes on its own.