Skip to content

fix: whole-repository dataflow review (8 defects) - #40

Open
SHSharkar wants to merge 1 commit into
mainfrom
arena/b9456349-ownpg
Open

SHSharkar wants to merge 1 commit into
mainfrom
arena/b9456349-ownpg

Conversation

@SHSharkar

@SHSharkar SHSharkar commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

A whole-repository review of the dataflow lifecycle across crates/, in two passes. Eight defects are fixed, each with a regression test or an existing test extended. The final section records what was verified clean and what could not be run.

Changes

Encryption is reported from the handshake, not from sslmode (connect/, tools/health.rs, doctor.rs)

pg_health and pg_doctor inferred encryption from the configured mode, so a pooled connection that fell back to plaintext reported as encrypted, and a Unix socket reported as encrypted too. A TlsUse flag set by the connector's connect future now records what the handshake produced. This is reliable because connect_raw awaits connect_tls and then startup and authentication before it returns.

Audit recovery hashes the whole last line (audit.rs)

Restarting recovered only the final 64 KiB of the last line and hashed that suffix. A line longer than the window produced a chain start linked to the wrong digest, and ownpg audit verify then rejected a file it had written itself. Recovery now hashes the complete last line, with the bounded read kept as the fallback for a line that will not fit in memory.

The audit log narrows an inherited file mode (audit.rs)

mode(0o600) applies only on creation. An audit.jsonl left by an earlier umask was opened and appended to with its broader bits intact, while the lines added to it carry statement class, relations, principal, and a short statement. The open path now applies 0600 to the descriptor before taking the lock, which also lets a single-user audit file recover without a manual chmod.

An RSA key component is bounded before caching (server/http/jwks.rs)

The EC and Ed25519 branches validated component widths; the RSA branch took any modulus and exponent. The key set is cached for the life of the process and refreshed from the configured key endpoint, so an oversized component stayed resident inside the 1 MiB body cap. The bounds match the ranges ring verifies, so no currently-working key is excluded.

Questions closed rather than changed

  • Session ownership gating is correct. The ownership check and the bind/unbind calls run only under older_client_sessions. rmcp 3.4.1 documents that legacy_session_mode applies only to legacy protocol versions and that requests negotiating 2026-07-28 are always served statelessly. The server advertises exactly 2025-11-25 and 2026-07-28, so the gated branch is the only one that can mint a session id.
  • refuse-writes is not bypassable through a read-only tool. audit_admits receives route.spec.read_only, and the four host tools marked read-only still have real side effects. Under the reading that the policy tests whether this call's own line could be written, the behaviour is consistent, so it was left alone.

Verification

No Rust toolchain exists in this environment, so rustfmt, cargo build, cargo test, Clippy, and rustdoc have not run against these changes, and tools/verify.sh could not run either. The following did run:

  • tree-sitter parse over all 79 files: zero errors or missing nodes
  • git diff --check: clean
  • the repository's static gate patterns by hand: no code comment, no em-dash, no banned wording, no markdown table
  • tool routing: 50 ToolSpec constants against 50 registered routes, both difference sets empty
  • a sweep over every pub struct *Settings field and every low-frequency pub field: every one resolves to a consumer
  • no unwrap or expect in production source outside tests
  • pg_restore -n is exact memcmp membership in PostgreSQL 18 and 19 sources, confirming the schema pinning needs no quoting
    Appended to the body: a second review pass.

Second pass: exhaustive sweep over every file

The first pass mixed targeted greps with reading. This pass ran mechanical rules over all 79 files under crates/ and read the files that pass had not opened at all (cli.rs, config_cmd.rs, man.rs, logging.rs, context.rs, libpq.rs, presets.rs, programs.rs, describe.rs, profile.rs, transaction.rs, objects.rs, catalog.rs, pooler.rs, residency, metrics.rs, limit.rs, jwks.rs, resources.rs, prompts.rs, stdio.rs).

Tooling: ast-grep rule pack (panic sites, unsafe, lossy casts, discarded results, lock acquisitions, fallible-defaulted values, secret exposure, error interpolation) plus tree-sitter parsing, run over the whole tree and filtered to production code by cutting each file at its #[cfg(test)] module.

