ssh

package
v2.3.12 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSshFlags

func AddSshFlags(flags *pflag.FlagSet, sshConf *SshConfig)

func DialSshRemote

func DialSshRemote(ctx context.Context, conf *SshConfig, stopChan <-chan struct{}) (remote *ssh.Client, err error)

DialSshRemote https://github.com/golang/go/issues/21478

func ExposeLocalPortToRemote added in v2.3.10

func ExposeLocalPortToRemote(ctx context.Context, remoteSSHServer, remotePort, localPort netip.AddrPort) error

ExposeLocalPortToRemote remote forwarding port (on remote SSH server network) local service to be forwarded

func GetClient

func GetClient() (*client.Client, *command.DockerCli, error)

func GetKrb5Path

func GetKrb5Path() string

func JumpTo

func JumpTo(ctx context.Context, bClient *ssh.Client, to SshConfig, stopChan <-chan struct{}) (client *ssh.Client, err error)

func NewPrincipal

func NewPrincipal(name types.PrincipalName, realm string) principal

NewPrincipal returns a new principal

func PortMapUntil

func PortMapUntil(ctx context.Context, conf *SshConfig, remote, local netip.AddrPort) error

func PrintLine

func PrintLine(f func(...any), msg ...string)

func PullImage

func PullImage(ctx context.Context, platform *v1.Platform, cli *client.Client, dockerCli *command.DockerCli, img string, out io.Writer) error

PullImage image.RunPull(ctx, c, image.PullOptions{})

func RemoteRun

func RemoteRun(client *ssh.Client, cmd string, env map[string]string) (output []byte, errOut []byte, err error)

func SCPAndExec

func SCPAndExec(stdout, stderr io.Writer, client *ssh.Client, filename, to string, commands ...string) error

SCPAndExec copy file to remote and exec command

func SshJump

func SshJump(ctx context.Context, conf *SshConfig, flags *pflag.FlagSet, print bool) (path string, err error)

func SshJumpAndSetEnv

func SshJumpAndSetEnv(ctx context.Context, conf *SshConfig, flags *pflag.FlagSet, print bool) error

func TransferImage

func TransferImage(ctx context.Context, conf *SshConfig, imageSource, imageTarget string, out io.Writer) error

TransferImage 1) if not special ssh config, just pull image and tag and push 2) if special ssh config, pull image, tag image, save image and scp image to remote, load image and push

Types

type CCache

type CCache struct {
	Version          uint8
	Header           header
	DefaultPrincipal principal
	Credentials      []*Credential
	Path             string
}

CCache is the file credentials cache as define here: https://web.mit.edu/kerberos/krb5-latest/doc/formats/ccache_file_format.html

func LoadCCache

func LoadCCache(cpath string) (*CCache, error)

LoadCCache loads a credential cache file into a CCache type.

func NewV4CCache

func NewV4CCache() *CCache

NewV4CCache creates a new Version 4 CCache with no credentials in it

func (*CCache) AddCredential

func (c *CCache) AddCredential(cred *Credential)

AddCredential adds a credential to a CCache

func (*CCache) Contains

func (c *CCache) Contains(p types.PrincipalName) bool

Contains tests if the cache contains a credential for the provided server PrincipalName

func (*CCache) GetClientPrincipalName

func (c *CCache) GetClientPrincipalName() types.PrincipalName

GetClientPrincipalName returns a PrincipalName type for the client the credentials cache is for.

func (*CCache) GetClientRealm

func (c *CCache) GetClientRealm() string

GetClientRealm returns the reals of the client the credentials cache is for.

func (*CCache) GetEntries

func (c *CCache) GetEntries() []*Credential

GetEntries filters out configuration entries an returns a slice of credentials.

func (*CCache) GetEntry

func (c *CCache) GetEntry(p types.PrincipalName) (*Credential, bool)

GetEntry returns a specific credential for the PrincipalName provided.

func (*CCache) Marshal

func (c *CCache) Marshal() ([]byte, error)

Marshal a CCache type into a byte string

func (*CCache) SetDefaultPrincipal

func (c *CCache) SetDefaultPrincipal(d principal)

SetDefaultPrincipal sets the default principal for a CCache

func (*CCache) Unmarshal

func (c *CCache) Unmarshal(b []byte) error

Unmarshal a byte slice of credential cache data into CCache type.

type Credential

type Credential struct {
	Client       principal
	Server       principal
	Key          types.EncryptionKey
	AuthTime     time.Time
	StartTime    time.Time
	EndTime      time.Time
	RenewTill    time.Time
	IsSKey       bool
	TicketFlags  asn1.BitString
	Addresses    []types.HostAddress
	AuthData     []types.AuthorizationDataEntry
	Ticket       []byte
	SecondTicket []byte
}

Credential holds a Kerberos client's ccache credential information.

type Krb5ClientState

type Krb5ClientState int
const (
	ContextFlagREADY = 128
	/* initiator states */
	InitiatorStart Krb5ClientState = iota
	InitiatorRestart
	InitiatorWaitForMutal
	InitiatorReady
)

type Krb5InitiatorClient

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

func NewKrb5InitiatorClientWithCache

func NewKrb5InitiatorClientWithCache(krb5Conf, cacheFile string) (kcl Krb5InitiatorClient, err error)

func NewKrb5InitiatorClientWithKeytab

func NewKrb5InitiatorClientWithKeytab(username string, krb5Conf, keytabConf string) (kcl Krb5InitiatorClient, err error)

func NewKrb5InitiatorClientWithPassword

func NewKrb5InitiatorClientWithPassword(username, password, krb5Conf string) (kcl Krb5InitiatorClient, err error)

func (*Krb5InitiatorClient) DeleteSecContext

func (k *Krb5InitiatorClient) DeleteSecContext() error

func (*Krb5InitiatorClient) GetMIC

func (k *Krb5InitiatorClient) GetMIC(micFiled []byte) ([]byte, error)

func (*Krb5InitiatorClient) InitSecContext

func (k *Krb5InitiatorClient) InitSecContext(target string, token []byte, isGSSDelegCreds bool) ([]byte, bool, error)

type SshConfig

type SshConfig struct {
	Addr             string
	User             string
	Password         string
	Keyfile          string
	Jump             string
	ConfigAlias      string
	RemoteKubeconfig string
	// GSSAPI
	GSSAPIKeytabConf string
	GSSAPIPassword   string
	GSSAPICacheFile  string
}

func GetBastion

func GetBastion(name string, defaultValue SshConfig) SshConfig

func ParseSshFromRPC

func ParseSshFromRPC(sshJump *rpc.SshJump) *SshConfig

func (SshConfig) AliasRecursion

func (config SshConfig) AliasRecursion(ctx context.Context, stopChan <-chan struct{}) (client *ssh.Client, err error)

func (SshConfig) Clone

func (s SshConfig) Clone() SshConfig

func (SshConfig) Dial

func (config SshConfig) Dial(ctx context.Context, stopChan <-chan struct{}) (client *ssh.Client, err error)

func (SshConfig) GetAuth

func (config SshConfig) GetAuth() ([]ssh.AuthMethod, error)

func (*SshConfig) IsEmpty added in v2.2.21

func (config *SshConfig) IsEmpty() bool

func (SshConfig) JumpRecursion

func (config SshConfig) JumpRecursion(ctx context.Context, stopChan <-chan struct{}) (client *ssh.Client, err error)

func (*SshConfig) ToRPC

func (config *SshConfig) ToRPC() *rpc.SshJump

Jump to

Keyboard shortcuts

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