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

Support tlsmode #555

Merged
merged 22 commits into from
Jul 19, 2024
Merged

Support tlsmode #555

merged 22 commits into from
Jul 19, 2024

Conversation

sitingren
Copy link
Member

@sitingren sitingren commented Jun 26, 2024

  • Add new connection option tlsmode.
  • When connection option ssl is not set, change its behavior from tlsmode='disable' to tlsmode='prefer'.
  • Update README TLS/SSL section.

Copy link

@kevinkarch88 kevinkarch88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look good and thorough to me. Approving.

README.md Outdated Show resolved Hide resolved
README.md Outdated
| 'disable' | False | only try a non-TLS connection. |
| 'prefer' | (not set) | (Default) first try a TLS connection; if TLS is disabled on the server, then fallback to a non-TLS connection. <br>Note: If TLS is enabled on the server and TLS connection fails, the client rejects the connection. |
| 'require' | True | connects using TLS without verifying certificates. If the TLS connection attempt fails, the client rejects the connection. |
| 'verify-ca' || connects using TLS and confirms that the server certificate has been signed by the certificate authority. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar nit, I would change the description slightly to say "...signed by a trusted certificate authority."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same change to the relevant part of verify-full

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -84,7 +95,7 @@ def _generate_and_set_certificates(self, mutual_mode=False):
# This CA certificate is used to verify client certificates
cur.execute('ALTER TLS CONFIGURATION server CERTIFICATE vp_server_cert ADD CA CERTIFICATES vp_CA_cert')
# Enable TLS. Connection succeeds if Vertica verifies that the client certificate is from a trusted CA.
# If the client does not present a client certificate, the connection uses plaintext.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good adjustment, more secure

raw_socket = self.enable_ssl(raw_socket, ssl_options)
# If TLSmode option and SSL option are set, TLSmode option takes precedence.
ssl_context = None
if tlsmode_options is not None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this logic be clearer as a function that takes tlsmode_options and ssl_options and returns the correct tlsmode?
tlsmode = _initTLSMode(self.options.get('tlsmode'), self.options.get('ssl'))

Copy link
Member Author

@sitingren sitingren Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this part will be wrapped into a function eventually, since this affects future works of making load balancing TLS encrypted, so I didn't do it. Now commit is pushed.

from typing import Optional


class TLSMode(Enum):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean. I like your implementation of this class.

Copy link
Contributor

@DMickens DMickens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look great

@sitingren sitingren merged commit 07f7a9b into vertica:master Jul 19, 2024
8 checks passed
@sitingren sitingren deleted the prefer-tls branch July 19, 2024 03:23
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 this pull request may close these issues.

4 participants