Defects found and fixed in this pass

  1. A refused credential was echoed. Error::ConfigInvalid renders as `{value}` is not a usable {setting}, and cannot_honor passed the value through. sslpassword, oauth_client_secret, and scram_client_key are refused keywords, so ownpg --dsn "host=db sslpassword=hunter2" printed the secret to stderr and into any log that captured the error. Those keywords now render as set.
  2. A scopeless OAuth token was granted read access. Principal::allows treats None as unrestricted and Some(vec![]) as holding nothing, so a JWT that authenticated but carried no ownpg:* scope failed every tools/call with 403 while reading resources and prompts succeeded, because principals.rs does not check scope. Claims are now filtered to known scopes, and a token left with none is refused at authentication.
  3. The savepoint list grew without bound. A repeated savepoint name appended a duplicate each time, and nothing in the engine caps the list, so the growth lasted as long as the handle stayed open. A repeated name is now recorded once.
  4. A dump could report success without a checksum. When spawn_blocking for the digest failed, the join error and the read error were both discarded and the tool reported success with output_sha256 absent. Both paths now log a warning.

Verified clean across the whole tree

  • 79 files parse with zero tree-sitter errors.
  • 50 ToolSpec constants against 50 registered routes, both difference sets empty.
  • Every pub struct *Settings field and every field appearing at most twice resolves to a consumer.
  • Every pub item in production code is referenced beyond its definition: zero unreachable items.
  • 38 error variants, each with an id() arm and a remedy() arm, no catch-all, no unused ErrorId.
  • No unwrap, expect, panic!, todo!, or unimplemented! in production source; the three unreachable! calls are the documented signal-handler branches.
  • No unsafe block anywhere.
  • Production lock acquisitions (150) re-read for re-entrant and cross-order acquisition: no same-mutex re-lock and no lock-order inversion.
  • Every environment variable the code reads (95) appears in the manual, and the manual's own test enforces it.
  • deny.toml against Cargo.lock: lazy_static and anyhow are banned but present only under their allow-listed wrappers; no skip entry is stale; every allow-build-script crate is in the lock.
  • deny.toml licence list, about.toml accepted list, and the Dockerfile third-party notice agree.
  • Workspace, both crates, server.json, and mcpb/manifest.json all carry 0.1.2.
  • Whole-tree comment, em-dash, banned-wording, and markdown-table greps, plus git diff --check: clean.
  • Suppression recheck dates: tools/check-suppressions.py passes.

Skill availability

No skill toolkit is installed in this environment and the repository has none. The Rust, data-flow, dead-end, and audit dimensions were run as the rule pack above plus direct reading; nothing was skipped for lack of a packaged skill.

Limitation, unchanged

There is still no Rust toolchain (static.rust-lang.org is unreachable from this sandbox and no rustc exists), so cargo, rustfmt, clippy, and tools/verify.sh did not run. Every claim above is static analysis or reading, not compiler output.

@SHSharkar SHSharkar changed the title fix: report observed TLS, survive long audit lines, narrow audit file mode, bound RSA keys fix: whole-repository dataflow review (8 defects) Dec 2, 2026
Eight defects found reviewing every file in crates/ against CLAUDE.md,
tools/verify.sh, and a rule pack run over the whole tree.

Encryption is reported from the handshake rather than the configured sslmode,
so a pooled connection that fell back to plaintext and a Unix socket no longer
report as encrypted.

Audit recovery hashes the whole last line instead of the final 64 KiB of it,
which used to link a restarted chain to the wrong digest once a line exceeded
the recovery window. The open path also narrows an existing audit file to 0600;
the mode was applied on creation and rotation only, so a file left by an
earlier umask kept its broader bits while receiving statement class, relations,
and principal.

A JSON Web Key Set drops an RSA key whose modulus or exponent is outside the
sizes the verifier accepts, where the EC and Ed25519 branches already checked.

A refused libpq credential keyword no longer echoes its value through
ConfigInvalid, which printed sslpassword, oauth_client_secret, or
scram_client_key to the terminal and to any log that captured the error.

An OAuth token whose claims carry none of this server's scopes is refused
instead of being treated as read-only: an empty scope list failed every
tools/call while resources and prompts succeeded.

A repeated savepoint name is recorded once, so a handle's savepoint list stops
growing while it stays open.

A dump whose output file cannot be checksummed warns instead of reporting
success with the digest missing.

Two production sites indexed or sliced, which clippy denies outside test code:
the trailing audit byte now reads through first(), and splitting a type element
at its WITH clause goes through get(), so a match that lands inside a multibyte
character is skipped rather than panicking.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@SHSharkar
SHSharkar force-pushed the arena/b9456349-ownpg branch from cb45f0d to 0e22ba9 Compare December 2, 2026 21:02
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.

1 participant