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

Enforce https for native-tls backend #2316

Closed
wants to merge 1 commit into from
Closed

Conversation

benlcb
Copy link

@benlcb benlcb commented Feb 6, 2023

Motivation and Context

@LukeMathWalker just set the minimum TLS version for native-tls to v.1.2: #2312
I suggest that we also enforce HTTPS connections, because this might prevent customers from accidentally supplying http URLs.

The main concern not to do this was that some customers might rely on http connections.
But given that http support can easily be re-enabled by customers as described in the added doc/comment (see diff), this should not be an issue.

The hyper_tls::HttpsConnector used here also doesn't sent https data to http endpoints, instead it will refuse to connect when given an http URL:

let is_https = dst.scheme_str() == Some("https");
// Early abort if HTTPS is forced but can't be used
if !is_https && self.force_https {
    return err(ForceHttpsButUriNotHttps.into());
}

Description

Forcing https connections by default for the native_tls connector.

Testing

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@benlcb benlcb requested a review from a team as a code owner February 6, 2023 17:54
pub fn native_tls() -> NativeTls {
let mut tls = hyper_tls::native_tls::TlsConnector::builder();
let tls = tls
.min_protocol_version(Some(hyper_tls::native_tls::Protocol::Tlsv12))
.build()
.unwrap_or_else(|e| panic!("Error while creating TLS connector: {}", e));
let http = hyper::client::HttpConnector::new();
hyper_tls::HttpsConnector::from((http, tls.into()))
let mut https = hyper_tls::HttpsConnector::from((http, tls.into()));
https.https_only(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we'd want the same change in HTTP_NATIVE_ROOTS as well, a few lines above.

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking about that, but the hyper_rustls::HttpsConnector doesn't seem to provide a way for customers to also allow http. So the original concern is still valid here.

Copy link
Contributor

@LukeMathWalker LukeMathWalker Feb 6, 2023

Choose a reason for hiding this comment

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

I'd be quite wary of having diverging behaviour on something like this between the two TLS backends we support - that can turn out to be quite surprising for users.

Copy link
Author

Choose a reason for hiding this comment

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

If you think that consistency is (more) important in this case, then this PR can be scrapped.

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion here is to apply the change to both backends, rather than to native-tls only.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it looks like we would need a breaking change for this, either returning the builder from fn https() or taking an argument for allow_http: bool on it, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Made a PR for this in hyper-rustls here.

Copy link
Contributor

@LukeMathWalker LukeMathWalker Feb 7, 2023

Choose a reason for hiding this comment

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

rustls uses a type-state builder, which requires configuration to be supplied in a specific order.
The "step" that you are currently in bleeds through the type signature as well.
Returning a partially configured rustls HTTPS connector doesn't look like an option - we need to provide one set of configuration with good defaults and then explain in the documentation section how they could configure it otherwise (linking to rustls' own docs).

@@ -84,15 +84,18 @@ pub mod conns {
/// Return a default HTTPS connector backed by the `hyper_tls` crate.
///
/// It requires a minimum TLS version of 1.2.
/// It allows you to connect to both `http` and `https` URLs.
/// It allows only https connections.
/// To enable http connections, call `https_only(false)` on the retured NativeTls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// To enable http connections, call `https_only(false)` on the retured NativeTls.
/// To enable http connections, call `https_only(false)` on the retured `NativeTls`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also:

  • Typo retured -> returned
  • Suggestion https_only(false) -> .https_only(false)

@82marbag
Copy link
Contributor

We're removing native-tls: #2675

I'm closing this issue

@82marbag 82marbag closed this May 15, 2023
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