Skip to content

On unix, .pgpass is being looked up in ~/postgresql, not in ~/ #3640

Description

@quassnoi

Before submitting

This repo is for Npgsql ADO.NET issues only. Entity Framework issues belong in Npgsql.EntityFrameworkCore.PostgreSQL for EF Core, or EntityFramework6.Npgsql for EF 6.x.

Steps to reproduce

  1. Read the documentation:

The file .pgpass in a user's home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise)

  1. Create a valid ~/.pgpass
  2. Run this code:
using Npgsql;

await using var connection = new NpgsqlConnection("Host=myhost;Username=myuser;Database=mydb;");
await connection.OpenAsync();
  1. Observe the error below.
  2. Copy ~/.pgpass to ~/postgresql/.pgpass
  3. Run the code above, this time without an error.

I don't think we should do this:

Path.Combine(appData, "postgresql", fileName) is string filePath &&

on unix environment for .pgpass

The issue

Describe what is not working as expected.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Unhandled exception. Npgsql.NpgsqlException (0x80004005): No password has been provided but the backend requires one (in MD5)
   at Npgsql.NpgsqlConnector.AuthenticateMD5(String username, Byte[] salt, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.ConnectorPool.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.ConnectorPool.<>c__DisplayClass38_0.<<Rent>g__RentAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Npgsql.NpgsqlConnection.<>c__DisplayClass41_0.<<Open>g__OpenAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
   at <Program>$.<<Main>$>d__0.MoveNext() in /workspaces/client/example1/example1.cs:line 5
--- End of stack trace from previous location ---
   at <Program>$.<<Main>$>d__0.MoveNext() in /workspaces/client/example1/example1.cs:line 13
--- End of stack trace from previous location ---
   at <Program>$.<Main>(String[] args)

Further technical details

Npgsql version: 5.0.4
PostgreSQL version: 13.2
Operating system: Ubuntu 20.04.2 LTS

Other details about my project setup:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions