session

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAWSConfig

func BuildAWSConfig(ctx context.Context, service string) (aws.Config, error)

func GenerateEphemeralSSHKey

func GenerateEphemeralSSHKey() (signer ssh.Signer, pubKeyAuthorizedFormat string, err error)

GenerateEphemeralSSHKey creates a throwaway Ed25519 key pair in memory. The returned signer is used directly for SSH authentication; the public key string (authorized_keys format) is what gets pushed via EC2 Instance Connect.

func GetEC2Password

func GetEC2Password(ctx context.Context, cfg aws.Config, instanceID, privateKeyPath string) (string, error)

GetEC2Password retrieves and decrypts the administrator password for a Windows EC2 instance. The privateKeyPath must be the path to the RSA private key (.pem) associated with the instance's key pair.

func HasVersionFlag

func HasVersionFlag(args []string) bool

HasVersionFlag checks if any of the arguments is -V (version query).

func InitializeClient

func InitializeClient()

func IsSSHCompatMode

func IsSSHCompatMode(args []string) bool

IsSSHCompatMode checks if the given os.Args indicate OpenSSH-compatible mode. This is true when the first argument after the program name starts with "-" (not a cobra subcommand) or when the binary is invoked via a symlink named "ssh".

func ParseHostPort

func ParseHostPort(target string, defaultUser string, defaultPort int) (user, host string, port int, err error)

ParseHostPort parses a target string in the format "[user@]host[:port]" and returns the user, host, and port components. If no user is specified, defaultUser is used. If no port is specified, defaultPort is used.

func ProxyHttpClient

func ProxyHttpClient() *awshttp.BuildableClient

BuildAWSConfig builds the AWS Config for the given service

func RunSSHCompat

func RunSSHCompat(osArgs []string) error

RunSSHCompat is the entry point for OpenSSH-compatible mode. It parses OpenSSH-style arguments, reads SSH config, merges settings, and establishes an SSH-over-SSM session.

func SSOLogout added in v1.2.0

func SSOLogout(ctx context.Context, profileName string) error

SSOLogout removes the cached SSO token for the given profile.

func SendInstanceConnectKey

func SendInstanceConnectKey(ctx context.Context, cfg aws.Config, instanceID, user, pubKeyContent string) error

SendInstanceConnectKey pushes a temporary SSH public key to an EC2 instance via EC2 Instance Connect. The key is valid for 60 seconds, which is enough time to establish a connection.

func StartEC2InstanceConnect

func StartEC2InstanceConnect(target string) error

StartEC2InstanceConnect starts a SSH session using EC2 Instance Connect.

func StartSSHDirectSession

func StartSSHDirectSession(target string) error

StartSSHDirectSession starts a direct SSH session to the target EC2 instance via AWS SSM without requiring an external SSH client.

func StartSSHSession

func StartSSHSession(target string) error

StartSSHSession starts a SSH session using AWS SSM.

func StartSSMPortForwarder

func StartSSMPortForwarder(target string, localPort int, remotePort int, remoteHost string) error

StartSSMPortForwarder starts a port forwarding session using AWS SSM. target is the EC2 instance to tunnel through (resolved via ID, alias, tag, IP, or DNS). localPort is the local listening port (0 = random). remotePort is the port on the instance (or remoteHost) to connect to. remoteHost is optional; if specified, the tunnel forwards to that host instead of the instance.

func StartSSMShell

func StartSSMShell(target string) error

StartSSMShell starts a shell session using AWS SSM

Types

type BrowserOpenError

type BrowserOpenError struct {
	Err error
}

BrowserOpenError Failed to open a browser

func (BrowserOpenError) Error

func (e BrowserOpenError) Error() string

func (BrowserOpenError) Unwrap

func (e BrowserOpenError) Unwrap() error

type CacheFileCreationError

type CacheFileCreationError struct {
	Err           error
	Reason        string
	CacheFilePath string
}

func (CacheFileCreationError) Error

