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

[discussion] pool ssl/tls connections - alternative 2 #206

Merged
merged 17 commits into from
Mar 2, 2021

Conversation

Tieske
Copy link
Contributor

@Tieske Tieske commented Mar 27, 2020

Here's the second option for safe keep-alive across ssl + proxy connections.

It implements a new connect method that does it all at once (connect, ssl-handshake, proxy)

This is (imo the better) alternative to #202 .

There are no tests since this is very hard to test without a proxy server. Yet tests are available in the originating code here: https://github.com/Kong/kong-plugin-aws-lambda/compare/better-connect?expand=1 , which includes a forward-proxy and full integration tests.

Input is appreciated @hamishforbes @pintsized @bungle .

replaces #201
fixes #161
replaces #205

Copy link
Member

@pintsized pintsized left a comment

Choose a reason for hiding this comment

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

Ok cool, thanks for this. I also prefer this to the other, more intrusive option. I guess the downside being there's a fair bit of code repetition between this and the existing proxy connection code.

Otherwise, generally looks good to me. I've added some comments.

I would really like to have tests around this stuff, as well as the existing forwarding proxy connection code. This was contributed code and not a use case of mine, so I've always been a bit nervous about it. I've just got travis builds working. I'm wondering if we can do something with Docker Compose to test against a forwarding proxy?

Happy to merge this as is with my minor comments addressed though. Please rebase against master before pushing changes, as you'll pick up the working travis config.

You'll also want to add your new module to the rockspec and .luacov, and bump LUACOV_NUM_MODULES in the Makefile for test coverage reporting.

Thanks!

lib/resty/http_connect.lua Show resolved Hide resolved
lib/resty/http.lua Outdated Show resolved Hide resolved
@Tieske Tieske force-pushed the connect-better branch 6 times, most recently from de36967 to fbe6d94 Compare April 6, 2020 10:01
@Tieske
Copy link
Contributor Author

Tieske commented Apr 6, 2020

@pintsized all updates done, please have another look

@Tieske
Copy link
Contributor Author

Tieske commented Apr 6, 2020

I would really like to have tests around this stuff, as well as the existing forwarding proxy connection code. This was contributed code and not a use case of mine, so I've always been a bit nervous about it. I've just got travis builds working. I'm wondering if we can do something with Docker Compose to test against a forwarding proxy?

Here's what we are using (docker-compose based):

@Tieske
Copy link
Contributor Author

Tieske commented Apr 17, 2020

@pintsized any updates?

PS. CI seems to be in a weird state. I can't click any of the links to check what's wrong?

@Tieske
Copy link
Contributor Author

Tieske commented Apr 27, 2020

ping

@pintsized
Copy link
Member

Hey, sorry (again) for being so slow. Things are pretty hectic for me at the moment.

It's passing local tests fine, I think it's just because your PR was submitted before I got Travis working - Github isn't getting the notification or something. Of course the important tests are the ones you're hosting (thanks for sending the details over).

My only concern with all of this is the amount of code duplication. Could / should request_uri (i.e. the simple path) not use your connector module instead? So the user would call set_proxy_options as they currently do if using request_uri, and it would just pass this to your interface? Ditto for connect_proxy actually, so we keep what we have to from the old API, but utilise your module?

I appreciate it's a bit of a mess at this stage, and that your contribution here is important for correctness. If we can push the old interface towards using this new code somehow, things will be much less likely to rot.

Having said all of this, I really don't have any time to work on it at the moment, and so if we need to merge this and come back to it, I can live with that. I'll hopefully have some proper time in a month or so. At which point I'd be keen to get something like your integration tests setup for this.

Thanks for your input, and sorry for not being more responsive!

@Tieske Tieske force-pushed the connect-better branch 2 times, most recently from bb81345 to 0021a71 Compare February 20, 2021 07:47
these options must be global since the https auth is used when
connecting, and the http one only when requesting.
So these settings span the process of connecting and requesting,
and hence we should not pass them into 'connect', because we would
have to ensure that the user would pass the same ones to
'request'.
also renames other variables to be more descriptive
the connect method cannot deal with the auth header for a http request,
only for https. Hence we store the value and inject is when making the
request. We need it on connect, to construct the proper pool-name.

We honor the existing request header if it is there, but that is a
bad idea, since the poolname is based on the one provided to
connect. So users should set the proxy options, and make requests
without that header to be safe.
required to be able to use aio_connect from the request_uri method,
since that method allows to use the proxy auth header for https proxy
requests.
@Tieske
Copy link
Contributor Author

Tieske commented Feb 25, 2021

@pintsized I updated the PR. I squashed the original PR into a single commit and added/changed step-by-step, to make the short hand method use the aio connect method (and fix some bugs that popped up).

