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

Abierto
#15,388 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust, wasm

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Rust
Estrellas
18.9k
Forks
2k
Merge medio
1 d 6 h
PR fusionados (30 d)
238

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bytecodealliance/wasmtime

Todos los issues de bytecodealliance/wasmtime

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.