server

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 44 Imported by: 1

Documentation

Overview

Package server provides a Charm Cloud server with HTTP and SSH protocols.

Index

Constants

This section is empty.

Variables

View Source
var MaxFSRequestSize int64 = 1024 * 1024 * 1024 // 1GB

MaxFSRequestSize is the maximum size of a request body for fs endpoints.

Functions

func CharmUserMiddleware

func CharmUserMiddleware(s *HTTPServer) func(http.Handler) http.Handler

CharmUserMiddleware looks up and authenticates a Charm user based on the provided JWT in the request.

func JWTMiddleware

func JWTMiddleware(pk crypto.PublicKey, iss string, aud []string) (func(http.Handler) http.Handler, error)

JWTMiddleware creates a new middleware function that will validate JWT tokens based on the supplied public key.

func PublicPrefixesMiddleware added in v0.10.0

func PublicPrefixesMiddleware(prefixes []string) func(http.Handler) http.Handler

PublicPrefixesMiddleware allows for the specification of non-authed URL prefixes. These won't be checked for JWT bearers or Charm user accounts.

func RequestLimitMiddleware

func RequestLimitMiddleware() func(http.Handler) http.Handler

RequestLimitMiddleware limits the request body size to the specified limit.

Types

type Config

type Config struct {
	BindAddr       string `env:"CHARM_SERVER_BIND_ADDRESS" envDefault:""`
	Host           string `env:"CHARM_SERVER_HOST" envDefault:"localhost"`
	SSHPort        int    `env:"CHARM_SERVER_SSH_PORT" envDefault:"35353"`
	HTTPPort       int    `env:"CHARM_SERVER_HTTP_PORT" envDefault:"35354"`
	StatsPort      int    `env:"CHARM_SERVER_STATS_PORT" envDefault:"35355"`
	HealthPort     int    `env:"CHARM_SERVER_HEALTH_PORT" envDefault:"35356"`
	DataDir        string `env:"CHARM_SERVER_DATA_DIR" envDefault:"data"`
	UseTLS         bool   `env:"CHARM_SERVER_USE_TLS" envDefault:"false"`
	TLSKeyFile     string `env:"CHARM_SERVER_TLS_KEY_FILE"`
	TLSCertFile    string `env:"CHARM_SERVER_TLS_CERT_FILE"`
	PublicURL      string `env:"CHARM_SERVER_PUBLIC_URL"`
	EnableMetrics  bool   `env:"CHARM_SERVER_ENABLE_METRICS" envDefault:"false"`
	UserMaxStorage int64  `env:"CHARM_SERVER_USER_MAX_STORAGE" envDefault:"0"`

	PublicKey  []byte
	PrivateKey []byte
	DB         db.DB
	FileStore  storage.FileStore
	Stats      stats.Stats
	// contains filtered or unexported fields
}

Config is the configuration for the Charm server.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with the values populated with the defaults or specified environment variables.

func (*Config) WithDB

func (cfg *Config) WithDB(db db.DB) *Config

WithDB returns a Config with the provided DB interface implementation.

func (*Config) WithErrorLogger added in v0.10.0

func (cfg *Config) WithErrorLogger(l *glog.Logger) *Config

WithErrorLogger returns a Config with the provided error log for the server.

func (*Config) WithFileStore

func (cfg *Config) WithFileStore(fs storage.FileStore) *Config

WithFileStore returns a Config with the provided FileStore implementation.

func (*Config) WithKeys

func (cfg *Config) WithKeys(publicKey []byte, privateKey []byte) *Config

WithKeys returns a Config with the provided public and private keys for the SSH server and JWT signing.

func (*Config) WithLinkQueue added in v0.10.0

func (cfg *Config) WithLinkQueue(q charm.LinkQueue) *Config

WithLinkQueue returns a Config with the provided LinkQueue implementation.

func (*Config) WithStats

func (cfg *Config) WithStats(s stats.Stats) *Config

WithStats returns a Config with the provided Stats implementation.

func (*Config) WithTLSConfig added in v0.10.0

func (cfg *Config) WithTLSConfig(c *tls.Config) *Config

WithTLSConfig returns a Config with the provided TLS configuration.

type HTTPServer

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

HTTPServer is the HTTP server for the Charm Cloud backend.

func NewHTTPServer

func NewHTTPServer(cfg *Config) (*HTTPServer, error)

NewHTTPServer returns a new *HTTPServer with the specified Config.

