Repository navigation
fix(indexer): debug index builds accept f:message, f:author and f:reverts in txn-meta - #2056
Conversation
…amespace A debug build's index build panicked on a commit carrying f:message or f:author (user claims the txn-meta parser admits) or a revert's f:reverts: the resolver's reserved-namespace debug_assert allowed only f:identity and db:receivedAt. The background indexer caught the panic, so its build failed quietly; a direct rebuild returned the panic as an error. Release builds compile the assert out and index these entries normally. fluree-vocab now lists the namespace's txn-meta names once (TXN_META_USER for the user claims, TXN_META for every name), and the parser's allowlist and the resolver's guard both read it. Graph sync's commit message uses the vocab constant.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz yes to naming the txn-meta vocabulary once in fluree-vocab. It's the right home, and the right fix for the two lists that drifted. My one headline note is that the list now has one source but only one of the three readers that build user txn-meta consults it: the JSON-LD sidecar checks it, while a TriG <#txn-meta> block in a transaction (TemplateSink::push_txn_meta) and in bulk import (resolve_trig_meta) check nothing. It's the same shape we keep meeting with JSON-LD terms (#2024, #2042): one concept read per surface with diverging rules. Here, though, I think the structural fix (one checked constructor that all three readers call) is small enough to land with this PR rather than later, since it also closes the debug panic for TriG and a provenance-forgery path in release (details below).
Full review below:
✅ Approving to unblock you — with 1 thing that needs to be addressed before this merges.
Thanks @bplatz, this is a tidy fix. The test reads all three values back after a direct rebuild, which is the right place to look: I reverted the guard to the old two-name rule and fluree_namespace_txn_meta_survives_indexing failed with the exact reserved namespace 7 panic. On what release builds were doing, the body's account holds: the guard is a debug_assert!, and past it emit_txn_meta_entry indexes the entry like any other, so release has been indexing f:message, f:author and f:reverts correctly all along.
Must address before merge:
fluree-db-transact/src/parse/txn_meta.rs:69: the TriG<#txn-meta>readers (template_sink.rs:296-344for transactions,trig_meta.rs:214-243for bulk import) never consult the allowlist. I reproduced the same debug panic through TriG withfluree:t, and with the indexer's debug assertions off the commit ends up with twof:tvalues, whilefluree:identityandfluree:revertsindex silently as forged provenance. The fix is one shared check that all three readers call, plus a TriG test. Details inline.
Optional, inline: the reserved-namespace list is still two copies (resolver.rs:35 / txn_meta.rs:62); a TXN_META ⊇ TXN_META_USER assert; the Python binding's literal "message".
Adherence to repo commitments:
- Patterns/abstractions:
⚠️ moves the names intofluree-vocab, the shared vocabulary crate, but the check itself still lives in one reader of three. - Performance (speed first, memory second): ✔ no performance-degradation risk: a
debug_assert!andconstslices; release paths are unchanged. - Deployment targets: ✔ n/a for the fix (debug-only on every host); the TriG gap is host-neutral (server
application/trig, embeddedinsert_turtle, CLIinsert, bulk import). - Testing:
⚠️ the new test is wired (grp_transact.rs:58-59), passes, and goes red with the old guard; there is no TriG case. - Conventions: ✔ multi-line commit body; clippy/fmt green in CI; no docs change needed for the release behavior.
Verified locally at fba7564db: cargo test -p fluree-db-api --test grp_transact it_txn_meta (23 passed, the new test by name), the guard-revert mutation (red, restored), and TriG probes in a debug build and with fluree-db-indexer's debug assertions off.
Approving now so you can merge without waiting on another pass from me. Just be sure the TriG check is in before you do.
| /// `f:author` — commit author (user claim; distinct from `f:identity` which is | ||
| /// the authenticated subject and is system-controlled). | ||
| const FLUREE_DB_USER_ALLOWED: &[&str] = &[fluree_vocab::db::MESSAGE, fluree_vocab::db::AUTHOR]; | ||
| const FLUREE_DB_USER_ALLOWED: &[&str] = fluree_vocab::db::TXN_META_USER; |
There was a problem hiding this comment.
🔴 Must address before merge: two of the three readers that build user txn-meta (fluree-db-transact/src/template_sink.rs:296-344 and fluree-db-transact/src/parse/trig_meta.rs:214-243) never consult this allowlist, so the debug panic this PR fixes still reproduces, and release builds index reserved provenance a user wrote.
extract_txn_meta is the JSON-LD sidecar's reader. A TriG GRAPH <#txn-meta> { … } block reaches a commit through two other readers: TemplateSink::push_txn_meta (every insert/upsert of TriG or graph-block Turtle, HTTP application/trig included) and resolve_trig_meta (bulk import, via import.rs:756). Both check the subject and that the predicate is an IRI, and nothing about its namespace. build_commit strips f:identity only when the request carries an identity (fluree-db-transact/src/commit.rs:618-628) and strips db:receivedAt always; everything else passes through.
I ran it at this head with a scratch test (insert_turtle of ex:a ex:p 1 . GRAPH <#txn-meta> { fluree:commit:this <pred> <obj> . }, then rebuild_index_from_commits and a query of #txn-meta):
fluree:t 99: the transaction commits, and the debug rebuild fails withindex build task panicked: TxnMetaEntry in reserved namespace 7 reached resolver — extract_txn_meta guard bypassed?. Withdebug-assertionsoff forfluree-db-indexer(which is what a release build compiles), the rebuild succeeds and the commit subject in#txn-metacarries bothf:t 1andf:t 99.fluree:identity "did:example:forged": commits, indexes, and reads back as the commit'sf:identity. The same claim as a JSON-LD sidecar is refused withonly f:message and f:author are user-settable, anddocs/transactions/overview.md:293promises "Any user-suppliedf:identityin the body is overridden".fluree:reverts "bafyforged": commits and indexes as revert provenance. With this PR the resolver's guard admitsreverts, so no build trips on it any more.
This PR didn't introduce it (trig_meta.rs has never had the check, back to the v4 baseline), but this is the PR where "the parser's allowlist and the resolver's guard both read it" becomes the stated rule, and the fix is one function. Something like a check_user_txn_meta_predicate(ns: u16, name: &str) -> Result<()> beside FLUREE_DB_USER_ALLOWED, called from extract_one_entry, from push_txn_meta (failing the sink with the same message) and from resolve_trig_meta, plus a test that a TriG <#txn-meta> block naming f:identity is refused like the JSON-LD one. That also makes the resolver's debug_assert mean what its message says.
Commenting here because template_sink.rs and trig_meta.rs are not in this diff.
There was a problem hiding this comment.
Fixed in bbb9498, along the lines you suggested. check_user_predicate sits beside the JSON-LD reader in parse/txn_meta.rs, and all three readers call it: extract_one_entry, TemplateSink::push_txn_meta (failing the sink) and resolve_trig_meta. They give the same message, so a TriG block naming fluree:identity is refused exactly like the JSON-LD sidecar.
New tests:
trig_txn_meta_refuses_fluree_provenance_predicatescovers a TriG insert withfluree:identity,fluree:reverts,fluree:t, and a predicate in each of the commit and URN namespaces;trig_txn_meta_message_and_author_survive_indexingchecks that the two claims still commit through TriG, index and read back;import_trig_txn_meta_refuses_fluree_provenance_predicatescovers bulk import.
With the check disabled in the sink, the insert test fails, because the forged claim commits. The same goes for the import test with the check disabled in resolve_trig_meta.
The overview doc's "is overridden" line now states the rule, and turtle.md's <#txn-meta> section says the same. The PR body calls out that a TriG transaction or import setting such a predicate now fails.
| /// `db:receivedAt`, `f:reverts`). They flow through the resolver like | ||
| /// ordinary entries so they stay queryable post-index. | ||
| fn is_fluree_db_txn_meta_entry(entry: &fluree_db_novelty::TxnMetaEntry) -> bool { | ||
| entry.predicate_ns == FLUREE_DB && db::TXN_META.contains(&entry.predicate_name.as_str()) |
There was a problem hiding this comment.
🟡 Optional: the namespace half of the rule is still two lists.
RESERVED_PREDICATE_NAMESPACES lives in this file (resolver.rs:35, [FLUREE_DB, FLUREE_COMMIT, FLUREE_URN]) and again in the parser (fluree-db-transact/src/parse/txn_meta.rs:62, [FLUREE_COMMIT, FLUREE_URN], with FLUREE_DB handled by the allowlist). The comment on this copy says it's duplicated to avoid a transact → indexer layering inversion, but this PR just gave both crates a shared home for the names in fluree-vocab, where the namespace codes already live too.
Moving the code list beside db::TXN_META (or making this predicate a fluree_vocab fn that both sides call) would close the second pair the same way. I recognize this is minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
There was a problem hiding this comment.
Folded in (bbb9498). fluree-vocab has a txn_meta module with RESERVED_NAMESPACES, user_may_set and may_hold. The readers' shared check calls user_may_set, and both resolver guards call may_hold, so the list and the layering comment are gone from both crates.
The guard's message now names the predicate. With may_hold narrowed to the user names as a mutation, the revert test fails with TxnMetaEntry 7:reverts in a reserved namespace reached the resolver — a txn-meta reader skipped the user-predicate check?.
| /// Every local name in this namespace a commit's txn-meta holds: the user | ||
| /// claims ([`TXN_META_USER`]) and the entries the system writes | ||
| /// (`f:identity`, `db:receivedAt`, and `f:reverts` on a revert). | ||
| pub const TXN_META: &[&str] = &[MESSAGE, AUTHOR, IDENTITY, RECEIVED_AT, REVERTS]; |
There was a problem hiding this comment.
🟡 Nit: TXN_META restates MESSAGE, AUTHOR rather than building on TXN_META_USER.
So the next user-settable name has to be added in two places, or the resolver panics on it again, which is the same drift this PR fixes, one level down. A const can't concatenate slices without a macro, so the cheapest guard is a unit test in fluree-vocab asserting every TXN_META_USER name is in TXN_META. It's one assert, so if you agree I'd rather see it folded in now.
There was a problem hiding this comment.
Added txn_meta::tests::txn_meta_holds_every_name_a_user_may_set in fluree-vocab (bbb9498), plus a table test of user_may_set / may_hold across the three reserved namespaces.
| commit_opts = commit_opts.with_txn_meta(vec![fluree_db_core::TxnMetaEntry::new( | ||
| fluree_vocab::namespaces::FLUREE_DB, | ||
| "message", | ||
| fluree_vocab::db::MESSAGE, |
There was a problem hiding this comment.
🟡 Nit: the Python binding's commit message still uses the literal (fluree-db-python/src/connection.rs:128-131).
It builds TxnMetaEntry::new(FLUREE_DB, "message", …). Using fluree_vocab::db::MESSAGE there too would finish the sweep this line starts.
Commenting here because fluree-db-python/src/connection.rs is not in this diff.
There was a problem hiding this comment.
Done in bbb9498: it's fluree_vocab::db::MESSAGE now.
Only the JSON-LD txn-meta reader checked predicates. A TriG <#txn-meta> block, in a transaction (TemplateSink::push_txn_meta) or in bulk import (resolve_trig_meta), took any IRI: fluree:t still tripped the resolver's debug panic, and in release builds it gave the commit a second f:t, while fluree:identity and fluree:reverts were indexed as the commit's provenance. fluree-vocab's txn_meta module now holds the whole rule: the reserved namespaces, user_may_set (what a transaction may set) and may_hold (what txn-meta may carry). All three readers refuse through one check with the JSON-LD message, and the resolver's guard reads may_hold, so the namespace list is no longer kept twice. A unit test asserts TXN_META holds every TXN_META_USER name. The Python binding's commit message uses db::MESSAGE.
…2068) into fix/write-fidelity-part2 Two conflicts, both with #2056, which fixed the same debug assertion this branch fixed in 9b7cc1a (the resolver's reserved-namespace guard rejected f:message, f:author and f:reverts in txn-meta): - fluree-db-indexer/src/run_index/resolve/resolver.rs: took main's version, the guard deciding through fluree_vocab::txn_meta::may_hold. This branch's widened is_system_txn_meta_entry admitted the same five names and goes; the file now equals main's. - fluree-db-api/tests/it_txn_meta.rs: kept both sides' tests, this branch's an_index_build_keeps_the_user_message_and_author (a file ledger through a full rebuild) beside #2056's. template_sink.rs, trig_meta.rs, txn_meta.rs, admin.rs and fluree-vocab merged cleanly: #2056's predicate check in the txn-meta path sits beside this branch's statement hashing and does not touch it.
Brings in #2102 (one HTTP status table), #2068, #2056, #2053, #2046, #2045 and the v4.2.4 release. - api error.rs: main's exhaustive status_code / error_type tables, with ApiError::ConfigUnavailable and TransactError::ConfigUnavailable classified as 500 err:storage/ReadFailure in both, and rows for them and RequestOverrideRefused in every_variant. - server error.rs: main's derivation from ApiError; this branch's ConfigUnavailable arms move to the API tables. - consensus: SubmissionError keeps both ConfigUnavailable and CommitContention. - server routes/transact.rs: both submission arms and test rows. - transaction.rs, tx_builder.rs: main's txn_attempts loops, with this branch's request-governance argument on every stage_plan / stage_all call.
Txn-meta now follows one predicate rule on every surface. The rule lives in
fluree-vocab, and every reader and the index resolver use it.Debug index builds panicked on
f:message,f:authorandf:revertsIn a debug build, indexing a commit whose txn-meta carries
f:messageorf:author(user claims the txn-meta parser admits), or a revert'sf:reverts, panicked in the resolver. Its reserved-namespacedebug_assertallowed onlyf:identityanddb:receivedAt. The background indexer catches the panic, so its build failed quietly; a direct rebuild returned it as an error (index build task panicked: TxnMetaEntry in reserved namespace 7 …). Release builds compile the assert out and index these entries normally.TriG
<#txn-meta>blocks took any predicateOnly the JSON-LD reader checked txn-meta predicates. The two TriG readers took any IRI: the
<#txn-meta>block in a transaction (TemplateSink::push_txn_meta:insert/upsertof TriG, including HTTPapplication/trig) and in bulk import (resolve_trig_meta). So in a TriG block:fluree:tstill tripped the debug panic, and in release builds gave the commit a secondf:t;fluree:identityandfluree:revertswere indexed as the commit's identity and revert provenance. The JSON-LD sidecar refuses the same claims.All three readers now refuse a predicate in a Fluree namespace other than
f:message/f:author, with the JSON-LD reader's message. Behavior change: a TriG transaction or import that sets such a predicate now fails instead of committing.One rule
The parser's allowlist and the resolver's guard had each kept their own lists, and those lists had drifted.
fluree-vocabnow holds them once:db::TXN_META_USER:message,author(what a user may set);db::TXN_META: those plus the system-writtenidentity,receivedAtandreverts;txn_meta::RESERVED_NAMESPACES,txn_meta::user_may_setandtxn_meta::may_hold. The readers' shared check callsuser_may_set, and the resolver's guard callsmay_hold, so the namespace list is no longer duplicated between transact and the indexer.A unit test asserts
TXN_METAholds everyTXN_META_USERname. Graph sync and the Python binding usedb::MESSAGEinstead of a string literal.Tests
it_txn_meta::fluree_namespace_txn_meta_survives_indexingcommits withf:messageandf:author, reverts a commit, rebuilds the index directly, and reads all three values back from#txn-meta.it_txn_meta::trig_txn_meta_refuses_fluree_provenance_predicates:fluree:identity,fluree:reverts,fluree:tand predicates in the commit and URN namespaces are refused in a TriG insert.it_txn_meta::trig_txn_meta_message_and_author_survive_indexing: both claims commit through TriG, index and read back.it_import::import_trig_txn_meta_refuses_fluree_provenance_predicates: bulk import refusesf:identityin the sidecar.Docs
docs/transactions/overview.mdsaid a user-suppliedf:identity"is overridden". It now states the rule: a transaction's txn-meta may carry onlyf:messageandf:authorfrom Fluree's namespaces.docs/transactions/turtle.mdsays the same for the<#txn-meta>block.Found while testing #2008, whose revert regression test logs the caught panic from a background build; the bug is on
mainindependently.