Repository navigation
Description
It is often desirable to run various HTTP servers that are only locally connectable. These could be local daemons that expose an HTTP API and/or web GUI, a local dev instance of a web server, et cetera.
For these use cases, using Unix domain sockets provides two major advantages over TCP on localhost:
- Namespacing. If two users on a system are running the same service, TCP requires them both to pick, configure, and remember different port numbers. With Unix domain sockets, each socket can live in the respective user's runtime directory and be named after the service.
- Access control. Even if the service is diligent only to bind to localhost, TCP still allows any (non-sandboxed) process or user on the machine to connect. Any access control has to be implemented by the service itself, which often involves implementing (hopefully with sufficient security) its own password authentication mechanism. Unix domain sockets, on the other hand, can take advantage of the access control functionality provided by the filesystem, and thus can easily be restricted to a single user or set of users. In the event that a service wants to allows multiple users to connect and discriminate between them, several operating systems provide a means of querying the UID of the connecting process, again without requiring it's own authentication scheme.
Indeed, due to these advantages, many servers/services already provide options for listening via a Unix domain socket rather a local TCP port. Unfortunately, there is not currently an agreed-upon way to address such a service in a URL. As a result, clients who choose to support it end up creating there own bespoke approach (e.g., a special command-line flag, or a custom URL format), while others choose not to support it so as not to bring their URL parsing out-of-spec (among other potential concerns).
Here are some of the various URL formats I've seen used or suggested:
- Transport only:
unix:/path/to/socket.sock. This lacks both the protocol and resource path, so it can only be used for clients that already know they'll be speaking to a specific HTTP API, and is not generally usable. - HTTP with socket path as the port:
http://localhost:[/path/to/socket.sock]/resource. Only allowed when host islocalhost. Paths containing]could either be disallowed or URL encoded. - Composite scheme with socket path as URL-encoded host:
http+unix://%2Fpath%2Fto%2Fsocket.sock/resource. Distinct scheme allows existinghttpURL parsing to stay the same. URL encoding reduces read- and type-ability. - Combining ideas from the previous two:
http+unix://[/path/to/socket.sock]/resourceor justhttp://[/path/to/socket.sock]/resource. (The latter would require using the leading/of the socket path to disambiguate from an IPv6 address.)
References:
Archived Google+ post suggesting the socket-as-port approach:
https://web.archive.org/web/20190321081447/https://plus.google.com/110699958808389605834/posts/DyoJ6W6ufET
My request for this functionality if Firefox, which sent me here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1688774
Some previous discussion that was linked in the Firefox bug:
https://daniel.haxx.se/blog/2008/04/14/http-over-unix-domain-sockets/
https://bugs.chromium.org/p/chromium/issues/detail?id=451721
Activity
annevk commentedon Feb 6, 2021
It seems you don't need just addressing for this, but some kind of protocol as well. I recommend using https://wicg.io/ to see if there's interest to turn this into something more concrete.
rkjnsn commentedon Feb 6, 2021
I'm not sure I understand why any additional protocol would be necessary. It's just HTTP over a stream socket. The server accepts connections and speaks HTTP just like it would for a TCP socket. Indeed, I can set up such a server today, and it works fine provided that the client provides a way to specify the socket, e.g.,
curl --unix-socket /path/to/socket.sock http://localhost/resource.avakar commentedon Jun 3, 2021
I don't even understand how this is not a thing yet. Especially now that Windows started supporting AF_UNIX sockets natively, it seems to be the best, cross-platform way to connect web and native apps without consuming a TCP port.
annevk commentedon Oct 20, 2021
Let me take a step back, what exactly is the ask from the URL Standard here?
rkjnsn commentedon Oct 23, 2021
The ask is for the URL standard to specify a syntax for referring to a page served via HTTP over a UNIX domain socket. Currently, applications that want to support connecting to an HTTP service have to pick from one of the following three:
--unix-socketcommand-line argument.None of these are ideal. Deciding on a standardized URL syntax allows different implementations to implement the functionality in a common, standards-compliant way.
annevk commentedon Oct 25, 2021
I see, https://wicg.io/ is the place for that. The URL standard defines the generic syntax. If you want to define the syntax for a particular URL scheme as well as behavior, you would do that in something that builds upon the URL standard. E.g., https://fetch.spec.whatwg.org/#data-urls for
data:URLs.rkjnsn commentedon Oct 25, 2021
Let me rephrase: the specific ask for the URL standard is to provide an allowance in the URL syntax for specifying a UNIX domain socket, either in lieu of the port (e.g.,
http://localhost:[/path/to/socket.sock]/resource) or in lieu of the hostname (e.g.,http://[/path/to/socket.sock]/resource), both of which are currently invalid according to the URL standard.annevk commentedon Oct 26, 2021
I recommend using something like
unix:/path/to/socket.sock?url=http://localhost/resource. We can't change the URL syntax for each new protocol that comes along.cyanogilvie commentedon Nov 4, 2021
It's the same protocol over a stream socket, just a different address (ie. authority part). Ok, so it's a different protocol in the sense of IP, but so are IPPROTO_IP and IPPROTO_IPV6, and the URL standard doesn't treat those as different. The relevant comparison I think are address families for stream sockets, like AF_INET, AF_INET6 and AF_UNIX. Once the stream socket has been established (as specified by the authority part of the URL), HTTP software shouldn't care or even know how the stream is transported.
Most invented, non-standard approaches for HTTP-over-unix-sockets seem to gravitate to something like a different scheme (since the authority part can't really be disambiguated from a hostname if relative socket paths are allowed from what I can see), like http+unix or https+unix, and then percent-encoding the socket into the authority part, and then everything works naturally from there from what I can see.
I've also seen (and used) enclosing the socket path in [] in the authority part and keeping the scheme as http or https, but I think that namespace clashes with IPv6 style numeric addresses like [::1]:80. RFC 3986 (in section 3.2.2) kind of leaves space for this by anticipating future formats within the [], and providing a version prefix to disambiguate them. Overall I like this approach the best (it extends into the error space so it doesn't change the interpretation of any valid existing URL, lives in an extension space envisioned by the standard, minimally extends just the appropriate part of the standard (authority part), keeps the schemes http and https to mean "this is a resource we talk to this authority using the http(s) protocol for", and so preserves compatibility for software that uses the scheme to know what protocol to speak with the authority over the socket.
annevk commentedon Nov 4, 2021
Changing the syntax of URLs is not really something we're willing to do. That has a substantive cost on the overall ecosystem. The benefits would have to be tremendous.
michael-o commentedon Nov 4, 2021
Syntax in
mod_proxy:karwa commentedon Nov 12, 2021
The strongest argument I can think of for this is: http(s) URLs have special parsing quirks which don't apply if the scheme is http+unix. So for a perfect 1:1 behaviour match, UDSs would need to use an actual http URL, not a custom scheme (similar to IP addresses).
That said, I'm also not a fan of adding yet another kind of host (file paths). My preference would be to use a combination of:
localhost,example,testandinvalidare all reserved and will never be allowed as a TLD, so something likeuds.localhostshould work), andThis is a perfectly valid HTTP URL, and should be capable of representing any HTTP request target.
Alternatively, you could try to get
udsorsocketas reserved TLDs, but I'm not sure how you'd go about doing that.(Note: this would also mean that all UDS URLs have the same origin, although that could be remedied by adding a discriminator to the fake hostname to make your own zones of trust, e.g.
123.uds.localhost)rkjnsn commentedon Nov 12, 2021
I'm not sure using the fragment is really tenable for these use cases (and local web dev, especially). Many web applications use the fragment for their own purposes in JavaScript, whereas the host (at least it my experience) tends to be handled more opaquely.
What would be the main drawback for allowing additional characters within [] for the host portion of an HTTP URL?
karwa commentedon Nov 12, 2021
Ah yes, you're right, it wouldn't work for local web development. I was thinking more about generic HTTP servers.
The main drawbacks IMO are:
Complexity. This standard has a hard-enough time trying to document existing browser behaviour without inventing new things. Then again, there is a reasonable counter-argument that URLs shouldn't have to stay frozen while other aspects of technology and the web evolve to meet new use-cases. There is a counter-counter argument that URLs are in a particularly sorry state compared to most other web technologies. Perhaps this is something for the future, once all browsers conform to this standard and things have stabilised a bit?
Possible loss of validation for IPv6 addresses. Unless we want to get in to the business of validating local system paths (and I'm quite sure nobody is thrilled by that idea) we would basically have to accept any non-empty string within
[]in the host portion of HTTP URLs. How do we knowhttp://[::::foo]/some/pathdoesn't refer to a valid path on some system somewhere?62 remaining items
yrro commentedon Jan 21, 2025
For comparison, OpenLDAP uses a different scheme for ldap-over-UNIX-sockets:
ldapi://%2Fusr%2Flocal%2Fvar%2Fldapiconnects to the socket at/usr/local/var/ldapi. There is no (documented) syntax for sockets in the 'abstract' namespace (i.e., those wheresun_path[0] == 0).thx1111 commentedon Jan 21, 2025
@robin-aws
Please provide or contrive an example.
Also, please clarify - the words "host" and "scheme" are specific and distinct terms-of-art as used in the RFC 3986 definition of a "URI", where "host" is a component of the "authority". By "host scheme", did you mean a "host", or a "scheme" - or something else?
You can find a list of registered "schemes" under "Uniform Resource Identifier (URI) Schemes" at: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
We may note that many of the "schemes" registered there, as seen in their description templates, define no "authority" component, and consist of only a "scheme" and "path". Obviously, without an "authority", there would be no "port". Even a "localhost" AF_UNIX URI would have to specify a "host" component, which is not optional if there is an "authority" in the URI, as for instance, literally "localhost". But then, either a "scheme" needs an "authority" - or it doesn't.
Nonetheless, any RFC 3986 defined URI is going to use the exact same definition of "authority", as defined in the RFC. The "authority" does not change with - is not a function of - the type of "scheme" selected. These are two distinct things, the "scheme" and the "authority", within the RFC.
I have not even proposed changing the definition of the "authority". I have only proposed extending the definition of the optional "port" component of the "authority", to allow for an AF_UNIX "path", as distinct from the "url-path" or "urlpath", as it was termed originally in RFC 1738:
@randomstuff
Hmm - rhetorically, how does a hostname of the form which you suggest, having the top-level domain "localhost", get routed around the Internet? I do not understand what you are describing there. Can you be more specific?
You could use the "userinfo" component of the "authority", preceding the "@" delimiter, to customize the effect of the URI. From the RFC, Section "3.2.1. User Information":
Did you mean something like that?
@yrro
In terms of RFC 3986, that format also places the UDS socketpath into the URI "authority". But, where is the "host" component? The URI "host" is required by the RFC when any "authority" is given. So this OpenLDAP ldapi URI scheme does not comply with RFC 3986, and neither is it registered with the IANA, as is.
But, same as above, "@ host" could be appended to that socketpath, to make it RFC compliant. Still, then URI "userinfo" will have been lost. Still, the socketpath could be added as a "password" for the "user", which is being deprecated anyway. But, strictly speaking, the RFC says:
So, the user could not visually discover or verify the actual UDS socketpath in a RFC compliant application using "socketpath as password".
@annevk
"Plenty of room to innovate" here seems like "code words" for "stuffing a square peg into a round hole." And, please explain how "room to innovate" is something the does not also mean "change the URL parser"?
The classic method used to make an easy problem seem difficult and complicated is to have more parameters than abstract variables. This then becomes a game of "musical chairs", and something always gets left-out, no matter how the parts are rearranged. That's a "fool's errand".
robin-aws commentedon Jan 21, 2025
@thx1111 - mea cupla, "host schemes" was a poor choice of words. Perhaps "kinds of authority" is a better phrase: the current URI syntax seems to be biased towards TCP, and your proposal tries to at least extend it to more naturally support UDS.
I do have another concrete example in mind: for my use case I also want to be able to do HTTP over VSOCKs. The address for a AF_VSOCK socket is a 32-bit port number together with a 32-bit context ID. I'm not sure how I'd encode a VSOCK address into an authority with your port proposal: something like
localhost:vsock/<port>/<cid>isn't terribly natural and could be interpreted as a UDS path instead.My point being that making the port either a number or a path is also not as future-proof as it could be: IF we want to make the authority syntax less of a round role for other kinds of authority, I'd be inclined to make the authority more opaque at the generix URI syntax level, so specific URI schemes can encode the kinds of authority they support more naturally and with less need for percent-encoding.
thx1111 commentedon Jan 21, 2025
@robin-aws
man 7 vsock:Casual inspection of this description from the man page reveals the terms "port number" and "host". Then, referring to the current version of RFC 3968, I see:
Rhetorically, what would happen if the VSOCK "host" were a URI "host" and a VSOCK "port number" were a URI "port" number?
Clearly, I'm not appreciating the actual problem there, since "host:port" is already defined in the RFC. What is the actual problem?
robin-aws commentedon Jan 21, 2025
You're correct that it's also possible to encode the VSOCK information in the URI as
http://1234567:123/.... But you don't have a clear indication that the authority uses the VSOCK address family, and it could easily be misinterpreted as an INET authority with1234567as a registered name instead.By the same argument, a UDS authority at
/path/to/socketcould be encoded ashttp://%2Fpath%2Fto%2Fsocket/...without your proposed extension. But that also leaves the address family implicit, and definitely has the readability of a square peg in a round hole. :)I'm trying to say that your proposal makes progress by allowing a path as a port as well as a number, but I think IF we're going to propose a URI syntax change, it should have deeper impact and provide enough flexibility to support other address families nicely as well.
(And to be clear I'm personally not enthusiastic at this point about a URI syntax change, given the
IPvFutureextension in 3986, which already does something similar, doesn't seem to be widely implemented AFAICT. I do think it may be productive to propose standard ways to encode authorities from more address families in the existing syntax, so multiple URI schemes such as http/https/ftp/smtp/... that operate on arbitrary stream interfaces could agree on standard approaches.)thx1111 commentedon Jan 22, 2025
@robin-aws
No, it could not be misinterpreted as an INET authority. And, "1234567" is not a valid top-level domain name.
From RFC 3986:
man 3 inet:man 7 ipv6This reference to a "first-match-wins" algorithm is just another tacit assumption of RFC 3986 which presumes the crafting of an appropriate heuristic. The application author is on-their-own for crafting that algorithm.
We could pretty much apply this same reasoning in the RFC - just presuming some heuristic provided by an application to recognize the URI authority "host" - to the interpretation of the URI authority "port", to distinguish a "*DIGIT" from a socketpath, as in ' path ":" '. There is nothing "novel" in that. It would simply be polite to articulate such a presumption in the RFC itself, if it were to be adopted as a de facto standard in applications.
peterjin-org commentedon Jan 22, 2025
@randomstuff's "soxidier" tool maps domain names to unix domain sockets, such that if the user went to http://name.username.users.uds.localhost/foo/bar then it would be effectively connecting to e.g.
/home/username/name, and making the requestGET /foo/bar HTTP/1.1, with the possibility of using symlinks to redirect connections to other sockets outside of this pattern.In this way, the syntax of the URL is not changed, as it looks like a normal URL with a domain name. Only the interpretation of the URL in terms of the network stack is changed.
Mapping domain names or IP addresses to unix domain sockets may be a bit hacky, but the mappings can be automatically generated and managed with scripts, SQL tables, and/or similar.
This basically shows that it is not necessary to modify the URL syntax to merely connect to a Unix domain socket, because as I've said, there are many URL parsers which would have to be updated, and it's not really practical to modify every one of them.
But modifying the URL syntax still has a few advantages. For example, you might have an app that may print out something like this on the console:
With both my and @randomstuff's solutions, one would have to register the Unix domain socket in the respective tools. But embedding the unix path in this manner does not have this restriction.
thx1111 commentedon Jan 22, 2025
@phjarea217
Well, fine. But, as I said, that is not an RFC 3986 compliant URI.
A list of IANA recognized top-level Domain Names can be found at: https://data.iana.org/TLD/tlds-alpha-by-domain.txt
"localhost" is not on that list.
Of course, you could configure your own local dns server to resolve "localhost" to some server on your local network, but that is not a general solution. It would be useless for accessing a host on the global Internet.
To be clear, with respect to the solution which I have proposed, the pros and cons come down to a question of a single ":" character. Seriously - the placement of a single ":" character in the context of the entire RFC 3986.
peterjin-org commentedon Jan 22, 2025
Section 3.2.2:
Unix domain socket URIs are not intended to have global scope, due to the local nature of Unix domain sockets. Sure, you might not be able to connect to sockets whose name contains a colon, but one could place a symlink at a file path which does not contain a colon, and point it to a file path that does contain a colon.
jdimpson commentedon Jan 22, 2025
Allowing use of DNS to resolve a URI to a Unix Domain Socket path sounds like a wonderful gift to hand to malevolent actors. Convincing a user to click a link that resolves to a well-known UDS-based service would become commonplace. Regardless of what any RFC says, a URI referring to local resources should look significantly different from one referring to external resources, so that no person and no legacy or naive code could be confused about what transport mechanism is involved in accessing the resource in question.
peterjin-org commentedon Jan 22, 2025
And this is why my solution involves the use of IPv6 link locals without scope id, as opposed to domain names (but domain names may still point to the IPv6 link local addresses), because at least on Linux, they fail to resolve in the network stack by default, however they can still be intercepted and made useful/usable by LD_PRELOAD libraries or eBPF programs.
And just to be clear with my last example with "/var/run/whatever.sock", that is not at all suggestive of the intended URI syntax. What I was suggesting was that if there were a URI syntax then an app would have some means of statelessly encoding the Unix domain socket path, whether it's directly embedding the path string, or substituting, escaping, or percent encoding special characters.
yrro commentedon Jan 22, 2025
Could the
.altspecial-use TLD be used? "This top-level label can be used as the final (rightmost) label to signify that the name is not rooted in the global DNS and that it should not be resolved using the DNS protocol."e.g.:
peterjin-org commentedon Jan 22, 2025
Sure, you could have a different TLD for the unix domain socket namespace, but it's still not intrinsically part of the url standard.
If you go to https://jsdom.github.io/whatwg-url/#url=aHR0cHM6Ly9uYW1lLnVzZXJuYW1lLnVzZXJzLnVkcy5sb2NhbGhvc3QvZm9vL2Jhcg==&base=YWJvdXQ6Ymxhbms= you see that the hostname portion of the URL http://name.username.users.uds.localhost/foo/bar is
name.username.users.uds.localhost.The ability to connect to a unix socket in this manner is realized because
name.username.users.uds.localhostor1234.vsock.altis interpreted at the DNS level to be meaningful (i.e. related to unix sockets), rather than at the URI level. At the URI level, these domain names just look like any other ordinary domain name.As I've said before, the interpretation of DNS names at the DNS level is operating system dependent and is modifiable by various subsystems. And, it is still necessary to parse the hostname as a domain name to determine that it has a tld of .alt in the first place.
So it's not really the issue of which TLD the unix domain socket namespace is "mounted" on.
thx1111 commentedon Jan 22, 2025
@jdimpson
To review, the topic of this discussion is "Addressing HTTP servers over Unix domain sockets". And now, addressing that goal, I have proposed interpreting an RFC 3986 "URI" - which is what is implied by the phrase "Addressing HTTP servers" in the title - more generally, so as to successfully resolve an AF_UNIX socket "filesystem pathname", as defined in
man 7 unix. A "filesystem pathname" is more specifically defined in "POSIX.1-2024", under "3.254 Pathname", here:https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html#tag_03_254
It is important to note that an AF_UNIX "address" has a format different from other socket address families, where RFC 3986 is especially biased in support of AF_INET and AF_INET6 sockets.
Also,
man 7 unixtells us:where "efficiently" generally implies side-stepping use otherwise of the local machine's IP stack.
And, while use of an AF_UNIX socket is "to communicate between processes on the same machine", at the same time, the meaning of "Addressing HTTP servers", again, implies use of an RFC 3986 "URI", which itself is subject to additional standards recommendations.
For instance, RFC 4007 extends the Textual Representation of an IPv6 address to include a "zone_id", using the "%" character as a delimiter, and RFC 6874 extends the definition of the RFC 3986 "URI" to address the use of this "%" delimiter, otherwise always treated as an escape character in a URI, such that the "%" character is replaced by its equivalent "escaped" representation, "%25":
Of course any delimiter, for whatever purpose, might be represented using an escaped character sequence, but RFC 6874 only apples to an IPv6 "ZoneID", and is of no use in IPv4 addresses, to otherwise describe an AF_UNIX "Pathname" address as a kind of "ZoneID".
More recently, 2020 June, RFC 8820, "URI Design and Ownership" contains some rather pointed comments warning about overly rigid, difficult, or presumptuous interpretations of the RFC 3986 "URI". For example, RFC 8615, "Well-Known Uniform Resource Identifiers (URIs)", extends the interpretation of the URI "path":
But, then it goes on to say:
So, a UDS pathname could not, itself, be used as a "/.well-known/" registered name in a URI. Still, a UDS pathname could be modified in other ways, such as using the escaped "/" character, "%2F". But "/.well-known/" registered names seem an unnecessarily complicated approach to accommodating every different address style in every different address family to be found in
man 7 address_families.More generally, the goal in addressing the question raised in this discussion is to provide a simple URI mechanism to accommodate the varied "address" formats used in the many
man 2 socket"address families". I have suggested that a single ":" delimiter is a pretty simple and effective solution.Now, to your point, you seem to be suggesting that some security conscious System Administrator, for example, such as yourself, would configure a publicly accessible server to provide open access to a UDS, and thereby, leave the system vulnerable to some kind of security breach. Is that correct?
Please explain - Why would you do that? Can you provide an example?
There is no standards specification which requires any computer system, networked or not, to provide open access to a UDS. In fact, there are quite a number of mechanisms, already in use, to allow a System Administrator to restrict access to system resources, especially including any networked computer system.
What prevents a System Administrator from making use of those security measures with respect to a UDS, as compared to any other socket family, and especially, as compared to AF_INET and AF_INET6 sockets?
peterjin-org commentedon Mar 13, 2025
Another example where changing the interpretation of domain names allows connections to Unix domain sockets is the Nginx "upstream" module: https://nginx.org/en/docs/http/ngx_http_upstream_module.html
Here, we use the URL
http://backendorhttp://dynamic. Again, this is a totally normal URL, with the host name of "backend" or "dynamic". Theupstreamblocks effectively change how domain names and hostnames are interpreted, such that it is possible for these domain names to resolve to Unix domain sockets.