question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect detection of pgpass file on non-Windows platform

See original GitHub issue

The driver handles pgpass file incorrectly on non-Windows operating systems, it searches for pgpass.conf while it should take a look at .pgpass. The default file location works right and depends on platform.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
YohDeadfallcommented, Oct 16, 2019

Here is a history of this file:

  1. Original version, environment variable was introduced in this repo in #1 and it was 3.2.
        internal static string? GetSystemPgPassFilePath()
        {
            var pgpassEnv = Environment.GetEnvironmentVariable("PGPASSFILE");
            if (pgpassEnv != null)
                return pgpassEnv;

            // ReSharper disable AssignNullToNotNullAttribute
            return PGUtil.IsWindows
                ? Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "postgresql", "pgpass.conf")
                : Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".pgpass");
            // ReSharper restore AssignNullToNotNullAttribute
        }
  1. Broken version by me.
        internal static string? GetSystemPgPassFilePath()
        {
            var pgpassEnv = Environment.GetEnvironmentVariable("PGPASSFILE");
            if (pgpassEnv != null)
                return pgpassEnv;

            return PGUtil.IsWindows
                ? Environment.GetEnvironmentVariable("APPDATA") is string appData ? Path.Combine(appData, "postgresql", "pgpass.conf") : null
                : Environment.GetEnvironmentVariable("HOME") is string home ? Path.Combine(home, "postgresql", "pgpass.conf") : null;
        }
  1. Broken version refactored by @roji, so the bug was hidden.
        internal static string? GetSystemPgPassFilePath()
            => Environment.GetEnvironmentVariable("PGPASSFILE") ??
               (Environment.GetEnvironmentVariable(PGUtil.IsWindows ? "APPDATA" : "HOME") is string appData
                ? Path.Combine(appData, "postgresql", "pgpass.conf")
                : null);
  1. Current version.
        internal static string? GetSystemPgPassFilePath()
            => Environment.GetEnvironmentVariable("PGPASSFILE") ?? (PGUtil.IsWindows
                ? Environment.GetEnvironmentVariable("APPDATA") is string appData ? Path.Combine(appData, "postgresql", "pgpass.conf") : null
                : Environment.GetEnvironmentVariable("HOME") is string home ? Path.Combine(home, "postgresql", ".pgpass") : null);

The bug was introduced in dev and backported to 4.1 via a rebase, so there is no breakage.

1reaction
rojicommented, Oct 15, 2019

FWIW we introduced pgpass support in 4.0 (#1442), but yeah, technically this is a breaking change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

postgresql: .pgpass not working
Make sure that the pgpass file has the correct format hostname:port:database:username:password (The Password File, passwordFromFile ). Each ...
Read more >
ubuntu - .pgpass with postgreSQL not working
Is the pgpass file set to mode 0600 (i.e. read/write only by the owner)? The client library will ignore it if it's group-...
Read more >
Thread: Have an encrypted pgpass file - Postgres Professional
Since .pgpass files contain plain-text passwords, I searched for an ... Here you side step those questions completely and make that the end...
Read more >
PostgreSQL Credentials | GitGuardian documentation
This detector catches PostgreSQL credentials in the form of a URI connection string, in a CLI command or stored in a pgpass file....
Read more >
Documentation: 15: E.5. Release 15
On non-Windows platforms, consult the HOME environment variable to find ... After an error is detected in psql's --single-transaction mode, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found