Skip to content

pgconn: os/user.Current is called even when user is explicitly configured, causing SIGFPE in distroless containers #2586

Description

@tobyguelly

Describe the bug
pgconn.ParseConfigWithOptions appears to call defaultSettings() before parsing and merging the connection string. defaultSettings() calls os/user.Current() to populate the default PostgreSQL user / passfile / servicefile.

This means os/user.Current() is called even when the connection string explicitly contains user=....

In minimal/distroless container environments this can crash during CGO user lookup before the provided PostgreSQL user is applied.

To Reproduce
Call pgconn.ParseConfigWithOptions within a distroless Docker container with CGO enabled which will subsequently use the crashing libc implementation of user.Current().

Expected behavior
If the connection string or environment explicitly provides user, pgx should not need to call os/user.Current() to determine a default user.

Ideally, user lookup would be lazy / conditional:

  • parse connection string
  • parse environment
  • merge provided settings
  • only call os/user.Current() if user, passfile, or servicefile defaults are actually needed

Actual behavior
pgx eagerly looks up default OS-user-derived information even when that information is not needed, because the PostgreSQL user has already been explicitly configured. The crash is the visible symptom, but the pgx behavior concern is the unnecessary eager lookup of default information before knowing whether those defaults are required.

Stack trace excerpt:

SIGFPE: floating-point exception
signal arrived during cgo execution

os/user._Cfunc_mygetpwuid_r(...)
os/user.lookupUnixUid(...)
os/user.current()
os/user.Current()

github.com/jackc/pgx/v5/pgconn.defaultSettings()
github.com/jackc/pgx/v5/pgconn.ParseConfigWithOptions(...)

Version

  • Go: go1.26.4 linux/amd64
  • pgx: v5.10.0
  • Go build uses CGO, so os/user.Current() uses the libc lookup

Additional context
Any of these workarounds avoids or mitigates the issue:

  • build with -tags osusergo
  • build with CGO_ENABLED=0, if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions