Skip to content

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

Closed
@BryanJacobs

Description

@BryanJacobs
  • asyncpg version: 0.27.0
  • PostgreSQL version: 14
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : Irrelevant
  • Python version: 3.10.9
  • Platform: Arch Linux x86_64
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: No
  • If you built asyncpg locally, which version of Cython did you use?: Didn't
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Irrelevant

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.

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