ssh

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SSHKeySize is the size of the SSH key.
	SSHKeySize     = 4096
	KnownHostsFile = "grafana_pdc_known_hosts"
)
View Source
const (
	// The exit code sent by the pdc server when the connection limit is reached.
	ConnectionLimitReachedCode  = 254
	ConnectionAlreadyExistsCode = 253

	RenewCertInterval = 5 * time.Minute
)

Variables

This section is empty.

Functions

func ParseSSHVersion added in v0.0.24

func ParseSSHVersion(version string) (int, int, error)

func RequireSSHVersionAbove9_2 added in v0.0.24

func RequireSSHVersionAbove9_2(major, minor int) error

Types

type Client added in v0.0.6

type Client struct {
	*services.BasicService

	SSHCmd string // SSH command to run, defaults to "ssh". Require for testing.
	// contains filtered or unexported fields
}

Client is a client for ssh. It configures and runs ssh commands

func NewClient

func NewClient(cfg *Config, logger log.Logger, km *KeyManager) *Client

NewClient returns a new SSH client in an idle state

func (*Client) SSHFlagsFromConfig added in v0.0.6

func (s *Client) SSHFlagsFromConfig() ([]string, error)

SSHFlagsFromConfig generates the array of flags to pass to the ssh command. It does not stop default flags from being overidden, but only the first instance of `-o` flags are used.

type Config

type Config struct {
	Args []string // deprecated

	KeyFile           string
	SSHFlags          []string // Additional flags to be passed to ssh(1). e.g. --ssh-flag="-vvv" --ssh-flag="-L 80:localhost:80"
	Port              int
	LogLevel          int
	PDC               pdc.Config
	LegacyMode        bool
	SkipSSHValidation bool
	// ForceKeyFileOverwrite forces a new ssh key pair to be generated.
	ForceKeyFileOverwrite bool
	// CertExpiryWindow is the time before the certificate expires to renew it.
	CertExpiryWindow time.Duration
	// CertCheckCertExpiryPeriod is how often to check that the current certificate
	// is valid and regenerate it if necessary.
	CertCheckCertExpiryPeriod time.Duration
	URL                       *url.URL
}

Config represents all configurable properties of the ssh package.

func DefaultConfig added in v0.0.6

func DefaultConfig() *Config

DefaultConfig returns a Config with some sensible defaults set

func (Config) KeyFileDir added in v0.0.6

func (cfg Config) KeyFileDir() string

func (*Config) RegisterFlags added in v0.0.6

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

type KeyManager added in v0.0.6

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

TODO KeyManager implements KeyManager. If needed, it gets new certificates signed by the PDC API.

If the service starts successfully, then the key and cert files will exist. It will attempt to reuse existing keys and certs if they exist.

func NewKeyManager added in v0.0.6

func NewKeyManager(cfg *Config, logger log.Logger, client pdc.Client) *KeyManager

NewKeyManager returns a new KeyManager in an idle state

func (*KeyManager) CreateKeys added in v0.0.6

func (km *KeyManager) CreateKeys(ctx context.Context, forceNewKeys bool) error

CreateKeys checks that the SSH public key, private key, certificate and known_hosts files for existence and validity, and generates new ones if required.

func (*KeyManager) Start added in v0.0.26

func (km *KeyManager) Start(ctx context.Context) error

Start ensures valid keys and certs exist, and optionally starts a background certificate refresh goroutine.

Jump to

Keyboard shortcuts

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