-
Notifications
You must be signed in to change notification settings - Fork 163
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 SSL/TLS support for Postgres connections #104
Conversation
Hi @wseaton, thanks for the PR! The logic of the connection construction looks pretty good to me and the docstrings make it very clear. There are only two things that I think might need some changes:
I can make some modifications for the 2 issues above as well as add some tests. Let me know if you have any concerns : ) |
Hey @wangxiaoying, thanks for the quick review!
Hmm, I agree, although I could not find a simple method to add custom client certificates when using
I can definitely fix this one.
Sure, feel free to make any modifications you wish :) One other thing I noticed was that the type alias for PgManager is not very ergonomic due to generics and may cause issues if we want to alternate between |
@wseaton Thanks for the quick reply : )
Indeed, I also found that openssl is necessary if we need to support client authentication. But it seems like it is not a common need. According to this doc, client side authentication is used to defend against impersonation, which is typically due to insecure password management. Also there seems to be some compatibility issue for openssl (between 1.0 and 1.1). Maybe we can only support server authentication for now (
Totally agreed. I'm trying to see whether there is a good way to make it more generic. It would be better if we could alter between |
@wangxiaoying refactored things a little bit, and moved the main logic for SSL construction into |
Hi @wseaton we made a big refactor in the last 24 hours. I rebased your code to the refactored main branch and solved several conflicts and force pushed. You can do |
b297764
to
ba6c2d8
Compare
@wangxiaoying just tested your latest |
@wseaton That's great! I cleaned up the code a little bit and tested with postgres on aws rds. If you think it's ok then we can merge it after review! |
Is there any possibility of adding support for the sslkey and sslcert for client auth? |
Hi @frostpuppet , we currently only support server-side authentication since client auth is less common. Adding support for client auth may require May I ask what's your use case scenario for client auth? |
Thanks for replying so quickly. My use case really revolves around the way our database is secured. Typically a client will request access and certificates are issued through a Vault. So in my case I only have 3 certs and no password is issued. |
As discussed in #103, currently there's no way to connect to a postgres database that mandates a TLS/SSL connection.
What this PR does is make it so
sslmode=required
is functional, and if a root cert and no client certs are passed it falls back to the behavior ofsslmode=verify-ca
.Example conn string:
There is a lot of upstream discussion on the topic and I've tried to link to it in doc strings where appropriate. Tested it on Amazon Redshift, but looking for pointers on how to add functional tests for this. All of the code probably isn't idiomatic rust either, so looking for some feedback there too. Thanks!