|
| 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 at the internal container-side paths so that runc |
| 34 | +// can bind-mount them into the container. This must be called before the |
| 35 | +// container is 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 | +// |
| 40 | +// Each side resolves socket paths from its own configuration using the |
| 41 | +// forward_id. |
| 42 | +service SocketForward { |
| 43 | + // Bind sets up the socket forward entries on the VM side. The VM creates |
| 44 | + // UNIX listener sockets at the paths given in socket_path. This RPC returns |
| 45 | + // only after all socket files have been created, so the caller can safely |
| 46 | + // proceed with container creation (runc bind mounts). |
| 47 | + rpc Bind(BindRequest) returns (google.protobuf.Empty); |
| 48 | + |
| 49 | + // Accept opens a server-streaming channel. When a process inside the |
| 50 | + // container connects to a forwarded listener socket, the VM sends a |
| 51 | + // ConnectRequest containing the stream_id and forward_id. The host |
| 52 | + // resolves the target host socket from its own configuration using |
| 53 | + // forward_id, dials it, and opens a vsock stream with the given stream_id |
| 54 | + // so the relay can start. |
| 55 | + rpc Accept(google.protobuf.Empty) returns (stream ConnectRequest); |
| 56 | +} |
| 57 | + |
| 58 | +// BindRequest is sent by the host before container creation to set up socket |
| 59 | +// forwards on the VM side. |
| 60 | +message BindRequest { |
| 61 | + repeated Socket sockets = 1; |
| 62 | +} |
| 63 | + |
| 64 | +// Socket describes a single forwarded UNIX socket. |
| 65 | +message Socket { |
| 66 | + // Opaque identifier for this forward. Each side uses it to resolve the local |
| 67 | + // socket path from its own configuration. |
| 68 | + string forward_id = 1; |
| 69 | + // Path of the UNIX listener socket in the VM's root filesystem |
| 70 | + // (/run/socketfwd/{forward_id}.sock). vminitd creates the socket here; |
| 71 | + // the shim has already rewritten the uds mount to a bind mount from |
| 72 | + // this path to the user-specified destination inside the container. |
| 73 | + string socket_path = 2; |
| 74 | +} |
| 75 | + |
| 76 | +// ConnectRequest is the streamed output of Accept. It notifies the host of a |
| 77 | +// new container-initiated connection. |
| 78 | +message ConnectRequest { |
| 79 | + // ID of the vsock stream. The host must open a stream with this ID after |
| 80 | + // receiving the notification so that the relay can start. |
| 81 | + string stream_id = 1; |
| 82 | + // Identifier of the socket forward entry. The host uses this to resolve the |
| 83 | + // target host socket path from its own configuration rather than trusting a |
| 84 | + // path supplied by the VM. |
| 85 | + string forward_id = 2; |
| 86 | +} |
0 commit comments