func (*HTTPServer) Shutdown added in v0.10.0

func (s *HTTPServer) Shutdown(ctx context.Context) error

Shutdown gracefully shut down the HTTP and health servers.

func (*HTTPServer) Start

func (s *HTTPServer) Start() error

Start start the HTTP and health servers on the ports specified in the Config.

type JSONWebKeyPair added in v0.10.0

type JSONWebKeyPair struct {
	PrivateKey *ed25519.PrivateKey
	JWK        jose.JSONWebKey
}

JSONWebKeyPair holds the ED25519 private key and JSON Web Key used in JWT operations.

func NewJSONWebKeyPair added in v0.10.0

func NewJSONWebKeyPair(pk *ed25519.PrivateKey) JSONWebKeyPair

NewJSONWebKeyPair creates a new JSONWebKeyPair from a given ED25519 private key.

type SSHLinker

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

SSHLinker implments proto.LinkTransport for the Charm SSH server.

func (*SSHLinker) Error

func (sl *SSHLinker) Error(l *charm.Link)

Error implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) LinkedDifferentUser

func (sl *SSHLinker) LinkedDifferentUser(l *charm.Link)

LinkedDifferentUser implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) LinkedSameUser

func (sl *SSHLinker) LinkedSameUser(l *charm.Link)

LinkedSameUser implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestDenied

func (sl *SSHLinker) RequestDenied(l *charm.Link)

RequestDenied implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestInvalidToken

func (sl *SSHLinker) RequestInvalidToken(l *charm.Link)

RequestInvalidToken implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestStart

func (sl *SSHLinker) RequestStart(l *charm.Link)

RequestStart implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestValidToken

func (sl *SSHLinker) RequestValidToken(l *charm.Link)

RequestValidToken implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) Requested

func (sl *SSHLinker) Requested(l *charm.Link) (bool, error)

Requested implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) Success

func (sl *SSHLinker) Success(l *charm.Link)

Success implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) TimedOut

func (sl *SSHLinker) TimedOut(l *charm.Link)

TimedOut implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) TokenCreated

func (sl *SSHLinker) TokenCreated(token charm.Token)

TokenCreated implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) TokenSent

func (sl *SSHLinker) TokenSent(_ *charm.Link)

TokenSent implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) User

func (sl *SSHLinker) User() *charm.User

User implements the proto.LinkTransport interface for the SSHLinker.

type SSHServer

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

SSHServer serves the SSH protocol and handles requests to authenticate and link Charm user accounts.

func NewSSHServer

func NewSSHServer(cfg *Config) (*SSHServer, error)

NewSSHServer creates a new SSHServer from the provided Config.

func (*SSHServer) LinkGen

func (me *SSHServer) LinkGen(lt charm.LinkTransport) error

LinkGen implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHServer) LinkRequest

func (me *SSHServer) LinkRequest(lt charm.LinkTransport, key string, token string, ip string) error

LinkRequest implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHServer) NewToken

func (me *SSHServer) NewToken() charm.Token

NewToken creates and returns a new Token.

func (*SSHServer) Shutdown added in v0.10.0

func (me *SSHServer) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the SSH server.

func (*SSHServer) Start

func (me *SSHServer) Start() error

Start serves the SSH protocol on the configured port.

type Server

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

Server contains the SSH and HTTP servers required to host the Charm Cloud.

func NewServer

func NewServer(cfg *Config) (*Server, error)

NewServer returns a *Server with the specified Config.

func (*Server) Close added in v0.11.0

func (srv *Server) Close() error

Close immediately closes all active net.Listeners for the HTTP, HTTP health and SSH servers.

func (*Server) Shutdown added in v0.10.0

func (srv *Server) Shutdown(ctx context.Context) error

Shutdown shuts down the HTTP, and SSH and health HTTP servers for the Charm Cloud.

func (*Server) Start

func (srv *Server) Start() error

Start starts the HTTP, SSH and health HTTP servers for the Charm Cloud.

type Session

type Session struct {
	ssh.Session
}

Session represents a Charm User's SSH session.

type SessionHandler

type SessionHandler func(s Session)

SessionHandler defines a function that handles a session for a given SSH command.

Directories

Path Synopsis
db
noop
Package noop provides a stats impl that does nothing.
Package noop provides a stats impl that does nothing.

Jump to

Keyboard shortcuts

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