proxy

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package proxy manages background connections, tunnels, and active sessions for applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEvent

type AuditEvent struct {
	Event     string    `json:"event"`
	App       string    `json:"app"`
	Target    string    `json:"target"`
	Upstream  string    `json:"upstream"`
	LocalAddr string    `json:"local_addr"`
	Time      time.Time `json:"time"`
	Error     string    `json:"error,omitempty"`
}

AuditEvent represents a proxy lifecycle event.

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer abstracts how we dial to an upstream service.

type DirectDialer

type DirectDialer struct{}

DirectDialer connects directly over the local network.

func (DirectDialer) DialContext

func (d DirectDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext implements Dialer.

type Logger

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

Logger helps record proxy audit events safely.

func NewLogger

func NewLogger(z *zap.Logger) *Logger

NewLogger creates a new audit logger to record proxy events.

func (*Logger) Expired

func (l *Logger) Expired(s *Session)

Expired emits an event when a proxy session reaches its TTL.

func (*Logger) Failed

func (l *Logger) Failed(s *Session, err error)

Failed emits an event when a proxy session encounters an error.

func (*Logger) Started

func (l *Logger) Started(s *Session)

Started emits an event when a proxy session starts.

func (*Logger) Stopped

func (l *Logger) Stopped(s *Session)

Stopped emits an event when a proxy session is gracefully stopped.

type Manager

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

Manager coordinates all active proxy sessions, saving state to disk and handling TTLs.

func NewManager

func NewManager(audit *Logger) *Manager

NewManager returns a new initialized proxy manager.

func (*Manager) GetLocalSession

func (m *Manager) GetLocalSession(id string) *Session

GetLocalSession returns an active session created by this process. This allows access to the session's internal state (like the HTTP Handler) which is not serialized to the JSON state file.

func (*Manager) GetLocalSessionByApp

func (m *Manager) GetLocalSessionByApp(appName string) *Session

GetLocalSessionByApp returns an active session created by this process for the given app name.

func (*Manager) List

func (m *Manager) List() ([]Session, error)

List returns all active proxy sessions.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, app apps.AppConfig, dialer Dialer, closer io.Closer) (*Session, error)

Start starts a proxy session and records it.

func (*Manager) Stop

func (m *Manager) Stop(id string) error

Stop stops a session by ID. If the session is owned by another process, it sends SIGTERM.

type SSHDialer

type SSHDialer struct {
	Client *sshclient.HoneyClient
}

SSHDialer connects to the upstream by tunneling through an SSH connection.

func (SSHDialer) DialContext

func (d SSHDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext implements Dialer.

type Session

type Session struct {
	ID        string         `json:"id"`
	App       apps.AppConfig `json:"app"`
	LocalAddr string         `json:"local_addr"` // Only set if a local port is bound
	StartedAt time.Time      `json:"started_at"`
	ExpiresAt time.Time      `json:"expires_at"`
	PID       int            `json:"pid"`

	// Handler is used for HTTP apps that should be routed by the main webserver.
	// It is nil for TCP apps or when not running inside the webserver process.
	Handler http.Handler `json:"-"`

	// Stop handles tearing down the local listener and connections.
	Stop context.CancelFunc `json:"-"`
}

Session represents an active application proxy session.

func StartHTTPProxy

func StartHTTPProxy(ctx context.Context, app apps.AppConfig, dialer Dialer, sessionID string, closer io.Closer) (*Session, error)

StartHTTPProxy constructs an HTTP reverse proxy and optionally binds it to 127.0.0.1. If app.LocalPort is 0, it skips binding the listener (used by the webserver dynamic proxy).

func StartTCPProxy

func StartTCPProxy(ctx context.Context, app apps.AppConfig, dialer Dialer, sessionID string, closer io.Closer) (*Session, error)

StartTCPProxy starts a raw TCP proxy bound to 127.0.0.1.

type StateManager

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

StateManager persists session data to a JSON file so multiple CLI processes and the Web UI can discover and cleanly terminate running proxies.

func NewStateManager

func NewStateManager() *StateManager

NewStateManager returns a StateManager configured for the local environment.

func (*StateManager) Add

func (m *StateManager) Add(s Session) error

Add adds a new session to the state.

func (*StateManager) List

func (m *StateManager) List() ([]Session, error)

List returns all active proxy sessions, removing expired ones from state.

func (*StateManager) Remove

func (m *StateManager) Remove(id string) error

Remove removes a session from the state by ID.

type TunnelDialer

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

TunnelDialer uses a custom dial function to natively dial upstream connections in memory without opening an OS-level listener port.

func NewTunnelDialer

func NewTunnelDialer(dialFn func(ctx context.Context, network, address string) (net.Conn, error)) *TunnelDialer

NewTunnelDialer creates a new generic TunnelDialer.

func (*TunnelDialer) DialContext

func (d *TunnelDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects directly to the background tunnel using the provided dial function.

Directories

Path Synopsis
Package reverseproxy provides a Teleport-inspired HTTP reverse proxy.
Package reverseproxy provides a Teleport-inspired HTTP reverse proxy.

Jump to

Keyboard shortcuts

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