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

Support request specific TLS configuration #358

Merged
merged 15 commits into from
May 7, 2021

Conversation

madsodgaard
Copy link
Contributor

@madsodgaard madsodgaard commented Apr 30, 2021

Adds support for request-specific TLS configuration:
Request(url: "https://webserver.com", tlsConfiguration: .forClient())

apple/swift-nio-ssl#280 must be released, before this can be merged.

@swift-server-bot
Copy link

Can one of the admins verify this patch?

5 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa
Copy link
Collaborator

Lukasa commented Apr 30, 2021

@swift-server-bot add to allowlist

@madsodgaard madsodgaard marked this pull request as ready for review May 5, 2021 15:43
Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Fab, thank you! This looks like a great start!

I left a few comments, mostly requesting changes that we don't accidentally merge the branch dependency.

@@ -139,12 +139,16 @@ final class ConnectionPool {
self.port = request.port
self.host = request.host
self.unixPath = request.socketPath
if let tls = request.tlsConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

@artemredkin should we add a test case that targets the pool directly here? Ie no actual connections?

Package.swift Outdated Show resolved Hide resolved
@weissi
Copy link
Contributor

weissi commented May 6, 2021

@madsodgaard hmm, weird 5.0 compiler warning (that we turn into errors):

[449/452] Compiling Swift Module 'AsyncHTTPClient' (15 sources)
/code/Sources/AsyncHTTPClient/BestEffortHashableTLSConfiguration.swift:16:18: error: result of call to 'bestEffortEquals' is unused
        lhs.base.bestEffortEquals(rhs.base)
                 ^               ~~~~~~~~~~
Build step 'Execute shell' marked build as failure

Also, async-http-client uses automatic format checking with SwiftFormat. If you run SwiftFormat over the source, then the "soundness" part should pass.

@madsodgaard
Copy link
Contributor Author

@weissi Whoops, forgot a return statement 😅

@weissi
Copy link
Contributor

weissi commented May 6, 2021

@madsodgaard also the API breakage checker detected an API breakage:

08:37:54 /* Removed Decls */
08:37:54 Constructor HTTPClient.Request.init(url:method:headers:body:) has been removed

Note that in Swift you cannot just add a new parameter (even if it has a default value) without breaking API. Instead of adding the tlsConfiguration: parameter with a default value, you'll need to add a new init with an extra (non-defaulted) parameter. The existing HTTPClient.Request.init(url:method:headers:body:) should then just call the new init with the extra parameter.

@weissi weissi requested a review from Lukasa May 6, 2021 12:48
@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label May 6, 2021
@@ -150,17 +150,22 @@ extension NIOClientTCPBootstrap {
let key = destination

let requiresTLS = key.scheme.requiresTLS
// Override optional connection pool configuration.
var keyConfiguration = configuration
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm finding the naming here somewhat confusing: keyConfiguration is not derived from the key but from configuration, and then we override it with the TLS configuration from key.

I think it'd be nice to wrap this logic up into something written as a function that clarifies what it does (merges config from two sources, preferring config in the key to the general configuration.

I'm also a bit uncertain as to why this is necessary. Why isn't configuration already carrying this TLS config?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, should this merge perhaps be done at a higher level, say when we create the HTTP1ConnectionProvider? I am a bit nervous about having two separate configs from the perspective of the connection provider: it should always be creating the exact same connection each time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

configuration is specific for the entire HTTPClient, so atm it passes down the configuration of client through all these methods. So, we need at some point to override the tlsConfiguration of it.

I moved the actual configuration "generation" to the place where we initialize the connection provider as you suggested, and added config(overriding:) to Key to retrieve key-specific configuration. Let me know, if this is better!

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Cool, this LGTM.

@Lukasa Lukasa requested a review from weissi May 7, 2021 12:42
Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you very much!

@weissi weissi merged commit ca722d8 into swift-server:main May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants