Skip to content

Add support for using TLS with PostgreSQL (#260) - #266

Closed
mossbanay wants to merge 3 commits into
rust-db:mainfrom
mossbanay:use_tls
Closed

mossbanay wants to merge 3 commits into
rust-db:mainfrom
mossbanay:use_tls

Conversation

@mossbanay

Copy link
Copy Markdown
Contributor

Hi, I would like to use Refinery with a PostgreSQL database over TLS similar to (#260).

It looked like this wasn't too difficult to implement, and seems to work fine from my local testing.
I've added a use_tls option that can be supplied in the toml config, and it also supports the original request of parsing from the connection string (though only disable and require are supported).

I don't often write Rust, let me know if you have any suggestions about this change.

Thanks

@mossbanay

Copy link
Copy Markdown
Contributor Author

I think some of the CI plans checking fmt fail because openssl packages aren't installed in the base image.
I was a bit worried this might happen, and same might be true of other people already using the package elsewhere.
Might be preferable to explicitly enabled postgres tls as a feature then? What do you think?

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think some of the CI plans checking fmt fail because openssl packages aren't installed in the base image.
I was a bit worried this might happen, and same might be true of other people already using the package elsewhere.
Might be preferable to explicitly enabled postgres tls as a feature then? What do you think?

Hi, and Thanks for this! Can we use the native-tls version instead?

Comment on lines +230 to +243
let use_tls = match query_params
.get("sslmode")
.unwrap_or(&Cow::Borrowed("disable"))
{
&Cow::Borrowed("disable") => Ok(false),
&Cow::Borrowed("require") => Ok(true),
_ => Err(()),
}
.map_err(|_| {
Error::new(
Kind::ConfigError("Invalid sslmode value, please use disable/require".into()),
None,
)
})?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let use_tls = match query_params
.get("sslmode")
.unwrap_or(&Cow::Borrowed("disable"))
{
&Cow::Borrowed("disable") => Ok(false),
&Cow::Borrowed("require") => Ok(true),
_ => Err(()),
}
.map_err(|_| {
Error::new(
Kind::ConfigError("Invalid sslmode value, please use disable/require".into()),
None,
)
})?;
let use_tls = match query_params
.get("sslmode")
.unwrap_or(&Cow::Borrowed("disable"))
{
&Cow::Borrowed("disable") => false,
&Cow::Borrowed("require") => true,
_ => return Error::new(
Kind::ConfigError("Invalid sslmode value, please use disable/require".into()),
None,
),
};

}

#[test]
fn build_no_tls_conn_from_str() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we do it all on one test? both the use not use and the invalid value?

@aig787

aig787 commented Jun 1, 2023

Copy link
Copy Markdown

@mossbanay any chance you'll have time to finish this up? If not I'm happy to take a swing at it.

@mossbanay

Copy link
Copy Markdown
Contributor Author

@aig787 Sorry slipped through my inbox. By all means go for it!

@mortenbirkelund

Copy link
Copy Markdown

Any updates on this?

@jxs

jxs commented Jul 25, 2025

Copy link
Copy Markdown
Member

superseeded by #353

@jxs jxs closed this Jul 25, 2025
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