ssh

package
v0.0.1-alpha83 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package ssh provides an SSH server that routes connections to sandbox containers. It uses the username as the session ID to identify which container to connect to. This enables VS Code Remote SSH to connect to sandbox sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Address to listen on (e.g., ":2222")
	Address string

	// HostKeyPath is the path to the SSH host key file.
	// If the file doesn't exist, a new key will be generated.
	HostKeyPath string

	// SandboxProvider is used to route connections to containers.
	SandboxProvider sandbox.Provider

	// UserInfoFetcher is used to get the default user for sandbox sessions.
	// If nil, commands run as root.
	UserInfoFetcher UserInfoFetcher

	// EnvVarFetcher is used to get environment variables from the session. If nil,
	// no runtime-managed env vars are applied.
	EnvVarFetcher EnvVarFetcher

	// ConnectionTracker is notified when SSH connections are established and closed.
	// If nil, connection tracking is disabled.
	ConnectionTracker ConnectionTracker
}

Config holds SSH server configuration.

type ConnectionTracker

type ConnectionTracker interface {
	// Track registers an active connection for sessionID and returns a release
	// function that must be called when the connection ends.
	Track(sessionID string) func()
}

ConnectionTracker tracks active connections per session. Implementations must be safe for concurrent use.

type EnvVarFetcher

type EnvVarFetcher interface {
	// GetEnvVarsForSession returns the merged environment variables to inject into
	// SSH sessions before applying client-provided env overrides.
	GetEnvVarsForSession(ctx context.Context, sessionID string) (map[string]string, error)
}

EnvVarFetcher fetches environment variables for a session from runtime-managed sources like visible credentials.

type Server

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

Server is an SSH server that routes connections to sandbox containers.

func New

func New(cfg *Config) (*Server, error)

New creates a new SSH server with the given configuration.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the address the server is listening on.

func (*Server) Start

func (s *Server) Start() error

Start begins accepting SSH connections.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts down the SSH server.

type UserInfoFetcher

type UserInfoFetcher interface {
	// GetUserInfo returns the default user for a sandbox.
	// Returns username, uid, gid, and any error.
	GetUserInfo(ctx context.Context, sessionID string) (username string, uid, gid int, err error)
}

UserInfoFetcher fetches user info from a sandbox. This is used to determine which user to run commands as.

Jump to

Keyboard shortcuts

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