mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
6147da58dd
Continues to address https://github.com/coder/coder-desktop-macos/issues/201 Identical to the windows command, except we don't write to stdio. We're retaining the system we have for logging on macOS, where we push logs over the tunnel and use the OS logger. I've tested that a build with this command works end-to-end with my new version of Coder Desktop macOS. Also brings in the soft net isolation changes from `main` of coder/tailscale.
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
//go:build darwin
|
|
|
|
package cli
|
|
|
|
import (
|
|
"golang.org/x/xerrors"
|
|
|
|
"cdr.dev/slog"
|
|
"github.com/coder/coder/v2/vpn"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
func (r *RootCmd) vpnDaemonRun() *serpent.Command {
|
|
var (
|
|
rpcReadFD int64
|
|
rpcWriteFD int64
|
|
)
|
|
|
|
cmd := &serpent.Command{
|
|
Use: "run",
|
|
Short: "Run the VPN daemon on macOS.",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(0),
|
|
),
|
|
Options: serpent.OptionSet{
|
|
{
|
|
Flag: "rpc-read-fd",
|
|
Env: "CODER_VPN_DAEMON_RPC_READ_FD",
|
|
Description: "The file descriptor for the pipe to read from the RPC connection.",
|
|
Value: serpent.Int64Of(&rpcReadFD),
|
|
Required: true,
|
|
},
|
|
{
|
|
Flag: "rpc-write-fd",
|
|
Env: "CODER_VPN_DAEMON_RPC_WRITE_FD",
|
|
Description: "The file descriptor for the pipe to write to the RPC connection.",
|
|
Value: serpent.Int64Of(&rpcWriteFD),
|
|
Required: true,
|
|
},
|
|
},
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
ctx := inv.Context()
|
|
|
|
if rpcReadFD < 0 || rpcWriteFD < 0 {
|
|
return xerrors.Errorf("rpc-read-fd (%v) and rpc-write-fd (%v) must be positive", rpcReadFD, rpcWriteFD)
|
|
}
|
|
if rpcReadFD == rpcWriteFD {
|
|
return xerrors.Errorf("rpc-read-fd (%v) and rpc-write-fd (%v) must be different", rpcReadFD, rpcWriteFD)
|
|
}
|
|
|
|
pipe, err := vpn.NewBidirectionalPipe(uintptr(rpcReadFD), uintptr(rpcWriteFD))
|
|
if err != nil {
|
|
return xerrors.Errorf("create bidirectional RPC pipe: %w", err)
|
|
}
|
|
defer pipe.Close()
|
|
|
|
tunnel, err := vpn.NewTunnel(ctx, slog.Make().Leveled(slog.LevelDebug), pipe,
|
|
vpn.NewClient(),
|
|
vpn.UseOSNetworkingStack(),
|
|
vpn.UseAsLogger(),
|
|
)
|
|
if err != nil {
|
|
return xerrors.Errorf("create new tunnel for client: %w", err)
|
|
}
|
|
defer tunnel.Close()
|
|
|
|
<-ctx.Done()
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|