ring
ring copied to clipboard
Add support for serving on Unix domain socket
Summary
These changes take advantage of jetty-unixsocket to allow serving on a socket, as in the following example:
(run-jetty handler {:http? false, :socket "/run/someapp.sock"})
## hostname is still required for making requests
curl --unix-socket /run/someapp.sock http://my-expected-hostname/url-path
Rationale
Unix sockets are simpler to implement access controls to than TCP sockets, as you can simply use file permissions. They are supported by common reverse proxies such as Apache and NGINX, and are thus reasonable for exposing a service through a proxy that may be handling authentication, without making that service available to all users on the host machine.
Possible enhancements:
- Options for file ownership and access controls
- A secure-by-default approach might see
:http?default false when:socketis set, unless:hostor:portare explicitly configured. - To avoid the additional dependency, socket support could be conditional on manually including the
jetty-unixsocketlibrary. It is not an overwhelmingly heavy dependency, though.
Note: it has proved nontrivial to get a test working, as clj-http does not support sockets, and the Clojure implementations that I've found do not seem to work as intended out of the box. I have verified that this implementation is operational manually, and I am willing to work through the process of getting a test working as long as you're interested in incorporating this functionality.