-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use and respect the passfile connection parameter #1129
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Use and respect the passfile connection parameter
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
- Loading branch information
commit 29f3a400f54725dfcc8a36253f4b14b938ce4135
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,7 @@ localhost:*:*:*:pass_C | |
if err != nil { | ||
t.Fatalf("Unexpected error writing pgpass file %#v", err) | ||
} | ||
defer os.Remove(pgpassFile) | ||
pgpass.Close() | ||
|
||
assertPassword := func(extra values, expected string) { | ||
|
@@ -221,8 +222,11 @@ localhost:*:*:*:pass_C | |
// localhost also matches the default "" and UNIX sockets | ||
assertPassword(values{"host": "", "user": "some_user"}, "pass_C") | ||
assertPassword(values{"host": "/tmp", "user": "some_user"}, "pass_C") | ||
// passfile connection parameter takes precedence | ||
os.Setenv("PGPASSFILE", "/tmp") | ||
assertPassword(values{"host": "server", "dbname": "some_db", "user": "some_user", "passfile": pgpassFile}, "pass_A") | ||
|
||
// cleanup | ||
os.Remove(pgpassFile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we still keep the cleanup step? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is in a defer next to where the file is created |
||
os.Setenv("PGPASSFILE", "") | ||
} | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the correct place to handle the env var is here:
pq/conn.go
Line 2009 in 381d253
then the logic after
parseEnviron
is called will automatically take care of making the connection string parameter override the env var:pq/connector.go
Line 61 in 381d253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are right, it makes sense. I didn't see that I focused in that function. Pushed a new commit.