diff --git a/api/openapi.yaml b/api/openapi.yaml index 901d727..f840550 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -15,7 +15,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/ControllerInfo' + $ref: '#/components/schemas/ControllerInfo' /cluster-settings: get: summary: "Retrieve cluster settings" @@ -27,7 +27,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/ClusterSettings' + $ref: '#/components/schemas/ClusterSettings' put: summary: "Update cluster settings" tags: @@ -38,7 +38,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/ClusterSettings' + $ref: '#/components/schemas/ClusterSettings' /service-accounts: post: summary: "Create a Service Account" @@ -50,7 +50,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/ServiceAccount' + $ref: '#/components/schemas/ServiceAccount' '409': description: Service Account resource with with the same name already exists get: @@ -65,7 +65,7 @@ paths: schema: type: array items: - $ref: '#components/schemas/ServiceAccount' + $ref: '#/components/schemas/ServiceAccount' /service-accounts/{name}: get: summary: "Retrieve a Service Account" @@ -77,7 +77,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/ServiceAccount' + $ref: '#/components/schemas/ServiceAccount' '404': description: Service Account resource with the given name doesn't exist put: @@ -90,7 +90,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/ServiceAccount' + $ref: '#/components/schemas/ServiceAccount' '404': description: Service Account resource with the given name doesn't exist delete: @@ -113,7 +113,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/Worker' + $ref: '#/components/schemas/Worker' '409': description: Worker resource with with the same name already exists get: @@ -128,7 +128,7 @@ paths: schema: type: array items: - $ref: '#components/schemas/Worker' + $ref: '#/components/schemas/Worker' /workers/{name}: get: summary: "Retrieve a Worker" @@ -140,7 +140,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/Worker' + $ref: '#/components/schemas/Worker' '404': description: Worker resource with the given name doesn't exist put: @@ -153,7 +153,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/Worker' + $ref: '#/components/schemas/Worker' '404': description: Worker resource with the given name doesn't exist delete: @@ -165,6 +165,35 @@ paths: description: Worker resource was successfully deleted '404': description: Worker resource with the given name doesn't exist + /workers/{name}/port-forward: + get: + summary: "Port-forward to a worker using WebSocket protocol" + tags: + - workers + parameters: + - in: query + name: port + description: Worker's TCP port number to connect to + schema: + type: integer + minimum: 1 + maximum: 65535 + required: true + - in: header + name: Connection + description: WebSocket protocol required header + required: true + - in: header + name: Upgrade + description: WebSocket protocol required header + required: true + responses: + '400': + description: Invalid port specified + '404': + description: Worker resource with the given name doesn't exist + '503': + description: Failed to establish connection with the requested worker /vms: post: summary: "Create a VM" @@ -176,7 +205,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/VM' + $ref: '#/components/schemas/VM' '409': description: VM resource with with the same name already exists get: @@ -191,7 +220,7 @@ paths: schema: type: array items: - $ref: '#components/schemas/VM' + $ref: '#/components/schemas/VM' /vms/{name}: get: summary: "Retrieve a VM" @@ -203,7 +232,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/VM' + $ref: '#/components/schemas/VM' '404': description: VM resource with the given name doesn't exist put: @@ -216,7 +245,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/VM' + $ref: '#/components/schemas/VM' '404': description: VM resource with the given name doesn't exist delete: @@ -239,7 +268,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/Events' + $ref: '#/components/schemas/Events' '404': description: VM resource with the given name doesn't exist post: @@ -252,7 +281,7 @@ paths: content: application/json: schema: - $ref: '#components/schemas/Events' + $ref: '#/components/schemas/Events' '404': description: VM resource with the given name doesn't exist /vms/{name}/port-forward: @@ -339,7 +368,7 @@ components: title: Events type: object items: - $ref: '#components/schemas/Event' + $ref: '#/components/schemas/Event' Event: title: Generic Resource Event type: object diff --git a/internal/command/portforward/portforward.go b/internal/command/portforward/portforward.go index a004652..6445077 100644 --- a/internal/command/portforward/portforward.go +++ b/internal/command/portforward/portforward.go @@ -8,7 +8,7 @@ func NewCommand() *cobra.Command { Short: "Forward TCP port to the resources", } - command.AddCommand(newPortForwardVMCommand()) + command.AddCommand(newPortForwardVMCommand(), newPortForwardWorkerCommand()) return command } diff --git a/internal/command/portforward/portspec.go b/internal/command/portforward/portspec.go index 46ab61a..592ade8 100644 --- a/internal/command/portforward/portspec.go +++ b/internal/command/portforward/portspec.go @@ -17,31 +17,47 @@ type PortSpec struct { func NewPortSpec(portSpecRaw string) (*PortSpec, error) { splits := strings.Split(portSpecRaw, ":") - if len(splits) > 2 { - return nil, fmt.Errorf("%w: expected no more than 2 components delimited by \":\", found %d", - ErrInvalidPortSpec, len(splits)) - } - - localPort, err := strconv.ParseUint(splits[0], 10, 16) - if err != nil { - return nil, err - } + switch len(splits) { + case 1: + remotePort, err := parsePort(splits[0]) + if err != nil { + return nil, err + } - remotePort := localPort + return &PortSpec{ + LocalPort: 0, + RemotePort: remotePort, + }, nil + case 2: + localPort, err := parsePort(splits[0]) + if err != nil { + return nil, err + } - if len(splits) > 1 { - remotePort, err = strconv.ParseUint(splits[1], 10, 16) + remotePort, err := parsePort(splits[1]) if err != nil { return nil, err } + + return &PortSpec{ + LocalPort: localPort, + RemotePort: remotePort, + }, nil + default: + return nil, fmt.Errorf("%w: expected 1 or 2 components delimited by \":\", found %d", + ErrInvalidPortSpec, len(splits)) + } +} + +func parsePort(s string) (uint16, error) { + port, err := strconv.ParseUint(s, 10, 16) + if err != nil { + return 0, err } - if localPort < 1 || remotePort < 1 || localPort > 65535 || remotePort > 65535 { - return nil, fmt.Errorf("%w: only ports in range [1, 65535] are allowed", ErrInvalidPortSpec) + if port < 1 || port > 65535 { + return 0, fmt.Errorf("%w: only ports in range [1, 65535] are allowed", ErrInvalidPortSpec) } - return &PortSpec{ - LocalPort: uint16(localPort), - RemotePort: uint16(remotePort), - }, nil + return uint16(port), nil } diff --git a/internal/command/portforward/portspec_test.go b/internal/command/portforward/portspec_test.go index 46bab7d..dd6e552 100644 --- a/internal/command/portforward/portspec_test.go +++ b/internal/command/portforward/portspec_test.go @@ -9,7 +9,7 @@ import ( func TestPortSpecNormal(t *testing.T) { portSpec, err := portforward.NewPortSpec("5555") require.NoError(t, err) - require.Equal(t, &portforward.PortSpec{LocalPort: 5555, RemotePort: 5555}, portSpec) + require.Equal(t, &portforward.PortSpec{LocalPort: 0, RemotePort: 5555}, portSpec) portSpec, err = portforward.NewPortSpec("8000:80") require.NoError(t, err) diff --git a/internal/command/portforward/worker.go b/internal/command/portforward/worker.go new file mode 100644 index 0000000..0d1dda6 --- /dev/null +++ b/internal/command/portforward/worker.go @@ -0,0 +1,83 @@ +package portforward + +import ( + "fmt" + "github.com/cirruslabs/orchard/internal/proxy" + "github.com/cirruslabs/orchard/pkg/client" + "github.com/spf13/cobra" + "net" +) + +func newPortForwardWorkerCommand() *cobra.Command { + command := &cobra.Command{ + Use: "worker WORKER_NAME [LOCAL_PORT]:REMOTE_PORT", + Short: "Forward TCP port to the worker", + Args: cobra.ExactArgs(2), + RunE: runPortForwardWorkerCommand, + } + + return command +} + +func runPortForwardWorkerCommand(cmd *cobra.Command, args []string) (err error) { + name := args[0] + portSpecRaw := args[1] + + portSpec, err := NewPortSpec(portSpecRaw) + if err != nil { + return err + } + + client, err := client.New() + if err != nil { + return err + } + + listener, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", portSpec.LocalPort)) + if err != nil { + return err + } + defer func() { + if listenerErr := listener.Close(); listenerErr != nil && err == nil { + err = listenerErr + } + }() + + fmt.Printf("forwarding %s -> %s:%d...\n", listener.Addr(), name, portSpec.RemotePort) + + errCh := make(chan error, 1) + + go func() { + for { + conn, err := listener.Accept() + if err != nil { + errCh <- err + + return + } + + go func() { + defer conn.Close() + + wsConn, err := client.Workers().PortForward(cmd.Context(), name, portSpec.RemotePort) + if err != nil { + fmt.Printf("failed to forward port: %v\n", err) + + return + } + defer wsConn.Close() + + if err := proxy.Connections(wsConn, conn); err != nil { + fmt.Printf("failed to forward port: %v\n", err) + } + }() + } + }() + + select { + case <-cmd.Context().Done(): + return cmd.Context().Err() + case err := <-errCh: + return err + } +} diff --git a/internal/command/vnc/vnc.go b/internal/command/vnc/vnc.go index 2312241..dc0deaa 100644 --- a/internal/command/vnc/vnc.go +++ b/internal/command/vnc/vnc.go @@ -8,7 +8,7 @@ func NewCommand() *cobra.Command { Short: "Open VNC session with the resource", } - command.AddCommand(newVNCVMCommand()) + command.AddCommand(newVNCVMCommand(), newVNCWorkerCommand()) return command } diff --git a/internal/command/vnc/worker.go b/internal/command/vnc/worker.go new file mode 100644 index 0000000..e89ca03 --- /dev/null +++ b/internal/command/vnc/worker.go @@ -0,0 +1,104 @@ +package vnc + +import ( + "fmt" + "github.com/cirruslabs/orchard/internal/proxy" + "github.com/cirruslabs/orchard/pkg/client" + "github.com/skratchdot/open-golang/open" + "github.com/spf13/cobra" + "net" +) + +func newVNCWorkerCommand() *cobra.Command { + command := &cobra.Command{ + Use: "worker WORKER_NAME", + Short: "Open VNC session with the worker", + Args: cobra.ExactArgs(1), + RunE: runVNCWorker, + } + + command.PersistentFlags().StringVarP(&username, "username", "u", "", + "VNC username") + command.PersistentFlags().StringVarP(&password, "password", "p", "", + "VNC password") + return command +} + +func runVNCWorker(cmd *cobra.Command, args []string) (err error) { + name := args[0] + + client, err := client.New() + if err != nil { + return err + } + + listener, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + return err + } + defer func() { + if listenerErr := listener.Close(); listenerErr != nil && err == nil { + err = listenerErr + } + }() + + fmt.Printf("forwarding %s -> %s:%d...\n", listener.Addr(), name, vncPort) + + errCh := make(chan error, 1) + + go func() { + for { + conn, err := listener.Accept() + if err != nil { + errCh <- err + + return + } + + go func() { + wsConn, err := client.Workers().PortForward(cmd.Context(), name, vncPort) + if err != nil { + fmt.Printf("failed to forward port: %v\n", err) + + return + } + defer wsConn.Close() + + if err := proxy.Connections(wsConn, conn); err != nil { + fmt.Printf("failed to forward port: %v\n", err) + } + }() + } + }() + + var credentialsComponent string + var credentialsComponentSanitized string + + if username != "" { + credentialsComponent = username + credentialsComponentSanitized = username + + if password != "" { + credentialsComponent += ":" + password + } + + credentialsComponent += "@" + credentialsComponentSanitized += "@" + } + + openURL := fmt.Sprintf("vnc://%s%s", credentialsComponent, listener.Addr().String()) + openURLSanitized := fmt.Sprintf("vnc://%s%s", credentialsComponentSanitized, listener.Addr().String()) + + fmt.Printf("opening %s...\n", openURLSanitized) + + if err := open.Start(openURL); err != nil { + fmt.Printf("failed to open: %v\n", err) + } + + select { + case <-cmd.Context().Done(): + return cmd.Context().Err() + case err := <-errCh: + return err + } +} diff --git a/internal/controller/api.go b/internal/controller/api.go index 642b770..4561f07 100644 --- a/internal/controller/api.go +++ b/internal/controller/api.go @@ -98,6 +98,9 @@ func (controller *Controller) initAPI() *gin.Engine { v1.GET("/workers", func(c *gin.Context) { controller.listWorkers(c).Respond(c) }) + v1.GET("/workers/:name/port-forward", func(c *gin.Context) { + controller.portForwardWorker(c).Respond(c) + }) v1.DELETE("/workers/:name", func(c *gin.Context) { controller.deleteWorker(c).Respond(c) }) diff --git a/internal/controller/api_vms_portforward.go b/internal/controller/api_vms_portforward.go index 85c7c11..98a56b9 100644 --- a/internal/controller/api_vms_portforward.go +++ b/internal/controller/api_vms_portforward.go @@ -47,23 +47,34 @@ func (controller *Controller) portForwardVM(ctx *gin.Context) responder.Responde return responderImpl } + // Commence port-forwarding + return controller.portForward(ctx, vm.Worker, vm.UID, uint32(port)) +} + +func (controller *Controller) portForward( + ctx *gin.Context, + workerName string, + vmUID string, + port uint32, +) responder.Responder { // Request and wait for a connection with a worker session := uuid.New().String() boomerangConnCh, cancel := controller.proxy.Request(ctx, session) defer cancel() // send request to worker to initiate port-forwarding connection back to us - err = controller.workerNotifier.Notify(ctx, vm.Worker, &rpc.WatchInstruction{ + err := controller.workerNotifier.Notify(ctx, workerName, &rpc.WatchInstruction{ Action: &rpc.WatchInstruction_PortForwardAction{ PortForwardAction: &rpc.WatchInstruction_PortForward{ Session: session, - VmUid: vm.UID, - VmPort: uint32(port), + VmUid: vmUID, + Port: port, }, }, }) if err != nil { - controller.logger.Warnf("failed to request port-forwarding from the worker %s: %v", vm.Worker, err) + controller.logger.Warnf("failed to request port-forwarding from the worker %s: %v", + workerName, err) return responder.Code(http.StatusServiceUnavailable) } diff --git a/internal/controller/api_workers_portforward.go b/internal/controller/api_workers_portforward.go new file mode 100644 index 0000000..0336841 --- /dev/null +++ b/internal/controller/api_workers_portforward.go @@ -0,0 +1,44 @@ +package controller + +import ( + storepkg "github.com/cirruslabs/orchard/internal/controller/store" + "github.com/cirruslabs/orchard/internal/responder" + v1 "github.com/cirruslabs/orchard/pkg/resource/v1" + "github.com/gin-gonic/gin" + "net/http" + "strconv" +) + +func (controller *Controller) portForwardWorker(ctx *gin.Context) responder.Responder { + if responder := controller.authorize(ctx, v1.ServiceAccountRoleAdminWrite); responder != nil { + return responder + } + + // Retrieve and parse path and query parameters + name := ctx.Param("name") + + portRaw := ctx.Query("port") + port, err := strconv.ParseUint(portRaw, 10, 16) + if err != nil { + return responder.Code(http.StatusBadRequest) + } + if port < 1 || port > 65535 { + return responder.Code(http.StatusBadRequest) + } + + var worker *v1.Worker + + if responder := controller.storeView(func(txn storepkg.Transaction) responder.Responder { + worker, err = txn.GetWorker(name) + if err != nil { + return responder.Error(err) + } + + return nil + }); responder != nil { + return responder + } + + // Commence port-forwarding + return controller.portForward(ctx, worker.Name, "", uint32(port)) +} diff --git a/internal/worker/rpc.go b/internal/worker/rpc.go index 221237d..71d7cea 100644 --- a/internal/worker/rpc.go +++ b/internal/worker/rpc.go @@ -81,26 +81,33 @@ func (worker *Worker) handlePortForward( return } - // Obtain VM - vm, ok := lo.Find(worker.vmm.List(), func(item *vmmanager.VM) bool { - return item.Resource.UID == portForwardAction.VmUid - }) - if !ok { - worker.logger.Warnf("port forwarding failed: failed to get the VM: %v", err) - - return - } + var host string + + if portForwardAction.VmUid == "" { + // Port-forwarding request to a worker + host = "localhost" + } else { + // Port-forwarding request to a VM, find that VM + vm, ok := lo.Find(worker.vmm.List(), func(item *vmmanager.VM) bool { + return item.Resource.UID == portForwardAction.VmUid + }) + if !ok { + worker.logger.Warnf("port forwarding failed: failed to get the VM: %v", err) + + return + } - // Obtain VM's IP address - ip, err := vm.IP(ctx) - if err != nil { - worker.logger.Warnf("port forwarding failed: failed to get VM's IP: %v", err) + // Obtain VM's IP address + host, err = vm.IP(ctx) + if err != nil { + worker.logger.Warnf("port forwarding failed: failed to get VM's IP: %v", err) - return + return + } } // Connect to the VM's port - vmConn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", ip, portForwardAction.VmPort)) + vmConn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", host, portForwardAction.Port)) if err != nil { worker.logger.Warnf("port forwarding failed: failed to connect to the VM: %v", err) diff --git a/pkg/client/client.go b/pkg/client/client.go index 62bb89c..e37c141 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -271,10 +271,10 @@ func (client *Client) wsRequest( if err != nil { if resp != nil { _ = resp.Body.Close() - } - if resp.StatusCode == http.StatusNotFound { - err = fmt.Errorf("%w (are you sure this VM exists on the controller?)", err) + if resp.StatusCode == http.StatusNotFound { + err = fmt.Errorf("%w (are you sure this VM exists on the controller?)", err) + } } return nil, err diff --git a/pkg/client/workers.go b/pkg/client/workers.go index a85bede..0862c89 100644 --- a/pkg/client/workers.go +++ b/pkg/client/workers.go @@ -4,8 +4,10 @@ import ( "context" "fmt" "github.com/cirruslabs/orchard/pkg/resource/v1" + "net" "net/http" "net/url" + "strconv" ) type WorkersService struct { @@ -65,3 +67,14 @@ func (service *WorkersService) Delete(ctx context.Context, name string) error { return nil } + +func (service *WorkersService) PortForward( + ctx context.Context, + name string, + port uint16, +) (net.Conn, error) { + return service.client.wsRequest(ctx, fmt.Sprintf("workers/%s/port-forward", url.PathEscape(name)), + map[string]string{ + "port": strconv.FormatUint(uint64(port), 10), + }) +} diff --git a/rpc/orchard.pb.go b/rpc/orchard.pb.go index 7285db9..3f80cfe 100644 --- a/rpc/orchard.pb.go +++ b/rpc/orchard.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 +// protoc-gen-go v1.31.0 // protoc (unknown) // source: orchard.proto @@ -157,8 +157,9 @@ type WatchInstruction_PortForward struct { // we can have multiple port forwards for the same vm/port pair // let's distinguish them by a unique session Session string `protobuf:"bytes,1,opt,name=session,proto3" json:"session,omitempty"` - VmUid string `protobuf:"bytes,2,opt,name=vm_uid,json=vmUid,proto3" json:"vm_uid,omitempty"` - VmPort uint32 `protobuf:"varint,3,opt,name=vm_port,json=vmPort,proto3" json:"vm_port,omitempty"` + // can be empty to request a forwarding to the worker itself + VmUid string `protobuf:"bytes,2,opt,name=vm_uid,json=vmUid,proto3" json:"vm_uid,omitempty"` + Port uint32 `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"` } func (x *WatchInstruction_PortForward) Reset() { @@ -207,9 +208,9 @@ func (x *WatchInstruction_PortForward) GetVmUid() string { return "" } -func (x *WatchInstruction_PortForward) GetVmPort() uint32 { +func (x *WatchInstruction_PortForward) GetPort() uint32 { if x != nil { - return x.VmPort + return x.Port } return 0 } @@ -257,7 +258,7 @@ var File_orchard_proto protoreflect.FileDescriptor var file_orchard_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x6f, 0x72, 0x63, 0x68, 0x61, 0x72, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x96, 0x02, 0x0a, + 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x91, 0x02, 0x0a, 0x10, 0x57, 0x61, 0x74, 0x63, 0x68, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x4f, 0x0a, 0x13, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x5f, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, @@ -268,27 +269,26 @@ var file_orchard_proto_rawDesc = []byte{ 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x53, 0x79, 0x6e, 0x63, 0x56, 0x4d, 0x73, 0x48, 0x00, 0x52, 0x0d, 0x73, 0x79, 0x6e, 0x63, 0x56, 0x6d, - 0x73, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x57, 0x0a, 0x0b, 0x50, 0x6f, 0x72, 0x74, 0x46, + 0x73, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x52, 0x0a, 0x0b, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x15, 0x0a, 0x06, 0x76, 0x6d, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x76, 0x6d, 0x55, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x76, 0x6d, 0x5f, 0x70, 0x6f, - 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x76, 0x6d, 0x50, 0x6f, 0x72, 0x74, - 0x1a, 0x09, 0x0a, 0x07, 0x53, 0x79, 0x6e, 0x63, 0x56, 0x4d, 0x73, 0x42, 0x08, 0x0a, 0x06, 0x61, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x25, 0x0a, 0x0f, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, - 0x77, 0x61, 0x72, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0x79, 0x0a, 0x0a, - 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x34, 0x0a, 0x05, 0x57, 0x61, - 0x74, 0x63, 0x68, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x11, 0x2e, 0x57, 0x61, - 0x74, 0x63, 0x68, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x30, 0x01, - 0x12, 0x35, 0x0a, 0x0b, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x12, - 0x10, 0x2e, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x44, 0x61, 0x74, - 0x61, 0x1a, 0x10, 0x2e, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x44, - 0x61, 0x74, 0x61, 0x28, 0x01, 0x30, 0x01, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x69, 0x72, 0x72, 0x75, 0x73, 0x6c, 0x61, 0x62, 0x73, - 0x2f, 0x6f, 0x72, 0x63, 0x68, 0x61, 0x72, 0x64, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x76, 0x6d, 0x55, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x09, 0x0a, 0x07, 0x53, + 0x79, 0x6e, 0x63, 0x56, 0x4d, 0x73, 0x42, 0x08, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0x25, 0x0a, 0x0f, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x44, + 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0x79, 0x0a, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x34, 0x0a, 0x05, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x11, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x49, 0x6e, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x30, 0x01, 0x12, 0x35, 0x0a, 0x0b, 0x50, + 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x12, 0x10, 0x2e, 0x50, 0x6f, 0x72, + 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x10, 0x2e, 0x50, + 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x44, 0x61, 0x74, 0x61, 0x28, 0x01, + 0x30, 0x01, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x63, 0x69, 0x72, 0x72, 0x75, 0x73, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x6f, 0x72, 0x63, 0x68, + 0x61, 0x72, 0x64, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/orchard.proto b/rpc/orchard.proto index de0823e..59505ad 100644 --- a/rpc/orchard.proto +++ b/rpc/orchard.proto @@ -18,8 +18,9 @@ message WatchInstruction { // we can have multiple port forwards for the same vm/port pair // let's distinguish them by a unique session string session = 1; + // can be empty to request port-forwarding to the worker itself string vm_uid = 2; - uint32 vm_port = 3; + uint32 port = 3; } message SyncVMs { } diff --git a/rpc/orchard_grpc.pb.go b/rpc/orchard_grpc.pb.go index e661c8d..b97afdd 100644 --- a/rpc/orchard_grpc.pb.go +++ b/rpc/orchard_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.2.0 +// - protoc-gen-go-grpc v1.3.0 // - protoc (unknown) // source: orchard.proto @@ -19,6 +19,11 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + Controller_Watch_FullMethodName = "/Controller/Watch" + Controller_PortForward_FullMethodName = "/Controller/PortForward" +) + // ControllerClient is the client API for Controller service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. @@ -39,7 +44,7 @@ func NewControllerClient(cc grpc.ClientConnInterface) ControllerClient { } func (c *controllerClient) Watch(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (Controller_WatchClient, error) { - stream, err := c.cc.NewStream(ctx, &Controller_ServiceDesc.Streams[0], "/Controller/Watch", opts...) + stream, err := c.cc.NewStream(ctx, &Controller_ServiceDesc.Streams[0], Controller_Watch_FullMethodName, opts...) if err != nil { return nil, err } @@ -71,7 +76,7 @@ func (x *controllerWatchClient) Recv() (*WatchInstruction, error) { } func (c *controllerClient) PortForward(ctx context.Context, opts ...grpc.CallOption) (Controller_PortForwardClient, error) { - stream, err := c.cc.NewStream(ctx, &Controller_ServiceDesc.Streams[1], "/Controller/PortForward", opts...) + stream, err := c.cc.NewStream(ctx, &Controller_ServiceDesc.Streams[1], Controller_PortForward_FullMethodName, opts...) if err != nil { return nil, err }