Skip to content

Support .pgpass file for passwordless connection in corporate/CI environments #275

Description

@chirag127

Problem

The PostgreSQL extension currently requires a password to be stored either in VS Code's secret storage (interactive only) or inline in the connection string. In corporate and CI environments, developers use a ~/.pgpass file (the standard PostgreSQL password file) to supply credentials without interactive prompts. The extension does not read .pgpass and instead always shows a password prompt or fails with authentication failed.

.pgpass format (for context)

# hostname:port:database:username:password
db.corp.example.com:5432:mydb:myuser:s3cr3t
*:5432:*:ci_runner:ci_password

File lives at ~/.pgpass (Unix) or %APPDATA%\postgresql\pgpass.conf (Windows). PostgreSQL's libpq reads it automatically, but the extension's custom connection logic bypasses it.

Steps to Reproduce

  1. Create a valid ~/.pgpass (or %APPDATA%\postgresql\pgpass.conf on Windows).
  2. In the extension, add a new connection with the matching host/port/db/user — leave password blank.
  3. Click Connect.
  4. Result: password authentication failed — extension never read .pgpass.

Expected Behaviour

Before prompting for a password, the extension should check .pgpass (standard location per OS) and use the matching entry if found. This aligns with psql/pg_dump CLI behaviour.

Proposed Implementation

  • Add a utility resolvePgpass(host, port, db, user) that reads and parses .pgpass from the OS-appropriate location.
  • Call it during connection before falling back to the password prompt.
  • Add a pgsql.pgpassFile setting to override the default path (useful for CI where .pgpass is at a non-standard location).

Environment

  • OS: Windows 11 Enterprise (path: %APPDATA%\postgresql\pgpass.conf) and Linux CI
  • VS Code: 1.89+
  • Extension: ms-ossdata.vscode-pgsql latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions