Skip to content

Commit

Permalink
[POC, DNM] Expose socks proxy (per user-v2 net, not per instance)
Browse files Browse the repository at this point in the history
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 <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Oct 22, 2024
1 parent 1c98589 commit b402bdb
Show file tree
Hide file tree
Showing 6 changed files with 871 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cmd/limactl/usernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func newUsernetCommand() *cobra.Command {
hostagentCommand.Flags().StringP("endpoint", "e", "", "exposes usernet api(s) on this endpoint")
hostagentCommand.Flags().String("listen-qemu", "", "listen for qemu connections")
hostagentCommand.Flags().String("listen", "", "listen on a Unix socket and receive Bess-compatible FDs as SCM_RIGHTS messages")
hostagentCommand.Flags().String("listen-socks", "", "listen for socks connectioss")
hostagentCommand.Flags().String("subnet", "192.168.5.0/24", "sets subnet value for the usernet network")
hostagentCommand.Flags().Int("mtu", 1500, "mtu")
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' ")
Expand Down Expand Up @@ -54,6 +55,10 @@ func usernetAction(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
socksSocket, err := cmd.Flags().GetString("listen-socks")
if err != nil {
return err
}
subnet, err := cmd.Flags().GetString("subnet")
if err != nil {
return err
Expand All @@ -72,6 +77,7 @@ func usernetAction(cmd *cobra.Command, _ []string) error {
os.RemoveAll(endpoint)
os.RemoveAll(qemuSocket)
os.RemoveAll(fdSocket)
os.RemoveAll(socksSocket)

// Environment Variables
// LIMA_USERNET_RESOLVE_IP_ADDRESS_TIMEOUT: Specifies the timeout duration for resolving IP addresses in minutes. Default is 2 minutes.
Expand All @@ -81,6 +87,7 @@ func usernetAction(cmd *cobra.Command, _ []string) error {
Endpoint: endpoint,
QemuSocket: qemuSocket,
FdSocket: fdSocket,
SocksSocket: socksSocket,
Subnet: subnet,
DefaultLeases: leases,
})
Expand Down
25 changes: 25 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ require (
k8s.io/client-go v0.31.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cybozu-go/log v1.6.1 // indirect
github.com/cybozu-go/netutil v1.4.2 // indirect
github.com/cybozu-go/usocksd v1.3.0 // indirect
github.com/cybozu-go/well v1.11.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/onsi/gomega v1.34.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/vishvananda/netlink v1.3.0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
)

require (
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
Expand Down
Loading

0 comments on commit b402bdb

Please sign in to comment.