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

Initial implementation of Wasi-tls (Transport Layer Security) #10249

Merged
merged 18 commits into from
Mar 7, 2025

Conversation

jsturtevant
Copy link
Contributor

@jsturtevant jsturtevant commented Feb 19, 2025

fixes: #10089

This adds a crate that provides the Wasmtime host implementation for the wasi-tls API.
The wasi-tls world allows WebAssembly modules to perform SSL/TLS operations,
such as establishing secure connections to servers.

This initially implements it with rustls which was already included in the repository.

There are a few items that still need to be resolved but are not specially related to the implementation but wanted to start the review to make sure things moving in the correct direction.

Thanks goes out to @badeend and @dicej as much of this was based on their prior work.

@jsturtevant jsturtevant requested review from a team as code owners February 19, 2025 23:40
@jsturtevant jsturtevant requested review from pchickey and removed request for a team February 19, 2025 23:40
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Feb 20, 2025
@badeend
Copy link
Contributor

badeend commented Feb 20, 2025

Looking great!

CI fails because Clippy being Clippy, and I suspect the build fails because there's some missing conditional compilation.

Aside from that, I;ve left behind some remarks:

output: StreamState<BoxOutputStream>,
}

impl AsyncWrite for TcpStreams {
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding this impl AsyncWrite for TcpStreams block and the impl AsyncRead for TcpStreams block below: I'm fine with them existing here, but AFAIK these have nothing to do with TLS right? If so, we could move them into the wasi-io subcrate at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, not specific to TLS it just enables passing wasi-io streams to libraries that require those traits (i.e. in this case the connect() method for rustls)

}
",
path: [
"../wasi-http/wit",
"../wasi-config/wit",
"../wasi-keyvalue/wit",
"../wasi-tls/wit/world.wit",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this being the wit file directly is bytecodealliance/wasm-tools#1996 (comment)

@jsturtevant jsturtevant force-pushed the wasi-tls-initial branch 2 times, most recently from bfea678 to f13938e Compare February 21, 2025 21:17
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

This looks great to me 👍

In terms of testing, would it be possible to also add a test (or multiple) that deal with the server-side as well. Ideally there'd either be a pre-generated cert check-in to the repo that they use or something generated at test-time perhaps per-test. That might help enable removing the dependency on example.com as well which has been flaky in the past, and while it's not the end of the world to have some flakiness it'd be best to insulate ourselves and have all the networking be purely local. Although I realize it's also good to test "is the system cert store actually used?" which necessarily requires external communication basially.

It might also be interesting, if local certs work, to test a variety of configurations related to invalid certificates to ensure that they do indeed all return an error instead of succeeding the authentication and such.

@jsturtevant
Copy link
Contributor Author

In terms of testing, would it be possible to also add a test (or multiple) that deal with the server-side as well.

Just to clarify, you mean to implement a server similar to what is done on wasi-http but with certs? We are going to need this for more advance scenarios later so works for me. I'll get started on it here

@alexcrichton
Copy link
Member

That's one route yeah, another being something similar to what wasi-sockets does where the client/server are both purely in-wasm and doens't require any external integration. The latter is a bit nicer from a "share this test suite in more places" perspective as well, but regardless I think either way is fine in the long run

@jsturtevant
Copy link
Contributor Author

sounds good. We didn't add the server side parts to the wasi-tls spec yet but it shouldn't be to hard to do a minimal version as well now that the client side is done. @badeend wdyt?

@alexcrichton
Copy link
Member

Oh I didn't look too closely at the tls bits here but if the server parts aren't implemented yet I don't mean to add more work here, so I think it's totally reasonable to land without that and plan to add more tests later too.

@badeend
Copy link
Contributor

badeend commented Feb 26, 2025

I'd prefer not to block this PR on the creation of server TLS connections from within a WASI guest. Creating server TLS connections brings along additional design complexity surrounding the handling of certificates & private keys from within a WASI guest.

If the goal is to reduce CI flakiness, we could also spin up a local TCP/TLS listener socket outside the guest, just before calling the test, and then connect to that from within the guest test.

@alexcrichton
Copy link
Member

I think let's focus on getting this initial set landed in-tree for now (aka landing the wasm-tools fixes and integrating that here). This'll be a bit flaky without a local server but that can be a follow-up item to do after landing.

@jsturtevant
Copy link
Contributor Author

(aka landing the wasm-tools fixes and integrating that here).

I tried pulling the fix (bytecodealliance/wasm-tools#2076) in from the main branch but looks like due to bytecodealliance/wasm-tools#2073, there were a few missing cases that need to be added to wit-bindgen and here. Would it be helpful to open PR's to stub those out or is there work being done on them? No rush/pressure, just want to be helpful if I can.

@alexcrichton
Copy link
Member

Good point! I started the update a few days ago but didn't publish it -- #10314 -- I'll work on landing that once all the wasm-tools changes are in, but if you want to rebase on that it can give a preview of what things are likely to look like

@jsturtevant jsturtevant force-pushed the wasi-tls-initial branch 7 times, most recently from cc95b3b to 955f727 Compare March 6, 2025 22:28
jsturtevant and others added 2 commits March 7, 2025 16:52
This crate provides the Wasmtime host implementation for the [wasi-tls] API.
The [wasi-tls] world allows WebAssembly modules to perform SSL/TLS operations,
such as establishing secure connections to servers. TLS often relies on other wasi networking systems
to provide the stream so it will be common to enable the [wasi:cli] world as well with the networking features enabled.

The initial implemntation is using rustls.

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
jsturtevant and others added 11 commits March 7, 2025 16:53
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
Signed-off-by: James Sturtevant <jstur@microsoft.com>
@jsturtevant
Copy link
Contributor Author

@badeend @alexcrichton We've merged all the outstand issues and I've rebased to bring in all the changes. I think this is ready for a final review. Thanks!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

I pushed a fix for the CI failure, and I double-checked and it looks like everything might actually work on s390x/riscv64 nowadays so I've updated to drop all the #[cfg] related to that. Otherwise looks good 👍

@alexcrichton alexcrichton enabled auto-merge March 7, 2025 18:16
@alexcrichton alexcrichton added this pull request to the merge queue Mar 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 7, 2025
@alexcrichton alexcrichton enabled auto-merge March 7, 2025 19:10
@alexcrichton alexcrichton added this pull request to the merge queue Mar 7, 2025
Merged via the queue into bytecodealliance:main with commit e8d5e3a Mar 7, 2025
154 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement wasi-tls
3 participants