MagicStack / asyncpg

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

Exception when attempting to fetch SSL info #884

Open bjones1 opened 2 years ago

bjones1 commented 2 years ago

Thanks for creating asyncpg! It's dramatically improved the performance of my open-source web application (Runestone Academy, a free interactive e-book).

To reproduce this bug, simply start asyncpg as a non-root user (one without permission to access /root).

I run asyncpg as a non-root user for improved security; this user lacks root access. During startup in asyncpg v. 0.25, I see the error like this:

  File "/srv/web2py/applications/runestone/.venv/lib/python3.9/site-packages/asyncpg/connection.py", line 2085, in connect
    return await connect_utils._connect(
  File "/srv/web2py/applications/runestone/.venv/lib/python3.9/site-packages/asyncpg/connect_utils.py", line 874, in _connect
  addrs, params, config = _parse_connect_arguments(timeout=timeout, **kwargs)
  File "/srv/web2py/applications/runestone/.venv/lib/python3.9/site-packages/asyncpg/connect_utils.py", line 640, in _parse_connect_arguments
  addrs, params = _parse_connect_dsn_and_args(
  File "/srv/web2py/applications/runestone/.venv/lib/python3.9/site-packages/asyncpg/connect_utils.py", line 543, in _parse_connect_dsn_and_args
    if not sslkey.exists():
  File "/usr/local/lib/python3.9/pathlib.py", line 1424, in exists
    self.stat()
  File "/usr/local/lib/python3.9/pathlib.py", line 1232, in stat
    return self._accessor.stat(self)
PermissionError: [Errno 13] Permission denied

In connect_utils.py line 543, asyncpg checks if a root-owned file exists. Unfortunately, a non-root user gets a permission denied exception instead of a False return value from exists(). It looks like wrapping this in a try/except would fix this bug. (It looks like a later exception needs PermissionError added to it.)

For me, reverting to asyncpg v. 0.24 causes my code to run without problems.

hyeongguen-song commented 1 year ago

Is there anything going on on this issue?