tunnel

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package tunnel opens the SSH connection to a profile's bastion and dials the database server through it. Connections are direct-tcpip channels handed to the driver: no local port is ever listened on, so no other account on this machine can use the tunnel.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuth = errors.New("ssh: authentication failed")

ErrAuth marks an authentication failure: the bastion refused the credentials, or the key passphrase is wrong.

View Source
var ErrHostKeyChanged = errors.New("ssh: REMOTE HOST IDENTIFICATION HAS CHANGED")

ErrHostKeyChanged is a bastion whose key differs from the one recorded in known_hosts: possibly an attacker in the middle. There is no override; the human edits known_hosts after checking the new key.

Functions

func HostKeyAlgorithms

func HostKeyAlgorithms(path string, p config.SSHProfile) ([]string, error)

HostKeyAlgorithms lists the host key algorithms to offer the bastion of p: those of the key types recorded for it in the known_hosts file at path, so that a bastion with several keys is not negotiated onto one that is not recorded (which would look like a changed key). With nothing recorded it lists the plain key algorithms, Ed25519 first and no certificates.

func KnownHosts

func KnownHosts(path string, confirm Confirm) (ssh.HostKeyCallback, error)

KnownHosts verifies host keys against the known_hosts file at path, as OpenSSH with StrictHostKeyChecking=ask: a recorded key must match, an unknown host is trusted only on confirm, and is then recorded.

func KnownHostsPath

func KnownHostsPath(home string) string

KnownHostsPath is the console account's known_hosts.

Types

type Confirm

type Confirm func(host, keyType, fingerprint string) bool

Confirm is asked whether to trust a host key seen for the first time.

type Options

type Options struct {
	Profile config.SSHProfile
	// Home is the console account's home directory, for "~" in Profile.Key.
	Home string
	// HostKey verifies the bastion's key (see KnownHosts).
	HostKey ssh.HostKeyCallback
	// HostKeyAlgorithms limits the host key algorithms offered to the
	// bastion (see HostKeyAlgorithms); empty keeps the library default.
	HostKeyAlgorithms []string
	// Secret returns a key passphrase or an SSH password; it is called only
	// when one is needed, and Open wipes what it returns.
	Secret func(prompt string) ([]byte, error)
	// AgentSock is the console's SSH_AUTH_SOCK, "" when unset.
	AgentSock string
	// Keepalive is the interval between keepalives; 0 means 30s.
	Keepalive time.Duration
}

Options configure Open.

type Tunnel

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

Tunnel is an open SSH connection to a bastion.

func Open

func Open(ctx context.Context, o Options) (*Tunnel, error)

Open connects and authenticates to the bastion.

func (*Tunnel) Close

func (t *Tunnel) Close() error

Close closes the SSH connection and every forwarded connection.

func (*Tunnel) Dial

func (t *Tunnel) Dial(ctx context.Context, network, addr string) (net.Conn, error)

Dial opens a connection to addr from the bastion. Only TCP is forwarded.

func (*Tunnel) Done

func (t *Tunnel) Done() <-chan struct{}

Done is closed once the tunnel is gone.

func (*Tunnel) HostKey

func (t *Tunnel) HostKey() string

HostKey is the SHA256 fingerprint of the bastion's host key.

Jump to

Keyboard shortcuts

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