proxy

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package proxy contains a collection of proxy handlers for the worker to call once a connection has been authorized. Each proxy handler should mark the connection as connected once the proxy has successfully been established.

Index

Constants

View Source
const (
	WebsocketStatusProtocolSetupError websocket.StatusCode = 3000
)

Variables

View Source
var (
	TcpHandlerName = "tcp"

	// ErrUnknownProtocol specifies the provided protocol has no registered handler
	ErrUnknownProtocol = errors.New("proxy: handler not found for protocol")

	// ErrProtocolAlreadyRegistered specifies the provided protocol has already been registered
	ErrProtocolAlreadyRegistered = errors.New("proxy: protocol already registered")

	// GetHandler returns the handler registered for the provided worker and
	// protocolContext. If a protocol cannot be determined or the protocol is
	// not registered nil, ErrUnknownProtocol is returned.
	GetHandler = tcpOnly
)
View Source
var GetEndpointDialer = directDialer

GetEndpointDialer returns a ProxyDialer which, when Dial() is called returns a net.Conn which reaches the provided endpoint.

View Source
var ProxyState proxyState

ProxyState contains the current state of proxies in this process.

Functions

func ProxyHandlerCounter added in v0.12.0

func ProxyHandlerCounter(h http.Handler) http.Handler

HttpHandlerCounter records how many requests are currently running in the wrapped Handler. This should be used for handlers that serve proxied traffic.

func RegisterHandler

func RegisterHandler(protocol string, handler Handler) error

func TestWsConn

func TestWsConn(t testing.TB, ctx context.Context) (clientConn, proxyConn *websocket.Conn)

TestWsConn creates a websocket client and handler simulating the local websocket proxy created during Boundary connect. The proxyConn returned should be used as the connection passed into the worker proxy handler, while the clientConn can be used to simulate the local end user connection.

Types

type DecryptFn added in v0.12.0

type DecryptFn func(ctx context.Context, from []byte, to proto.Message) error

DecryptFn decrypts the provided bytes into a proto.Message

type Handler

type Handler func(controlCtx context.Context, dataCtx context.Context, df DecryptFn, c net.Conn, pd *ProxyDialer, connId string, pb *anypb.Any, rm RecordingManager) (ProxyConnFn, error)

Handler is the type that all proxies need to implement to be called by the worker when a new client connection is created. If there is an error ProxyConnFn must be nil. If there is no error ProxyConnFn must be set. When Handler has returned, it is expected that the initial connection to the endpoint has been established.

type Option

type Option func(*Options)

Option - how Options are passed as arguments.

func WithInjectedApplicationCredentials added in v0.10.0

func WithInjectedApplicationCredentials(creds []*serverpb.Credential) Option

WithInjectedApplicationCredentials provides an optional injected application credentials to use when establishing a proxy

func WithPostConnectionHook added in v0.12.0

func WithPostConnectionHook(fn func(net.Conn)) Option

WithPostConnectionHook provides a hook function to be called after a connection is established in a dialFunction. When a dialer accepts WithPostConnectionHook the passed in function should be called prior to any other blocking call.

type Options

type Options struct {
	WithInjectedApplicationCredentials []*serverpb.Credential
	WithPostConnectionHook             func(net.Conn)
}

Options = how options are represented

func GetOpts

func GetOpts(opt ...Option) Options

GetOpts - iterate the inbound Options and return a struct.

type ProxyConnFn added in v0.12.0

type ProxyConnFn func()

ProxyConnFn is called after the call to ConnectConnection on the cluster. ProxyConnFn blocks until the specific request that is being proxied is finished

type ProxyDialer added in v0.12.0

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

ProxyDialer dials downstream to eventually get to the target host.

func NewProxyDialer added in v0.12.0

func NewProxyDialer(ctx context.Context, df func(...Option) (net.Conn, error)) (*ProxyDialer, error)

Returns a new proxy dialer using the provided function to get the net.Conn.

func (*ProxyDialer) Dial added in v0.12.0

func (d *ProxyDialer) Dial(ctx context.Context, opt ...Option) (net.Conn, error)

Dial uses the provided dial function to get a net.Conn and record its net.Addr information. The returned net.Addr should contain the information for the endpoint that is being proxied to. All provided options (for example WithPostConnectionHook) are passed into the dial function associated with this ProxyDialer.

func (*ProxyDialer) LastConnectionAddr added in v0.12.0

func (d *ProxyDialer) LastConnectionAddr() *proxyAddr

LastConnectionAddr returns the net.Addr of the last non nil net.Conn returned from the Dial() call. Nil is returned if a non nil net.Conn has never been returned from Dial().

type RecordingManager added in v0.13.0

type RecordingManager any

RecordingManager allows a handler for a protocol that supports recording.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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