Documentation
¶
Index ¶
- Constants
- Variables
- func AddJWTAuth(config *ssh.ClientConfig, jwtToken string) *ssh.ClientConfig
- func CreateHostKeyCallback(verifier HostKeyVerifier) ssh.HostKeyCallback
- func EncodePrivateKeyToPEM(privateKey crypto.Signer) ([]byte, error)
- func GeneratePrivateKey(keyType KeyType) ([]byte, error)
- func GeneratePublicKey(key []byte) ([]byte, error)
- func Handshake(ctx context.Context, conn net.Conn, addr string, config *ssh.ClientConfig) (*ssh.Client, error)
- func RequestJWTToken(ctx context.Context, client proto.DaemonServiceClient, ...) (string, error)
- func VerifyHostKey(storedKeyData []byte, presentedKey []byte, peerAddress string) error
- type DaemonHostKeyVerifier
- type HostKeyVerifier
- type KeyType
- type PTYSession
- type PeerKeyLookup
Constants ¶
const ( NetBirdSSHConfigFile = "99-netbird.conf" UnixSSHConfigDir = "/etc/ssh/ssh_config.d" WindowsSSHConfigDir = "ssh/ssh_config.d" )
const RSAKeySize = 2048
RSAKeySize is a size of newly generated RSA key
Variables ¶
var ( // ErrPeerNotFound indicates the peer was not found in the network ErrPeerNotFound = errors.New("peer not found in network") // ErrNoStoredKey indicates the peer has no stored SSH host key ErrNoStoredKey = errors.New("peer has no stored SSH host key") )
var DefaultTerminalModes = ssh.TerminalModes{ ssh.ECHO: 1, ssh.TTY_OP_ISPEED: 14400, ssh.TTY_OP_OSPEED: 14400, ssh.VINTR: 3, ssh.VQUIT: 28, ssh.VERASE: 127, ssh.VKILL: 21, ssh.VEOF: 4, ssh.VEOL: 0, ssh.VEOL2: 0, ssh.VSTART: 17, ssh.VSTOP: 19, ssh.VSUSP: 26, ssh.VDISCARD: 15, ssh.VREPRINT: 18, ssh.VWERASE: 23, ssh.VLNEXT: 22, }
DefaultTerminalModes are the PTY modes used by the interactive terminal clients.
Functions ¶
func AddJWTAuth ¶ added in v0.60.0
func AddJWTAuth(config *ssh.ClientConfig, jwtToken string) *ssh.ClientConfig
AddJWTAuth prepends JWT password authentication to existing auth methods. This ensures JWT auth is tried first while preserving any existing auth methods.
func CreateHostKeyCallback ¶ added in v0.60.0
func CreateHostKeyCallback(verifier HostKeyVerifier) ssh.HostKeyCallback
CreateHostKeyCallback creates an SSH host key verification callback using the provided verifier. It tries multiple addresses (hostname, IP) for the peer before failing.
func EncodePrivateKeyToPEM ¶
EncodePrivateKeyToPEM encodes a private key to PEM format.
func GeneratePrivateKey ¶
GeneratePrivateKey creates a private key of the specified type.
func GeneratePublicKey ¶
GeneratePublicKey returns the public part of the private key.
func Handshake ¶ added in v0.77.1
func Handshake(ctx context.Context, conn net.Conn, addr string, config *ssh.ClientConfig) (*ssh.Client, error)
Handshake runs the SSH client handshake on an already dialed conn and returns the resulting client. Dialing bounds only the TCP establishment; without a deadline on the socket a peer that accepts and then goes silent blocks the handshake forever, so the context deadline is applied to conn for the duration of the handshake. conn is closed on any error.
func RequestJWTToken ¶ added in v0.60.0
func RequestJWTToken(ctx context.Context, client proto.DaemonServiceClient, stdout, stderr io.Writer, useCache bool, hint string, openBrowser func(string) error) (string, error)
RequestJWTToken requests or retrieves a JWT token for SSH authentication
func VerifyHostKey ¶ added in v0.60.0
VerifyHostKey verifies an SSH host key against stored peer key data. Returns nil only if the presented key matches the stored key. Returns ErrNoStoredKey if storedKeyData is empty. Returns an error if the keys don't match or if parsing fails.
Types ¶
type DaemonHostKeyVerifier ¶ added in v0.60.0
type DaemonHostKeyVerifier struct {
// contains filtered or unexported fields
}
DaemonHostKeyVerifier implements HostKeyVerifier using the NetBird daemon
func NewDaemonHostKeyVerifier ¶ added in v0.60.0
func NewDaemonHostKeyVerifier(client proto.DaemonServiceClient) *DaemonHostKeyVerifier
NewDaemonHostKeyVerifier creates a new daemon-based host key verifier
func (*DaemonHostKeyVerifier) VerifySSHHostKey ¶ added in v0.60.0
func (d *DaemonHostKeyVerifier) VerifySSHHostKey(peerAddress string, presentedKey []byte) error
VerifySSHHostKey verifies an SSH host key by querying the NetBird daemon
type HostKeyVerifier ¶ added in v0.60.0
HostKeyVerifier provides SSH host key verification
type KeyType ¶
type KeyType string
KeyType is a type of SSH key
const ECDSA KeyType = "ecdsa"
ECDSA is key of type ecdsa
const ED25519 KeyType = "ed25519"
ED25519 is key of type ed25519
const RSA KeyType = "rsa"
RSA is key of type rsa
type PTYSession ¶ added in v0.77.1
type PTYSession struct {
Session *ssh.Session
Stdin io.WriteCloser
Stdout io.Reader
Stderr io.Reader
}
PTYSession is an interactive shell session with a PTY and its I/O pipes.
func StartPTYSession ¶ added in v0.77.1
func StartPTYSession(client *ssh.Client, cols, rows int) (*PTYSession, error)
StartPTYSession opens a session on the client, requests an xterm-256color PTY with the default terminal modes, wires up the I/O pipes and starts a shell. The session is closed on any error.
type PeerKeyLookup ¶ added in v0.77.1
PeerKeyLookup returns the stored SSH host key for a peer address.
func (PeerKeyLookup) VerifySSHHostKey ¶ added in v0.77.1
func (l PeerKeyLookup) VerifySSHHostKey(peerAddress string, presentedKey []byte) error
VerifySSHHostKey implements HostKeyVerifier by looking up the stored key and comparing it against the presented key.