ssh

package
v1.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthAnswered = errors.New("interactive auth has already been answered")

ErrAuthAnswered is returned when an auth that already has a response is answered again, say from a second browser tab.

Functions

func CreateDirectorySSH

func CreateDirectorySSH(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, remotePath string) error

Creates remotePath on the host, including any missing parent directories, and does nothing if it is already there.

func DownloadFileFromSCP

func DownloadFileFromSCP(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, remotePath string, localPath string) error

Copies a single remote file to localPath over SSH

func RunSSHCommand

func RunSSHCommand(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, command, target string) (string, string, error)

runSSHCommand runs one command on the host and waits for it to finish, returning what it wrote to stdout and to stderr.

Both streams are returned whether the command succeeded or not: what a failing command printed is usually what explains it, and a caller that reads the output — the job id sbatch announces, say — still wants to see what came back. Whatever went to stderr is folded into the error as well, so a caller that only checks err is no worse off than before. The streams are returned as the command wrote them, trailing newline included; a caller parsing them should trim.

func ShellQuote

func ShellQuote(s string) string

ShellQuote wraps s for the remote login shell, which is what runs the scp command line. A path is user supplied, so it cannot be interpolated bare.

func UploadFileToSCP

func UploadFileToSCP(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, localPath string, remotePath string) error

Uploads a single local file to a remote endpoint

Types

type Challenger

type Challenger interface {
	Challenge(ctx context.Context, name, instruction string, prompts []Prompt) ([]string, error)
}

type FileMetadata

type FileMetadata struct {
	Path string
	Size int64
	Mode os.FileMode
}

func GetSCPFileMetadata

func GetSCPFileMetadata(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, remotePath string) (*FileMetadata, error)

Reads the mode, size and name a remote scp announces for a single remote file, without transferring its contents.

type GlobalSSHContext

type GlobalSSHContext struct {
	InteractiveAuthStore *SSHInteractiveAuthStore
	ConnectionPool       *SSHConnectionPool
}

func NewGlobalSSHContext

func NewGlobalSSHContext() *GlobalSSHContext

type Prompt

type Prompt struct {
	Text string `json:"text"`
	Echo bool   `json:"echo"` // false => secret (password/OTP), render masked
}

type SSHConnectionPool

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

SSHConnectionPool shares one authenticated connection between every caller dialing with the same config. Besides saving handshakes, this keeps an interactive login from asking the user for a password or OTP once per command.

func (*SSHConnectionPool) Close

func (p *SSHConnectionPool) Close()

Close closes every pooled connection, borrowed or not.

type SSHDialConfig

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

func NewSSHDialConfig

func NewSSHDialConfig(host string, port int, sshUsername string, cred credmodel.SSHCredential, userId string) SSHDialConfig

type SSHInteractiveAuth

type SSHInteractiveAuth struct {
	AuthId    string
	CreatedAt time.Time
	// contains filtered or unexported fields
}

func NewSSHInteractiveAuth

func NewSSHInteractiveAuth(authId string, dialConfig SSHDialConfig) *SSHInteractiveAuth

func (*SSHInteractiveAuth) Answered

func (s *SSHInteractiveAuth) Answered() bool

func (*SSHInteractiveAuth) Banner

func (s *SSHInteractiveAuth) Banner() string

Banner is the text the server sent before login ("NCSA Delta System ..."), if any.

func (*SSHInteractiveAuth) Challenge

func (s *SSHInteractiveAuth) Challenge(ctx context.Context, name, instruction string, prompts []Prompt) ([]string, error)

func (*SSHInteractiveAuth) Name

func (s *SSHInteractiveAuth) Name() string

func (*SSHInteractiveAuth) Read

func (s *SSHInteractiveAuth) Read() ([]Prompt, string)

func (*SSHInteractiveAuth) SetResponse

func (s *SSHInteractiveAuth) SetResponse(response []string, err error) error

Should be set from the websocket server. Only the first call wins: closing authWaitSignal twice would panic.

func (*SSHInteractiveAuth) Target

func (s *SSHInteractiveAuth) Target() (host string, port int, loginUser, credentialID string)

type SSHInteractiveAuthStore

type SSHInteractiveAuthStore struct {
	// List of interactive SSH auths keyed by user ID, then by auth ID
	Auths map[string]map[string]*SSHInteractiveAuth

	// User ID mapping to subscriber channels
	SubscriberQueue map[string]chan struct{}
	// contains filtered or unexported fields
}

func (*SSHInteractiveAuthStore) AddAuth

func (store *SSHInteractiveAuthStore) AddAuth(auth *SSHInteractiveAuth)

func (*SSHInteractiveAuthStore) GetAuth

func (store *SSHInteractiveAuthStore) GetAuth(userId, authId string) (*SSHInteractiveAuth, bool)

func (*SSHInteractiveAuthStore) ListAuthsForUser

func (store *SSHInteractiveAuthStore) ListAuthsForUser(userId string) []*SSHInteractiveAuth

func (*SSHInteractiveAuthStore) NextAuthForUser

func (store *SSHInteractiveAuthStore) NextAuthForUser(userId string) (*SSHInteractiveAuth, <-chan struct{})

This is for retrieving the earliest created interactive auth for a user. It only returns auths that have not been answered yet, or nil if there are none. The returned channel closes the next time the user's auths are added or removed. Both are taken under one lock, so a change right after the call is never missed.

func (*SSHInteractiveAuthStore) RemoveAuth

func (store *SSHInteractiveAuthStore) RemoveAuth(userId, authId string)

Jump to

Keyboard shortcuts

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