sshgateway

package
v0.7.23 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOrGenerateHostKey

func LoadOrGenerateHostKey(path string) (ssh.Signer, error)

LoadOrGenerateHostKey returns an ssh.Signer for the host private key at path. If the file does not exist, an ed25519 key is generated and persisted with 0600 permissions. The parent directory is created with 0700 if needed.

func ParseAuthorizedKey

func ParseAuthorizedKey(raw string) (ssh.PublicKey, error)

ParseAuthorizedKey parses a single OpenSSH-format public key. Trailing comments and whitespace are tolerated.

Types

type Config

type Config struct {
	ListenAddr     string
	HostKeyPath    string
	AcceptDeadline time.Duration
	// ToolboxPort is the in-container HTTP port toolboxd listens on. Used by
	// session-attach mode to dial the WebSocket directly. If zero, session
	// mode is disabled and the gateway falls back to one-shot exec.
	ToolboxPort int
	// RemoteAPIBaseURL enables cross-node SSH routing. When non-empty (cluster
	// mode), a connection for a sandbox NOT owned by this node is authenticated
	// against the owner's authoritative key and its session is bridged through
	// this node's own v1 API, which clusterForwardWrap reverse-proxies to the
	// owner over the cert-pinned mTLS channel. Empty (single-node) disables the
	// remote path entirely — behaviour is byte-for-byte the pre-cluster gateway.
	// Conventionally the loopback API address, e.g. "http://127.0.0.1:8080".
	RemoteAPIBaseURL string
	// RemoteAPIToken is the PAT presented on the loopback v1 call. Only used
	// when RemoteAPIBaseURL is set.
	RemoteAPIToken string
	// ContainerEngine is the host runtime engine ("docker" | "containerd").
	// On containerd, sandboxes are containerd tasks (not docker containers), so
	// the docker-exec one-shot path cannot reach them — the gateway runs the
	// command through the in-container toolbox session instead. Empty defaults
	// to the docker behaviour.
	ContainerEngine string
}

Config carries the gateway's runtime parameters.

type DockerExec

type DockerExec interface {
	ExecCreate(ctx context.Context, containerID string, cmd []string, env []string, workdir string, tty bool) (string, error)
	ExecStart(ctx context.Context, execID string, tty bool) (*docker.ExecSession, error)
	ExecResize(ctx context.Context, execID string, height, width int) error
	ExecInspect(ctx context.Context, execID string) (exitCode int, running bool, err error)
}

DockerExec is the slice of *docker.Client the gateway needs. It exists so the gateway can be tested with a fake.

type Gateway

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

Gateway terminates SSH connections on the host and bridges accepted shell / exec sessions to a docker exec stream inside the target sandbox container.

Auth is per-sandbox: every sandbox is created with a freshly generated ed25519 keypair, the public key is persisted on the sandbox row, and that key is the only one authorized to SSH into that specific sandbox. There is no global key.

func New

func New(logger *slog.Logger, cfg Config, svc SandboxLookup, dockerCli DockerExec) (*Gateway, error)

New constructs a Gateway. It loads or generates the host key. Returns an error if the gateway cannot be initialized — callers should treat this as fatal.

func (*Gateway) Start

func (g *Gateway) Start(ctx context.Context) error

Start opens the TCP listener and accepts connections until ctx is cancelled.

type SandboxLookup

type SandboxLookup interface {
	GetSandbox(ctx context.Context, id string) (*models.Sandbox, error)
	TouchSandbox(ctx context.Context, id string) error
}

SandboxLookup is the slice of *service.Service the gateway needs.

Jump to

Keyboard shortcuts

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