Repository navigation
make governance default-allow tri-state so ledger config applies - #1625
Conversation
bplatz
left a comment
There was a problem hiding this comment.
Read through the whole change; the core is sound. Two things I went looking for and can clear:
- Cache digest is handled correctly.
hash_governancewidens toNone=0 / Some(false)=1 / Some(true)=2, so it stays injective within a version. Residual: old-falseand new-Noneboth hash to0, so a retry spanning a rolling upgrade could hit a stale entry. The docstring already scopes the contract to "same client, same retry", so I'd just note it in the PR body rather than change anything. - No path silently loosens. The only widening is config -> unset-request, which is the intended fix.
Four inline comments. Two more that don't anchor to a line:
No server-level test for the changed seam. New coverage is API-layer plus header unit tests, but nothing drives an actual HTTP request with fluree-identity against an f:defaultAllow true ledger. The header field changed shape and inject_into_opts was restructured, so that seam is worth one integration test — #1627 adds exactly that harness in policy_integration.rs.
The f:defaultAllow false + anonymous hole gets sharper, not softer. After this lands, half of f:defaultAllow works as operators expect (true opens identity requests) and half still silently does nothing (false doesn't close anonymous ones). Someone who verifies the first will reasonably assume the second. The pinned test documents it and #1627's setting-groups.md rewrite explains it — I'm flagging it as a decision to make deliberately, not a change request here.
Merge note: this and #1627 both rewrite the same doc comment on PolicyDefaults::default_allow (fluree-db-core/src/ledger_config.rs:73-77) — a direct textual conflict. They also both touch extract/headers.rs and consensus/caching.rs at different hunks. Whoever lands second should keep #1627's version of that doc comment; it's strictly more informative and already describes the post-merge semantics.
| // `--default-allow` is a presence flag: absent stays unset so the | ||
| // ledger's `f:defaultAllow` can apply. There is no CLI spelling for | ||
| // an explicit `false`. | ||
| default_allow: self.default_allow.then_some(true), |
There was a problem hiding this comment.
This changes CLI behavior and removes the escape hatch in the same stroke. Against a ledger with f:defaultAllow true, fluree query --identity did:... used to return nothing and now returns everything (the fix) — but there's no longer any spelling for the old deny-by-default posture, since remote_client.rs also only sends the header when true. Worth adding --default-allow[=true|false] or a --no-default-allow counterpart.
There was a problem hiding this comment.
Good catch, and you're right that this was the worst of the four — the other notes are about precision, this one actually took a capability away. Fixed: there's now a --no-default-allow counterpart, clap-enforced mutually exclusive with --default-allow, so the three states are --default-allow → Some(true), --no-default-allow → Some(false), neither → unset and the ledger's f:defaultAllow governs. fluree query --as did:... --no-default-allow gets the old deny-by-default posture back explicitly.
On the spelling — I went with the --no- counterpart rather than --default-allow[=true|false] mostly because it's what the CLI already does: --no-color, --no-user, --no-conflicts, --no-vended-credentials are all in cli.rs today, and the num_args = 0..=1 shape only ever shows up for optional values (paths, aliases), never for a boolean. So --default-allow=false would have been a novel arg shape for us. Happy to switch if you'd rather have the single-flag form though — it's a small change and I don't feel strongly.
You were also right that remote_client.rs was half the bug and not just a detail: I'd have fixed the flag and still shipped a CLI where the posture silently evaporated over HTTP while working embedded. Both the header builder (policy_headers) and the JSON-LD body-opts path (inject_policy_into_json_opts) now send the explicit false as well as true, and there are tests on both so that seam can't quietly rot again.
| default_allow: self.default_allow.unwrap_or(false), | ||
| // Already tri-state here; it used to collapse to `false` at this | ||
| // boundary, which is the same lost-unset bug one scope down. | ||
| default_allow: self.default_allow, |
There was a problem hiding this comment.
The flattening is fixed here, but the asymmetry one level up defeats it for one shape. SourcePolicyOverride::has_policy() counts default_allow.is_some(), while GovernanceOptions::has_any_policy_inputs() deliberately counts only Some(true).
So a per-source override setting only default_allow: false passes has_policy() -> wrap_policy -> merge_policy_opts -> has_any_policy_inputs() is false -> falls to the config-defaults path -> config's f:defaultAllow true overwrites the explicit false.
Pre-existing (the old .unwrap_or(false) reached the same place), but the PR body claims this scope was fixed too. Either align has_policy() with has_any_policy_inputs(), or make the config path respect an explicit request value.
There was a problem hiding this comment.
This is the one I'm most glad you found — I'd convinced myself the SourcePolicyOverride scope was done and it wasn't, and the PR body said so, which is worse. Your trace is exactly right: has_policy() counts is_some(), has_any_policy_inputs() counts only Some(true), so an override naming only default_allow: false gets applied as an override and then lands on the config-defaults path, where config's f:defaultAllow true overwrites the explicit false.
I took your second option — making the config path respect an explicit request value — rather than aligning has_policy() with has_any_policy_inputs(). Aligning the two predicates would have fixed this shape by making the override stop being an override at all, which trades a wrong value for a silently ignored one, and it would also have pulled Some(false) into "counts as a policy input" through the back door, which is the semantics change I deliberately avoided elsewhere in this PR. So merge_policy_opts is now precedence-correct instead of path-dependent: config fills only a genuine unset, and an explicit request value always survives. Override control is still the one thing entitled to overrule an explicit caller value, so OverrideControl::None and the non-permitted-identity case continue to force config, and the truth table is unchanged and still pinned.
Worth flagging that this made me delete one of my own tests: I'd written config_overwrites_explicit_false_on_the_no_policy_input_path, which pinned precisely the behavior you're calling a bug. It's now explicit_false_survives_the_no_policy_input_path, plus per_source_override_of_only_default_allow_false_survives_config driving the real SourcePolicyOverride::to_query_connection_options() shape end-to-end, and override_control_none_still_forces_config_over_explicit_request so the exception stays honest. And you're right that it was pre-existing — the old .unwrap_or(false) reached the same place — but the PR body claimed the scope was fixed, so I've corrected that claim rather than leave it overstated.
| /// which is the fail-closed direction for a security-relevant header. | ||
| fn header_bool_opt(headers: &HeaderMap, name: &str) -> Option<bool> { | ||
| get_header_str(headers, name) | ||
| .map(|v| v.eq_ignore_ascii_case("true") || v == "1" || v.is_empty()) |
There was a problem hiding this comment.
The doc comment above contradicts this line: it says "anything present but unrecognized reads as Some(false), which is the fail-closed direction", but v.is_empty() is in the truthy disjunction, so a present-but-empty fluree-default-allow: yields Some(true).
Behavior is unchanged from is_header_truthy, so this is a comment fix rather than a code fix — but it's a comment about a security-relevant header, which is exactly what a future reader will take at face value.
There was a problem hiding this comment.
You're right, and it's a comment fix rather than a code fix — but I want to say why I landed there rather than just asserting it, since "make the empty case fail closed" was genuinely tempting for a security-relevant header.
The empty-is-truthy convention isn't local to this function: is_header_truthy treats true / 1 / empty identically, and that's how every boolean Fluree header behaves — a bare fluree-track-meta: means "on". If I made empty read as Some(false) only for fluree-default-allow, then the same header value would mean opposite things depending on which header it was attached to, which seems like a worse footgun than the one we're fixing, and it'd be invisible at the call site. So the behavior stays shared and the comment now says what the code actually does: true / 1 / empty are truthy, a bare fluree-default-allow: is Some(true), and only a present, non-empty, unrecognized value (0, no, nonsense) reads as explicit false.
Also worth noting the test was already right where the prose was wrong — default_allow_header_is_tri_state asserts Some("") → Some(true) — so this was only ever a comment that would have misled a reader, which is more or less exactly your point.
| let opts = GovernanceOptions { | ||
| identity: Some(identity_iri.to_string()), | ||
| default_allow, | ||
| default_allow: Some(default_allow), |
There was a problem hiding this comment.
Hard-wiring Some(..) means this helper can never inherit the ledger's f:defaultAllow — the one public entry point that takes an identity is the one that opts out of the fix. Only a test calls it today, but it's pub and re-exported from lib.rs. Either take impl Into<Option<bool>>, or document it as deliberately an explicit-override helper.
There was a problem hiding this comment.
Fair, and the framing that got me was "the one public entry point that takes an identity is the one that opts out of the fix" — that's a real inconsistency regardless of how few callers it has today. Took the impl Into<Option<bool>> option, so wrap_identity_policy_view(&ledger, iri, false) still compiles for the explicit case and wrap_identity_policy_view(&ledger, iri, None) now defers to the ledger's f:defaultAllow. Doc comment and the example both updated to describe it as tri-state.
bplatz
left a comment
There was a problem hiding this comment.
Left some feedback below to look at before merge
Config now fills only a genuine unset; override control still forces its values over a policy-carrying request. A per-source override naming only default_allow: false was reaching the config-defaults path and being overwritten there, since has_policy() counts is_some() while has_any_policy_inputs() counts only Some(true).
The tri-state left the CLI with no spelling for deny-by-default. The explicit false now also travels over HTTP, on both the header and the body-opts path, so the posture doesn't silently work only embedded.
# Conflicts: # fluree-db-api/src/dataset.rs
|
@bplatz — the four review-body notes, in order: On no server-level test for the changed seam: ## Review body — no server-level test for the changed seam Agreed, and this was the right thing to push on: I did check the first one isn't vacuous, since "identity-carrying request sees everything" and "request wasn't enforced at all" would look identical from the outside: with the pre-fix precedence temporarily restored it returns On the I think your framing of this is sharper than mine was, and it's the part of this that I'd most like a decision on rather than a patch. "Half of Mechanically it's that an anonymous request never builds a On cache digest residual: ## Review body — cache digest residual Thanks for chasing this one down independently — I'd looked at injectivity within a version and hadn't thought about the rolling-upgrade window. Noted in the PR body rather than changed, as you suggested: old- On merge conflict with #1627: ## Review body — merge conflict with #1627 Agreed on all counts, including which version wins: whoever lands second should keep #1627's |
|
Follow-up on the anonymous + One thing that came out of writing it up, since it sharpens your framing rather than just restating it — I'd assumed the write path behaved the same way as reads, and it doesn't. Probing over HTTP: with Which is to say your "gets sharper, not softer" read was right, and then some. |
GovernanceOptions.default_allowwas a barebool, so "the caller didn't say" and "the caller said false" were indistinguishable — andmerge_policy_optsreturned the request opts unchanged whenever any policy input was present. The consequence: merely supplying an identity acted as an implicit override back to deny, so an operator who setf:defaultAllow trueon a ledger never saw it apply to any identity-carrying request.default_allowis nowOption<bool>: request wins when explicitly set, ledger config fills unset, and the fallback stays fail-closed. Resolution collapses to a concrete bool at one boundary (effective_default_allow()in the policy builder) so theOptiondoesn't leak past it.The same lost-unset flattening existed one scope down in
SourcePolicyOverride, which was alreadyOption<bool>but collapsed tofalseon read. Carrying the tri-state through there was necessary but not sufficient:SourcePolicyOverride::has_policy()countsis_some()whilehas_any_policy_inputs()counts onlySome(true), so a per-source override naming onlydefault_allow: falsewas applied as an override but then landed on the config-defaults path, where config'sf:defaultAllow trueoverwrote the explicitfalse.merge_policy_optsis now precedence-correct rather than path-dependent: config fills only a genuine unset, and an explicit request value always survives. The one thing still entitled to overrule an explicit caller value is override control (OverrideControl::None/ a non-permitted identity), which continues to force config — the documented truth table is unchanged and still pinned.One deliberate semantics choice to flag: an explicit
Some(false)does not count as a policy input inhas_any_policy_inputs(), exactly as the bare bool behaved. Counting it would have flipped anonymous writes against af:defaultAllow falseledger from unenforced to enforced — a much bigger behavior change than this PR intends. The cost is that "anonymous but enforce default-deny" remains inexpressible; happy to revisit that separately if we want it.The CLI keeps both spellings:
--default-allowand a new--no-default-allow(clap-enforced mutually exclusive), with neither leaving the value unset so the ledger'sf:defaultAllowgoverns.--no-default-allowis the deny-by-default escape hatch, and thefluree-default-allowheader now travels for an explicitfalseas well astrue, so the posture survives over HTTP instead of silently working only embedded.Cache-digest residual.
hash_governancewidens toNone=0 / Some(false)=1 / Some(true)=2, so it stays injective within a version. Across a rolling upgrade it is not: a pre-upgradefalseand a post-upgradeNoneboth hash to0, so a retry spanning the upgrade could hit a stale entry. Not worth a change — the digest's docstring already scopes the contract to "same client, same retry,"GovernanceOptionsreaches no durable ledger or raft state (it lives only on request/queue-envelope types), and the window is one deploy wide.The two existing fail-closed posture tests pass unchanged, plus new coverage for config reaching identity-only requests, explicit request-level override in both directions, the previously-untestable unset case, the per-source
default_allow: falseshape, CLI tri-state parsing and header emission, and a server-level integration test driving real HTTP with a Bearer identity against anf:defaultAllow trueledger. Full workspace suite green.Note on the
fluree-default-allowheader: truthiness is byte-for-byte the shared convention every boolean Fluree header uses (true,1, or empty), so a barefluree-default-allow:reads asSome(true); only a present, non-empty, unrecognized value reads as explicitfalse.