-
Notifications
You must be signed in to change notification settings - Fork 35
Add configurable and extendable ssl options #52
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
base: main
Are you sure you want to change the base?
Changes from all commits
25b39f7
7ce9137
c661fc5
a3c7139
5f78560
75bb9ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,22 +166,28 @@ In Postgres, conventions used, including in connection URI are as follow: | |
|
|
||
| ### `pog` SSL usage | ||
|
|
||
| In `pog`, setting up an SSL connection simply ask you to indicate the proper flag | ||
| in `pog.Config`. The different options are `SslDisabled`, `SslUnverified` & | ||
| `SslVerified`. Because of the nature of the 3 modes of SSL, and because talking | ||
| to your database should be highly secured to protect you against man-in-the-middle | ||
| attacks, you should always try to use the most secured setting. | ||
| In `pog`, SSL configuration is designed to be both secure and flexible. The library provides three SSL modes through the `Ssl` type: | ||
|
|
||
| - `SslVerified`: The most secure option that verifies CA certificates (recommended) | ||
| - `SslUnverified`: Enables SSL without certificate verification (use with caution) | ||
| - `SslDisabled`: No SSL encryption (not recommended for production) | ||
|
|
||
| Both `SslVerified` and `SslUnverified` modes support Server Name Indication (SNI), which is essential for proper certificate verification when connecting to databases using virtual hosting or multi-domain certificates. | ||
|
|
||
| ```gleam | ||
| import pog | ||
|
|
||
| pub fn connect() { | ||
| pog.default_config() | ||
| |> pog.ssl(pog.SslVerified) | ||
| |> pog.ssl(pog.SslVerified(sni_enabled: True)) | ||
| |> pog.connect | ||
| } | ||
| ``` | ||
|
|
||
| The `sni_enabled` parameter (defaults to `True`) helps ensure proper SSL certificate verification by sending the server name during the SSL handshake. This is particularly important for: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it default to true? How is that?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that was my original plan but realised default are not that simple in Gleam, I'll remove it, good catch |
||
| - Databases using virtual hosting | ||
| - Certificates covering multiple domain names | ||
|
|
||
| ### Need some help? | ||
|
|
||
| You tried to setup a secured connection, but it does not work? Your container | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,14 +69,14 @@ pub type Ssl { | |
| /// option to use SSL and should be always used by default. | ||
| /// Never ignore CA certificate checking _unless you know exactly what you are | ||
| /// doing_. | ||
| SslVerified | ||
| SslVerified(sni_enabled: Bool) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the sni_enabled property and recommend to set this to true please 🙏 |
||
| /// Enable SSL connection, but don't check CA certificate. | ||
| /// `SslVerified` should always be prioritized upon `SslUnverified`. | ||
| /// As it implies, that option enables SSL, but as it is unverified, the | ||
| /// connection can be unsafe. _Use this option only if you know what you're | ||
| /// doing._ In case `pog` can not find the proper CA certificate, take a look | ||
| /// at the README to get some help to inject the CA certificate in your OS. | ||
| SslUnverified | ||
| SslUnverified(sni_enabled: Bool) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the sni_enabled property and recommend to set this to true please 🙏 |
||
| /// Disable SSL connection completely. Using this option will let the | ||
| /// connection unsecured, and should be avoided in production environment. | ||
| SslDisabled | ||
|
|
@@ -113,7 +113,19 @@ pub fn password(config: Config, password: Option(String)) -> Config { | |
|
|
||
| /// Whether to use SSL or not. | ||
| /// | ||
| /// (default: False) | ||
| /// The SSL configuration provides three modes: | ||
| /// - `SslVerified`: Most secure option that verifies CA certificates (recommended) | ||
| /// - `SslUnverified`: Enables SSL without certificate verification (use with caution) | ||
| /// - `SslDisabled`: No SSL encryption (not recommended for production) | ||
| /// | ||
| /// Each SSL mode can be configured with SNI (Server Name Indication) support, | ||
| /// which is particularly useful for virtual hosting and multi-domain certificates. | ||
| /// | ||
| /// Example: | ||
| /// ```gleam | ||
| /// pog.default_config() | ||
| /// |> pog.ssl(pog.SslVerified(sni_enabled: True)) | ||
| /// ``` | ||
| pub fn ssl(config: Config, ssl: Ssl) -> Config { | ||
| Config(..config, ssl:) | ||
| } | ||
|
|
@@ -125,10 +137,10 @@ pub fn connection_parameter( | |
| name name: String, | ||
| value value: String, | ||
| ) -> Config { | ||
| Config( | ||
| ..config, | ||
| connection_parameters: [#(name, value), ..config.connection_parameters], | ||
| ) | ||
| Config(..config, connection_parameters: [ | ||
| #(name, value), | ||
| ..config.connection_parameters | ||
| ]) | ||
| } | ||
|
|
||
| /// Number of connections to keep open with the database | ||
|
|
@@ -290,8 +302,8 @@ fn extract_ssl_mode(query: option.Option(String)) -> Result(Ssl, Nil) { | |
| use query <- result.then(uri.parse_query(query)) | ||
| use sslmode <- result.then(list.key_find(query, "sslmode")) | ||
| case sslmode { | ||
| "require" -> Ok(SslUnverified) | ||
| "verify-ca" | "verify-full" -> Ok(SslVerified) | ||
| "require" -> Ok(SslUnverified(sni_enabled: True)) | ||
| "verify-ca" | "verify-full" -> Ok(SslVerified(sni_enabled: True)) | ||
| "disable" -> Ok(SslDisabled) | ||
| _ -> Error(Nil) | ||
| } | ||
|
|
||
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.
Can you add a note saying it's recommended to set this to true please