Skip to content

Redact graph source config secrets - #1534

Merged
zonotope merged 6 commits into
mainfrom
fix/info-cred-leak
Jul 23, 2026
Merged

zonotope merged 6 commits into
mainfrom
fix/info-cred-leak

Conversation

@zonotope

Copy link
Copy Markdown
Contributor

Problem

fluree info <gs> and fluree iceberg info <gs> printed the full graph-source config as pretty JSON — including catalog.auth.client_secret, i.e. a live Snowflake PAT / OAuth2 client secret or bearer token. ConfigValue has a redacting Debug impl, but every CLI print path serializes via serde, which bypasses it, so the secret landed in terminal scrollback, script logs, and CI output. The server routes already redact through redact_graph_source_config; the CLI's local print paths were the unpatched surface. (A redacting Serialize on the type itself is not an option: persistence requires lossless serialization — CI-locked tests assert the stored config carries the secret for query-time catalog auth. The type-level fix, ConfigValue::SecretRef, is tracked separately in #1500 §3.)

Fix

All CLI graph-source rendering now goes through a single new module, fluree-db-cli/src/graph_source_display.rs, which routes every config through the existing fail-closed redactor before printing. Local nameservice records are converted with build_generic_graph_source_info — the same redacted DTO the server's /info route emits (now pub in fluree-db-api) — so local and remote sources render identically through one renderer, and redaction happens at the API layer rather than being re-implemented per print site. Remote responses are re-redacted client-side as defense-in-depth against unredacting servers; the redactor is idempotent, so already-clean responses render unchanged.

The refactor also collapses duplication this bug was hiding in: the two print functions existed verbatim in both info.rs and iceberg.rs, and the source-type label mapping existed three times across the workspace (CLI ×1 after its own dedup, server ×1, plus the private graph_source_type_label in fluree-db-api). All of it now resolves to the one API helper, so a future label or field change cannot drift between the CLI, the server, and the API.

Hardening beyond the original leak

  • Container-shaped secrets (fluree-db-api): redact_json_secrets only masked scalar values under secret keys; a secret hidden in a container shape ({"token": ["tok-1"]}, {"client_secret": {"value": "..."}}) passed through unredacted. Containers under a secret key are now redacted with inverted strictness — every scalar leaf inside is masked except the env_var/java_property reference identifiers — closing the gap for hand-authored or out-of-band records while preserving the env-var debugging affordance. This hardens every consumer of the shared redactor (server /info, events route, CLI). Complements Harden redact_graph_source_config: denylist of secret key names fails open for future fields #1504, which tracks the key-name denylist failing open.
  • Fail-closed on unparseable configs: a stored config that does not parse now renders as [redacted:unparseable] (matching the server-side semantics) instead of being silently omitted — an operator no longer concludes a misparsed (and possibly secret-bearing) config doesn't exist, and its raw bytes are never echoed.
  • The redaction property is a tested invariant: the print functions are thin wrappers over render_* functions returning String, and tests feed secret-bearing records and server responses through the real render seam, asserting the secrets are absent, [redacted] is present, and non-secret identifying fields (client id, scope, catalog URI) survive. A refactor that drops the redaction call now fails the suite instead of silently reintroducing the leak.

User-visible output changes

  • client_secret, token, and other secret values print as "[redacted]" everywhere (the point of the PR).
  • The unified renderer prints Retracted: whenever the field is present, so remote output for generic (BM25/Vector/Geo) sources gains that line; local output keeps it.
  • Index ID: always prints, showing (none) when the source has no index; previously remote output omitted the line entirely.
  • Empty configs are omitted consistently: "{}", "{ }", and "{\n}" all suppress the Configuration section (previously only the byte-exact "{}" did, via a string comparison in the server DTO builder).
  • Unparseable configs render a Configuration section containing [redacted:unparseable] instead of nothing.

Verification

Unit tests cover the render seam end-to-end (secret masking local and remote, env-var name preservation, fail-closed unparseable, non-secret configs rendering in full) plus new API-side tests for container-shaped secrets and whitespace-variant empty configs; the existing per-variant redaction canaries and lossless-storage assertions all still pass, including under --features iceberg. Verified live against the issue's reproduction: fluree iceberg map --oauth2-client-secret "$PAT" ... followed by fluree info <gs> --direct and fluree iceberg info <gs> prints "client_secret": "[redacted]" with zero occurrences of the raw secret, while the stored nameservice record still carries it (persistence remains lossless). Clippy is clean and cargo fmt --check passes across the touched crates.

Closes #1497

@zonotope
zonotope requested review from aaj3f and bplatz July 22, 2026 19:07

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approve.

Well-executed credential-disclosure fix. The CLI's info/iceberg info print paths serialized stored graph-source configs with to_string_pretty and no redaction, dumping live OAuth2 client secrets and bearer tokens to the terminal, while the server route already redacted.

The fix consolidates all rendering into one module that routes through the existing fail-closed redactor, deletes the duplicated leak sites, and hardens the shared redactor for container-shaped secrets and unparseable configs — with the redaction property captured as a tested invariant so a future refactor that drops the call fails the suite.

