tsnet_relay

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 19 Imported by: 0

README

DeepSource

Tailscale Relay

Work in progress. Expect breaking changes.

Easily create relays b/w services running on tailscale

Usage

Usage of ./tsnet-relay:
  -advertise-tags string
        Tags to use for the server
  -config string
        Path to the configuration file (default "config.json")
  -ephemeral
        Use an ephemeral hostname
  -hostname string
        Hostname to use for the server
  -idle-timeout int
        Exit after specified number of seconds with no incoming connections (0 to disable)
  -state string
        State store to use for the server (default "mem:")
  -verbose
        Enable verbose logging

Configuration

The configuration file is a JSON file with the following format:

{
  "tunnels": [
    {
      "enabled": true,
      "name": "expose-remote-locally",
      "source": "tcp://:3000",
      "destination": "tcp+tailnet://fake-server.fake-network.ts.net:2746"
    },
    {
      "enabled": true,
      "name": "expose-local-on-tsnet",
      "source": "tcp+tailnet://:3001",
      "destination": "tcp://127.0.0.1:3000"
    }
  ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveAuthKey

func ResolveAuthKey(ctx context.Context, v, tags string) (string, error)

ResolveAuthKey either returns v unchanged (in the common case) or, if it starts with "tskey-client-" (as Tailscale OAuth secrets do) parses it like

tskey-client-xxxx[?ephemeral=false&bar&preauthorized=BOOL&baseURL=...]

and does the OAuth2 dance to get and return an authkey. The "ephemeral" property defaults to true if unspecified. The "preauthorized" defaults to false. The "baseURL" defaults to https://api.tailscale.com. The passed in tags are required, and must be non-empty. These will be set on the authkey generated by the OAuth2 dance.

Types

type Config

type Config struct {
	Tunnels []Tunnel `json:"tunnels"`
}

Config represents the application configuration

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

LoadConfig reads and parses the configuration file

func ReloadConfig

func ReloadConfig(ctx context.Context, configPath string, srv *Server, oldConfig *Config) (*Config, error)

ReloadConfig reloads the configuration and updates the tunnels

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the tsnet server and its configuration

func NewServer

func NewServer(hostname string, ephemeral bool, stateStore ipn.StateStore, authKey string) *Server

NewServer creates a new Server instance

func (*Server) CloseTunnels

func (s *Server) CloseTunnels()

CloseTunnels closes all active tunnels

func (*Server) Dial

func (s *Server) Dial(ctx context.Context, network, address string) (net.Conn, error)

Dial creates a new connection to the specified address

func (*Server) Listen

func (s *Server) Listen(network, address string) (net.Listener, error)

Listen creates a new listener for the specified network and address

func (*Server) SetupTunnels

func (s *Server) SetupTunnels(ctx context.Context, tunnels []Tunnel) error

SetupTunnels initializes all enabled tunnels

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown gracefully shuts down the server

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start initializes and starts the tsnet server

func (*Server) StartIdleTimeoutChecker

func (s *Server) StartIdleTimeoutChecker(ctx context.Context, timeout time.Duration)

StartIdleTimeoutChecker starts a goroutine to check for idle timeout

func (*Server) StopTunnel

func (s *Server) StopTunnel(name string)

StopTunnel disables a single tunnel

type Tunnel

type Tunnel struct {
	Name        string `json:"name"`
	Enabled     bool   `json:"enabled"`
	Source      string `json:"source"`
	Primary     bool   `json:"primary"`
	Destination string `json:"destination"`
}

Tunnel represents a single tunnel configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL