asyncpg: SSL Certificate Verify Failed
- 13.0:
- 9.6.1:
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce the issue with a local PostgreSQL install? Yes, Heroku.:
- 3.6.3:
- Windows 10:
- Do you use pgbouncer? No:
- Did you install asyncpg with pip? Yes:
I was getting the same issue as #119 . I enabled the ssl=True in the await asyncpg.create_pool(self.dsn, ssl=True)
- and the same occurs with connect.
So then I used the SSL keyword param, and got ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 38 (10 by maintainers)
Commits related to this issue
- Add ssl context for database connection For some reason asyncpg doesn't connect with just db URI, see: https://github.com/MagicStack/asyncpg/issues/238 — committed to pltnk/toptracksbot by pltnk 4 years ago
- Added certificate by instruction https://github.com/MagicStack/asyncpg/issues/238#issuecomment-355137900 — committed to Na3aga/gmbot by moxxiq 4 years ago
- Can run locally, not only from server with ssl, thanks https://github.com/MagicStack/asyncpg/issues/238#issuecomment-588432863 . PEP8 tabs in decorator — committed to Na3aga/gmbot by moxxiq 4 years ago
Thanks, guys, here is what eventually works for me:
@imbolc I think there’s little point in actually using the certificate if you disable verification (
ctx.verify_mode = ssl.CERT_NOTE
).Work too
OK, so I went and created a test RDS instance to test. The following works perfectly for me:
Where
rds-combined-ca-bundle.pem
was downloaded from https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pemAsyncpg doesn’t work with
verify-full
. Can you please suggest a solution? Thanks.Connecting with psql:
Asyncpg connect script:
Error:
Tried the same with sqlalchemy with psycopg2 driver. It works great.
I still get the same error. It works with pyscopg2, but not with asyncpg, os not sure why
I’ve noticed this problem recently as well.
A few things I’ll add:
sslmode
settings for postgres. I’d imagine asyncpg should properly translate values likerequired
,verify-full
, etc to the right SSL context? Or make it clear how users can emulate those different behaviors by constructing it themselves? The value thats mentioned throughout Heroku devcenter isrequired
, which (according to the PG docs) forces SSL, but doesn’t do any validation. I believe the solution above in this comment achieves that?I’ve used Node on Heroku before, with this pg package, and I always used
ssl: true
in my configuration. That seems to translate to something similar in that package here (sincethis.ssl
istrue
, all of the attribute access on it returnsundefined
) as the SSL context without validation mentioned above.Duh. Replace
capath
withcafile
and it should work.Well, that’s weird. I’ll try to reproduce. Meanwhile you can disable the certificate verification like this: