migrate-db: redact credentials from the postgres DSN in logs - #101
Merged
Merged
Conversation
openDestDb logs the destination postgres DSN verbatim, and the DSN is where the database password lives. The line is logged at info level, which since lightninglabs#98 is what `-v` selects: before that commit `-v` set the level to `error`, so the documented verbose invocation kept the password out of stderr. It doesn't anymore, and in the k8s setup lndinit is meant for, stderr is the pod log. Rather than looking for the parts of a DSN that are known to be sensitive, we keep only the ones that are known not to be. A connection string we fail to fully understand must not leak a password, so anything outside the allow list is dropped, and a DSN we can't parse at all is replaced wholesale. Both notations postgres accepts are handled, the URL one and the keyword/value one, since a password can hide in the userinfo section, in a query parameter or in a `password=` field.
djkazic
force-pushed
the
fix-postgres-dsn-log-leak
branch
from
September 17, 2026 14:34
f280908 to
851d251
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
migrate-dblogs the destination postgres DSN verbatim, and the DSN is wherethe database password lives:
The line is at info level, which is what
-vselects since #98; before that PR-vset the level toerrorand kept the password out ofstderr. In the k8ssetup
lndinitis built for,stderris the pod log.The line predates #98 and the handler defaults to info, so an invocation with no
flags at all printed the DSN before as well. Fixing the log line covers both
paths, which is why this doesn't touch the
-vchange.redactDsnkeeps only the parameters known not to hold a secret and dropseverything else, rather than hunting for the ones that do: a blocklist that is
wrong once prints the password, an allow list that is wrong just prints less.
A DSN that doesn't parse is replaced wholesale. Both notations
pgxaccepts arehandled, since a password can sit in the userinfo section, in a query parameter
or in a
password=field:postgres://alice:s3cr3t@localhost:5432/lnd?sslmode=disablepostgres://alice@localhost:5432/lnd?sslmode=disablepostgres://alice@localhost:5432/lnd?password=s3cr3tpostgres://alice@localhost:5432/lndhost=localhost user=alice password=s3cr3t dbname=lndhost=localhost user=alice dbname=lndpostgres://alice:s3cr3t@loc alhost/lnd[redacted]Host, port, database and user survive, which is what the line is there for.
TestRedactDsncovers each notation, the three hiding places, an unparsable DSNand a quoted value with spaces, asserting on every case that the password
appears nowhere in the output. The other
logger.Infosites log secret names,not values, so this was the only one the level change widened.