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 Wasmtime RPC RFC #40

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

Conversation

rvolosatovs
Copy link
Member

@rvolosatovs rvolosatovs commented Nov 1, 2024

Signed-off-by: Roman Volosatovs <[email protected]>

Selects the interfaces to import using the plugin.
The value is a sequence comma-separated interface specifiers.
For example: `wasi:keyvalue` or `wasi:keyvalue,wasi:nn`
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this wouldn't allow using multiple plugins at the same time. Only a single plugin exposing multiple interfaces. Maybe a syntax like -P import=wasi:keyvalue=wrpc+tcp://[::1]:7761 -P import=wasi:nn=wrpc+unix://run/user/1000/wasi_nn.sock would work?

Copy link
Member Author

@rvolosatovs rvolosatovs Nov 1, 2024

Choose a reason for hiding this comment

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

Definitely open to suggestions here, I struggled to come up with a design, which would not feel overloaded and as I mention in the open questions section, I've decided to start with a singleton plugin because of the CLI design concerns and the fact that shared state (e.g. resources) gets increasingly more tricky as number of plugins grows.

Perhaps we would just need to come up with wasmtime.toml-or-similar config file eventually, which would define the mapping, since mapping every single interface to an endpoint on the CLI feels quite tedious if the number of interfaces is large.
On the other hand, that's probably not much worse than the likes of:

docker run -v$path:$path -w$path

so perhaps endpoint per-interface is fine at least to start with

```

To improve usability, Wasmtime could standardize on default socket address or Unix domain socket path to use.
For example, I chose port `7761` as the default for TCP, which is specified as "unassigned" in [IANA registry](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?&page=108).
Copy link
Contributor

Choose a reason for hiding this comment

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

If a default port is used, should it be registered with IANA? And what should the default be for unix domain sockets? /run/user/<uid>/<package_name>.sock?

Copy link
Member Author

Choose a reason for hiding this comment

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

I chose 7761 pretty arbitrarily, if this RFC is accepted and we're happy with this number, IANA registration sounds like the right thing to pursue.

In terms of the UDS path I guess we'd need to first determine if we want plugins to be composable or if we want it to be a singleton. If we go the multiple-plugins route:

$os-specific-runtime-dir/wrpc/wasi/$name.sock

e.g.

/run/user/$uid/wrpc/wasi/http.sock
/run/user/$uid/wrpc/wasi/keyvalue.sock
/run/user/$uid/wrpc/myorg/mypackage.sock

seems like a reasonable default for wRPC-based plugins on UDS.

[wRPC] is transport-agnostic, with 4 supported transports at the time of writing:
- TCP
- Unix domain sockets
- QUIC
Copy link
Contributor

Choose a reason for hiding this comment

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

How is authentication handled? Would it require a CA certificate or are self-signed certificates allowed?

Copy link
Member Author

@rvolosatovs rvolosatovs Nov 1, 2024

Choose a reason for hiding this comment

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

Depends on the implementation, ultimately wasmtime CLI user would be the one to decide. One thing to note though is that in current implementation, SAN is (ab?)used to specify the function being called: https://github.com/bytecodealliance/wrpc/blob/628e6bf79416ca2671d0a3c79ac25949f9bf84d8/crates/transport-quic/src/lib.rs#L29-L42

Currently, self-signed or not, the server (plugin) needs to generate a cert with appropriate SANs.

This can easily be changed/made configurable to e.g. be specified in the stream header as done for e.g. TCP and UDS https://github.com/bytecodealliance/wrpc/blob/628e6bf79416ca2671d0a3c79ac25949f9bf84d8/crates/transport/src/frame/conn/client.rs#L33-L43
I feel like being able to sign served plugin capabilities may come in quite handy, but I don't have strong feelings about this

Update: wRPC transport will reuse a singular QUIC connection for calls and open a bidirectional stream per invocation: bytecodealliance/wrpc#445

Wasmtime would be free to choose the connection strategy. I think the default should be enforcing that the plugin cert is signed by either know CAs from OS cert pool or, perhaps, webpki. E.g.: https://github.com/wasmCloud/wasmCloud/blob/a0e816316573e01e166e0a8366203a5ba8f7f1e5/crates/core/src/tls.rs#L55-L66

Users would probably need to be able to also specify custom CA and certs on command line though and optionally enable --insecure, which would allow self-signed certs

# Open questions
[open-questions]: #open-questions

- How do plugin imports work together with host builtins? I think the right solution here is to throw an error if e.g. both built-in `wasi:keyvalue` *and* `wasi:keyvalue` plugin import are specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

The only option that would allow backward compatibility on the Wasmtime side I think would be to make plugins shadow builtin implementations.

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.

2 participants