Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BryanJacobs opened this issue Mar 11, 2023 · 0 comments · Fixed by #1063
Closed

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

BryanJacobs opened this issue Mar 11, 2023 · 0 comments · Fixed by #1063

Comments

@BryanJacobs
Copy link

  • 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.

elprans added a commit that referenced this issue Aug 15, 2023
If `HOME` points to a regular file (or `/dev/null`), make sure we don't
crash unnecessarily, and if we do need to crash, so so informatively.

Fixes: #1014
elprans added a commit that referenced this issue Aug 15, 2023
If `HOME` points to a regular file (or `/dev/null`), make sure we don't
crash unnecessarily, and if we do need to crash, so so informatively.

Fixes: #1014
elprans added a commit that referenced this issue Aug 17, 2023
If `HOME` points to a regular file (or `/dev/null`), make sure we don't
crash unnecessarily, and if we do need to crash, so so informatively.

Fixes: #1014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant