func forwardConnection(l net.Listener, connection dialer, remoteAddress, connectionType string) {
	defer func() {
		if err := l.Close(); err != nil {
			fmt.Printf("Failed closing listener: %v\n", err)
		}
	}()
	for {
		c, err := l.Accept()
		if err != nil {
			fmt.Printf("Failed to accept connection: %v\n", err)
			return
		}
		remoteSock, err := connection.Dial(connectionType, remoteAddress)
		if err != nil {
			fmt.Printf("Failed to open remote connection: %v\n", err)
			return
		}
		go handleClient(c, remoteSock)
	}
}
forwardConnection accepts local connections, and forwards them to remote address.

TODO: Should we do some error handling here?
package ssh
import (
	"fmt"
	"io"
	"net"
	"net/url"
	"os"
	"time"
	"github.com/google/uuid"
	gossh "golang.org/x/crypto/ssh"
	"golang.org/x/crypto/ssh/agent"
	"github.com/flexkube/libflexkube/internal/util"
	"github.com/flexkube/libflexkube/pkg/host/transport"
)
const (
	SSHAuthSockEnv = "SSH_AUTH_SOCK"
)
type Config struct {
	Address string `json:"address,omitempty"`
	Port int `json:"port,omitempty"`
	User string `json:"user,omitempty"`
	Password string `json:"password,omitempty"`
	ConnectionTimeout string `json:"connectionTimeout,omitempty"`
	RetryTimeout string `json:"retryTimeout,omitempty"`
	RetryInterval string `json:"retryInterval,omitempty"`
	PrivateKey string `json:"privateKey,omitempty"`
}
type ssh struct {
	address           string
	user              string
	connectionTimeout time.Duration
	retryTimeout      time.Duration
	retryInterval     time.Duration
	auth              []gossh.AuthMethod
	sshClientGetter   func(network, address string, config *gossh.ClientConfig) (*gossh.Client, error)
}
type sshConnected struct {
	client   dialer
	address  string
	uuid     func() (uuid.UUID, error)
	listener func(string, string) (net.Listener, error)
}
type dialer interface {
	Dial(network, address string) (net.Conn, error)
}
func (d *Config) New() (transport.Interface, error) {
	if err := d.Validate(); err != nil {
		return nil, fmt.Errorf("validating config: %w", err)
	}
	ct, _ := time.ParseDuration(d.ConnectionTimeout)  
	rt, _ := time.ParseDuration(d.RetryTimeout)       
	ri, _ := time.ParseDuration(d.RetryInterval)      
	s := &ssh{
		address:           fmt.Sprintf("%s:%d", d.Address, d.Port),
		user:              d.User,
		connectionTimeout: ct,
		retryTimeout:      rt,
		retryInterval:     ri,
		auth:              []gossh.AuthMethod{},
		sshClientGetter:   gossh.Dial,
	}
	if d.Password != "" {
		s.auth = append(s.auth, gossh.Password(d.Password))
	}
	if d.PrivateKey != "" {
		signer, _ := gossh.ParsePrivateKey([]byte(d.PrivateKey))  
		s.auth = append(s.auth, gossh.PublicKeys(signer))
	}
	if authSock := os.Getenv(SSHAuthSockEnv); authSock != "" {
		authConn, err := net.Dial("unix", authSock)
		if err != nil {
			return nil, fmt.Errorf("dialing SSH agent: %w", err)
		}
		signers, err := agent.NewClient(authConn).Signers()
		if err != nil {
			return nil, fmt.Errorf("getting public keys from SSH agent: %w", err)
		}
		s.auth = append(s.auth, gossh.PublicKeys(signers...))
	}
	return s, nil
}
func (d *Config) Validate() error {
	var errors util.ValidateErrors
	if d.Address == "" {
		errors = append(errors, fmt.Errorf("address must be set"))
	}
	if d.User == "" {
		errors = append(errors, fmt.Errorf("user must be set"))
	}
	if d.Password == "" && d.PrivateKey == "" && os.Getenv(SSHAuthSockEnv) == "" {
		errors = append(errors, fmt.Errorf("at least one authentication method must be available"))
	}
	if _, err := gossh.ParsePrivateKey([]byte(d.PrivateKey)); d.PrivateKey != "" && err != nil {
		errors = append(errors, fmt.Errorf("parsing private key: %w", err))
	}
	if d.Port == 0 {
		errors = append(errors, fmt.Errorf("port must be set"))
	}
	errors = append(errors, d.validateDurations()...)
	return errors.Return()
}
func (d *Config) validateDurations() util.ValidateErrors {
	var errors util.ValidateErrors
	if _, err := time.ParseDuration(d.ConnectionTimeout); err != nil {
		errors = append(errors, fmt.Errorf("parsing connection timeout: %w", err))
	}
	if _, err := time.ParseDuration(d.RetryTimeout); err != nil {
		errors = append(errors, fmt.Errorf("parsing retry timeout: %w", err))
	}
	if _, err := time.ParseDuration(d.RetryInterval); err != nil {
		errors = append(errors, fmt.Errorf("parsing retry interval: %w", err))
	}
	return errors
}
func (d *ssh) Connect() (transport.Connected, error) {
	sshConfig := &gossh.ClientConfig{
		Auth:    d.auth,
		Timeout: d.connectionTimeout,
		User:    d.user,
		HostKeyCallback: gossh.InsecureIgnoreHostKey(),
	}
	var connection *gossh.Client
	var err error
	start := time.Now()
	for time.Since(start) < d.retryTimeout {
		if connection, err = d.sshClientGetter("tcp", d.address, sshConfig); err == nil {
			return newConnected(d.address, connection), nil
		}
		time.Sleep(d.retryInterval)
	}
	return nil, err
}
func newConnected(address string, connection dialer) transport.Connected {
	return &sshConnected{
		client:   connection,
		address:  address,
		uuid:     uuid.NewRandom,
		listener: net.Listen,
	}
}
func (d *sshConnected) ForwardUnixSocket(path string) (string, error) {
	unixAddr, err := d.randomUnixSocket()
	if err != nil {
		return "", fmt.Errorf("generating random socket to listen: %w", err)
	}
	localSock, err := d.listener("unix", unixAddr.String())
	if err != nil {
		return "", fmt.Errorf("listening on address %q: %w", unixAddr, err)
	}
	path, err = extractPath(path)
	if err != nil {
		return "", fmt.Errorf("parsing path %q: %w", path, err)
	}
	go forwardConnection(localSock, d.client, path, "unix")
	return fmt.Sprintf("unix://%s", unixAddr.String()), nil
}
func handleClient(client, remote io.ReadWriteCloser) {
	defer func() {
		if err := client.Close(); err != nil {
			fmt.Printf("Failed closing client connection: %v\n", err)
		}
		if err := remote.Close(); err != nil {
			fmt.Printf("Closing remote: %v\n", err)
		}
	}()
	chDone := make(chan bool)
	go func() {
		if _, err := io.Copy(client, remote); err != nil {
			fmt.Printf("Error while copy remote->local: %s\n", err)
		}
		chDone <- true
	}()
	go func() {
		if _, err := io.Copy(remote, client); err != nil {
			fmt.Printf("Error while copy local->remote: %s\n", err)
		}
		chDone <- true
	}()
	<-chDone
}