server

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package server provides the CLI for dcx-agent, a minimal binary that runs inside containers and exposes an SSH surface for host-side dcx.

Package server — the netgate enforces which source IPs may complete an SSH handshake. It is wired into gliderlabs/ssh's ConnCallback, which runs before any SSH bytes are exchanged. A nil return from the callback closes the connection.

The gate is the load-bearing pre-handshake filter. Even though Docker's -p <bind>:<host>:<container> restricts which host interface accepts packets, the agent may bind 0.0.0.0 inside the container (WSL2 NAT) — in that case the gate is the only layer enforcing "loopback-only by default."

Package server implements the TCP SSH server that runs inside dcx-managed containers. It is bundled into the `dcx-agent` binary and invoked as `dcx-agent listen`.

All client connections complete public-key authentication against a mounted authorized_keys file. A pre-handshake IP gate rejects any source address outside the configured allowlist (loopback by default).

Index

Constants

View Source
const DefaultReadyFilePath = "/var/lib/dcx/agent-ready"

DefaultReadyFilePath is the sentinel the agent writes once Accept is live inside the container. Readable from the host via `docker exec cat`.

Variables

This section is empty.

Functions

func Execute

func Execute() error

Execute runs the agent CLI.

Types

type Config added in v0.7.0

type Config struct {
	User        string
	Shell       string
	WorkDir     string
	HostKeyPath string

	// Paths (in order) to check for authorized pubkeys. First match wins.
	// Typically [DCXSecretPath("authorized_keys"),
	// filepath.Join(userHome, ".ssh", "authorized_keys")].
	AuthorizedKeysPaths []string

	// Pre-handshake loopback gate. A non-loopback remote address has its
	// connection closed before any SSH bytes are exchanged.
	Gate *Gate

	// Path to write the ready sentinel once Accept is live. Empty means skip
	// the sentinel (useful for tests). In production this points at
	// /var/lib/dcx/agent-ready inside the container, readable via
	// `docker exec cat`.
	ReadyFile string
}

Config holds everything required to build a Server.

type Gate added in v0.7.0

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

Gate is an IP allowlist. It answers the question: should this source address be allowed through the handshake?

func FromCIDRs added in v0.7.0

func FromCIDRs(cidrs []string) (*Gate, error)

FromCIDRs parses a list of CIDR strings (or bare IPs, which are treated as /32 or /128) into a Gate. Returns an error if any entry is malformed.

An empty list returns a Gate that rejects all connections. Callers that want "loopback-only" should either combine with Loopback or include "127.0.0.0/8" and "::1/128" explicitly.

func Loopback added in v0.7.0

func Loopback() *Gate

Loopback returns a Gate that permits only 127.0.0.0/8 and ::1/128.

func (*Gate) Allow added in v0.7.0

func (g *Gate) Allow(addr net.Addr) bool

Allow reports whether the given address is permitted. Returns false for nil addresses, non-IP addresses, unparseable host components, and IPs outside the configured CIDRs.

func (*Gate) Extend added in v0.7.0

func (g *Gate) Extend(cidrs []string) (*Gate, error)

Extend returns a new Gate that accepts everything this gate accepts plus the additional CIDRs. It is used when the auto-detected WSL2 Hyper-V gateway needs to be added to a loopback-only gate at runtime.

type Server

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

Server is the SSH server.

func NewServer

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

NewServer builds a server from a Config.

func (*Server) Listen added in v0.7.0

func (s *Server) Listen(ctx context.Context, addr string) error

Listen binds a TCP listener on addr and serves until ctx is cancelled.

When ctx is cancelled, in-flight sessions are given 10 seconds to drain via ssh.Server.Shutdown; if any remain, they are forcibly closed.

type ShellConfig

type ShellConfig struct {
	// Args to add when starting an interactive shell (replaces default -l)
	Args []string
	// Env vars to set
	Env []string
}

ShellConfig contains shell-specific configuration for integration.

func SetupShellIntegration

func SetupShellIntegration(shell string) ShellConfig

SetupShellIntegration creates integration files and returns shell configuration. This enables terminal title updates showing the typed command (like Kitty/Ghostty).

Jump to

Keyboard shortcuts

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