Open drewwells opened 5 months ago
Can you provide an example redacted log entry? That would help narrow down the bad code. I can't find anywhere that doesn't redact the password when logging.
here you have one:
ts=2024-06-05T07:34:28.288Z caller=postgres_exporter.go:731 level=error err="Error opening connection to database (host=XXX%20port=5432%20user=YYY%20password=ZZZ%20dbname=AAA%20sslmode=require): pq: password authentication failed for user \"YYY\""
@EvertonCalgarotto That log entry looks like it's from an old version of the exporter. What version are you using?
v0.10.1
v0.10.1 is very old. The most recent is v0.15.0. That log entry should not happen on the most recent version.
v0.10.1. The code on most recent looks the same, is there anything sanitizing these passwords?
It looks like the cause there is that the old redaction func is not accounting for the key=value style of DSN. The newer structures for DSN do account for this.
The best thing to do here on the code side would probably be to parse this into the DSN and use the String() func from that.
Short term, you could use a URL style connection string which should redact this (postgres://username:password@host/?params)
Ah okay, so if we used the more modern dsn, we would not be seeing the passwords in our logs?
is this the new format you're referring to?
postgres://<username>:<password>@<host>:<port>/<database>?sslmode=require
Yes with that format you should not be seeing the password. I believe that the format you reference is correct.
That said, this should still be resolved in code.
Proposal
Use case. Why is this important? We don't want to log our database passwords in our logs. Add a feature to remove passwords when logging out DSN. If there's other auth methods for exporter, maybe it's sufficient to document that using DSN with password will include the password in the log.