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

Aperta
#15,388 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust, wasm

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
Rust
Stelle
18.9k
Fork
2k
Merge medio
1g 6h
PR unite (30g)
238

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bytecodealliance/wasmtime

Tutte le issue di bytecodealliance/wasmtime

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.