-
Notifications
You must be signed in to change notification settings - Fork 262
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
Networking API design #370
Comments
Interesting thoughts! Here are some thoughts to go with them :-). One of the big ideas in WASI is that we don't have to think in terms of "which abstraction level should WASI as a whole target?", because can target multiple levels. We could have bare sockets APIs for programs doing their own POP3, transparent-TLS sockets APIs for programs doing custom protocols, and high-level HTTP fetch/proxy APIs for programs that just want to do simple HTTP operations, all in WASI at the same time. APIs in wasm are virtualizable -- there's no syntactic difference between a system call and a library call, so if we design things well, it should be possible to implement the high-level APIs as pure wasm modules that call the low-level APIs. This means that implementations that want to minimize their surface area can do that. Other implementations will want to implement the high-level APIs natively, because they'll be able to do high-level optimizations that depend on having the high-level information about how the protocols are being used. So we can let implementations choose.
Right; there are efforts underway to design a Wasm-level way to do async, so at the WASI level we're mostly just keeping an eye on those efforts right now to avoid duplicating work.
Popular operating systems don't expose bare TCP APIs, so while in theory that might be the lowest-level abstraction layer, in practice most implementations today wouldn't be able to support it. Bekerley-style sockets are the lowest-level API that is widely supported by existing OS's, so that seems more practical than bare TCP, at least to start with. And as I mentioned at the top, we can work on high-level APIs independently of the low-level APIs.
Yes. This is one of the expectations of the Berkeley sockets prototype -- it's ok to have an additional capability argument, because wasi-libc will be the thing which provides the standard Berkeley sockets API, handling the capability argument implicitly.
The rough idea is that they'll be passed into main from the outside, similarly to how the preopened directories are opened, and then passed into the APIs as needed. This is an area where the current infrastructure is very primitive at this time, but which we plan to develop into a major more general framework, especially once the underlying Wasm platform provides better mechanisms for doing so.
In the sockets prototype , the idea is to have an address pool. The details of what's in the pool and how it decides which connections are permitted are areas where I expect the API will evolve.
They'll need a handle to do so. But given a handle, the details of what can be done with that handle will be dependent on the individual API design.
Yes. As above, the current infrastructure for this is primitive right now, but this is something we want to enable.
WASI does have a |
How do you see the relationship between "capabilities" and "files"? In the object-capability world, the reference is the capability. And when talking about file descriptors Wikipedia has the following to say:
Suggestion: Regardless of how capabilities get transported into a Wasm module, wasi-libc needs a way to take a collection of capabilities and somehow redirect every C-function call to the correct handle. Some options:
Out of these three, the first one has my preference. Let me try to answer some of my own questions:
One way to implement this: let the Wasm module "proof" the relationship between a domain name and an ip address:
This workflow is based on the presumption that applications usually perform a DNS lookup before connecting.
I guess just like any other piece of data:
The embedder will block unwanted behaviour either way.
Seems like a niche, but: sure. Maybe not in the first iteration.
Whether it is transparent or not, TLS seems like a large effort on its own. Not something to just "tag on" in a network proposal. Having said that, it doesn't mean TLS can't integrate into a socket API. For example: var sock1 = socket_create(cap);
socket_connect(sock1, ...);
tls_upgrade_client_socket(sock1, ...);
socket_send(sock1, "My private data"); |
Small comment, but I personally find the "allow based on DNS domains, remember IP address behind domains, verify on that" method a bit unsound, and i have a feeling it can expose an attack surface to exploit (e.g. to "shift" or "trick" the DNS checker that the address resolved is actually an address that's allowed to be connected, or something along the lines) Can't, then, the Also, I think TAPS might be onto something with abstracting the actual connecting process from the capability/requirements aspect, i personally still dont know how it'll then be possible for a server to "properly receive" those connections (if TAPS can make connection method decisions on a myriad of variables), but the prospect is interesting, certainly if that means (per that example) that SMTP/POP3 clients can now become browser-native, which was a real eyebrow-raiser for me, as that aspect could rapidly change how the browser can play a role in experimenting and working with old APIs (maybe then finally a new mail protocol will be designed and implemented through these rapidly-versioned web-based client libraries) |
What ever is decided upon for the primary API I do think it would be good to have an API for managing a network device directly e.g A standardized API for network card drivers In addition Programs like Lokinet implement TCP/UDP on top of their protocols in this case for supporting existing protocols on their mixed net by default Being able to write these once to support any wasm (Also wanted to mention distributed API'S like ipfs BitTorrent and hyperdrive. |
How do we follow progress of this design, is there an API working group or another medium used to host discussion? So far I have noted bytecodealliance/wasmtime#70 which has fizzled out with no progress since almost a year ago and this issue appears to be going the same way. Perhaps something like https://github.com/WebAssembly/wasi-crypto should exist? |
A number of different people have started work on sockets at various points, and I don't know all the reasons why this work hasn't progressed. But I can explain some of the things in the broader context here. One of the things that's happened in the WASI Subgroup is that we've learned a lot about the limitations of the This is an evolving scene, and there's not a lot of documentation yet, and the tooling is still maturing. To follow the space, I encourage people to attend the Subgroup meetings if they can, and ask questions in the issue trackers here. Beyond that, lots of people are expecting to be writing lots more documentation soon. And, I'm expecting some major new proposals built on the new tools soon. And yes, proposals will have dedicated proposal repositories that people can follow and participate in. |
Could you maybe point me to the "async" story? This sounds interesting from a number of perspectives for me. Also, to summarize; work isnt being done on WASI networking because core collaboration/definition tools are being reworked? |
The async functions and streams presentation which was recently presented in the WASI Subgroup is a starting point. The Component examples presentation to the WASI Subgroup gives some examples of what this might look like in practice.
Work is being done; in the presentations I linked here, there are examples which involve networking. And as I mentioned above, there are some proposals in flight. |
I don't know if it is sound. Definitely something that needs extra investigation. I've created a small POC in C# to demonstrate the idea.
Definitely possible, but that would require all existing software written for BSD sockets to be modified. I think it boils down to: BSD sockets don't have a notion of domain names. So any solution that applies domainname-based restrictions on sockets is going to be an imperfect solution in some way or another. For example: my POC would not work for applications that ship their own DNS client. @sunfishcode |
I've created an initial draft at: https://github.com/badeend/WASI-Networking |
Refer to [ Networking API design](WebAssembly/WASI#370) and [feat(socket): berkeley socket API v2](WebAssembly/WASI#459) Support the socket API of synchronous mode, including socket/bind/listen/accept/send/recv/close/shutdown, the asynchronous mode isn't supported yet. Support adding `--addr-pool=<pool1,pool2,..>` argument for command line to identify the valid ip address range. And add the sample.
Refer to [Networking API design](WebAssembly/WASI#370) and [feat(socket): berkeley socket API v2](WebAssembly/WASI#459): - Support the socket API of synchronous mode, including `socket/bind/listen/accept/send/recv/close/shutdown`, the asynchronous mode isn't supported yet. - Support adding `--addr-pool=<pool1,pool2,..>` argument for command line to identify the valid ip address range - Add socket-api sample and update the document
…#1036) Refer to [Networking API design](WebAssembly/WASI#370) and [feat(socket): berkeley socket API v2](WebAssembly/WASI#459): - Support the socket API of synchronous mode, including `socket/bind/listen/accept/send/recv/close/shutdown`, the asynchronous mode isn't supported yet. - Support adding `--addr-pool=<pool1,pool2,..>` argument for command line to identify the valid ip address range - Add socket-api sample and update the document
@badeend how was this completed? Only bytecodealliance/wasm-micro-runtime#1036 was merged, which is not an API RFC or completed proposal to do networking? |
Maybe he doesn't recognize the difference between WASI and WAMR. |
I think this issue is closed as there is an initial design proposal here: If you are interested in tracking progress on networking for WASI, that design proposal is currently listed there as Phase 1, with the following note:
|
Oh. |
…#1036) Refer to [Networking API design](WebAssembly/WASI#370) and [feat(socket): berkeley socket API v2](WebAssembly/WASI#459): - Support the socket API of synchronous mode, including `socket/bind/listen/accept/send/recv/close/shutdown`, the asynchronous mode isn't supported yet. - Support adding `--addr-pool=<pool1,pool2,..>` argument for command line to identify the valid ip address range - Add socket-api sample and update the document
I've had some thoughts, and here's my braindump. Feedback is welcome.
1. Which use cases should the WASI networking APIs account for?
The official WebAssembly website mentions lots of use cases: https://webassembly.org/docs/use-cases/. I've kept the cases that seem relevant and added some of my own:
2. Which protocols should be focused on first?
For reference, I've compiled a non-exhaustive list of commonly used protocols:
UDP, TCP, DNS, HTTP1/2/3, QUIC, TLS, SSH, SFTP, FTP(S), SMTP, POP3, IMAP, WebRTC, WebSockets, gRPC, UNIX sockets.
Notes on HTTP
Outside the browser
Many runtimes (Java, .NET, ...) have built their own HTTP stack on top of the OS provided socket API's. Even if WASI was to provide an HTTP interface, it seems unlikely existing codebases would switch to it anytime soon.
Inside the browser
Browsers already have an HTTP API:
fetch()
. All WASI can provide is a wrapper for that function.Also, all WASI's current proposals are, as far as I can see, blocking synchronous functions. And browsers won't swallow that. Until there is an general answer for asynchronicity in Wasm/WASI, I propose to leave this use case out of scope for the networking proposal.
My thoughts
TCP and UDP are the lingua franca of the web with pretty much every other protocol in existence built on top of that. It seems logical to start with these, although I'd be happy to be proven wrong.
Pros:
Cons:
3. What should and shouldn't be allowed?
Prior art regarding blocking unwanted network activity:
"*://developer.mozilla.org/*"
.Random questions
connect(fd, "[2a00:1450:400e:80d::200a]", 443)
. However, if a Wasm embedder whishes to block network access based on the host, they'll probably want to do so based on the domain name instead of meaningless IP addresses.4. What should be the general API design?
Follow the designs of existing API's or come up with something new?
Is it a goal to have one unifying API abstracting away multiple protocols? This is what "TAPS" mentioned in 315 seems to be doing. If there is a time to steer away from the conventional API's, this would be it.
Many existing applications are built on the presumption that the OS doesn't anything higher-level than Berkeley-sockets and therefore already bundle their own implementations for the other protocols one way or another. Whatever the WASI networking API's end up looking like, is it a goal to provide a compatibility layer similar to wasi-libc automagically remapping
open()
toopenat()
?What should be the interface boundary? "Networking" is a very broad topic. Assuming embedders will only implement interfaces that are relevant to them, where should the dividing line between interfaces be placed? Some fictional examples for illustration:
wasi_sockets
vswasi_tcp
&wasi_udp
wasi_http
vswasi_http_server
&wasi_http_client
Transparent TLS
I've seen this idea surface multiple times in this repository: unify unencrypted and encrypted connections into a single API.
Some considerations:
My thoughts
The WASI overview document mentions:
... hinting at a POSIX-sockets API. This might be an obvious answer since they're well understood and an industry standard.
Random questions:
socket(...)
function that includes a "capability" file descriptor. This is not standard and breaks existing software. Should a compatibility workaround be deviced?5. Gather feedback
It would be wise to reach out to existing Wasm embedders and get their vision on what the networking API should and shouldn't be allowed to do. For example: Fastly is both a founding member of the bytecode alliance and an embedder. They'll probably have something to say about what networking functionalities they want to allow inside their workers, if any.
The text was updated successfully, but these errors were encountered: