C API: `wasi_config_inherit_network` does not let a guest use TCP or UDP

Đang mở
#15,388 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, wasm

Hướng nghiên cứu

Start by comparing the C API setup using wasi_config_inherit_network with the command line invocation that succeeds, then trace how wasmtime_component_linker_add_wasip2 applies network permissions. The Rust guest source and reproduction steps provide a way to check the behavior. Done means the C API guest can connect to the local TCP listener, matching the documented permission and command line behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

wasmtime:c-api
Test Case

A Rust program built for wasm32-wasip2. I cannot attach the binary here, the source is short:

use std::net::TcpStream;

fn main() {
    let addr = std::env::args().nth(1).unwrap();
    match TcpStream::connect(&addr) {
        Ok(_) => println!("connected"),
        Err(e) => {
            println!("refused: {e}");
            std::process::exit(1);
        }
    }
}
Steps to Reproduce
  • Start a TCP listener on 127.0.0.1, on any port.
  • With the C API, create a WASI configuration and allow the network:
wasi_config_t *cfg = wasi_config_new();
wasi_config_inherit_network(cfg);
wasi_config_allow_ip_name_lookup(cfg, true);
wasmtime_context_set_wasi(context, cfg);
  • Add WASI to a component linker with wasmtime_component_linker_add_wasip2, instantiate the component, and call wasi:cli/run with the listener's address as the argument.
Expected Results

The program prints connected. The documentation of wasi_config_inherit_network in wasi.h says that "any address can be bound by the guest or connected to by the guest using any protocol".

The same component prints connected with the command line: wasmtime run -S inherit-network test.wasm 127.0.0.1:PORT.

Actual Results

The program prints refused: Permission denied (os error 2). The listener never receives a connection.

Name lookup works after wasi_config_allow_ip_name_lookup(cfg, true), so the configuration is applied. Only TCP and UDP stay refused.

Versions and Environment

Wasmtime version or commit: 48.0.1 (C API)

Operating system: macOS

Architecture: aarch64

Extra Info

I found this while writing Erlang bindings on top of the C API (https://github.com/benoitc/erlang-wasmtime).

Ngôn ngữ chính
Rust
Star
18.9k
Fork
2k
Merge trung bình
1 ngày 6 giờ
Pull request đã merge (30 ngày)
238

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bytecodealliance/wasmtime

Tất cả issue của bytecodealliance/wasmtime

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.