Documentation
¶
Overview ¶
Package server implements portholed: it accepts client sessions over WebSocket+yamux (docs/protocol.md), keeps the registry of tunnels and routes public HTTP and TCP traffic into them (DESIGN.md §3.5).
Every client session owns a context. Closing a session releases its tunnels, closes its listeners, streams and transports and waits for every goroutine it started. Server.Close does the same for all sessions.
Index ¶
- Constants
- Variables
- func HostKeyFingerprint(dir string) (string, error)
- func LoadHostKey(dir string) (ssh.Signer, error)
- type Options
- type Server
- func (s *Server) Close() error
- func (s *Server) Handler() http.Handler
- func (s *Server) ReloadTLS() error
- func (s *Server) ReplayRequest(ctx context.Context, id uint64) (traffic.Request, error)
- func (s *Server) Run(ctx context.Context) error
- func (s *Server) Serve(ctx context.Context, ln net.Listener) error
- func (s *Server) StartAdminSocket(ln net.Listener) error
- func (s *Server) StartMetricsListener(ln net.Listener) error
- func (s *Server) StartSSHGateway(ln net.Listener) error
- func (s *Server) Traffic() *traffic.Log
Constants ¶
const (
// HostKeyFile is the name of the gateway host key inside the data directory.
HostKeyFile = "ssh_host_ed25519_key"
)
Variables ¶
var ( // ErrRequestNotFound means the request is not (or no longer) in the journal. ErrRequestNotFound = errors.New("server: request not found in the traffic log") // ErrReplayRefused means the request exists but cannot be replayed; the wrapped text says why. ErrReplayRefused = errors.New("server: request cannot be replayed") )
Errors of ReplayRequest.
Functions ¶
func HostKeyFingerprint ¶
HostKeyFingerprint returns the SHA256 fingerprint of the existing gateway host key in dir.
Types ¶
type Options ¶
type Options struct {
Config *config.Config
Store store.Store
Logger *slog.Logger
Version string
// Now returns the current time; nil means time.Now. Tests use it to move token expiry.
Now func() time.Time
// HeartbeatInterval is the ping period (default proto.DefaultHBMilli ms).
HeartbeatInterval time.Duration
// RevalidateInterval is how often tokens of live sessions are re-read from the store (default 30 s).
RevalidateInterval time.Duration
// HandshakeTimeout bounds session establishment (default 10 s).
HandshakeTimeout time.Duration
// RemoteOpenTimeout bounds the wait for a client's answer to a remote tunnel request (default 15 s).
RemoteOpenTimeout time.Duration
// SSHIdleTimeout closes SSH gateway connections without open channels after this long (default 60 s).
SSHIdleTimeout time.Duration
// Metrics receives the Prometheus instrumentation. Nil turns it off, unless cfg.MetricsListen is set: then
// the server creates its own.
Metrics *metrics.Metrics
}
Options configures a Server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the portholed core. Create it with New and always release it with Close (Run and Serve do so).
func (*Server) Close ¶
Close ends every session (clients receive a shutting_down error), closes all TCP listeners and transports and waits for all goroutines started by the server. It is safe to call more than once.
func (*Server) Handler ¶
Handler returns the HTTP handler for the public listener: the control endpoint, /healthz and the virtual hosts of HTTP tunnels.
func (*Server) ReloadTLS ¶
ReloadTLS re-reads the TLS certificate and key files immediately instead of waiting for the periodic modification-time check; portholed calls it on SIGHUP. A failed reload keeps the previous certificate. The outcome is logged here; the error is returned for callers that want to react to it. It fails when TLS is not configured or Serve has not loaded the certificate yet.
func (*Server) ReplayRequest ¶
ReplayRequest sends the request with the given journal id again through the handler of its tunnel (not over the network) and returns the new journal entry, whose ReplayOf is id. The request must have been inspected with its detail still kept and its body must not be truncated. Headers that were stored as REDACTED (Authorization, Cookie, ...) are not sent, so a replay of an authenticated request reaches the service without credentials.
func (*Server) Run ¶
Run listens on cfg.Listen (TLS when configured) and serves until ctx is done, then shuts down gracefully within cfg.ShutdownGrace and closes every session and TCP listener.
func (*Server) StartAdminSocket ¶
StartAdminSocket serves the admin API on ln in the background until the server closes. It takes ownership of ln, which must be reachable only by trusted local users: every caller on it is a full administrator.
func (*Server) StartMetricsListener ¶
StartMetricsListener serves /metrics and /debug/pprof/ on ln in the background until the server closes. It takes ownership of ln. The endpoints are unauthenticated, so a listener that is not on a loopback address is logged as a warning (it is the operator's call, for example behind a firewall or a private network).
func (*Server) StartSSHGateway ¶
StartSSHGateway serves the SSH gateway on ln in the background until the server closes. It takes ownership of ln and returns once the host key is loaded.