Skip to content

Support proxying to unix sockets #592

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dometto
Copy link

@dometto dometto commented Jul 28, 2025

Summary

This PR adds support for proxying to servers that are listening on a Unix socket. The Node http client library already supports unix sockets, so adding this functionality was just a matter of setting the right values for the connection options.

It also adds a test for the new functionality.

Rationale

JupyterHub already supports listening on unix sockets.

However, at this point, servers spawned by the hub have no way of contacting the Hub, as configurable-http-proxy is not capable of proxying back to the Hub when it listens on a unix socket. This functionality would therefore mean a significant step towards being able to host all JupyterHub services on a unix socket. Apart from some (probably small) performance benefits compared to TCP, this would also mean security gains in situations where endusers have shell access to the machine running Jupyter services (while servers listening on TCP can be contacted by any user on the system, unix sockets can be secured using normal file permissions).

A next step would be to allow configurable-http-proxy to listen on unix sockets itself, for both the proxy server and the API server. This should be pretty trivial, as Node's http server library already supports listening on unix sockets. This feature is already used in the test in this PR.

Details

  • The current implementation will treat any url with a protocol starting with unix as a unix socket path, so unix+http:// (which is used by JupyterHub) and unix:// will both work.
  • When adding a route, it is important to pass in a url-encoded version of the path to the Unix socket: unix+http://%2Ftmp%2F/test.sock, and not unix+http:///tmp/test.sock. This again follows the current expectations of JupyterHub. When passing in the unencoded path, URL.parse will interpret /tmp/test.sock as the path, and set hostname to an empty string.

var proxyOptions = { target };

if (target.protocol.startsWith("unix")) {
proxyOptions.secure = false;
Copy link
Author

Choose a reason for hiding this comment

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

No support for SSL on unix sockets; this is not really needed anyway.

@dometto dometto force-pushed the connect_to_unix_socket branch from e5e243d to 36a6940 Compare July 29, 2025 06:16
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.

1 participant