|
| 1 | +/* |
| 2 | + Copyright The containerd Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +syntax = "proto3"; |
| 18 | + |
| 19 | +package nerdbox.services.socketforward.v1; |
| 20 | + |
| 21 | +import "google/protobuf/empty.proto"; |
| 22 | + |
| 23 | +option go_package = "github.com/containerd/nerdbox/api/services/socketforward/v1;socketforward"; |
| 24 | + |
| 25 | +// SocketForward provides UNIX domain socket forwarding across the VM boundary |
| 26 | +// over vsock streams. Container processes connect to listener sockets created |
| 27 | +// by vminitd; connections are relayed to the corresponding host-side socket. |
| 28 | +// |
| 29 | +// The ttrpc server runs inside the VM (vminitd) and the ttrpc client runs on |
| 30 | +// the host (shim). All RPCs are initiated by the host: |
| 31 | +// |
| 32 | +// - Bind: the host tells the VM which sockets to set up. The VM creates |
| 33 | +// UNIX listener sockets in the root mount ns so that crun can bind-mount |
| 34 | +// them into the container. This must be called before the container is |
| 35 | +// created. |
| 36 | +// - Accept: the host opens a server-streaming channel to receive |
| 37 | +// notifications when a process inside the container connects to a |
| 38 | +// forwarded socket. |
| 39 | +service SocketForward { |
| 40 | + // Bind sets up the socket forward entries on the VM side. The VM creates |
| 41 | + // UNIX listener sockets at the paths given in socket_path. This RPC returns |
| 42 | + // only after all socket files have been created, so the caller can safely |
| 43 | + // proceed with container creation (crun bind mounts). |
| 44 | + rpc Bind(BindRequest) returns (google.protobuf.Empty); |
| 45 | + |
| 46 | + // Accept is a bidirectional streaming RPC used to coordinate forwarded |
| 47 | + // connections. The VM sends a ConnectRequest when a container process |
| 48 | + // connects to a forwarded socket; the host resolves the forward_id, |
| 49 | + // dials the target host socket, opens a vsock stream, and sends back a |
| 50 | + // ConnectResult reporting success or failure. On failure the VM closes |
| 51 | + // the pending container connection immediately. |
| 52 | + rpc Accept(stream ConnectResult) returns (stream ConnectRequest); |
| 53 | +} |
| 54 | + |
| 55 | +// BindRequest is sent by the host before container creation to set up socket |
| 56 | +// forwards on the VM side. |
| 57 | +message BindRequest { |
| 58 | + repeated Socket sockets = 1; |
| 59 | +} |
| 60 | + |
| 61 | +// Socket describes a single forwarded UNIX socket. |
| 62 | +message Socket { |
| 63 | + // Opaque identifier for this forward. Each side uses it to resolve the local |
| 64 | + // socket path from its own configuration. |
| 65 | + string forward_id = 1; |
| 66 | + // Path of the UNIX listener socket in the VM's root filesystem (e.g. |
| 67 | + // /run/socketfwd/{forward_id}.sock). vminitd creates the socket here; |
| 68 | + // the shim has already rewritten the uds mount to a bind mount from |
| 69 | + // this path to the user-specified destination inside the container. |
| 70 | + string socket_path = 2; |
| 71 | +} |
| 72 | + |
| 73 | +// ConnectRequest is sent by the VM on the Accept stream to notify the host of |
| 74 | +// a new container-initiated connection. |
| 75 | +message ConnectRequest { |
| 76 | + // ID of the vsock stream. The host must open a stream with this ID after |
| 77 | + // a successful ConnectResult so that the relay can start. |
| 78 | + string stream_id = 1; |
| 79 | + // Identifier of the socket forward entry. The host uses this to resolve the |
| 80 | + // target host socket path from its own configuration rather than trusting a |
| 81 | + // path supplied by the VM. |
| 82 | + string forward_id = 2; |
| 83 | +} |
| 84 | + |
| 85 | +// ConnectResult is sent by the host on the Accept stream in response to each |
| 86 | +// ConnectRequest. It reports whether the host successfully dialed the target |
| 87 | +// socket. On failure the VM closes the pending container connection |
| 88 | +// immediately. |
| 89 | +message ConnectResult { |
| 90 | + // ID of the vsock stream from the corresponding ConnectRequest. |
| 91 | + string stream_id = 1; |
| 92 | + // Non-empty if the host failed to dial the target socket. The VM closes |
| 93 | + // the pending connection when error is set. |
| 94 | + string error = 2; |
| 95 | +} |
0 commit comments