Documentation
¶
Overview ¶
Package pgdsn reads PostgreSQL connection strings (DSNs) the way the driver does, to keep their secrets out of places they must not reach: Redact for `sqi-server config print`, and WithoutPassword for a pg_dump command line, which any local user can read from the process list.
It imports only the standard library, so any package can use it. The keyword/value tokenizer mirrors pgx's (and libpq's), because a regular expression cannot: see [parseKeywordValueDSN]. A URL-form DSN is checked for every way Go's url.Parse and the driver's libpq-style parser can disagree (see [urlDSNAmbiguous]), and refused where they can.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Redact ¶
Redact returns dsn with its password (and sslpassword, the client key's passphrase) replaced by a placeholder, in either DSN form. A DSN without a password is returned unchanged.
The form is chosen as pgx chooses it: a DSN is a URL only when it starts with exactly "postgres://" or "postgresql://", and anything else is keyword/value.
It fails closed. A URL-form DSN whose password cannot be reliably located, because url.Parse refuses it or because [urlDSNAmbiguous] says that Go's reading of it and the PostgreSQL driver's can differ, is reduced to its scheme and a placeholder. A keyword/value DSN is tokenized as pgx tokenizes it (see [parseKeywordValueDSN]); one it cannot tokenize is reduced to the placeholder alone. A keyword/value DSN that does carry a password is rebuilt from its pairs, so its spacing and quoting may change, but pgx reads every other setting back exactly as before.
func SetsSSLPassword ¶
SetsSSLPassword reports whether dsn sets a non-empty sslpassword, the client key's passphrase, or cannot be read reliably enough to tell (see WithoutPassword), so a caller with no safe way to pass one on can refuse.
func WithoutPassword ¶
WithoutPassword returns dsn with its password and sslpassword removed, for a place the DSN can be seen but its secrets must not be: a pg_dump command line. It reads dsn exactly as Redact does, and refuses (rest "", ok false) wherever Redact fails closed: a URL-form DSN that url.Parse refuses or that [urlDSNAmbiguous] says the driver may read differently, and a keyword/value DSN that [parseKeywordValueDSN] cannot tokenize.
A URL-form DSN keeps every byte but those removed: the password of the userinfo (with its ":"; with the "@" too when no user name is left), and every query pair whose key is password or sslpassword in any case. A keyword/value DSN with no such key is returned as it came; otherwise it is rebuilt from its other pairs, as Redact rebuilds it. Either way pgx (and libpq, whose parsers pgx's mirror) reads back every other setting as before.
An upper-case PASSWORD key goes too: pgx sends it to the server as a runtime parameter and libpq rejects it, and it is most likely a password either way.
Types ¶
This section is empty.