Documentation
¶
Index ¶
- Constants
- func MapSSHPermitToSocks(sshFlags []string) (domains []string, err error)
- func NewListenerFromChannel(parent ssh.Conn, nc <-chan ssh.NewChannel, promMetrics *promMetrics) net.Listener
- func ParseSSHVersion(version string) (int, int, error)
- func RequireSSHVersionAbove9_2(major, minor int) error
- func ToNetConn(parent ssh.Conn, ch ssh.Channel, l *listener) net.Conn
- type Client
- type Config
- type KeyManager
- type LoggerWriterAdapter
- type PDCStatus
- type PermitRemoteOpen
Constants ¶
const ( // SSHKeySize is the size of the SSH key. SSHKeySize = 4096 KnownHostsFile = "grafana_pdc_known_hosts" )
const ( // The exit code sent by the pdc server when the connection limit is reached. ConnectionLimitReachedCode = 254 ConnectionAlreadyExistsCode = 253 // String returned from PDC when the PDC agent successfully connects SuccessfulConnectionResponse = "This is Grafana Private Datasource Connect!" )
Variables ¶
This section is empty.
Functions ¶
func MapSSHPermitToSocks ¶ added in v0.0.58
MapSSHPermitToSocks maps sshFlags for PermitRemoteOpen to -domains
func NewListenerFromChannel ¶ added in v0.0.58
func NewListenerFromChannel(parent ssh.Conn, nc <-chan ssh.NewChannel, promMetrics *promMetrics) net.Listener
NewListenerFromChannel creates a net.Listener that listens for new requests on an ssh channel and converts the request to a net.Conn. The connection that received the channel is required for implementing the net.Conn interface.
func RequireSSHVersionAbove9_2 ¶ added in v0.0.24
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) Collect ¶ added in v0.0.33
func (s *Client) Collect(ch chan<- prometheus.Metric)
func (*Client) Describe ¶ added in v0.0.33
func (s *Client) Describe(ch chan<- *prometheus.Desc)
func (*Client) SSHFlagsFromConfig ¶ added in v0.0.6
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 string
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
// MetricsAddr is the port to expose metrics on
MetricsAddr string
ParseMetrics bool
// Connections is the number of connections to open
Connections int
// Used for local development.
// DevPort is the port number for the PDC gateway
DevPort int
// Use Go-based SSH instead of OpenSSH
GoSSH bool
PermitDomains []string
ConnectionTimeout time.Duration
}
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 (*Config) RegisterFlags ¶ added in v0.0.6
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
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.
type LoggerWriterAdapter ¶ added in v0.0.40
type LoggerWriterAdapter struct {
// contains filtered or unexported fields
}
Wraps a logger, implements io.Writer and writes to the logger. If successfulConnectionCallback is not nil, it will be called when the adapter sees the SuccessfulConnectionResponse from the server.
func NewLoggerWriterAdapter ¶ added in v0.0.40
func NewLoggerWriterAdapter(logger log.Logger, level string, parser *logMetricsParser, connCB func()) LoggerWriterAdapter
type PermitRemoteOpen ¶ added in v0.0.58
type PermitRemoteOpen struct {
Domains []string
}
func (*PermitRemoteOpen) Allow ¶ added in v0.0.58
Allow socks5.WithRule doesn't allow multiple rules, so we need to combine our rules here. 1. We only allow `CONNECT` commands, not `BIND` or `ASSOCIATE`. 2. We support domain filtering via the new -permit-domains flag. We make a best effort to support `-ssh-flag='-o PermitRemoteOpen=mysql.example.com:3306` style as well.