I made an effort to make commits atomic so for review it is probably easiest to review individual commits.

Can you please have another look?

@pintsized
Copy link
Member

Awesome man, thanks for the effort here. I'll go through it properly by the end of the week.

@Tieske
Copy link
Contributor Author

Tieske commented Feb 26, 2021

there was another flaky test, updated the commit and pushed again, CI is green now.

Copy link
Member

@pintsized pintsized left a comment

Choose a reason for hiding this comment

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

OK, looking good 👍

Aside from the minor comments that I added, my only real concerns are the test coverage and the increased API surface.

For the test coverage, the major difference seems to be that connect_proxy no longer has any coverage at all. Am I right in thinking this method is really only there for backwards compatibility with code using the generic interface? I personally have almost no experience with forward proxy semantics, and all of the use cases here have been contributed by others. I'm more than a little nervous about breaking things I don't understand ;)

But this leads me to wonder if we should be marking anything as deprecated whilst we're at it? I guess I'm thinking; if someone new comes to this module, are we making it clear enough what they should reach for first, since they now have even more options? Seems like we could deprecate the old connect signatures, and also the connect_proxy method?

I guess that includes ssh_handshake too. Originally I just tried to keep the interface similar to the other cosocket modules, but the reality is that HTTP semantics are just more complicated than that, and my sense is we should encourage everyone to use your "all in one" method, right? Can you think of use cases that aren't covered by that?

I think we're also missing test coverage for a non https proxy, but that appears to be true on the master branch too.

Again, thanks for all the effort here.

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
lib/resty/http.lua Outdated Show resolved Hide resolved
lib/resty/http.lua Show resolved Hide resolved
lib/resty/http.lua Show resolved Hide resolved
lib/resty/http_connect.lua Show resolved Hide resolved
lib/resty/http_connect.lua Show resolved Hide resolved
@@ -151,14 +151,53 @@ Creates the http object. In case of failures, returns `nil` and a string describ

## connect

`syntax: ok, err = httpc:connect(aio_options_table)`

`syntax: ok, err = httpc:connect(host, port, options_table?)`

Copy link
Member

Choose a reason for hiding this comment

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

Do you think perhaps we should deprecate the old interface? Seems like we could use your new interface, without ssl or proxy options, and get the same behaviour without much cost?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.

These days everything is ssl mostly. Doing the steps manual is causing a lot of code duplication, and is very tedious because there are so many edge cases one needs to think of. A lot of parameters to each of the connect, handshake, and proxy calls share a lifetime over all the three methods.

That is exactly what caused me to rewrite the whole thing, such that it would be less error prone.

@Tieske
Copy link
Contributor Author

Tieske commented Feb 27, 2021

OK, looking good 👍

Aside from the minor comments that I added, my only real concerns are the test coverage and the increased API surface.

For the test coverage, the major difference seems to be that connect_proxy no longer has any coverage at all. Am I right in thinking this method is really only there for backwards compatibility with code using the generic interface?

Yes

I personally have almost no experience with forward proxy semantics, and all of the use cases here have been contributed by others. I'm more than a little nervous about breaking things I don't understand ;)

But this leads me to wonder if we should be marking anything as deprecated whilst we're at it? I guess I'm thinking; if someone new comes to this module, are we making it clear enough what they should reach for first, since they now have even more options? Seems like we could deprecate the old connect signatures, and also the connect_proxy method?

I guess that includes ssh_handshake too.

Yes probably all three should be deprecated, and examples updated to use the aio method

Originally I just tried to keep the interface similar to the other cosocket modules, but the reality is that HTTP semantics are just more complicated than that, and my sense is we should encourage everyone to use your "all in one" method, right? Can you think of use cases that aren't covered by that?

Nope

I think we're also missing test coverage for a non https proxy, but that appears to be true on the master branch too.

Again, thanks for all the effort here.

👍

@pintsized
Copy link
Member

Ok, I'll merge this and rework the docs, deprecating the old connection syntax.

@pintsized pintsized merged commit e1090f9 into ledgetech:master Mar 2, 2021
@Tieske Tieske deleted the connect-better branch March 2, 2021 10:44
@Tieske
Copy link
Contributor Author

Tieske commented Mar 2, 2021

Nice! 🎉

@Tieske
Copy link
Contributor Author

Tieske commented Mar 14, 2021

@pintsized fyi: I just created an updated version of the Kong Lambda plugin which has integration tests for keepalive and proxy connections. The tests in the branch run against the master branch of the http client. Everything is green.

Just extra confirmation all seems well, since proxy tests are lacking in the lib.

@pintsized
Copy link
Member

Nice, good to know! I'll cut a new release soon...

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.

connect_proxy with pooled connection fails
2 participants