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

オープン
#15,388 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust, wasm

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
18.9k
フォーク
2k
平均マージ
1日 6時間
マージ済み PR(30日)
238

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytecodealliance/wasmtime のほかの issue

bytecodealliance/wasmtime の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。