need a way to pass rustls::ServerConfig for TLS configuration#676
Merged
davepacheco merged 2 commits intomainfrom May 25, 2023
Merged
need a way to pass rustls::ServerConfig for TLS configuration#676davepacheco merged 2 commits intomainfrom
rustls::ServerConfig for TLS configuration#676davepacheco merged 2 commits intomainfrom
Conversation
luqmana
approved these changes
May 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: This PR has a breaking change to the TLS API. I believe it'll be easy for consumers to move past. If you're using Dropshot with TLS and this looks painful, I'd like to hear from you -- soon.
Today, Dropshot supports TLS by providing a
ConfigDropshotTlsin theConfigDropshotthat you use to construct a Dropshot server.ConfigDropshotTlshas variants for providing a TLS certificate via either files or raw bytes. This is a pretty static mechanism. If consumers want to change the certificate at runtime (e.g., to rotate it without downtime), they can userefresh_tls()on the server.oxidecomputer/omicron#3164 wants to use TLS SNI to be able to select the certificate based on what server the client says they're connecting to. To do this, the certificate selection needs to be more dynamic than
refresh_tls()allows. Fortunately, under the covers, when you start Dropshot with TLS, it always just converts theConfigDropshotTlsinto arustls::ServerConfigand uses that. The rustls interface lets you use SNI (or just change certificates at runtime) by providing your own certificate resolver. For a consumer like Omicron whose certificates are truly dynamic, it's much cleaner to just pass arustls::ServerConfigdirectly into Dropshot and have it use that. Omicron will no longer need to bother withrefresh_tls()after that.This PR makes the following changes:
ConfigDropshotTls::Dynamicthat wraps arustls::ServerConfigConfigDropshotTlsfromConfigDropshot. This is a breaking change, but it's easy to move past (see below).HttpServerStart::new_tls()that's the same asHttpServerStart::new()but also accepts anOption<ConfigDropshotTls>. If that argument isNone, the server does not use TLS.The motivation for the breaking change is that
ConfigDropshotis intended to be dropped directly into a consumer's configuration file type (e.g., some type that's deserialized with serde from toml). But when usingConfigTls::Dynamic, there's nothing you can put in a config file to describe the TLS configuration. The conclusion: separate the static config from the TLS config. It's up to the consumer to decide how to get the TLS config and provide it separately to Dropshot (in the a new argument).For consumers not using TLS, there's no breaking change.
For consumers using TLS:
ConfigDropshotin an actual configuration file, if no action is taken, the existing TLS-related properties will be ignored. If you want to accept TLS configuration the same as before this PR, you can include aConfigDropshotTlsproperty in the config file alongside theConfigDropshotone. I believe (but have not tested) that you could do this without breaking your own consumers by defining a new typeConfigDropshotWithTlswith aConfigDropshotand aConfigDropshotTlsplus#[serde(flatten)]so that all the properties show up in the same place they used to.HttpServerStarter::new(), they must callHttpServerStarter::new_tls()and provideSome(ConfigDropshotTls)for someConfigDropshotTlsvalue. The same values that were supported before are still supported.Some other thoughts:
ConfigDropshotTlsin their config file that they ignore) or creating extra compatibility stuff (e.g., a separateConfigDropshotV2that doesn't have the TLS stuff). At our stage, I generally prefer to make breaking changes in Dropshot rather than keep compatibility cruft.HttpServerStarter::builder()with afn with_tls<T: Into<rustls::ServerConfig>>(t: T)and then define conversions fromConfigDropshotTlsintorustls::ServerConfig.refresh_tls()and say that if you want to change things at runtime, provide your ownrustls::ServerConfig.I'm aware of two Dropshot TLS consumers: