Skip to content

Commit 33e18b1

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

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

cli/vpndaemon_darwin.go

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

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)