func (e CacheFileCreationError) Error() string

func (CacheFileCreationError) Unwrap

func (e CacheFileCreationError) Unwrap() error

type CacheFilepathGenerationError

type CacheFilepathGenerationError struct {
	ProfileName        string
	ProfileSSOStartURL string
	Err                error
}

CacheFilepathGenerationError failed to generate a valid filepath for the given SSO start URL

func NewCacheFilepathGenerationError

func NewCacheFilepathGenerationError(ProfileName string, ProfileSSOStartURL string, err error) CacheFilepathGenerationError

func (CacheFilepathGenerationError) Error

func (CacheFilepathGenerationError) Unwrap

type ConfigFileLoadError

type ConfigFileLoadError struct {
	Err error
}

ConfigFileLoadError failed to load default config

func (ConfigFileLoadError) Error

func (e ConfigFileLoadError) Error() string

func (ConfigFileLoadError) Unwrap

func (e ConfigFileLoadError) Unwrap() error

type CredCacheError

type CredCacheError struct {
	Err error
}

CredCacheError failed to retrieve creds from ssoCredsProvider

func (CredCacheError) Error

func (e CredCacheError) Error() string

func (CredCacheError) Unwrap

func (e CredCacheError) Unwrap() error

type GetCallerIdError

type GetCallerIdError struct {
	Err error
}

GetCallerIdError stsClient.GetCallerIdentity failed

func (GetCallerIdError) Error

func (e GetCallerIdError) Error() string

func (GetCallerIdError) Unwrap

func (e GetCallerIdError) Unwrap() error

type IdentityResult

type IdentityResult struct {
	Identity *sts.GetCallerIdentityOutput
	Error    error
}

IdentityResult contains the result of stsClient.GetCallerIdentity. If Identity is nul and error is not nul that can indicate that the credentials might be invalid.

type LoadingConfigFileError

type LoadingConfigFileError struct {
	ConfigFilePath string
	Err            error
}

LoadingConfigFileError failed to load the config file

func NewLoadingConfigFileError

func NewLoadingConfigFileError(configFilePath string, err error) LoadingConfigFileError

func (LoadingConfigFileError) Error

func (e LoadingConfigFileError) Error() string

func (LoadingConfigFileError) Unwrap

func (e LoadingConfigFileError) Unwrap() error

type MissingProfileError

type MissingProfileError struct {
	ProfileName    string
	ConfigFilePath string
	Err            error
}

MissingProfileError failed to find the requested profile

func NewMissingProfileError

func NewMissingProfileError(profileName string, configFilePath string, err error) MissingProfileError

func (MissingProfileError) Error

func (e MissingProfileError) Error() string

func (MissingProfileError) Unwrap

func (e MissingProfileError) Unwrap() error

type OsUserError

type OsUserError struct {
	Err error
}

OsUserError failed to retrieve user from osUser

func (OsUserError) Error

func (e OsUserError) Error() string

func (OsUserError) Unwrap

func (e OsUserError) Unwrap() error

type ProfileValidationError

type ProfileValidationError struct {
	ProfileName    string
	ConfigFilePath string
	FieldName      string
	CurrentValue   string
	ExpectedValue  string
}

ProfileValidationError error validating the given AWS profile. A required value may be missing.

func NewProfileValidationError

func NewProfileValidationError(profileName string, configFilePath string, fieldName string, currentValue string, expectedValue string) ProfileValidationError

func (ProfileValidationError) Error

func (e ProfileValidationError) Error() string

type SSHArgs

type SSHArgs struct {
	User           string            // -l flag or user@ prefix
	Host           string            // positional destination (after extracting user@)
	Port           int               // -p flag (default 22)
	IdentityFile   string            // -i flag
	ConfigFile     string            // -F flag
	DisablePTY     bool              // -T flag
	Options        map[string]string // -o key=value pairs
	Command        string            // trailing command after destination (joined)
	Verbose        int               // -v count (1, 2, or 3)
	NoCommand      bool              // -N flag
	DynamicForward string            // -D flag (ignored, stored for compat)
	ForwardAgent   bool              // -A flag
	ExitOnForward  bool              // -f flag (background, ignored)
	ForcePTY       bool              // -t flag
	Subsystem      bool              // -s flag
}

