Documentation ¶
Index ¶
- func DirectTCPIPHandler(ctx context.Context, mux *SSHSMux, srv *SSHMesh, newChan ssh.NewChannel)
- func KeysEqual(ak, bk ssh.PublicKey) bool
- func SessionHandler(ctx context.Context, sconn *SSHSMux, newChannel ssh.NewChannel)
- type Command
- type KV
- type Mux
- type Proxy
- type RemoteExec
- type SSHCA
- type SSHCMux
- func (sshc *SSHCMux) ClientSession()
- func (sc *SSHCMux) Dial(ctx context.Context, addr string) error
- func (sc *SSHCMux) DialConn(ctx context.Context, tcon net.Conn, addr string) error
- func (ssht *SSHCMux) Exec(cmd string, env map[string]string) (*RemoteExec, error)
- func (c *SSHCMux) ListenTCP(domain string, port uint32) (uint32, error)
- func (c *SSHCMux) OpenStream(n string, data []byte) (*Stream, error)
- func (sc *SSHCMux) Proxy(ch io.ReadWriteCloser, dstp string, s string)
- func (sshc *SSHCMux) StayConnected(addr string)
- type SSHMesh
- func (ssht *SSHMesh) AddAuthorizedFile(auth []byte)
- func (ss *SSHMesh) Client(ctx context.Context, dst string) (*SSHCMux, error)
- func (ss *SSHMesh) FromEnv(ctx context.Context, base string)
- func (ssht *SSHMesh) HandleServerConn(nConn net.Conn)
- func (st *SSHMesh) InitMux(mux *http.ServeMux)
- func (ssht *SSHMesh) ListenAndStart() (net.Listener, error)
- func (srv *SSHMesh) Proxy(ctx context.Context, dest string, ch io.ReadWriteCloser) (*Proxy, error)
- func (ssht *SSHMesh) PubString()
- func (s *SSHMesh) SetKeys(priv string, hostc string, clientc string) (*SSHMesh, error)
- func (s *SSHMesh) Sign(pub ssh.PublicKey, certType uint32, names []string) ([]byte, *ssh.Certificate, error)
- func (s *SSHMesh) SignCert(cert *ssh.Certificate) ([]byte, error)
- func (ssht *SSHMesh) Start(ctx context.Context) error
- type SSHSMux
- func (c *SSHSMux) Filecmd(request *sftp.Request) error
- func (c *SSHSMux) Filelist(request *sftp.Request) (sftp.ListerAt, error)
- func (c *SSHSMux) Fileread(request *sftp.Request) (io.ReaderAt, error)
- func (c *SSHSMux) Filewrite(request *sftp.Request) (io.WriterAt, error)
- func (c *SSHSMux) OpenStream(n string, data []byte) (*Stream, error)
- type Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirectTCPIPHandler ¶
DirectTCPIPHandler is for 'direct-tcpip' channel type, to support client-originated reverseForwards. It runs on the server side.
See RFC 4254 7.2 RFC 4254 7.2" aria-label="Go to See RFC 4254 7.2">¶
- When client starts with a -L CPORT:host:port, and connects to CPORT - Also when client uses socks for dynamic reverseForwards (-D) - jump (-J)
If the destination port is 22/15022 - existing connections can be used to avoid an extra TCP connection.
Laddr is typically 127.0.0.1 (unless ssh has an open socks, and other machines use it)
func SessionHandler ¶
func SessionHandler(ctx context.Context, sconn *SSHSMux, newChannel ssh.NewChannel)
Basic untrusted session handler.
Types ¶
type Command ¶
type Command struct {
Run func(env map[string]string, args []string, in io.Reader, out io.WriteCloser, err io.WriteCloser)
}
type Mux ¶
type Mux struct { // LastSeen time.Time ConnectTime time.Time // network stream // May be an original con with net.Conn with remote/local addr NetConn io.ReadWriteCloser }
Mux represents a TCP (or other protocol) connection with multiplexed streams on top. It can be used for SSH client, server, H2 and many protocols multiplexing streams.
type Proxy ¶
type RemoteExec ¶
RemoteExec is a "session" channel.
type SSHCA ¶
func NewSSHCA ¶
func NewSSHCA(privk crypto.PrivateKey) *SSHCA
func (*SSHCA) AuthorizedKey ¶
type SSHCMux ¶
type SSHCMux struct { Mux *SSHMesh // If set, a persistent connection will be maintained and // - mux reverseForwards registered for 22, 80, 443 // - accept streams and trust auth Waypoint bool // TODO: CIDR/Networks ReverseForwards map[string]string LastConnected time.Time // The SSH Conn object SSHConn ssh.Conn // TODO: limit by domain ? AuthorizedCA []ssh.PublicKey // Same as the transport CertChecker *ssh.CertChecker SSHClient *ssh.Client // Last received remote key (should be a Certificate) RemoteKey ssh.PublicKey // contains filtered or unexported fields }
SSHCMux is a multiplexed client connection to a single destination. That corresponds to a H2 connection - it is possible to have multiple SSHCMux connections to the same destination at the same time.
func (*SSHCMux) ClientSession ¶
func (sshc *SSHCMux) ClientSession()
func (*SSHCMux) Dial ¶
Dial opens one TCP or H2 connection to addr. It blocks until the SSH handshake is done.
func (*SSHCMux) ListenTCP ¶
ListenTCP requests the remote peer open a listening socket on port.
Regular SSH servers don't multiplex on port. RFC4254: "" means that connections are to be accepted on all protocol
families supported by the SSH implementation. o "0.0.0.0" means to listen on all IPv4 addresses. o "::" means to listen on all IPv6 addresses. o "localhost" means to listen on all protocol families supported by the SSH implementation on loopback addresses only ([RFC3330] and [RFC3513]). o "127.0.0.1" and "::1" indicate listening on the loopback interfaces for IPv4 and IPv6, respectively.
Port 0 is usually supported.
func (*SSHCMux) OpenStream ¶
OpenStream creates a new stream. This uses the same channel in both directions.
func (*SSHCMux) Proxy ¶
func (sc *SSHCMux) Proxy(ch io.ReadWriteCloser, dstp string, s string)
Proxy an incoming stream to a destination, for remotely accepted steams (-R) TODO: optimize.
func (*SSHCMux) StayConnected ¶
StayConnected will maintain an active connection, typically with a jump host.
'addr' is the IP:port to connect to - not the 'canonical' service.
type SSHMesh ¶
type SSHMesh struct { Mesh *meshauth.Mesh // Address to listen on as SSH. Will default to 14022 for regular nodes and // 15022 for gateways. Address string `json:"sshd_addr,omitempty"` Listener net.Listener `json:"-"` CertChecker *ssh.CertChecker `json:"-"` // Multiplexed clients to upstream hosts, by destination. // May disconnect - the same client is reused. Clients sync.Map // [string,*SSHCMux] ConnectErrors atomic.Int64 // Map of public key to user ID. // Key is the marshalled public key (from authorized_keys), value is the user ID (comment) UsersKeys map[string]string `json:"-"` // Signer is the 'workload identity' signer. It is using the main workload // private key (workload key), but with a host certificate. Signer ssh.Signer `json:"-"` // SignerClient is a client workload identity - using the SA cert when // a CA is used. Otherwise, same as Signer. SignerClient ssh.Signer `json:"-"` // Forward is a function that will proxy a stream to a destination. // If missing, it will be dialed. // Used on a server for all client forwarding - except locally connected clients. Forward func(context.Context, string, io.ReadWriteCloser) `json:"-"` // WIP: Internally defined commands. InternalCommands map[string]*Command `json:"-"` // Root CA keys - will be authorized to connect and create tunnels, not get shell. AuthorizedCA []ssh.PublicKey `json:"-"` // WIP: Custom channel handlers. ChannelHandlers map[string]func(ctx context.Context, sconn *SSHSMux, newChannel ssh.NewChannel) `json:"-"` // TokenChecker will verify the password field - as a JWT or other forms. TokenChecker func(password string) (claims map[string]string, e error) `json:"-"` // Deprecated - Credentials CertHost string `json:"ssh.crt,omitempty"` // Deprecated - Credentials CertClient string `json:"ssh-client.crt,omitempty"` // AuthorizedKeys is the same as authorized_keys file. // The keys are used as 'trusted sources' for authentication. Any user key can be used for shell/debug access. // The CA keys are allowed to connect - but can get a shell only if 'role=admin' is present in the cert. // // If empty, the SSH_AUTHORIZED_KESY env is used, falling back to authorized_keys in current dir and $HOME/.ssh AuthorizedKeys string `json:"authorized_keys,omitempty"` sync.Mutex // contains filtered or unexported fields }
SSHMesh is a minimal L4S (ambient) mesh implementation based on SSH, and compatible with standard SSH clients and servers.
func NewSSHMesh ¶
NewSSHMesh creates the SSHMesh object. Must call SetKeys() or FromEnv() before using it.
If the key is missing, a self-signed key is generated.
Extensions compared to regular sshd: - can use JWT tokens as password - based on Issuer config. - multiplex forwarded ports 22, 80, 443 - optimized for the use of a CA for both client and server.
TODO: As a server, it can also prove its workload ID with a JWT and jumpstart known_hosts !
func (*SSHMesh) AddAuthorizedFile ¶
AddAuthorizedFile will load the ssh "authorized_files" content.
All CAs are added separately, and will also be used for host authorization. The 'comment' field is saved - and will be used as 'user' when public key auth is using that key.
func (*SSHMesh) Client ¶
Client returns a SSH client for a destination. It may be disconnected - first call is always disconnected.
func (*SSHMesh) HandleServerConn ¶
Handles a connection as SSH server, using a net.Conn - which might be tunneled over other transports. SSH handles multiplexing and packets.
func (*SSHMesh) Sign ¶
func (s *SSHMesh) Sign(pub ssh.PublicKey, certType uint32, names []string) ([]byte, *ssh.Certificate, error)
Sign will sign a client or server certificate.
Each host can sign - the resulting cert should be under the host trust.
type SSHSMux ¶
type SSHSMux struct { Mux // ServerConn - also has Permission ServerConn *ssh.ServerConn // Includes the private key of this node SSHServer *SSHMesh RemoteKey ssh.PublicKey // For server-side sessions, this is the last active session. // With multiplexing, multiple sessions may be in effect. SessionStream ssh.Channel FQDN string }
SSHSMux is a server ssh connection.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
sshd
Module
|
|
sshgate
Module
|
|
bufferv2
Package bufferv2 provides the implementation of a non-contiguous buffer that is reference counted, pooled, and copy-on-write.
|
Package bufferv2 provides the implementation of a non-contiguous buffer that is reference counted, pooled, and copy-on-write. |
bufferv2/bits
Package bits includes all bit related types and operations.
|
Package bits includes all bit related types and operations. |
syscall
Package syscall provides functionalities that grpc uses to get low-level operating system stats/info.
|
Package syscall provides functionalities that grpc uses to get low-level operating system stats/info. |
pkg
|
|