Skip to content

Commit 03a0cd2

Browse files
committed
chore: add vpn-daemon run command for macos
1 parent 415273f commit 03a0cd2

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

cli/vpndaemon_darwin.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//go:build darwin
2+
3+
package cli
4+
5+
import (
6+
"cdr.dev/slog"
7+
"github.com/coder/coder/v2/vpn"
8+
"github.com/coder/serpent"
9+
"golang.org/x/xerrors"
10+
)
11+
12+
func (r *RootCmd) vpnDaemonRun() *serpent.Command {
13+
var (
14+
rpcReadFD int64
15+
rpcWriteFD int64
16+
)
17+
18+
cmd := &serpent.Command{
19+
Use: "run",
20+
Short: "Run the VPN daemon on macOS.",
21+
Middleware: serpent.Chain(
22+
serpent.RequireNArgs(0),
23+
),
24+
Options: serpent.OptionSet{
25+
{
26+
Flag: "rpc-read-fd",
27+
Env: "CODER_VPN_DAEMON_RPC_READ_FD",
28+
Description: "The file descriptor for the pipe to read from the RPC connection.",
29+
Value: serpent.Int64Of(&rpcReadFD),
30+
Required: true,
31+
},
32+
{
33+
Flag: "rpc-write-fd",
34+
Env: "CODER_VPN_DAEMON_RPC_WRITE_FD",
35+
Description: "The file descriptor for the pipe to write to the RPC connection.",
36+
Value: serpent.Int64Of(&rpcWriteFD),
37+
Required: true,
38+
},
39+
},
40+
Handler: func(inv *serpent.Invocation) error {
41+
ctx := inv.Context()
42+
43+
if rpcReadFD < 0 || rpcWriteFD < 0 {
44+
return xerrors.Errorf("rpc-read-fd (%v) and rpc-write-fd (%v) must be positive", rpcReadFD, rpcWriteFD)
45+
}
46+
if rpcReadFD == rpcWriteFD {
47+
return xerrors.Errorf("rpc-read-fd (%v) and rpc-write-fd (%v) must be different", rpcReadFD, rpcWriteFD)
48+
}
49+
50+
pipe, err := vpn.NewBidirectionalPipe(uintptr(rpcReadFD), uintptr(rpcWriteFD))
51+
if err != nil {
52+
return xerrors.Errorf("create bidirectional RPC pipe: %w", err)
53+
}
54+
defer pipe.Close()
55+
56+
tunnel, err := vpn.NewTunnel(ctx, slog.Make().Leveled(slog.LevelDebug), pipe,
57+
vpn.NewClient(),
58+
vpn.UseOSNetworkingStack(),
59+
vpn.UseAsLogger(),
60+
)
61+
if err != nil {
62+
return xerrors.Errorf("create new tunnel for client: %w", err)
63+
}
64+
defer tunnel.Close()
65+
66+
<-ctx.Done()
67+
return nil
68+
},
69+
}
70+
71+
return cmd
72+
}

cli/vpndaemon_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !windows
1+
//go:build !windows && !darwin
22

33
package cli
44

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ replace github.com/tcnksm/go-httpstat => github.com/coder/go-httpstat v0.0.0-202
3636

3737
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
3838
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
39-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20250724015444-494197765996
39+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20250729141742-067f1e5d9716
4040

4141
// This is replaced to include
4242
// 1. a fix for a data race: c.f. https://github.com/tailscale/wireguard-go/pull/25

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,8 @@ github.com/coder/serpent v0.10.0 h1:ofVk9FJXSek+SmL3yVE3GoArP83M+1tX+H7S4t8BSuM=
926926
github.com/coder/serpent v0.10.0/go.mod h1:cZFW6/fP+kE9nd/oRkEHJpG6sXCtQ+AX7WMMEHv0Y3Q=
927927
github.com/coder/ssh v0.0.0-20231128192721-70855dedb788 h1:YoUSJ19E8AtuUFVYBpXuOD6a/zVP3rcxezNsoDseTUw=
928928
github.com/coder/ssh v0.0.0-20231128192721-70855dedb788/go.mod h1:aGQbuCLyhRLMzZF067xc84Lh7JDs1FKwCmF1Crl9dxQ=
929-
github.com/coder/tailscale v1.1.1-0.20250724015444-494197765996 h1:9x+ouDw9BKW1tdGzuQOWGMT2XkWLs+QQjeCrxYuU1lo=
930-
github.com/coder/tailscale v1.1.1-0.20250724015444-494197765996/go.mod h1:l7ml5uu7lFh5hY28lGYM4b/oFSmuPHYX6uk4RAu23Lc=
929+
github.com/coder/tailscale v1.1.1-0.20250729141742-067f1e5d9716 h1:hi7o0sA+RPBq8Rvvz+hNrC/OTL2897OKREMIRIuQeTs=
930+
github.com/coder/tailscale v1.1.1-0.20250729141742-067f1e5d9716/go.mod h1:l7ml5uu7lFh5hY28lGYM4b/oFSmuPHYX6uk4RAu23Lc=
931931
github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e h1:JNLPDi2P73laR1oAclY6jWzAbucf70ASAvf5mh2cME0=
932932
github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI=
933933
github.com/coder/terraform-provider-coder/v2 v2.9.0 h1:nd9d1/qHTdx5foBLZoy0SWCc0W13GQUbPTzeGsuLlU0=

0 commit comments

Comments
 (0)