95 Commits

Author SHA1 Message Date
Christophe Fergeau
bfdef222a5 build: Remove // +build tags
`govet` now complains about them as they’ve been superseded by
`//go:build` for a while now:
```
test-win-sshproxy/suite_test.go:2:1: buildtag: +build line is no longer needed (govet)
```

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-10-30 11:47:43 +01:00
openshift-merge-bot[bot]
9e98ea7340 Merge pull request #555 from cfergeau/no-wrap
Stop using github.com/pkg/errors
2025-09-24 15:31:12 +00:00
Christophe Fergeau
0bec21cab9 gvproxy: Stop using errors.Wrap
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-24 17:21:20 +02:00
Christophe Fergeau
1a1613d9f1 ssh-over-vsock: Stop using errors.Wrap
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-24 17:21:18 +02:00
Christophe Fergeau
c37bc7b687 gvforwarder: Stop using errors.Wrap
This is deprecated in favour of `%w` use.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-24 17:21:17 +02:00
Christophe Fergeau
9be4413f80 gvforwarder: Add more logging during startup
This should help understand what gvforwarder is doing when it does not work as expected.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-16 11:26:01 +02:00
Christophe Fergeau
fca66c8872 gvforwarder: Report error on int16 overflow
This error path returned from `rx` but did not report an error as all the other error paths.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-16 11:25:59 +02:00
Christophe Fergeau
e8329ce718 gvforwarder: Use slices.Contains
The `contains` helper is now part of the `slices` package

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-16 11:25:56 +02:00
Andre Buryndin
c58b936857 gvproxy: Enable config file based configuration
This is a little rethink of how to configure. Since the previous
implementation disallows to use the compiled binaries in releases, I
have prepared a more flexible version. However, the legacy behavior
(without configuration file) remains as is (proven by unit tests).

List of changes
    Enable -config flag. If no such flag provided, then remain the original behavior
    Partial refactoring of the initialization process

Most of all changes are tested, see unit tests.

I'm trying to enable multi-VM local lab which should support different
host OS, guest OS, guest arches. With this tool I have resolved the
significant problem with the proper VM networking (at least for MacOS).

Signed-off-by: Andre Buryndin <themrecco@gmail.com>
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-12 14:07:01 +02:00
Christophe Fergeau
c247b31e20 lint: Fix error appearing after the go 1.24 go.mod change
GOOS=windows /Applications/Xcode.app/Contents/Developer/usr/bin/make lint
"/Users/teuf/dev/gvisor-tap-vsock/tools/bin"/golangci-lint run
cmd/win-sshproxy/main.go:99:17: printf: non-constant format string in call to github.com/sirupsen/logrus.Errorf (govet)
		logrus.Errorf("Error saving thread id: " + err.Error())
		              ^
cmd/win-sshproxy/main.go:111:17: printf: non-constant format string in call to github.com/sirupsen/logrus.Errorf (govet)
		logrus.Errorf("Error occurred in execution group: " + err.Error())

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-09-10 10:15:58 +02:00
Gunjan Vyas
c60cf839d6 Fix all linting errors found by cross-lint
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
2025-09-03 13:05:13 +05:30
openshift-merge-bot[bot]
d0ce48ae94 Merge pull request #512 from dpdornseifer/feature/ec2_metadata_access
Added EC2 Metadata Service Access Flag
2025-06-10 12:22:22 +00:00
Gunjan Vyas
31193c50af lint fix: fix linter errors after migrating to v2
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
2025-05-22 09:41:04 +02:00
David Dornseifer
3cf598b298 Added EC2 Metadata Service Access Flag
Added `ec2-metadata-access` flag to allow TCP traffic being routed to AWS EC2 metadata service explicitly.
This flag is required for easy AWS Nitro Enclave to EC2 IMDSv2 communication via gvproxy. Originally
`lincLocal` access has been blocked in #f4a40d2 to prevent issues with CoreOS VM.

Signed-off-by: David Dornseifer <dornseid@amazon.com>
2025-05-15 13:57:13 +02:00
Christophe Fergeau
d888e1a82d gvproxy: Add --pcap option
Instead of always writing to a `capture.pcap` file in the current
directory when --debug is used, this commit introduces a separate --pcap
argument, which can also be used to specify the path to the capture
file.
These pcap files can get huge, and are not always useful when debug logs
are requested, so it’s better to separate --debug and --pcap.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2025-04-24 16:33:38 +02:00
Luca Stocchi
4bbb832355 fix vfkit socket disposal
when disposing the vfkit socket, gvproxy fails at removing it bc it tries to remove the unixgram uri (e.g. unixgram:///var/folders/n4/n5hyrstd2739lcy9903jn8f40000gn/T/podman/podman-gvproxy.sock).
This patch fixes it by extracting the path from the uri.

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
2025-03-11 18:25:02 +01:00
Yevhen Vydolob
788ed77e8f Trim 'search' list field on macOS
According to macOS 'man 5 resolver' 'search' is limited to six domains with a total of 256 characters. This commit uses only 256/6 domains and cuts rest.

Since glibc 2.26 Linux has no limitation on 'search'.

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
2025-03-04 10:31:25 +02:00
openshift-merge-bot[bot]
45ea6bbb97 Merge pull request #429 from lstocchi/i425
Add --services flag to start API without using --listen flag
2025-01-30 16:01:54 +00:00
Luca Stocchi
d1a7ed9c3d Add --services flag to start API without using --listen flag
In the current implementation when gvproxy is started with the --listen option, it exposes a HTTP API with several endpoints like /connect, /stats, /services ...
The /connect endpoint, however, is only used when the gvforwarder tool is running on the guest, and, when using different connectivities like --listen-vfkit or --listen-qemu, it is not really necessary.

This commit adds a new flag --services that allows to start the HTTP API without the /connect endpoint. It could be used when using different network connectivity and still wanting a lighter HTTP API. It accepts the endpoint where it will be reachable E.g. gvproxy --listen-vfkit .... --services unix:///tmp/svc_gvproxy.sock

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
2025-01-21 17:36:44 +01:00
openshift-merge-bot[bot]
5f09250426 Merge pull request #442 from lstocchi/noELService
Warn user and keep executing if Event Log Service is stopped
2025-01-08 13:40:16 +00:00
lstocchi
cf01d72ae6 Warn user and keep executing if Event Log Service is stopped
As reported by https://github.com/containers/podman/issues/21426 , it
may happen that during a Windows update the Event Log Service is
disabled automatically without the user noticing it. In this case win-sshproxy
fails at starting bc it is not able to write logs.

However, the Event Log Service could also be disabled voluntarely by the
user and we cannot be sure that the user want/can re-enable it. In such a case,
a warn log is printed and win-sshproxy keeps executing. It
should be up to the user to decide if to start the Event Log service again or keep
running win-sshproxy without logs.

Signed-off-by: lstocchi <lstocchi@redhat.com>
2025-01-08 14:27:30 +01:00
Chris Pick
fd3f756c13 Fix error "-forward-sock" -> "--forward-sock"
Signed-off-by: Chris Pick <chris@chrispick.com>
2024-12-21 16:04:03 -05:00
lstocchi
08769de7e0 win-sshproxy.tid created before thread id is available
this commit fixes a potential race condition that prevented the tests to succeed
when running in a github workflow.
Basically the thread id was not actually available before
writing it on the file, resulting in a thread id equals to 0 written in it.
So, when the tests were trying to retrieve the thread id to use it to send
the WM_QUIT signal, they failed.

This patch adds a check on the thread id before writing
it on the file. Now, if the thread id is 0, it keeps calling winquit to
retrieve it. If, after 10 secs, there is no success it returns an error.

Signed-off-by: lstocchi <lstocchi@redhat.com>
2024-11-29 11:18:44 +01:00
Gunjan Vyas
ffcc6608b3 Disable ssh port forwarding when value of -ssh-port is -1
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
2024-10-04 19:38:35 +05:30
Christophe Fergeau
d909c7968a lint: Fix non-constant format string error
This fixes
cmd/gvproxy/main.go:106:12: printf: non-constant format string in call to github.com/sirupsen/logrus.Infof (govet)
	log.Infof(version.String())
	          ^
make: *** [Makefile:49: lint] Error 1

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2024-08-22 12:13:02 +02:00
Yevhen Vydolob
c2a5985dc9 Fix lint errors
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
2024-03-06 14:31:00 +02:00
openshift-merge-bot[bot]
493d512e83 Merge pull request #315 from cfergeau/debug
Improve gvproxy error reporting, and improve gvproxy --version in a corner case
2024-02-01 16:06:28 +00:00
Brent Baude
3f305f5d2e Add log-file to proxy builder
The original PR only enabled log-file on the command line.  This PR adds
log-file to gvproxy's builder (for consumption) and adds trivial test.

Also, when --debug is used, we seed the log file with some environment
information

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-01-22 09:18:43 -06:00
Christophe Fergeau
731467742d gvproxy: Add more context to errors
Some errors are currently not logged, or without much context.
This commit adds prefixes to some of these, to make it easier to
understand the codepaths which caused gvproxy to exit.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2024-01-22 15:02:51 +01:00
Brent Baude
4c2c7bb28f Add --log-file to gvproxy
Add ability specify a log-file for log messages.  This PR redirects are
logged messages from the logrus logger to a given file.  It is intended
to help debug gvproxy failures and usage.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-01-16 07:57:12 -06:00
Christophe Fergeau
f64bf1988b cmd/*: Add -version flag to executables
This sets the version to `git describe --always --dirty` using the
`-X github.com/containers/gvisor-tap-vsock/pkg/types.ModuleVersion`
linker flag.

This adds a -version flag to all binaries which currently have
command-line flags.

Correct versioning when installing from tarballs, and through
`go install` will be addressed in the next commits.

This fixes https://github.com/containers/gvisor-tap-vsock/issues/295

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2023-12-20 16:50:09 +01:00
Jason T. Greene
4c6193e834 Add graceful shutdown support for gvproxy on Win
Leverages WM_CLOSE and WM_QUIT events on win32 for SIGTERM like behavior
The improved/updated logic is now implemented in a shared containers/winquit module
Also, refactors win-sshproxy.exe to be consistent (had it's own precursor impl)

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2023-09-22 13:04:59 +02:00
Paul Holzinger
49a1f884c7 gvproxy: add docker.internal dns entries
Some tools hard code the `host.docker.internal` dns name so it is not
possible to run them with podman right now. Adding the entry is simple
so we should support it for better compatibility.

Also remove crc.testing, podman does not depend on it since at least
v4.0 and it seems like there are no other users.

see https://github.com/containers/podman/issues/19361

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-08-04 14:08:59 +02:00
Philipp Winter
9a6dda3f4c Remove unnecessary allocations and Write calls.
This commit improves networking performance by 1) moving an unnecessary
allocation to outside the hot loop and by 2) eliminating an unnecessary
Write call.

This result in ~7% faster throughput as measured via iperf3 and a custom
Web service to measure requests per second.  Note that this is *despite*
the append call.

Signed-off-by: Philipp Winter <phw@brave.com>
2023-06-27 10:00:07 +02:00
Christophe Fergeau
715fc532f2 Add vfkit support
Communication must happen over a connected datagram unix socket. This
reuses most of the work which was done for bess.
Since there is no 'accept' with unixgram sockets which could be used to
get the address to send the data back to (ie the VM address), this adds
a handshake between the VM and gvproxy:
- gvproxy listens on a unixgram socket at a known location
- vfkit connects to this location
- vfkit sends "VFKT"
- gvproxy receives this message and gets the VM address from it
- network traffic can now happen between gvproxy and vfkit

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2023-06-22 15:37:41 +02:00
Keiichi Shimamura
11db9f4c1a set proper protocol for stdio
Signed-off-by: Keiichi Shimamura <sakai135@users.noreply.github.com>
2023-03-14 09:56:50 +01:00
sakai135
17048f5996 connect over stdio for wsl
This adds stdio as a way to communicate between gvproxy and vm mainly for use
with WSL2, although it should work for other cases as well.

When network connections between WSL2 and the Windows host are blocked, stdio
is the only reliable way to establish a channel between WSL2 and the Windows
host. Hyper-V socket for WSL2 is a possibility, but it requires undocumented
APIs and admin privileges.

Signed-off-by: Keiichi Shimamura <sakai135@users.noreply.github.com>
2023-02-14 16:28:55 +01:00
Christophe Fergeau
d046d2e261 vm: Make network configuration optional
Add command line option to make network configuration of the TAP
interface optional.

This allows to use create the tap device using 'native' tools, for
example:
 # nmcli connection add type tun ifname tap0 con-name tap0 mode tap
 # nmcli conn up tap0 ifname tap0

The advantage of not doing the configuration in the 'vm' binary is that
we don't need to hardcode the name of a dhcp client and call it from go
code, we can just use native OS networking (NetworkManager,
systemd-resolved, ...) and let it do its work.

There is currently no dhcp client easily available in ubi8 images, and
for the images we use in CRC, we'd prefer not to use a busybox base
image, this work helps with that.

After this change, 'vm' can be started as a systemd service:

[Unit]
Description=gvisor-tap-vsock traffic forwarder
BindsTo=sys-devices-virtual-net-tap0.device
After=sys-devices-virtual-net-tap0.device

[Service]
Restart=on-success
TimeoutStopSec=70
ExecStart=/usr/bin/gvisor-tap-vsock-forwarder -preexisting

[Install]
WantedBy=default.target

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2022-09-06 15:06:18 +02:00
Christophe Fergeau
b98e2748de net: Add timeout to http.Serve calls
golangci-lint reports the lack of timeouts as errors:

cmd/gvproxy/main.go:423:10: G114: Use of net/http serve function that has no support for setting timeouts (gosec)
		err := http.Serve(ln, mux)
		       ^
cmd/test-companion/main.go:44:12: G114: Use of net/http serve function that has no support for setting timeouts (gosec)
	log.Fatal(http.ListenAndServe(":8080", mux))
	          ^
test/port_forwarding_test.go:41:14: G114: Use of net/http serve function that has no support for setting timeouts (gosec)
			if err := http.Serve(ln, mux); err != nil {
			          ^

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2022-09-06 18:33:45 +05:30
Christophe Fergeau
8c72b59df3 ioutil: Switch away from deprecated package
ioutil has been deprecated since golang 1.16.
This commit uses the replacement methods from the os or io packages.
This should fix some golangci-lint CI failures.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2022-09-06 18:33:45 +05:30
Burt Holzman
85d4763c1e Change ssh-port to listen on localhost only
Signed-off-by: Burt Holzman <burt@fnal.gov>
2022-03-02 12:55:59 -06:00
Jason T. Greene
db04e7ddba Implement windows ssh proxy with windows pipe support
Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2022-01-14 01:33:01 -06:00
Guillaume Rose
52d1a63b1f Use a small helper for tests instead of pulling images
Also use ssh local tool for running ssh commands.
2022-01-06 16:02:28 +01:00
Akihiro Suda
826b1b6f6f Support BESS protocol (for UML)
BESS protocol transferrs L2 packets as AF_UNIX SOCK_SEQPACKET .
BESS protocol has been used by the vector network interfaces of User Mode Linux (UML).

```
(terminal 1) $ bin/gvproxy -debug -listen unix:///tmp/network.sock -listen-bess unixpacket:///tmp/bess.sock
(terminal 2) $ linux.uml vec0:transport=bess,dst=/tmp/bess.sock,depth=128,gro=1,mac=5a:94:ef:e4:0c:ee root=/dev/root rootfstype=hostfs init=/bin/bash mem=2G
(terminal 2: UML)$ ip addr add 192.168.127.2/24 dev vec0
(terminal 2: UML)$ ip link set vec0 up
(terminal 2: UML)$ ip route add default via 192.168.127.254
```

More docs about the User Mode Linux with BESS socket transport: https://www.kernel.org/doc/html/latest/virt/uml/user_mode_linux_howto_v2.html#bess-socket-transport

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-01-05 16:29:33 +09:00
Christophe Fergeau
da532d62aa cmd/vm: Remove '--change-default-route'
This is a no-op since:

commit 63ad932977664aff2b763d23f1e9efc5a6d001b4
Author: Guillaume Rose <gurose@redhat.com>
Date:   Thu Apr 29 15:13:55 2021 +0200

    Use DHCP instead of custom handshake between daemon and the VM
2021-11-30 11:47:41 +01:00
Jason T. Greene
38243c6a55 Add support for multiple unix socket forwards over ssh 2021-10-20 22:23:21 -05:00
Jason T. Greene
36209fdc5a Initial implementation of static unix socket forwarding over ssh 2021-10-13 11:05:13 -05:00
Guillaume Rose
384e40bdde gvproxy can start without listening a port or a socket on the host
gvproxy can be controlled from the inside network directly.
2021-10-12 09:46:16 +02:00
Guillaume Rose
ec068dea94 Add endpoint to configure port forwarding without going to the host 2021-10-12 09:46:16 +02:00
Guillaume Rose
4b82a55a3f Copy host search domains to the VM 2021-09-27 15:59:52 +02:00