socketbridge

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package socketbridge provides host-side socket forwarding via docker exec. It connects to a container running socket-forwarder and multiplexes socket connections between the container and host agents (GPG, SSH).

This implements a muxrpc-like protocol over stdin/stdout, avoiding the need for network access from container to host.

Package socketbridge provides socket forwarding between host and container via muxrpc-style protocol over docker exec stdin/stdout.

Index

Constants

View Source
const (
	MsgData   byte = 1 // Socket data
	MsgOpen   byte = 2 // New connection (payload = socket type)
	MsgClose  byte = 3 // Connection closed
	MsgPubkey byte = 4 // GPG public key data
	MsgReady  byte = 5 // Forwarder ready
	MsgError  byte = 6 // Error message
)

Message types (must match socket-forwarder)

View Source
const ProtocolVersion = 1

ProtocolVersion is the muxrpc wire protocol version. Bump when the message format or semantics change incompatibly.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

type Bridge struct {

	// Warnings receives user-visible warning messages (typically stderr).
	// If nil, warnings are suppressed.
	Warnings io.Writer
	// contains filtered or unexported fields
}

Bridge manages socket forwarding to a container.

func NewBridge

func NewBridge(containerID string, gpgEnabled bool, log *logger.Logger) *Bridge

NewBridge creates a new socket bridge for the given container. gpgEnabled indicates whether GPG agent forwarding is configured.

func (*Bridge) SetGPGPubkey

func (b *Bridge) SetGPGPubkey(pubkey []byte)

SetGPGPubkey sets the GPG public key to send to the container. Must be called before Start if GPG forwarding is enabled.

func (*Bridge) Start

func (b *Bridge) Start(ctx context.Context) error

Start launches the socket-forwarder in the container and begins forwarding.

func (*Bridge) Stop

func (b *Bridge) Stop() error

Stop terminates the bridge and cleans up. It is safe to call multiple times.

func (*Bridge) Wait

func (b *Bridge) Wait() error

Wait blocks until the bridge exits.

type Manager

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

Manager tracks per-container bridge daemon processes. It spawns detached "clawker bridge serve" subprocesses that forward GPG and SSH agent sockets into running containers.

Manager implements SocketBridgeManager.

func NewManager

func NewManager(cfg config.Config, log *logger.Logger) *Manager

NewManager creates a new socket bridge Manager.

func (*Manager) EnsureBridge

func (m *Manager) EnsureBridge(containerID string, gpgEnabled bool) error

EnsureBridge ensures a bridge daemon is running for the given container. It is idempotent — if a bridge is already running, it returns immediately.

func (*Manager) IsRunning

func (m *Manager) IsRunning(containerID string) bool

IsRunning returns true if a bridge daemon is running for the given container.

func (*Manager) StopAll

func (m *Manager) StopAll() error

StopAll stops all known bridge daemons.

func (*Manager) StopBridge

func (m *Manager) StopBridge(containerID string) error

StopBridge stops the bridge daemon for the given container.

type Message

type Message struct {
	Type     byte
	StreamID uint32
	Payload  []byte
}

Message represents a protocol message.

type SocketBridgeManager

type SocketBridgeManager interface {
	// EnsureBridge ensures a bridge daemon is running for the given container.
	// It is idempotent — if a bridge is already running, it returns immediately.
	EnsureBridge(containerID string, gpgEnabled bool) error
	// StopBridge stops the bridge daemon for the given container.
	StopBridge(containerID string) error
	// StopAll stops all known bridge daemons.
	StopAll() error
	// IsRunning returns true if a bridge daemon is running for the given container.
	IsRunning(containerID string) bool
}

SocketBridgeManager is the interface for managing socket bridge daemons. Commands interact with this interface (not the concrete Manager) to enable test mocking via sockebridgemocks.SocketBridgeManagerMock.

type SocketConfig

type SocketConfig struct {
	Path string `json:"path"` // Unix socket path in container
	Type string `json:"type"` // "gpg-agent" or "ssh-agent"
}

SocketConfig defines a socket to forward.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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