-
Notifications
You must be signed in to change notification settings - Fork 405
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
add support for sslcert, sslkey and sslrootcert parameters #768
Conversation
asyncpg/connect_utils.py
Outdated
@@ -442,6 +458,21 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user, | |||
else: | |||
sslmode = SSLMode.disable | |||
|
|||
if sslcert is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An explicit SSLContext
passed to connect()
is considered to be of higher priority than the environment, so let's move this block inside if isinstance(ssl, (str, SSLMode)):
above.
asyncpg/connect_utils.py
Outdated
if sslcert: | ||
ssl.load_cert_chain(sslcert, keyfile=sslkey) | ||
if sslrootcert: | ||
ssl.load_verify_locations(cafile=sslrootcert) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_verify_locations
also supports CRL (just call it again), so let's add that while we are here.
You are a hero! This works great. |
Can this PR be approved and merged please ? Most deployments use SSL settings. |
asyncpg/connection.py
Outdated
@@ -1755,6 +1755,10 @@ async def connect(dsn=None, *, | |||
max_cacheable_statement_size=1024 * 15, | |||
command_timeout=None, | |||
ssl=None, | |||
sslcert=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for all the extra arguments in connect()
. If you need to customize the certs, you are supposed to pass an appropriate SSLContext
in the ssl
argument.
I removed the redundant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested to call SSLContext.load_verify_locations()
twice - as far as the second is CRL, the CA cert set in the first call is not overwritten, so I think this PR is good.
Changes ------- * Drop support for Python 3.5 (#777) (by @and-semakin in da58cd2 for #777) * Add support for Python 3.10 (#795) (by @elprans in abf5569 for #795) * Add support for asynchronous iterables to copy_records_to_table() (#713) (by @elprans in 1d33ff6 for #713) * Add support for coroutine functions as listener callbacks (#802) (by @elprans in 41da093 for #802) * Add support for sslcert, sslkey and sslrootcert parameters to DSN (#768) (by @jdobes and @elprans in c674e86 for #768) * Add copy_ wrappers to Pool (#661) (by @elprans in a6b0f28 for #661) * Add issubset and issuperset methods to the Range type (#563) (by @kdorsel in de07d0a for #563) Fixes ----- * Break connection internal circular reference (#774) (by @fantix in d08a9b8 for #774) * Make Server Version Extraction More Flexible (#778) (by @Natrinicle in d076169 for #778)
Changes ------- * Drop support for Python 3.5 (#777) (by @and-semakin in da58cd2 for #777) * Add support for Python 3.10 (#795) (by @elprans in abf5569 for #795) * Add support for asynchronous iterables to copy_records_to_table() (#713) (by @elprans in 1d33ff6 for #713) * Add support for coroutine functions as listener callbacks (#802) (by @elprans in 41da093 for #802) * Add support for sslcert, sslkey and sslrootcert parameters to DSN (#768) (by @jdobes and @elprans in c674e86 for #768) * Add copy_ wrappers to Pool (#661) (by @elprans in a6b0f28 for #661) * Add issubset and issuperset methods to the Range type (#563) (by @kdorsel in de07d0a for #563) Fixes ----- * Break connection internal circular reference (#774) (by @fantix in d08a9b8 for #774) * Make Server Version Extraction More Flexible (#778) (by @Natrinicle in d076169 for #778)
Changes ------- * Drop support for Python 3.5 (#777) (by @and-semakin in da58cd2 for #777) * Add support for Python 3.10 (#795) (by @elprans in abf5569 for #795) * Add support for asynchronous iterables to copy_records_to_table() (#713) (by @elprans in 1d33ff6 for #713) * Add support for coroutine functions as listener callbacks (#802) (by @elprans in 41da093 for #802) * Add support for sslcert, sslkey and sslrootcert parameters to DSN (#768) (by @jdobes and @elprans in c674e86 for #768) * Add copy_ wrappers to Pool (#661) (by @elprans in a6b0f28 for #661) * Add issubset and issuperset methods to the Range type (#563) (by @kdorsel in de07d0a for #563) Fixes ----- * Break connection internal circular reference (#774) (by @fantix in d08a9b8 for #774) * Make Server Version Extraction More Flexible (#778) (by @Natrinicle in d076169 for #778)
Allows to set
sslcert
,sslkey
andsslrootcert
connection parameters. Fixes #238 as it's not possible to set customSSLContext
object with loaded CA certificate in current version.Example: