mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-10-07 09:40:56 +08:00

With this PR expose API can handle npipe as a protocol which is used in windows to expose socket to named pipe. Following is now working. (Tested with CRC) ``` --- captured from the VM --- $ curl http://host.crc.testing:7777/services/forwarder/all | jq . [ { "local": "127.0.0.1:2222", "remote": "192.168.127.2:22", "protocol": "tcp" }, { "local": "127.0.0.1:9090", "remote": "192.168.127.2:9090", "protocol": "tcp" }, { "local": "\\\\.\\pipe\\crc-podman", "remote": "ssh-tunnel://core@192.168.127.2:22/run/podman/podman.sock?key=C%3A%5CUsers%5Cprkumar%5C.crc%5Cmachines%5Ccrc%5Cid_ecdsa", "protocol": "npipe" } ] \\.\pipe\crc-http - - [23/Feb/2022:10:38:20 +0530] "POST /network/services/forwarder/expose HTTP/1.1" 200 0 INFO Listening on: \\.\pipe\crc-podman > $Env:DOCKER_HOST = "npipe:////./pipe/crc-podman" > .\docker.exe info Client: Context: default Debug Mode: false Server: Containers: 1 Running: 1 Paused: 0 Server Version: 3.4.4 Storage Driver: overlay Backing Filesystem: xfs Supports d_type: true ``` Signed-off-by: Praveen Kumar <kumarpraveen.nitdgp@gmail.com> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package sshclient
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/url"
|
|
"os/user"
|
|
"strings"
|
|
|
|
winio "github.com/Microsoft/go-winio"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/sddl-for-device-objects
|
|
// Allow built-in admins and system/kernel components
|
|
const SddlDevObjSysAllAdmAll = "D:P(A;;GA;;;SY)(A;;GA;;;BA)"
|
|
|
|
func ListenNpipe(socketURI *url.URL) (net.Listener, error) {
|
|
user, err := user.Current()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Also allow current user
|
|
sddl := fmt.Sprintf("%s(A;;GA;;;%s)", SddlDevObjSysAllAdmAll, user.Uid)
|
|
config := winio.PipeConfig{
|
|
SecurityDescriptor: sddl,
|
|
MessageMode: true,
|
|
InputBufferSize: 65536,
|
|
OutputBufferSize: 65536,
|
|
}
|
|
path := strings.Replace(socketURI.Path, "/", "\\", -1)
|
|
|
|
listener, err := winio.ListenPipe(path, &config)
|
|
if err != nil {
|
|
return listener, errors.Wrapf(err, "Error listening on socket: %s", socketURI)
|
|
}
|
|
|
|
logrus.Info("Listening on: " + path)
|
|
|
|
return listener, nil
|
|
}
|