MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

User with /dev/null homedir can't connect to database #1014

Closed BryanJacobs closed 1 year ago

BryanJacobs commented 1 year ago

When asyncpg is run with a home-dir-less user, it cannot connect to a database because pathlib.Path.Home() may resolve to /dev/null or similar.

In connect_utils.py, around line 551, asyncpg attempts to load an SSL client certificate from the executing user's home dir. If the user doesn't have a home dir, this may result in a path like /dev/null/.postgresql/postgresql.crt and throw a NotADirectoryError. The intent was to ignore such errors, but only FileNotFoundException is caught.

The result is that users whose home directories aren't directories, as such, at all... can't connect to database servers even without using SSL.

I think the catch should be more comprehensive, and for a non-SSL-mandated connection we should proceed regardless of the reason the file can't be read.