tunnel

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const PeerConnectPath = "/tunnel/peer"

PeerConnectPath is the internal websocket endpoint used to connect Obot tunnel servers to one another.

Variables

This section is empty.

Functions

func ConnectURL

func ConnectURL(serverURL string) (string, error)

ConnectURL returns the tunnel websocket endpoint on an Obot instance.

func CredentialID

func CredentialID(credentialValue string) (string, error)

CredentialID returns the non-secret identifier used to narrow credential lookups before the full digest is verified.

func CredentialMatches

func CredentialMatches(credentialValue, token string) bool

CredentialMatches reports whether token matches a stored credential digest.

func CredentialPreview

func CredentialPreview(credentialValue string) (string, error)

CredentialPreview returns the 16-byte preview stored with a credential.

func Dial

func Dial(ctx context.Context, serverURL, token string) (*websocket.Conn, error)

Dial opens one authenticated websocket connection to an Obot instance.

func NewCredential

func NewCredential() (token, credentialValue string, err error)

NewCredential creates a 64-byte bearer token and the non-reversible value stored on an MCPTunnel.

func Run

func Run(ctx context.Context, serverURL, token string) error

Run keeps a tunnel connected until ctx is canceled. Failed handshakes and lost connections are retried with bounded exponential backoff.

func ValidateCatalogEntryTunnelReferences

func ValidateCatalogEntryTunnelReferences(ctx context.Context, client kclient.Client, manifest types.MCPServerCatalogEntryManifest) error

ValidateCatalogEntryTunnelReferences verifies every tunnel reference in a catalog manifest, including remote components embedded in a composite.

func ValidateReference

func ValidateReference(ctx context.Context, client kclient.Client, name, target string) error

ValidateReference checks that name identifies an MCPTunnel whose current AllowedURLs authorize target.

func ValidateServerTunnelReferences

func ValidateServerTunnelReferences(ctx context.Context, client kclient.Client, manifest types.MCPServerManifest) error

ValidateServerTunnelReferences verifies every tunnel reference in a runtime server manifest, including remote components embedded in a composite.

Types

type Authenticator

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

Authenticator authenticates the credential stored on the MCPTunnel that owns the supplied bearer token. It yields a non-user principal restricted by the API authorizer to opening a tunnel connection.

func NewTunnelAuthenticator

func NewTunnelAuthenticator(tunnels kclient.Reader) *Authenticator

NewTunnelAuthenticator creates a tunnel credential authenticator.

func (*Authenticator) AuthenticateRequest

func (a *Authenticator) AuthenticateRequest(req *http.Request) (*authenticator.Response, bool, error)

AuthenticateRequest implements authenticator.Request.

type Manager

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

Manager owns the tunnel sessions, the remotedialer peer mesh, and the HTTP bridge used by Obot's existing MCP HTTP client.

func NewManager

func NewManager(ctx context.Context, bridgeBaseURL string, tunnels kclient.Reader, peerConfig PeerConfig) (*Manager, error)

NewManager creates a tunnel manager whose bridge is served from bridgeBaseURL. The caller must register ServeBridge on the HTTP server mux. Supplying a peer config enables remotedialer peering; the controller layer feeds discovered EndpointSlice peers through ReconcilePeers. An omitted or empty config keeps single-replica mode.

func (*Manager) AuthenticateRequest

func (m *Manager) AuthenticateRequest(req *http.Request) (*authenticator.Response, bool, error)

AuthenticateRequest authenticates requests generated for the internal tunnel bridge and websocket connections made by another Obot replica.

func (*Manager) BridgeAuthorization

func (m *Manager) BridgeAuthorization() (name, value string)

BridgeAuthorization returns the internal header that must accompany bridge requests. ServeBridge removes this header before forwarding the request to the tunnel client.

func (*Manager) BridgeHost

func (m *Manager) BridgeHost() string

BridgeHost returns the gateway host:port that must be allowlisted by the safe MCP HTTP client.

func (*Manager) BridgeURL

func (m *Manager) BridgeURL(tunnelName, rawURL string) (string, error)

BridgeURL converts an ordinary HTTP(S) target and MCPTunnel name into an internal URL on the gateway bridge.

func (*Manager) Close

func (m *Manager) Close()

Close stops local tunnel sessions and all outgoing peer reconnect loops.

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll closes only the tunnel clients accepted by this replica. It must not disconnect sessions owned by healthy peers during a rolling shutdown.

func (*Manager) Connections

func (m *Manager) Connections() []apitypes.TunnelConnection

Connections preserves the process-local snapshot returned by earlier versions of Manager. Use ConnectionsContext for an installation-wide view.

func (*Manager) ConnectionsContext

func (m *Manager) ConnectionsContext(ctx context.Context) ([]apitypes.TunnelConnection, error)

ConnectionsContext returns a deterministic installation-wide snapshot of the configured tunnels that currently have a local or peer-advertised session. A connection may disappear immediately after the snapshot is taken.

func (*Manager) Disconnect

func (m *Manager) Disconnect(name string)

Disconnect closes all tunnel clients with this name attached to this replica. Call DisconnectCredential when the previous credential ID is available so clients attached to other replicas can also be reached.

func (*Manager) DisconnectCredential

func (m *Manager) DisconnectCredential(name, credentialID string)

DisconnectCredential closes all sessions using a tunnel's previous credential. Control connections are routed through remotedialer so clients attached to other replicas can also be reached.

func (*Manager) HTTPClient

func (m *Manager) HTTPClient(tunnelName string, timeout time.Duration) (*http.Client, error)

HTTPClient returns an HTTP client that routes every request through the named tunnel. Redirects rewritten by the bridge remain on the same tunnel.

func (*Manager) ReconcilePeers

func (m *Manager) ReconcilePeers(desired map[string]string)

ReconcilePeers updates the remotedialer peer mesh to match desired. It is called by the all-replica EndpointSlice controller.

func (*Manager) ServeBridge

func (m *Manager) ServeBridge(w http.ResponseWriter, r *http.Request)

ServeBridge forwards an HTTP request over the tunnel selected by the encoded internal bridge target in the request path.

func (*Manager) ServeConnect

func (m *Manager) ServeConnect(w http.ResponseWriter, r *http.Request, name string)

ServeConnect upgrades an authorized request for name. The name must come from the tunnel principal established by TunnelAuthenticator.

func (*Manager) ServePeer

func (m *Manager) ServePeer(w http.ResponseWriter, r *http.Request)

ServePeer accepts an internal remotedialer connection from another Obot replica. Authentication is performed both by Obot middleware and by remotedialer against the discovered peer set.

type PeerConfig

type PeerConfig struct {
	ID               string
	Token            string
	ServiceName      string
	ServiceNamespace string
}

PeerConfig configures authentication and discovery of the other Obot replicas that participate in the tunnel remotedialer mesh. An entirely empty config disables peering; otherwise every field is required.

func (PeerConfig) Enabled

func (c PeerConfig) Enabled() bool

Enabled reports whether a valid config enables tunnel peering. Call Validate first when an invalid partial config must be distinguished from a disabled config.

func (PeerConfig) Validate

func (c PeerConfig) Validate() error

Validate verifies that tunnel peering is either fully disabled or fully configured.

Jump to

Keyboard shortcuts

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