SSHArgs holds the parsed OpenSSH-compatible command-line arguments.

func ParseSSHArgs

func ParseSSHArgs(args []string) (*SSHArgs, error)

ParseSSHArgs parses OpenSSH-compatible command-line arguments. It handles the subset of flags that VSCode Remote SSH uses.

func (*SSHArgs) GetOption

func (a *SSHArgs) GetOption(key string) (string, bool)

GetOption returns the value of an SSH option (case-insensitive key match).

type SSHHostConfig

type SSHHostConfig struct {
	HostName            string
	User                string
	Port                string
	IdentityFile        string
	StrictHostKeyCheck  string
	UserKnownHostsFile  string
	ConnectTimeout      string
	ServerAliveInterval string
	ServerAliveCountMax string
}

SSHHostConfig holds the resolved configuration for a single SSH host.

func ParseSSHConfig

func ParseSSHConfig(configFile, host string) *SSHHostConfig

ParseSSHConfig reads an SSH config file and returns the resolved settings for the given host. It processes Host directives and applies matching blocks in order (first match wins for each directive, per OpenSSH semantics).

type SSOLoginInput

type SSOLoginInput struct {
	// ProfileName name of the profile in ~/.aws/config. [profile <ProfileName>]
	ProfileName string

	// LoginTimeout max time to wait for user to complete the SSO OIDC URL flow. This should be > 60 seconds. Default value is 90 seconds
	LoginTimeout time.Duration

	// Headed if true a browser will be opened with the URL for the SSO OIDC flow. You will have the [LoginTimeout] to
	// complete the flow in the browser.
	Headed bool

	// ForceLogin if true forces a new SSO OIDC flow even if the cached creds are still valid.
	ForceLogin bool

	// URLWriter where to write the auth URL in headless mode; defaults to os.Stderr if nil
	URLWriter io.Writer
}

type SSOLoginOutput

type SSOLoginOutput struct {
	Credentials      *aws.Credentials
	CredentialsCache *aws.CredentialsCache
	IdentityResult   *IdentityResult
}

func SSOLogin

func SSOLogin(ctx context.Context, params *SSOLoginInput) (*SSOLoginOutput, error)

Login runs through the AWS CLI login flow if there isn't a ~/.aws/sso/cache file with valid creds. If ForceLogin is true then the login flow will always be triggered even if the cache is valid

type SSONotLoggedInError added in v1.2.0

type SSONotLoggedInError struct {
	ProfileName string
}

SSONotLoggedInError is returned when trying to logout but no cached token exists

func (SSONotLoggedInError) Error added in v1.2.0

func (e SSONotLoggedInError) Error() string

type SsoOidcClientError

type SsoOidcClientError struct {
	Err error
}

SsoOidcClientError Failed to register ssoOidcClient

func (SsoOidcClientError) Error

func (e SsoOidcClientError) Error() string

func (SsoOidcClientError) Unwrap

func (e SsoOidcClientError) Unwrap() error

type SsoOidcTokenCreationError

type SsoOidcTokenCreationError struct {
	Err error
}

SsoOidcTokenCreationError failed to retrieve user from osUser

func (SsoOidcTokenCreationError) Error

func (SsoOidcTokenCreationError) Unwrap

func (e SsoOidcTokenCreationError) Unwrap() error

type StartDeviceAuthorizationError

type StartDeviceAuthorizationError struct {
	Err error
}

StartDeviceAuthorizationError Failed to startDeviceAuthorization

func (StartDeviceAuthorizationError) Error

func (StartDeviceAuthorizationError) Unwrap

Jump to

Keyboard shortcuts

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