Use and respect the passfile connection parameter#1129
Merged
rafiss merged 2 commits intolib:masterfrom Jul 7, 2023
Merged
Conversation
The postgres documentation[1] regarding the password file, states that: password file to use can be specified using the connection parameter passfile or the environment variable PGPASSFILE. The current implementation of lib/pq only respects the environment variable PGPASSFILE. This is not correct, but also limiting, as the PGPASSFILE is global and we might want to use different files for different clients in the same program. Fixing that is easy, by just checking the parameter passfile first, and if not, pull the value from PGPASSFILE. [1] https://www.postgresql.org/docs/current/libpq-pgpass.html
rafiss
requested changes
Jun 28, 2023
Collaborator
rafiss
left a comment
There was a problem hiding this comment.
thanks for your contribution!
| assertPassword(values{"host": "server", "dbname": "some_db", "user": "some_user", "passfile": pgpassFile}, "pass_A") | ||
|
|
||
| // cleanup | ||
| os.Remove(pgpassFile) |
Collaborator
There was a problem hiding this comment.
can we still keep the cleanup step?
Contributor
Author
There was a problem hiding this comment.
it is in a defer next to where the file is created
conn.go
Outdated
| return | ||
| } | ||
| filename := os.Getenv("PGPASSFILE") | ||
| // Get passfile from the options, if empty, get it from envvar |
Collaborator
Contributor
Author
There was a problem hiding this comment.
I see you are right, it makes sense. I didn't see that I focused in that function. Pushed a new commit.
Now the connection only checks the parameter passfile, that is populated by parseEnviron. Refactored the test for this
Contributor
Author
|
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.
The postgres documentation[1] regarding the password file, states
that:
password file to use can be specified using the connection parameter
passfile or the environment variable PGPASSFILE.
The current implementation of lib/pq only respects the environment
variable PGPASSFILE. This is not correct, but also limiting, as
the PGPASSFILE is global and we might want to use different files
for different clients in the same program.
Fixing that is easy, by just checking the parameter passfile first,
and if not, pull the value from PGPASSFILE.
[1] https://www.postgresql.org/docs/current/libpq-pgpass.html
How to test
Start a postgres
Run the test
go test -run TestPgpass -v .