Repository navigation
Description
Summary
Four engine-side changes needed to support reading Snowflake-managed Iceberg tables whose data files live in an operator-owned S3 bucket, via either credential path — while holding the line that performance must not degrade under any credential configuration.
Two of the four are unconditional wins that stand on their own merits, independent of any customer:
- Use the inline
metadatathe catalog already hands us — saves ~1 S3 round-trip per table, in every configuration, on the first cold touch. - Fail closed on the silent vended→ambient downgrade — a security fix that also establishes the invariant the disk cache's safety argument depends on.
ConfigValue::SecretRef+hydrate()— the engine half of the credential-rotation fix.- A scope discriminant on the disk cache key — a ~10-line hedge that makes per-graph-source identity (mechanism B) a one-liner later instead of a re-architecture.
All anchors verified at a8de70e0f64454e4e3c736f203a9de4499dece45 (the fully-optimized head, PR-5 tip).
1. Use load_response.metadata instead of re-fetching it from S3
We are issuing an S3 GET per table for bytes the catalog already gave us.
LoadTableResult.metadata is a spec field returned inline on a successful loadTable, and the engine already parses and retains it — fluree-db-iceberg/src/catalog/rest.rs:377-383, catalog/mod.rs:31-36:
"so callers can read the full table schema/snapshot without a second S3 fetch"
But the query path never reads it. r2rml.rs:1343-1390 goes in-memory cache → disk cache → storage.read(metadata_location) — a fresh S3 GET. The intended consumers are named at rest.rs:377-379 ("metadata preview"); the read path was simply never wired up.
Live-verified against Snowflake Horizon (account ABACYOU-PP85756, customer-owned external volume, 2026-07-14): loadTable returns 3,438 bytes of inline metadata with full schemas, current-snapshot-id, and 2 snapshots. So rest.rs:378's claim ("Snowflake Horizon / Polaris include it") is confirmed live, not just asserted in a comment.
Why this is the purest form of the constraint: it saves ~1 S3 RTT/table (~85–98 ms on the measured link, docs/audit/**/06-per-file-cost.md:66) in every configuration, with no cache, no disk I/O, and no security surface — and it fires on the first cold touch, whereas the disk cache by definition only helps the second.
- Use
load_response.metadatawhenSome; keep the S3 fetch as theNonefallback (already handled). - Retire the
TableMetadatadisk-cache layer — it caches something we were handed. - Assert in a live test:
load_response.metadata.is_some()andr2rml.read_metadataspan count n=0.
Open: exact r2rml.read_metadata cost is UNVERIFIED (the span is new — 11-pr8-cold-floor.md:102). One cold run sizes the win. The fallback makes the change safe regardless.
2. Fail closed on the silent vended→ambient downgrade
r2rml.rs:1226 branches on the response, not the config:
if let Some(ref credentials) = load_response.credentials { /* vended */ }
else { /* from_default_chain — ambient */ }With vended_credentials: true — the default (fluree-db-iceberg/src/config.rs:344-346) — a catalog that authorizes loadTable but returns no credentials causes a silent downgrade to the process's ambient identity, logged only at info! ("Using ambient AWS credentials", r2rml.rs:1249).
In a deployment where the ambient identity is a shared Lambda execution role, that silently grants a catalog-scoped graph source the shared role's entire S3 reach. That is a fail-open.
This was flagged in an earlier audit as a warn!-vs-info! nit. It is more than that: fixing it is what makes "catalog gate == storage gate" true by construction under vended credentials — which is precisely the invariant the disk cache's "secret-free" safety argument rests on (see §4).
- When
io.vended_credentials == trueand the response carries no credentials, error — do not fall through to ambient. - Give it a distinct, typed error (see §5) so callers can tell "catalog won't vend" from "storage denied".
- Opting into ambient must be explicit (
vended_credentials: false), which is already the BYO-IAM contract.
3. ConfigValue::SecretRef + hydrate() — the rotation fix, engine half
Context: solo currently resolves a catalog's secret reference at bind time and bakes the literal into every virtual dataset's graph-source config. Rotating the credential breaks every previously-bound dataset. (Filed separately on the solo side.)
db already models the right design. AuthConfig::OAuth2ClientCredentials { client_secret: ConfigValue } (fluree-db-iceberg/src/auth/mod.rs:77) takes a ConfigValue. And fluree-db-api/src/graph_source/cache.rs:52-60 describes the intended behaviour verbatim:
"keyed by a fingerprint of the raw config JSON. When a Bearer/OAuth secret is sourced from an env var or secret store, that JSON stores the reference, not the secret… A bounded TTL lets a rotated secret self-heal."
The seam exists: r2rml.rs:1100 fingerprints the raw config; create_provider_arc() (which calls client_secret.resolve()) sits inside the cache-miss branch. This is finishing a design that is ~90% built.
- Add
ConfigValue::SecretRef { secret_ref: String }alongsideLiteral/Dynamic(config_value.rs:47-62). - Add an async
hydrate(&resolver) -> AuthConfigpass that rewritesSecretRef → Literal, called atr2rml.rs:1104immediately beforecreate_provider_arc(). This keepsresolve()sync (config_value.rs:120) and avoids rippling async throughcreate_provider/create_provider_arc— non-trivial in this crate, which has a known async-recursion trap. - Define the resolver as an injected trait. db must stay tenant-agnostic: the host constructs the resolver per-request with the authenticated tenant captured, and performs its own authorization inside. db never learns what a tenant is.
- Fail closed: a
SecretRefwith no injected resolver (OSS, CLI, tests) must hard-error with an actionable message. - Ensure
ConfigValue::SecretRef'sSerializeis redacting — seefluree infoprints OAuth2client_secretin plaintext — ConfigValue redacts Debug but not Serialize #1497; the existing redactingDebug(config_value.rs:64-68) does not cover the serde path.
⚠️ The ordering trap — please read before implementing
hydrate() MUST run strictly AFTER rest_client_cache_key (r2rml.rs:1100) computes the fingerprint.
The fingerprint is deliberately taken over the raw, reference-bearing JSON. Hydrating first means every rotation silently re-keys the client cache — costing a resolver call and a full OAuth exchange per query, instead of once per 900s per process. It is a one-line ordering mistake that converts a bounded cost into an unbounded one, and it would not fail any test.
Cost
+1 resolver call per REST-client build = once per 900s per process. Zero per query. Zero per table. Against the measured baseline (cold loadTable ≈ 1.3–3 s/table — the dominant cold term; OAuth exchange ≈ 0.5 s once per process), this is ≤5% of the step it already sits behind. No credential configuration becomes second-class.
Follow-up (not required here)
401 → refresh is not self-healing today: create_provider_arc resolves ConfigValue → String once (auth/mod.rs:135-136), and refresh() reuses the stale String (oauth2.rs:124), so rest.rs:212-218 re-exchanges with the dead secret and 401s again. Rotation self-heals only at the 900s TTL. Having the provider hold ref+resolver and re-resolve inside fetch_token turns 900s of staleness into one round-trip, at the cost of one resolver call per 401 only.
4. Disk-cache scope discriminant (hedge for mechanism B)
No leak exists today — do not re-key now. DiskCatalogCache is keyed on a hash of metadata_location (disk_catalog_cache.rs:164-166), and that is currently safe by construction:
IoConfig(fluree-db-iceberg/src/config.rs:329-342) has exactly four fields —vended_credentials,s3_region,s3_endpoint,s3_path_style. There is no role-ARN / assume-role / per-source identity field.S3IcebergStorage::from_default_chain(io/storage.rs:268-280) takes only region/endpoint/path_style and callsaws_config::defaults(...)— the process's ambient identity.- The workspace's only
AssumeRole(fluree-db-api/src/vended_credentials.rs:156-176) is Fluree vending credentials out for its own ledger storage proxy — not on the Iceberg consumption path.
So every graph source in a process reads S3 as the same identity. Two graph sources sharing a metadata_location have identical access. Stronger: the cache is only ever populated by a successful read using that shared identity, so anything in it is something any graph source in that process could have fetched itself.
It stops being safe when mechanism B (per-graph-source sts:AssumeRole) lands — which is on the roadmap. At that point graph sources get different S3 identities, and a shared key defeats the isolation that is B's entire purpose.
What is actually gated (only these two layers matter):
-
TableMetadata— not a leak in any configuration. The catalog hands it to you inline on a successfulloadTable(§1). Catalog authorization discloses the schema by protocol. -
scan_files+count_stats— columnlower_bounds/upper_boundsand per-filerecord_count(disk_catalog_cache.rs:294-297) come from manifests, i.e. S3 objects behind the storage gate. These are the only layers that move data across a gate. -
Add a scope discriminant to
path()(disk_catalog_cache.rs:164-168), constant today. BumpCACHE_FORMAT_VERSION(:119). ~10 lines; makes B's arrival a one-liner.
⚠️ When B lands: do NOT key on the credential
The naive (metadata_location, identity) re-key is a performance catastrophe: vended credentials rotate on every loadTable, so keying on the credential yields a new key per process — 0% hit rate under the default configuration.
Key on a stable scope fingerprint (the catalog-auth config — what rest_clients is already keyed on), and only for scan_files/count_stats. Cost is ≈0, because the dominant hit is same graph source, different process ("persists across process restarts", disk_catalog_cache.rs:3) — not cross-source sharing. Re-keying only splits entries between identities that were never legitimately sharing.
Rejected: a per-identity HeadObject access proof. The arithmetic is survivable (1 RTT ≈ 90 ms against ~500–1200 ms saved), but it is dominated — re-keying costs zero RTT where the probe costs one per table per process, forever.
5. Typed storage-permission errors
Storage auth failures surface as QueryError::Internal(format!("Failed to create S3 storage: {e}")) — an opaque 500 with the reason only in the string. IcebergError::Credential is never constructed on this path.
This pushes the classification burden onto every caller. Solo currently has to regex \b403\b to guess, which collides with its auth category and misfires — an S3 AccessDenied is a 403, so an admin with a missing bucket grant gets told "authentication failed" and rotates a perfectly good PAT.
- Add a typed permission-denied variant carrying bucket/key/region.
- Distinguish "catalog would not vend" (§2) from "storage denied".
- Do not disturb the 401→refresh-retry path (
rest.rs:212-218) — it matches on the catalog auth failure and is a perf mechanism (it avoids failing the query). Adding a storage-side variant must not change catalog-side matching.
6. verify_storage_access(&config, table)
Solo needs to verify at configuration time that the stack can actually read a data file, not merely reach the catalog. Doing that host-side means hand-rolling an S3 HeadObject with a different client than the engine uses — which defeats the point: it would validate a path queries don't take.
- Expose an API that resolves the table and proves storage reachability through the engine's own storage construction, so the probe is fidelity-guaranteed by construction rather than by keeping two code paths in sync.
- Return the typed error from §5.
- Reuse the existing caches where possible; this must not become a per-query cost.
Non-goals / notes
s3:ListBucketis not required. There are zerolist_objects/ListObjectscalls influree-db-iceberg/orfluree-db-api/src/graph_source/. The catalog returnsmetadata-location; every hop after (manifest list → manifests → Parquet) is an absolute path fetched by exact key. Consumers should grants3:GetObjectonly — and can prefix-scope it. Consequence for runbooks: withoutListBucket, a GET on a missing key returns 403 AccessDenied, not 404 NoSuchKey.- Minor, pre-existing:
path()usesDefaultHasher(disk_catalog_cache.rs:165). Rust does not guarantee its algorithm across toolchain releases, so a toolchain bump silently re-keys the whole cache directory — a one-time full miss thatCACHE_FORMAT_VERSIONwill not catch. Worth a stable hasher while touching this file.
Definition of done
- Every change measured against the virtual-dataset benchmark corpus; no regression in any band, in either credential configuration.
- §1 verified live: inline metadata used,
r2rml.read_metadatan=0. - §2 verified: vended-configured + no-creds response errors instead of downgrading.
- §3 verified: rotation self-heals within one client TTL; fingerprint unchanged across a rotation (i.e. hydration is provably after the key).
- The live Snowflake rig reproduces both paths (vended and BYO-IAM) against a customer-owned bucket.
Activity
aaj3f commentedon Jul 14, 2026
Consumers:
ConfigValue::SecretRef+hydrate()) is the engine half of fluree/solo#782 — a live credential-rotation defect.verify_storage_access) unblock fluree/solo#783's error dispatch and its configuration-time storage probe.fluree infoprints OAuth2client_secretin plaintext — ConfigValue redacts Debug but not Serialize #1497.§1 and §2 stand alone. Using the inline
metadatais a free ~1 S3 RTT/table in every configuration on the first cold touch (live-verified against Horizon: 3,438 bytes returned inline), and failing closed on the vended→ambient downgrade is a security fix in its own right. Neither needs a consumer to justify it.aaj3f commentedon Jul 15, 2026
Heads-up for §3 from the solo side (found while grounding fluree/solo#782 against the engine rev solo currently pins,
f084a1ee16):ConfigValueis#[serde(untagged)], andDynamic's three fields are allOption+#[serde(default)]. Consequence: any new object wire form — e.g.{"secret_ref": "fsec:v1:sm:…"}— already deserializes successfully today asDynamic { env_var: None, java_property: None, default_val: None }(untagged ignores unknown fields), then fails atresolve()with a misleading env-var-shaped error. A bare-string form has the opposite trap:Literalmatches first and the ref string itself becomes the "secret".So when adding
SecretRef:Dynamicin the enum (serde tries untagged variants in order);Literal/Dynamic;Dynamic— enum ordering only fixes new binaries. Likely acceptable (solo gates rollout by bumping the pin before writing refs), but worth stating.Solo consumes §3 via a
fluree-db-apipin bump (currentlyf084a1ee16) to a SHA on the db branch. Please publish the intended wire shape + resolver-trait signature under "Interface commitments" indb-progress.mdas soon as they're stable — the solo half of #782 is sequenced around them.aaj3f commentedon Jul 15, 2026
DB session — grounding complete at
eee643572(feat/external-s3-iceberg, stacked on #1501 head + 3 F20 commits). Every anchor re-verified; all substantive claims hold. Decisions, for the record:LoadTableResponse.metadatais only populated by a real RESTloadTablein the current call: session-cache/60s-TTL reconstructions (catalog_session.rs:54-71) and Direct mode (r2rml.rs:1300-1305) always carrymetadata: None. Full removal of the diskmetadatalayer would therefore regress Direct-mode cross-process cold starts, which were never "handed" the bytes. Inline path skips disk+S3 entirely; the in-mem → disk → S3 fallback stays for theNonecases. Live outcome unchanged: Snowflake vends inline ⇒r2rml.read_metadatan=0.IcebergError::StorageAccessDenied { bucket, key, region, message }classified at the S3 call sites inio/storage.rs;QueryErrorgainsStorageAccessDenied+CatalogCredentialsNotVended(generic —fluree-db-querystays iceberg-agnostic; mapping helper influree-db-api); server maps both to HTTP 403 with machine codesSTORAGE_ACCESS_DENIED/CATALOG_CREDENTIALS_NOT_VENDED(today an S3 403 surfaces as 400 INVALID_QUERY). The 401→refresh path is status-based on the catalog call (rest.rs:212-218) and is structurally untouched.r2rml.rs:1245else-branch) andbuild_preview_storagecallers (iceberg_catalog.rs:730), so preview/generate can't silently succeed on a path queries won't take.SecretRefmust be the object shape{"secret_ref": "..."}and the variant must sit betweenLiteralandDynamic— untagged serde tries variants in declaration order andDynamic(all-default fields) matches any object, so declared after Dynamic the ref would be silently swallowed. Resolver =#[async_trait] SecretResolverdefined influree-db-iceberg, injected per-request via a cheapFluree::with_secret_resolver(...)clone; hydration at the fourcreate_provider_arcsites, strictly afterrest_client_cache_key(r2rml.rs:1100/:1104). Resolver failures constructIcebergError::Credential— currently dead code, never built anywhere; this gives it its first real semantics.DefaultHasher,CACHE_FORMAT_VERSION1→2.metadata_locationalone would be neither necessary nor sufficient under prefix-scoped grants.Interface DRAFTs (SecretRef wire shape, resolver trait, error codes,
verify_storage_accesssignature) are published in the cross-session progress file; they'll be recorded here as they stabilize with commit shas.perf(r2rml): use inline loadTable metadata instead of re-fetching fro…
feat(r2rml): disk catalog cache scope discriminant + stable key hash (#…
feat(iceberg): typed storage-permission errors + fail-closed vended d…
feat(iceberg): ConfigValue::SecretRef + async hydrate() + SecretResol…
feat(iceberg): verify_storage_access — config-time probe through the …
fix(cli): redact secrets in local info/iceberg-info config output (#1497
perf(r2rml): use inline loadTable metadata instead of re-fetching fro…
feat(r2rml): disk catalog cache scope discriminant + stable key hash (#…
feat(iceberg): typed storage-permission errors + fail-closed vended d…
feat(iceberg): ConfigValue::SecretRef + async hydrate() + SecretResol…
feat(iceberg): verify_storage_access — config-time probe through the …
fix(iceberg): reconcile BYO-IAM credential handling with the loadTabl…
Merge perf/r2rml-f17-union-budget (8aaa1eb) into feat/lambda-usability
Merge feat/lambda-usability into perf/family-c-filter-join (family-c …
fix(api): un-orphan build()'s #[cfg(native)] from with_secret_resolver