sshgateway

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttestBridgedCall added in v0.6.9

func AttestBridgedCall(h http.Header, call auditlog.SSHGatewayCall)

AttestBridgedCall puts call on h with this process's attestation. The gateway calls it on every request it bridges to its own node's API.

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.

func TakeBridgedCall added in v0.6.9

func TakeBridgedCall(h http.Header, sandboxID string) (auditlog.SSHGatewayCall, bool)

TakeBridgedCall removes the gateway's headers from h, whatever they hold, and returns the call they carry only when this process attested it and it names sandboxID, the sandbox the request's path targets. Anything else (no headers, a forged or copied MAC, another sandbox, a header sent twice) is ok=false: the request is then just the operator's call it looks like.

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) CloseAll added in v0.6.9

func (g *Gateway) CloseAll() int

CloseAll closes every open SSH connection and returns how many it closed.

func (*Gateway) Start

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

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

type OwnerSessionRecorder added in v0.6.9

type OwnerSessionRecorder interface {
	SSHSessionsRecordedByOwner() bool
}

OwnerSessionRecorder is the slice of *service.Service that says whether the owner of a sandbox records the SSH sessions this gateway bridges to it (cluster mode, once every member runs a build that does; see bridgeSession). A lookup without it keeps the record on this node.

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.

type SessionRecorder added in v0.6.8

type SessionRecorder interface {
	RecordSSHSession(ctx context.Context, sandboxID, session string)
}

SessionRecorder is the slice of *service.Service that writes an SSH session's audit record (plans/identity-and-access.md §5.9, CEO review D3): SSH runs commands in a sandbox without touching the API, so without it SSH would be the one way to run a command that leaves no record. The gateway checks for it on its SandboxLookup, so a lookup that does not implement it (tests) records nothing.

Jump to

Keyboard shortcuts

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