Repository navigation
🔒 fix(sink/postgres): redact ConnectError on export path (SEC-01-FUP3/FUP4) - #184
Conversation
There was a problem hiding this comment.
Pull request overview
Closes remaining SEC-01 redaction gaps in internal/sink/postgres by ensuring runtime Export-path errors cannot leak Postgres DSN host/user/db details via *pgconn.ConnectError, and simplifies parse-error redaction to a single fail-closed path.
Changes:
- Route Export-path
Begin,Commit, andExec/CopyFromfailures throughredactedConnectErrorwhile preserving existing sentinel error wrapping. - Collapse
redactedParseErrorto always return a static redacted message (removing a vestigial typed-branch). - Add focused tests verifying both
errors.Is(..., <sentinel>)behavior and absence of DSN tokens in error strings across Export-path sites.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/sink/postgres/pool.go | Simplifies DSN parse-error redaction and continues to provide ConnectError redaction helper. |
| internal/sink/postgres/bulk_export.go | Redacts *pgconn.ConnectError for row/bulk upsert execution paths by wrapping with redactedConnectError. |
| internal/sink/postgres/backend.go | Redacts *pgconn.ConnectError on runtime Export path (Begin, Commit, delete paths). |
| internal/sink/postgres/backend_export_redact_test.go | Adds regression tests ensuring ConnectError redaction and sentinel preservation on Export-related code paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // single unconditional return (SEC-01-FUP4). The typed error remains available | ||
| // programmatically to callers via the original err; only the returned string | ||
| // is redacted. |
…/FUP4) Wrap every pgx-returned error on the runtime Export path (pool.Begin, tx.Commit, both delete Exec calls, row-upsert Exec, bulk staging Exec, CopyFrom, and merge Exec) through the existing redactedConnectError helper so a lazy pool-reconnect *pgconn.ConnectError can no longer re-embed the tenant user, database, or target host into controller status/events. Non-ConnectError faults (PgError, context deadlines) pass through unchanged for diagnosis, and the sentinel errors.Is chain is preserved so callers still see a non-nil failure. Also collapse the vestigial *pgconn.ParseConfigError type check in redactedParseError: post-FUP1 both branches returned the identical static message, so it discriminated nothing (SEC-01-FUP4).
c8cb851 to
c9654e9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (1)
internal/sink/postgres/pool.go:54
- The comment on
redactedParseErrorsays the typed error remains available programmatically via the originalerr, but the function ignores its input and callers (e.g.newGuardedPool) return only the redacted error, so the original parse error is not available to downstream callers. This is misleading; either adjust the comment to reflect that the original error is intentionally dropped, or change the implementation to preserve it safely.
func redactedParseError(_ error) error {
// Fail closed for EVERY parse fault: never fold any free-form pgx text (which
// may echo the DSN or host) back into the returned string. Post-FUP1 the
// *pgconn.ParseConfigError type check discriminated nothing — both it and the
// fallthrough returned this identical static message — so it is collapsed to a
// single unconditional return (SEC-01-FUP4). The typed error remains available
// programmatically to callers via the original err; only the returned string
// is redacted.
return errors.New("parse postgres DSN: invalid connection string")
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |



What
Closes the last two SEC-01 redaction gaps in
internal/sink/postgres, both found by an independent reviewer after SEC-01 / SEC-01-FUP merged.SEC-01-FUP3 (P2) — redact
*pgconn.ConnectErroron the runtime Export pathSEC-01-FUP redacted
*pgconn.ConnectErrorat construct time (pool.Ping,ensureTable), but the runtime Export path still wrapped a lazy pool-reconnect*pgconn.ConnectErrorunredacted via%w, re-embedding the tenant user / database / host (plus the netguard resolver echo) into controller status/events.Every pgx-returned error on the Export path is now routed through the existing
redactedConnectErrorhelper (reused, not re-implemented):b.pool.BeginErrBeginTxFailedtx.CommitErrCommitTxFailedtx.ExecErrDeleteAllFailedtx.ExecErrDeleteStaleFailedtx.ExecErrUpsertFailedtx.ExecErrBulkUpsertCreateStagingFailedtx.CopyFromErrBulkUpsertCopyFailedtx.ExecErrBulkUpsertMergeFailedredactedConnectErrormatches*pgconn.ConnectErrorviaerrors.Asand returns a static message; non-ConnectError faults (PgError, context deadlines) pass through unchanged for diagnosis, and the sentinelerrors.Ischain is preserved so callers/controller still see a non-nil failure. The error is redacted, never swallowed.Excluded (already covered):
connection.gopool.Pingandbackend.goensureTableare redacted by SEC-01-FUP; decode /buildUpsertRowserrors carry no host.SEC-01-FUP4 (P3) — collapse the vestigial branch
redactedParseError's*pgconn.ParseConfigErrortype check discriminated nothing post-FUP1 — both theerrors.Asbranch and the fallthrough returned the identical static message. Collapsed to a single unconditional fail-closed return. Behavior is identical.TDD (RED first)
New
backend_export_redact_test.godrives a real*pgconn.ConnectError(netguard dial against127.0.0.1:1, rejected pre-egress — hermetic, no Docker):b.Export.ErrCommitTxFailed) is wrapped with the same helper but has no dedicated hermetic test: a*pgconn.ConnectErrorcannot surface on Commit of an already-open tx, and there is no seam to inject one. The wrap is defense-in-depth and passes non-ConnectError through unchanged.Each test asserts BOTH
errors.Is(err, <sentinel>)AND that the error string contains nouser=/tenantuser/tenantdb/127.0.0.1. RED confirmed pre-fix at every site (e.g.begin tx: failed to connect to+ "user=tenantuser database=tenantdb", anddelete all: failed to connect to ...); GREEN post-fix. A fixture guard fails loudly if pgx ever stops leaking the host so the tests can't pass vacuously.Gates (all green)
go build ./...,go vet ./...,task lint(0 issues),task verify,task test(postgres 85.7%),task coverage85.8% ≥ 85% floor,task scrubok.Scope: additive,
internal/sink/postgresonly. Does not touchinternal/sink/gitorinternal/controller.