Documentation
¶
Overview ¶
Package server accepts SSH connections and serves the "sftp" subsystem. Shell, exec, port forwarding and every other channel or request type are refused.
Index ¶
Constants ¶
const ( PolicyModern = "modern" PolicyCompat = "compat" )
Crypto policies (ROADMAP §7.6). There are no per-algorithm settings: x/crypto silently drops names it does not know, so a typo would weaken nothing visibly, and its default lists still contain SHA-1 variants.
const ( DefaultHandshakeTimeout = 30 * time.Second DefaultIdleTimeout = 15 * time.Minute DefaultKeepaliveInterval = 30 * time.Second DefaultMaxConnections = 256 DefaultMaxPerSource = 16 DefaultMaxPreauth = 64 DefaultMaxSessions = 4 DefaultMaxAuthTries = 6 )
Defaults (ROADMAP §7.5).
Variables ¶
var CryptoPolicies = []string{PolicyModern, PolicyCompat}
CryptoPolicies lists the valid crypto_policy values.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// HostKeys are used for key exchange, at most one per key type.
HostKeys []ssh.Signer
// HostCertificates are certificates of HostKeys (ssh.NewCertSigner),
// each offered while it is valid.
HostCertificates []ssh.Signer
// AnnouncedKeys are announced with HostKeys and proved on request, but
// not used for key exchange: next and previous keys (ADR 0008).
AnnouncedKeys []ssh.Signer
// AnnounceHostKeys announces the host keys to OpenSSH clients after
// login (hostkeys-00@openssh.com), so that they learn new ones.
AnnounceHostKeys bool
Auth *auth.Authenticator
Mounts *vfs.Table
// Grants returns the mounts an authenticated user may access; nil
// grants every mount with all permissions (zero-config).
Grants func(user string) []vfs.Grant
Audit *audit.Logger
Log *slog.Logger
// Metrics counts connections, logins and SFTP operations; nil counts
// nothing.
Metrics *obs.Metrics
// Hooks gets the file events (ADR 0010); nil runs no hooks. It lives
// for the process: Reload does not replace it, the caller updates it.
Hooks *hooks.Dispatcher
// Methods lists the enabled login methods, auth.MethodPublicKey and
// auth.MethodPassword; empty means public keys only.
Methods []string
// Bans refuses sources that keep failing to log in; nil disables bans.
Bans *auth.BanTable
// CryptoPolicy is PolicyModern (default) or PolicyCompat.
CryptoPolicy string
// Zero values take the defaults. A negative IdleTimeout or
// KeepaliveInterval disables it.
HandshakeTimeout time.Duration
IdleTimeout time.Duration
KeepaliveInterval time.Duration
MaxConnections int
MaxConnectionsPerIP int // per IPv4 address or IPv6 /64
MaxPreauthConnections int
MaxSessionsPerConn int
MaxOpenHandles int // per SFTP session, default sftpd.DefaultMaxHandles
MaxAuthTries int
// DisconnectRevoked makes Reload close the connections whose login the
// new configuration would refuse (reload.disconnect_removed_users).
DisconnectRevoked bool
// TrustedProxies are the peers whose connections begin with a PROXY
// protocol header that names the client (ADR 0011): unmapped
// addresses and prefixes, none of length 0. A connection from another
// peer that begins with a header is refused. Each connection is
// classified by the configuration current at its accept.
TrustedProxies []netip.Prefix
}
Config configures a Server. New fixes CryptoPolicy, Audit, Log and Metrics; Reload changes the rest.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves SFTP over SSH.
func New ¶
New validates cfg and returns a Server. The caller keeps cfg.Mounts open while it is the current table (see Reload).
func (*Server) ActiveBans ¶ added in v0.4.0
ActiveBans returns the number of sources banned now; 0 with bans off.
func (*Server) Reload ¶ added in v0.4.0
Reload switches new logins to cfg, and new connections to its host keys; CryptoPolicy, Audit, Log and Metrics are ignored. Open connections keep their host keys, also for re-keying; logged-in connections keep the configuration they logged in under; with cfg.DisconnectRevoked, those whose login cfg would refuse are closed, and Reload returns how many. Bans, connection counts and the password hashing limit carry over. The caller keeps cfg.Mounts open while it is the current table and may drop its reference to the previous table once Reload returns.
func (*Server) Serve ¶
Serve accepts connections on ln until ctx is canceled or ln fails. It closes ln. In-flight connections keep running; see Shutdown.