diff --git a/coordinator.go b/coordinator.go index 32a5eaa..c62cee2 100644 --- a/coordinator.go +++ b/coordinator.go @@ -9,22 +9,52 @@ import ( "tailscale.com/types/key" ) +// TailscaleCoordinator is the interface that wraps the tailscale coordinator +// methods. type TailscaleCoordinator interface { + // ControlKey returns the control key for coordinator. ControlKey() key.MachinePrivate + // LegacyControlKey returns the legacy control key for coordinator. LegacyControlKey() key.MachinePrivate + // RegisterMachine is responsible for registering the machine with the + // coordinator. It returns the registration response from the coordinator + // and an error if any. RegisterMachine(req tailcfg.RegisterRequest, peerPublicKey key.MachinePublic) (tailcfg.RegisterResponse, error) + // DerpMap returns the DERP map from the coordinator. DerpMap() (tailcfg.DERPMap, error) + // KeepAliveInterval is the keep alive interval of the coordinator. KeepAliveInterval() time.Duration + // PollNetMap handles the netmap polling request from a tailscale client. It + // returns a channel of netmap responses and a channel of errors. + // + // - If the request is a streaming one, the channels are not to be closed + // and new responses will be sent on the channels. + // + // - If the request is a non-streaming one, the channels are to be closed + // after the first response is sent. + // + // - If the request gets closed or cancelled by the tailscale client, the + // context will be cancelled and the channels shall not be used anymore. PollNetMap(ctx context.Context, req tailcfg.MapRequest, peerPublicKey key.MachinePublic) (chan tailcfg.MapResponse, chan error) + // SetDNS handles the DNS setting request from a tailscale client. SetDNS(req tailcfg.SetDNSRequest, peerPublicKey key.MachinePublic) (tailcfg.SetDNSResponse, error) + // HealthChange handles the health change request from a tailscale client. HealthChange(req tailcfg.HealthChangeRequest) + // IDToken handles the ID token request from a tailscale client. IDToken(req tailcfg.TokenRequest, peerPublicKey key.MachinePublic) (tailcfg.TokenResponse, error) + // SSHAction handles the SSH action request from a tailscale client. + // + // It returns the SSH action response and an error if any. Additionally, the + // entire request is provided to the implementation as the request may + // contain additional information that is not known to the library. + // + // This method handles all noise requests to the `/ssh/action/*` pattern. SSHAction(r *http.Request, peerPublicKey key.MachinePublic) (tailcfg.SSHAction, error) } diff --git a/handlers/mux.go b/handlers/mux.go index 1014ab7..b31a0ec 100644 --- a/handlers/mux.go +++ b/handlers/mux.go @@ -7,6 +7,8 @@ import ( "github.com/loft-sh/tunnel" ) +// CoordinatorHandler returns a http.Handler that handles all requests to the +// coordinator, including the noise requests. func CoordinatorHandler(coordinator tunnel.TailscaleCoordinator) http.Handler { mux := chi.NewMux()