Skip to content

postgres/gcppostgres: redact password from connection errors - #3752

Merged
vangent merged 1 commit into
google:masterfrom
herdiyana256:fix-gcppostgres-credential-leak
Jul 23, 2026
Merged

postgres/gcppostgres: redact password from connection errors#3752
vangent merged 1 commit into
google:masterfrom
herdiyana256:fix-gcppostgres-credential-leak

Conversation

@herdiyana256

@herdiyana256 herdiyana256 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

OSS VRP Issue 541240334

Both error paths in gcppostgres.go format the raw *url.URL with %v:

  • lazyCredsOpener.OpenPostgresURL, when Application Default Credentials fail to load
  • URLOpener.OpenPostgresURL, when the instance path fails to parse

Since url.URL's default String() method includes the userinfo password in plain text, any password supplied in the gcppostgres:// URL ends up in the returned error in both cases.

This switches both call sites to url.URL.Redacted(), which masks the password with "xxxxx" while keeping the rest of the URL for debugging. Added a test covering the malformed-path case.

go test ./postgres/... passes.

Both lazyCredsOpener.OpenPostgresURL (on ADC load failure) and
URLOpener.OpenPostgresURL (on malformed instance path) format the raw
*url.URL into the returned error with %v, which includes any userinfo
password verbatim. Use url.URL.Redacted() instead, matching the fix
already applied in secrets/localsecrets and the docstore/pubsub
default dialers.
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@0361726). Learn more about missing BASE report.

Files with missing lines Patch % Lines
postgres/gcppostgres/gcppostgres.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3752   +/-   ##
=========================================
  Coverage          ?   75.29%           
=========================================
  Files             ?      104           
  Lines             ?    14202           
  Branches          ?        0           
=========================================
  Hits              ?    10694           
  Misses            ?     2770           
  Partials          ?      738           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vangent
vangent merged commit 28f1a2a into google:master Jul 23, 2026
15 of 16 checks passed
@vangent

vangent commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for fixing these issues!

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.

2 participants