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

Add unix socket support to http.request #99

Open
aleclarson opened this issue Mar 31, 2018 · 7 comments
Open

Add unix socket support to http.request #99

aleclarson opened this issue Mar 31, 2018 · 7 comments

Comments

@aleclarson
Copy link
Contributor

Or provide an example of using http.client to communicate with a Unix socket.

@daurnimator
Copy link
Owner

This isn't supported at the moment because I couldn't figure out how it would work. If you have a usecase could you tell me:

  • What should SNI contain?
  • What host should TLS verify against?
  • What should be in the Host header
  • What the interaction with proxies is

@aleclarson
Copy link
Contributor Author

For now, I'm using it in development only, so I haven't considered TLS behavior. Maybe the :authority header should have to be set by the caller? Or default to localhost? I don't have much knowledge of HTTP proxies, so can't offer any opinions on that.

@aleclarson
Copy link
Contributor Author

I'm writing a higher level module that wraps lua-http, so no immediate action is necessary on your end.

@daurnimator
Copy link
Owner

Added help-wanted label, as answers to the above questions need to be determined before solving this request.

@algernon
Copy link

While this is an ancient report, I'd like to share some information for my use case for wanting unix socket support in http.request.

The major reason for it is that I'd like to talk to the Docker API via a unix socket. The API is HTTP over a unix socket, no TLS, the host header is ignored, by the looks of it.

As an experiment, I used socat to proxy between the docker socket and TCP: socat -d -v -d TCP-L:2376,fork UNIX:/var/run/docker.sock. With that set, DOCKER_HOST=localhost:2376 docker version will generate the following HTTP request on the socket:

GET /v1.41/version HTTP/1.1\r
Host: localhost:2376\r
User-Agent: Docker-Client/20.10.14 (linux)\r
\r

To this, the docker API just responds with an ordinary HTTP response with a JSON payload. When connecting via the socket itself, the docker client sets docker as the host, doesn't make a difference.

So pretty much all I want from http.request is to be able to connect to a unix socket, not care about SNI, TLS, proxies, or the host header at all. Just connect, send the request, parse the reply, done. Probably not a complete solution for all use-cases involving unix-sockets (it's not even a complete solution for docker, see below), but it'd be a step forward.

Now, why do I want to connect to the Docker API via a unix socket, rather than telling my docker daemon to listen on tcp too? Because by default, tcp is unencrypted, so any local user would be able to talk to my docker, while the unix socket has permissions. I could, of course, ask Docker to only allow clients that present a TLS cert signed by a trusted CA, but that's a whole lot of work when the client is on the same host anyway. Thus, talking to Docker from Lua is easiest if I can do it over a unix socket.

@daurnimator
Copy link
Owner

daurnimator commented Apr 20, 2022

@algernon note that you can use http_client.negotiate(yoursocket, options, timeout) where yoursocket is a unix socket. (but then you don't get all the special handling in http.request)

Perhaps some of the logic in http.request could be factored out so you can enter in with your own socket?
But that brings up all sorts of questions on how e.g. redirects should be handled.

@daurnimator
Copy link
Owner

There's some interesting discussion over at whatwg/url#577 about how to indicate a unix socket should be used with a URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants