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

feat: add support for keymanager service to create TLS connection using sslmode=verify-full #36

Merged
merged 10 commits into from
Dec 27, 2024

Conversation

ArjunKarthik
Copy link
Collaborator

@ArjunKarthik ArjunKarthik commented Dec 18, 2024

PR Description:

  • This PR adds feature to enable and disable TLS communication between application and database.
  • With this changes TLS can be enabled in verify-full mode where connection between application and DB will be encrypted and server root ca will also be verified which prevents MITM. For more info Postgres documentation
  • This functionality is under feature flag "postgres_ssl", and only available in the release build

Steps to enable TLS:

"database.enable_ssl" in the env should be true and "database.root_ca" should be provided for enabling "verify-full" ssl mode.

Steps to disable TLS

"database.enable_ssl" is an optional field, So setting it as false or not at all having this config in the env will prevent the application to establish connection with DB using TLS.

@ArjunKarthik ArjunKarthik self-assigned this Dec 18, 2024
src/storage.rs Outdated

let mut roots = rustls::RootCertStore::empty();

match env::var(DB_ROOT_CA_PATH) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of env better take it from the config

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't read this from config as this method is being called from establish_connection method.

We are not calling establish_connection in our code directly instead, we are passing the method to custom_setup param of ManagerConfig. establish_connection method only accept &str parameter where we can't pass our Config

Copy link
Member

Choose a reason for hiding this comment

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

So, instead of passing this function for custom_setup you can pass a closure, and you can move the CA environment value in the closure from from_config's context.

src/storage.rs Outdated Show resolved Hide resolved
src/storage.rs Outdated Show resolved Hide resolved
dracarys18
dracarys18 previously approved these changes Dec 20, 2024
Copy link
Member

@dracarys18 dracarys18 left a comment

Choose a reason for hiding this comment

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

LGTM

src/storage.rs Outdated

let mut roots = rustls::RootCertStore::empty();

match env::var(DB_ROOT_CA_PATH) {
Copy link
Member

Choose a reason for hiding this comment

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

So, instead of passing this function for custom_setup you can pass a closure, and you can move the CA environment value in the closure from from_config's context.

keyspace = "encryption_db"
timeout = 60
cache_size = 120
enable_ssl = false
Copy link
Member

Choose a reason for hiding this comment

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

why are you removing cassandra? is this intended?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah

@dracarys18 dracarys18 merged commit 1ef277b into main Dec 27, 2024
2 checks passed
@dracarys18 dracarys18 deleted the encrypt_database_connection_url branch December 27, 2024 06:19
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.

3 participants