mulery

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 20 Imported by: 0

README

Mulery

The idea behind what's being built here is a server that can handle thousands of simultaneous client connections. The server is essentially a command and control center for the clients. A simple server is provided, as a library and a binary. The server is only useful with the client library that is not provided as a binary. You need to instrument your own logic. The primary use case is to proxy http requests back into the http server running on the client.

You run the server. Then you run 5000 clients that make a persistent connect to the server and register themselves with a configurable id. You can now send http requests to the server with a special header that contains the client's registered ID. The server proxies the web request back into the client through the previously-established persistent connection.

We use this so our clients do not have to open a port (port forward) for our server to communicate with the software they deployed on premesis. It allows our servers to distribute load and reliably reach back into the running end-user application.

How

Websockets and some reverse-proxy engineering.

Documentation

Overview

Package mulery provides an application wrapper around the mulery/server module. This is full of assumptions, but very configurable. Use it as-is, or use it as an example for your own server package.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("provided key is not authorized")

Functions

This section is empty.

Types

type AllowedIPs

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

AllowedIPs determines who make can requests.

func MakeIPs

func MakeIPs(upstreams []string) *AllowedIPs

MakeIPs turns a list of CIDR strings, IPs or dns hostnames into a list of net.IPNet. This "allowed" list is later used to check incoming IPs from web requests. Starts a go routine that does periodic dns lookups for hostnames in the upstreams list.

func (*AllowedIPs) Contains

func (n *AllowedIPs) Contains(ip string) bool

Contains returns true if an IP is allowed.

func (*AllowedIPs) Start added in v0.0.4

func (n *AllowedIPs) Start()

func (*AllowedIPs) Stop added in v0.0.4

func (n *AllowedIPs) Stop()

Stop the running allow IP routine.

func (*AllowedIPs) String

func (n *AllowedIPs) String() string

String turns a list of allowedIPs into a printable masterpiece.

type Config

type Config struct {
	ListenAddr string `json:"listenAddr" toml:"listen_addr" yaml:"listenAddr" xml:"listen_addr"`
	AuthURL    string `json:"authUrl" toml:"auth_url" yaml:"authUrl" xml:"auth_url"`
	AuthHeader string `json:"authHeader" toml:"auth_header" yaml:"authHeader" xml:"auth_header"`
	// Providing a header=>name map here will put these request headers into the apache log output.
	LogHeaders map[string]string `json:"logHeaders" toml:"log_headers" yaml:"logHeaders" xml:"log_headers"`
	// List of IPs or CIDRs that are allowed to make requests to clients.
	Upstreams []string `json:"upstreams" toml:"upstreams" yaml:"upstreams" xml:"upstreams"`
	// Optional directory where SSL certificates are stored.
	CacheDir string `json:"cacheDir" toml:"cache_dir" yaml:"cacheDir" xml:"cache_dir"`
	// CFToken is used to create DNS entries to validate SSL certs for acme.
	CFToken string `json:"cfToken" toml:"cf_token"  yaml:"cfToken" xml:"cf_token"`
	// Email is used for acme certificate registration.
	Email string `json:"email" toml:"email" yaml:"email" xml:"email"`
	// DNS Names that we are allowed to create SSL certificates for.
	SSLNames StringSlice `json:"sslNames" toml:"ssl_names" yaml:"sslNames" xml:"ssl_names"`
	// Path to app log file.
	LogFile string `json:"logFile" toml:"log_file" yaml:"logFile" xml:"log_file"`
	// Number of log files to keep when rotating.
	LogFiles int `json:"logFiles" toml:"log_files" yaml:"logFiles" xml:"log_files"`
	// Rotate the log file when it reaches this many megabytes.
	LogFileMB int64 `json:"logFileMb" toml:"log_file_mb" yaml:"logFileMb" xml:"log_file_mb"`
	// Path for http log.
	HTTPLog string `json:"httpLog" toml:"http_log" yaml:"httpLog" xml:"http_log"`
	// Number of http log files to keep when rotating.
	HTTPLogs int `json:"httpLogs" toml:"http_logs" yaml:"httpLogs" xml:"http_logs"`
	// Rotate the http log file when it reaches this many megabytes.
	HTTPLogMB int64 `json:"httpLogMb" toml:"http_log_mb" yaml:"httpLogMb" xml:"http_log_mb"`
	// RedirectURL is where to send a request to any unknown path. Unauthorized is returned otherwise.
	RedirectURL string `json:"redirectUrl" toml:"redirect_url" yaml:"redirectUrl" xml:"redirect_url"`
	*server.Config
	// contains filtered or unexported fields
}

Config is the input data to run this app. Read from a config file.

func LoadConfigFile

func LoadConfigFile(path string) (*Config, error)

LoadConfigFile does what its name implies.

func (*Config) ApacheLogFormat

func (c *Config) ApacheLogFormat() string

func (*Config) Debugf

func (c *Config) Debugf(msg string, v ...interface{})

Debugf writes log lines... to stdout and/or a file.

func (*Config) Errorf

func (c *Config) Errorf(msg string, v ...interface{})

Errorf writes log lines... to stdout and/or a file.

func (*Config) HandleAll

func (c *Config) HandleAll(resp http.ResponseWriter, _ *http.Request)

func (*Config) HandleOK added in v0.0.4

func (c *Config) HandleOK(resp http.ResponseWriter, _ *http.Request)

func (*Config) KeyValidator

func (c *Config) KeyValidator(ctx context.Context, header http.Header) (string, error)

KeyValidator validates client secret keys against an nginx auth proxy. The actual auth proxy is: http://github.com/Notifiarr/mysql-auth-proxy

func (*Config) PrintConfig

func (c *Config) PrintConfig()

PrintConfig logs the current configuration information.

func (*Config) Printf

func (c *Config) Printf(msg string, v ...interface{})

Printf writes log lines... to stdout and/or a file.

func (*Config) SetupLogs

func (c *Config) SetupLogs()

SetupLogs starts the logs rotation and sets logger output to the configured file(s). You must call this before calling Start to setup logs, or things will panic.

func (*Config) Shutdown

func (c *Config) Shutdown()

func (*Config) Start

func (c *Config) Start()

Start HTTP server.

func (*Config) ValidateUpstream

func (c *Config) ValidateUpstream(next http.Handler) http.Handler

type StringSlice

type StringSlice []string

func (StringSlice) Contains

func (s StringSlice) Contains(str string) bool

Directories

Path Synopsis
cmd
Package mulch provides shared methods, structures and variables used by mulery client library, server library and server application.
Package mulch provides shared methods, structures and variables used by mulery client library, server library and server application.

Jump to

Keyboard shortcuts

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