Skip to content

Commit b402bdb

Browse files
committed
[POC, DNM] Expose socks proxy (per user-v2 net, not per instance)
Usage: ``` curl \ --proxy socks5h://localhost/$HOME/.lima/_networks/user-v2/user-v2_socks.sock \ 192.168.104.4 ``` This is similar to the `limactl tunnel` proposal (PR 2710). While PR 2710 creates a proxy per an instance, this commit creates a proxy per a user-v2 network. Remarks: - Only works for user-v2 networks. - DNS lookup is not implemented yet in this POC. Could be taken from https://github.com/norouter/norouter/blob/v0.6.5/pkg/agent/socks/socks.go#L57-L75 - https://github.com/cybozu-go/usocksd is a dependency hog (See the `go.mod` diff). Should be replaced with a fork or another library. Overall, PR 2710 might be better than this commit, as PR 2710 works for any network driver, does not need an additional DNS resolver, and does not incur additional `go.mod` deps. Signed-off-by: Akihiro Suda <[email protected]>
1 parent 1c98589 commit b402bdb

File tree

6 files changed

+871
-3
lines changed

6 files changed

+871
-3
lines changed

cmd/limactl/usernet.go

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func newUsernetCommand() *cobra.Command {
2222
hostagentCommand.Flags().StringP("endpoint", "e", "", "exposes usernet api(s) on this endpoint")
2323
hostagentCommand.Flags().String("listen-qemu", "", "listen for qemu connections")
2424
hostagentCommand.Flags().String("listen", "", "listen on a Unix socket and receive Bess-compatible FDs as SCM_RIGHTS messages")
25+
hostagentCommand.Flags().String("listen-socks", "", "listen for socks connectioss")
2526
hostagentCommand.Flags().String("subnet", "192.168.5.0/24", "sets subnet value for the usernet network")
2627
hostagentCommand.Flags().Int("mtu", 1500, "mtu")
2728
hostagentCommand.Flags().StringToString("leases", nil, "pass default static leases for startup. Eg: '192.168.104.1=52:55:55:b3:bc:d9,192.168.104.2=5a:94:ef:e4:0c:df' ")
@@ -54,6 +55,10 @@ func usernetAction(cmd *cobra.Command, _ []string) error {
5455
if err != nil {
5556
return err
5657
}
58+
socksSocket, err := cmd.Flags().GetString("listen-socks")
59+
if err != nil {
60+
return err
61+
}
5762
subnet, err := cmd.Flags().GetString("subnet")
5863
if err != nil {
5964
return err
@@ -72,6 +77,7 @@ func usernetAction(cmd *cobra.Command, _ []string) error {
7277
os.RemoveAll(endpoint)
7378
os.RemoveAll(qemuSocket)
7479
os.RemoveAll(fdSocket)
80+
os.RemoveAll(socksSocket)
7581

7682
// Environment Variables
7783
// LIMA_USERNET_RESOLVE_IP_ADDRESS_TIMEOUT: Specifies the timeout duration for resolving IP addresses in minutes. Default is 2 minutes.
@@ -81,6 +87,7 @@ func usernetAction(cmd *cobra.Command, _ []string) error {
8187
Endpoint: endpoint,
8288
QemuSocket: qemuSocket,
8389
FdSocket: fdSocket,
90+
SocksSocket: socksSocket,
8491
Subnet: subnet,
8592
DefaultLeases: leases,
8693
})

go.mod

+25
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ require (
5555
k8s.io/client-go v0.31.1
5656
)
5757

58+
require (
59+
github.com/beorn7/perks v1.0.1 // indirect
60+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
61+
github.com/cybozu-go/log v1.6.1 // indirect
62+
github.com/cybozu-go/netutil v1.4.2 // indirect
63+
github.com/cybozu-go/usocksd v1.3.0 // indirect
64+
github.com/cybozu-go/well v1.11.0 // indirect
65+
github.com/hashicorp/hcl v1.0.0 // indirect
66+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
67+
github.com/onsi/gomega v1.34.1 // indirect
68+
github.com/pelletier/go-toml v1.9.5 // indirect
69+
github.com/prometheus/client_golang v1.14.0 // indirect
70+
github.com/prometheus/client_model v0.3.0 // indirect
71+
github.com/prometheus/common v0.37.0 // indirect
72+
github.com/prometheus/procfs v0.8.0 // indirect
73+
github.com/spf13/afero v1.8.2 // indirect
74+
github.com/spf13/cast v1.5.0 // indirect
75+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
76+
github.com/spf13/viper v1.12.0 // indirect
77+
github.com/subosito/gotenv v1.4.0 // indirect
78+
github.com/vishvananda/netlink v1.3.0 // indirect
79+
github.com/vishvananda/netns v0.0.4 // indirect
80+
gopkg.in/ini.v1 v1.66.6 // indirect
81+
)
82+
5883
require (
5984
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
6085
github.com/VividCortex/ewma v1.2.0 // indirect

0 commit comments

Comments
 (0)