Repository navigation
fix(cli): route policy commands to the bundle each action's scope binds - #1311
Conversation
policy validate/test/explain matched every bundle bound to graph.<id> or cluster and refused when both matched, which is the layout the policy guide documents. A cluster bundle was also compiled as a graph bundle, and graph_list/config_manage were evaluated against the graph bundle. Select bundles per scope the way serving does: graph actions from the --graph bundle, graph_list and config_manage from the cluster bundle, each compiled as its own kind, with no fallback between scopes. Closes ModernRelay#761
ragnorc
left a comment
There was a problem hiding this comment.
Review of #1311 at 605f715a
Why. omnigraph policy validate|test|explain refused the layout that the docs tell users to apply: one bundle bound to a graph and one bundle bound to cluster (#761). A cluster with only a cluster bundle also failed, and explain --action graph-list asked the wrong bundle.
What and how. The CLI now selects at most one bundle for each scope, as serving does. A graph action uses the bundle bound to --graph. graph_list and config_manage use the cluster bundle, which is now compiled as a cluster bundle. When a scope has no bundle, the command refuses and names that scope. The other scope's bundle never answers.
Impact. The policy commands now work on a normal cluster. policy validate prints one line for each applied bundle.
Outcome: no blocking defects. I compared the routing with serving (crates/omnigraph-server/src/settings.rs:150-184) and with config validation, which already refuses a bundle that mixes binding kinds (policy_mixed_binding_kinds) and two bundles for one scope (duplicate_policy_binding, crates/omnigraph-cluster/src/config.rs). They agree. The new regression test fails on main for the predicted reason and passes at this head (see Validation). One design change is recommended (R1). The other items are optional.
Recommended (R1): the cause of #761 is still present
The cause of #761 is a copied rule. The CLI had its own copy of "applied bindings → one bundle per scope, compiled as its kind", and that copy drifted from serving. This PR replaces the wrong copy with a correct one. The rule now exists in three places:
- server:
crates/omnigraph-server/src/settings.rs:150-184. It fills one slot per graph and oneclusterslot, then removesgraph.og_cataloginto a separate catalogue slot (line 184); - cluster deployment authorization:
crates/omnigraph-cluster/src/authorization.rs:261-292. It compiles one engine per binding; - CLI:
PolicyBundles::select(crates/omnigraph-cli/src/commands/control/mod.rs:239-310, this PR).
The rule "which bundle kind answers an action" also exists twice: scope_of (control/mod.rs:227) and validate_kind_alignment (crates/omnigraph-policy/src/lib.rs:716-726, where a cluster engine admits Cluster and Server actions).
The copies already differ. Serving does not count the catalogue binding as a graph bundle. The CLI without --graph counts every graph.* binding (control/mod.rs:271). A probe at this head, with a graph bundle, a cluster bundle and an og_catalog bundle applied:
$ omnigraph policy validate --target <cluster>
cluster `<cluster>` has 2 graph policy bundles ([catalogue-access, graph-access]); pass --graph <id> to select one
Serving finds one graph bundle in this layout. Main also refuses it (with "has 3 policy bundles"), so this is not a regression. It shows that the copies drift.
Proposal: make omnigraph-cluster, which owns ServingPolicy, the single owner. Add one function that routes &[ServingPolicy] into { cluster, catalogue, graphs: BTreeMap<graph id, bundle> } and refuses duplicate or unknown bindings. Use it in settings.rs, authorization.rs and this command. Also move the action-to-engine-kind mapping into omnigraph-policy (for example PolicyAction::engine_kind()), and use it in validate_kind_alignment and in the CLI.
- Cost: one small public type, and about 40 lines moved from each caller.
- Removes: two copies that can drift.
- After five more changes of this kind, each change edits one place. Likely changes are stacked bundles per scope (the comment at
settings.rs:151calls them "a later slice") or a new scope kind. Today each one needs three edits that agree.
If this is too large for this PR, please open a follow-up issue. Also change the PolicyBundles doc comment so it says it is a copy of serving's routing, not only that it routes "the way serving routes them".
Optional
- O1. One header for test failures. When both groups fail, the error repeats its header, because each
run_testscall adds one and the loop joins them (control/mod.rs:104-120). Probe at this head:Collect the case lines from both groups and print one header.policy tests failed: andrew-reads: expected Allow but got deny policy tests failed: bruno-lists: expected Allow but got deny - O2. One fixture builder.
converged_policy_cluster(tests/support/mod.rs:832) repeats thecluster.yamltemplate and setup ofconverged_loaded_cluster(tests/support/mod.rs:788).docs/dev/testing.mdasks to extend the existing fixture. One builder with an optional graph bundle, an optionalclusterbundle and an optional seed would keep one copy of the template. - O3. Coverage. The test covers "no
--graph" only for the cluster-only layout. Onevalidatecall without--graphon the two-bundle layout would cover the main documented case on that path.
Checked and found correct
PolicyTestConfig::loadstill refuses a test file withversionother than 1 before the cases are split, so a file with no cases cannot skip that check (probe:version: 2,cases: []→policy test version must be 1).- Failure lines carry the case
id, so splitting the cases does not renumber them. - The graph-id label used without
--graph("default") only names the Cedar resource entity. It does not change decisions, and the behavior is unchanged from main. - Context: #1175 adds
maintainandreclaimas graph-scoped actions.scope_ofsends them to the graph bundle with no change. Because the match overPolicyResourceKindis exhaustive, a new resource kind will fail to compile here. That is the correct failure mode.
Tradeoffs and liability
The PR removes a wrong rule and adds no public API, state or storage effect. Lance is not involved. It adds about 125 net lines to the CLI. Most of these are the third copy of the binding routing (R1), and that copy is the main long-term cost.
Validation
Clean detached worktree at 605f715a (base ead05c40 = current main).
- Regression proof:
cargo dev-nextest -E 'package(omnigraph-cli) & (test(/issue_761/) | test(/^cli_data::policy_/))'- at
605f715a: 4 passed; - with
crates/omnigraph-cli/src/commands/control/mod.rsfromead05c40(tests from the head):policy_commands_route_each_action_to_its_bound_bundle_issue_761failed withgraph `knowledge` in cluster … matches 2 policy bundles ([graph-access, server-access]), which is the predicted reason; the other 3 passed. The file was then restored.
- at
cargo dev-nextest --no-fail-fast -E 'package(omnigraph-policy) | (package(omnigraph-cli) & (kind(lib) | kind(bin) | test(/policy/)))': 409 passed, 9 failed. All 9 failures are server-backed tests (system_local::local_cli_*_policy,system_remote::remote_policy_enforces_branch_first_cli_workflow,cli_data::a_policy_refused_served_load_reports_not_started). They failed with "server did not become ready or report its bound address" on this sandbox, also when run one at a time. None of them call thepolicycommands.Test Workspacepassed at this exact head in CI.- CLI probes at
605f715afor O1, the catalogue case in R1, and the test-file version check (temporary clusters under/tmp, removed). cargo fmt --all --check,git diff --check,scripts/check-agents-md.sh: clean. I did not runscripts/check-docs.py(this host lacks the pinned docs environment). CI reports it green.- CI at
605f715a: 26 passed, 4 skipped, 1 pending (Storage Upgrade Compatibility). - Not run: clippy, GQT, DST, the full workspace graph. This PR does not change GQT-expressible behavior, so a CLI integration test is the correct owner for the regression.
|
I merged
|
|
I merged
|
|
I merged
|
Summary
omnigraph policy validate|test|explainnow pick a bundle per scope the way a server does. Graph actions are answered by the bundle bound to--graph <id>.graph_listandconfig_manageare answered by the bundle bound tocluster, compiled as a cluster bundle. Neither scope falls back to the other.Closes #761
Reproduction
On main
2e7921c4(and unchanged atead05c40), with the layoutdocs/user/operations/policy.mddocuments (graph-access→[knowledge],server-access→[cluster]), every policy command refused:The new test
cli_data::policy_commands_route_each_action_to_its_bound_bundle_issue_761fails on main with that error and passes with this change. It also covers the other two defects from the issue: a cluster whose only bundle is theclusterone (validated as a graph bundle on main, soconfig_managewas refused), andexplain --action graph-list/config-manage(evaluated against the graph bundle on main, so the answer could never beallow).Root cause
select_cluster_policyincrates/omnigraph-cli/src/commands/control/mod.rsmatched every bundle bound tograph.<id>orcluster, required exactly one, and always compiled it withPolicyEngine::load_graph_from_source. Serving (crates/omnigraph-server/src/settings.rs) routes bindings to one slot per graph plus oneclusterslot and loads the cluster slot withload_cluster_from_source. The CLI had drifted from that model.Change
PolicyBundles::selectresolves at most one graph-bound bundle (by--graph, or the sole graph-bound bundle without it) and at most oneclusterbundle. Two bundles for one scope stay a loud error, as serving refuses them.explainroutes byPolicyAction::resource_kind():Graph→ graph bundle;Server/Cluster→ cluster bundle.testpartitions cases the same way and runs each group against its bundle; failures from both groups are reported together.validatechecks each applied bundle of the selection as its own kind and prints onepolicy valid:line per bundle. It refuses only when neither scope has a bundle.no policy bundle bound to graph …/no policy bundle bound to the cluster scope), never answered by the other bundle.Docs:
docs/user/operations/policy.md(Validate and test) states the routing. Skill:references/server-policy.mdreplaces the "matches 2 policy bundles" limitation with the routing rule, and the matching row leaves theSKILL.mdgotchas table. Release note:changelog.d/policy-commands-route-by-scope.fixed.md;docs/releases/v0.15.0.mdregenerated.Decisions and alternatives
--scopeflag: the action already determines which bundle a server consults, so a flag would only let the user pick a wrong answer.--graph, keep the existing rule (the sole graph-bound bundle, else ask for--graph) instead of validating every graph's bundle; that would change output for multi-graph clusters and is not needed for this defect.Evidence
cargo dev-nextest -E 'package(omnigraph-cli) | package(omnigraph-policy) | (binary(=integration) & test(/policy/))'(withRUST_MIN_STACK=16777216as CI sets it): 829 of 830 pass. The one failure,cli_cluster::managed_lifecycle_capture_and_retry_records_refuse_symlinks_without_reading_targets(exit 1 instead of 2 on a symlinkedcluster pushsource), is in managedcluster pushcode this change does not touch; the local box runs tests as root. CI on this PR is the reference for it.cargo dev-clippy,cargo fmt --all --check,scripts/check-agents-md.sh,scripts/check-docs.py: clean.Tests added
cli_data::policy_commands_route_each_action_to_its_bound_bundle_issue_761, with aconverged_policy_clusterfixture intests/supportthat applies a graph bundle, a cluster bundle, or both.Risks and not verified
policy validategains a second line when a cluster bundle is applied. Scripts that read only the first line still see the graph bundle first.omnigraph-cli, which is the only crate whose code changed. Lance is not involved.Workflow run: run-wf-reproduce-modernrelay-omnigraph-issue-20261109T0142Z-9674b3
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261109T0310Z-90e65a
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261109T0510Z-5e7651
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261109T0640Z-4c2279