I verified the denylist covers the two secrets that actually serialize (token, client_secret), that the env-var preservation matches the ConfigValue wire shape precisely, that no other CLI config-print path was missed, and that lossless persistence is untouched. The depth is right: it fixes at the API layer so CLI and server share one redactor.

Adherence to repo commitments

  • Patterns/abstractions: ✔ Extends redact_graph_source_config/build_generic_graph_source_info; collapses three duplicated helpers into one.
  • Performance (speed first, memory second): ✔ CLI display path only, off the query engine — no regression risk.
  • Testing: ✔ New render-seam tests + API container-shape/empty-config tests; ran locally at HEAD → 147 passed, 0 failed. Existing per-variant canaries and lossless-storage assertions still pass.
  • Conventions: ⚠️ Clippy-clean (incl. 23 denied lints) and fmt-clean; only gap is the PR title / intermediate commit messages not using the fix(cli): conventional-commit prefix that feeds release notes. No AI-attribution trailers.

Verified locally at branch HEAD: traced secret-key coverage against the real AuthConfig/ConfigValue serialization, swept the CLI crate for missed print paths, confirmed no feature-gating coverage trap, re-ran the targeted redaction/render tests.

Recommend merge.

let lower = key.to_ascii_lowercase();
SECRET_REF_SAFE_KEYS.iter().any(|s| *s == lower)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional (residual risk, already tracked). SECRET_CONFIG_KEYS is a key-name allowlist, so a secret stored under a key not on the list still prints in the clear — the container-shape hardening only triggers when the outer key is already a secret key.

This is the documented "fails open" behavior tracked in #1504, and this PR correctly brings the CLI to parity with the server rather than solving it here. No change requested; flagging only so the guarantee's edge is explicit in the review record.

let mut redacted = false;
match value {
JsonValue::Object(map) => {
for (k, v) in map.iter_mut() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional (note, not a defect). redact_secret_subtree preserves a string value under any key named env_var/java_property at any depth inside a secret subtree.

That's the intended debugging affordance (those keys hold a name, not a value) and matches ConfigValue::Dynamic, so it's correct — worth only a mental note that a self-inflicted config storing a literal secret under a key literally named env_var would preserve it.

@zonotope
zonotope merged commit 64b70cc into main Jul 23, 2026
13 checks passed
@zonotope
zonotope deleted the fix/info-cred-leak branch July 23, 2026 14:08
aaj3f added a commit that referenced this pull request Jul 29, 2026
Reconcile graph-source secret redaction + CLI /info display refactor:
- ledger_info.rs: union redact_json_secrets — keep lambda's ConfigValue::SecretRef preservation (is_secret_ref_object, checked first) AND main's #1534 fail-closed container handling (redact_secret_subtree / SECRET_REF_SAFE_KEYS).
- cli iceberg.rs & info.rs: adopt main's unified graph_source_display module; drop the now-orphaned inline print/redact helpers and their tests (coverage moved to graph_source_display.rs).
q-qp-p pushed a commit to q-qp-p/fluree-db that referenced this pull request Aug 4, 2026
PR fluree#1528 (big-Iceberg-audit implementation + browse-parity + family-C,
approved by bplatz) was merged while its base still pointed at the scaffolding
branch perf/audit-mainmerge-base, so its content landed there instead of main.
This merges current main (carrying fluree#1520, fluree#1507, fluree#1514, fluree#1477) into the audit
content so the combined tree can be proposed to main.

Conflict resolutions:
- fluree-db-iceberg/src/mor_guard.rs (add/add): family-C converged superset.
  Its W1/W2 fail-closed guard bodies are byte-identical to main's; it omits the
  ensure_summary_scannable / ensure_manifests_scannable planner helpers, which
  the family-C planners inline. Verified those helpers have no remaining callers.
- fluree-db-iceberg/src/lib.rs, scan/planner.rs, scan/send_planner.rs: family-C
  inlined-guard arms (+ has_delete_manifests ScanPlan stamp). Main's non-conflict
  additions (parse_manifest_list_with_deletes, the F-AUD-1 mor_guard_tests
  fixtures) auto-merged and were preserved.
- fluree-db-api/src/graph_source/iceberg_catalog.rs: main's W3-evolved preview
  stats guard (typed 409 error, hoisted allow_mor, table_display,
  preview_counts_are_upper_bounds) — a functional superset of the audit's older
  F-AUD-1 form. Its preview_summary_guard called the dropped ensure_summary_scannable;
  inlined that helper's body (mor_deletes_allowed + ensure_no_summary_deletes),
  matching how the family-C planners inline the same guard.
- fluree-db-api/src/format/mod.rs: family-C crawl formatter (crawl uses
  format_node_object_binding; the format_binding_with_result re-export is unused).
  Gated the crawl-only formatter helpers and their Binding import behind the
  iceberg feature to clear a pre-existing fluree#1528 featureless dead-code gap.
- fluree-db-api/src/ledger_info.rs: auto-merged as the union of main's fluree#1534
  redaction machinery and the audit /info mor-approximate extensions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fluree info prints OAuth2 client_secret in plaintext — ConfigValue redacts Debug but not Serialize

2 participants