Add Option to Ignore SSH Config File (#1788)

This provides a new configuration option that will turn off the ssh
config parsing. It also removes the flag required to override the ssh
config values with internal json values
This commit is contained in:
Sylvie Crowe 2025-01-21 19:04:21 -08:00 committed by GitHub
parent 2155ec327d
commit 385d01148c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 16 deletions

View File

@ -309,9 +309,9 @@ declare global {
type ConnKeywords = {
"conn:wshenabled"?: boolean;
"conn:askbeforewshinstall"?: boolean;
"conn:overrideconfig"?: boolean;
"conn:wshpath"?: string;
"conn:shellpath"?: string;
"conn:ignoresshconfig"?: boolean;
"display:hidden"?: boolean;
"display:order"?: number;
"term:*"?: boolean;

View File

@ -699,10 +699,29 @@ func ConnectToClient(connCtx context.Context, opts *SSHOpts, currentClient *ssh.
if jumpNum > SshProxyJumpMaxDepth {
return nil, jumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: fmt.Errorf("ProxyJump %d exceeds Wave's max depth of %d", jumpNum, SshProxyJumpMaxDepth)}
}
// todo print final warning if logging gets turned off
sshConfigKeywords, err := findSshConfigKeywords(opts.SSHHost)
if err != nil {
return nil, debugInfo.JumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: err}
rawName := opts.String()
fullConfig := wconfig.GetWatcher().GetFullConfig()
internalSshConfigKeywords, ok := fullConfig.Connections[rawName]
if !ok {
internalSshConfigKeywords = wshrpc.ConnKeywords{}
}
var sshConfigKeywords *wshrpc.ConnKeywords
if utilfn.SafeDeref(internalSshConfigKeywords.ConnIgnoreSshConfig) {
var err error
sshConfigKeywords, err = findSshDefaults(opts.SSHHost)
if err != nil {
err = fmt.Errorf("cannot determine default config keywords: %w", err)
return nil, debugInfo.JumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: err}
}
} else {
var err error
sshConfigKeywords, err = findSshConfigKeywords(opts.SSHHost)
if err != nil {
err = fmt.Errorf("cannot determine config keywords: %w", err)
return nil, debugInfo.JumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: err}
}
}
parsedKeywords := &wshrpc.ConnKeywords{}
@ -713,19 +732,10 @@ func ConnectToClient(connCtx context.Context, opts *SSHOpts, currentClient *ssh.
parsedKeywords.SshPort = &opts.SSHPort
}
rawName := opts.String()
fullConfig := wconfig.GetWatcher().GetFullConfig()
internalSshConfigKeywords, ok := fullConfig.Connections[rawName]
if !ok {
internalSshConfigKeywords = wshrpc.ConnKeywords{}
}
// cascade order:
// ssh config -> (optional) internal config -> specified flag keywords -> parsed keywords
partialMerged := sshConfigKeywords
if internalSshConfigKeywords.ConnOverrideConfig {
partialMerged = mergeKeywords(partialMerged, &internalSshConfigKeywords)
}
partialMerged = mergeKeywords(partialMerged, &internalSshConfigKeywords)
partialMerged = mergeKeywords(partialMerged, connFlags)
sshKeywords := mergeKeywords(partialMerged, parsedKeywords)
@ -910,6 +920,31 @@ func findSshConfigKeywords(hostPattern string) (connKeywords *wshrpc.ConnKeyword
return sshKeywords, nil
}
func findSshDefaults(hostPattern string) (connKeywords *wshrpc.ConnKeywords, outErr error) {
sshKeywords := &wshrpc.ConnKeywords{}
userDetails, err := user.Current()
if err != nil {
return nil, err
}
sshKeywords.SshUser = &userDetails.Username
sshKeywords.SshHostName = &hostPattern
sshKeywords.SshPort = utilfn.Ptr(ssh_config.Default("Port"))
sshKeywords.SshIdentityFile = ssh_config.DefaultAll("IdentityFile", hostPattern, ssh_config.DefaultUserSettings) // use the sshconfig here. should be different later
sshKeywords.SshBatchMode = utilfn.Ptr(false)
sshKeywords.SshPubkeyAuthentication = utilfn.Ptr(true)
sshKeywords.SshPasswordAuthentication = utilfn.Ptr(true)
sshKeywords.SshKbdInteractiveAuthentication = utilfn.Ptr(true)
sshKeywords.SshPreferredAuthentications = strings.Split(ssh_config.Default("PreferredAuthentications"), ",")
sshKeywords.SshAddKeysToAgent = utilfn.Ptr(false)
sshKeywords.SshIdentitiesOnly = utilfn.Ptr(false)
sshKeywords.SshIdentityAgent = utilfn.Ptr(ssh_config.Default("IdentityAgent"))
sshKeywords.SshProxyJump = []string{}
sshKeywords.SshUserKnownHostsFile = strings.Fields(ssh_config.Default("UserKnownHostsFile"))
sshKeywords.SshGlobalKnownHostsFile = strings.Fields(ssh_config.Default("GlobalKnownHostsFile"))
return sshKeywords, nil
}
type SSHOpts struct {
SSHHost string `json:"sshhost"`
SSHUser string `json:"sshuser"`

View File

@ -484,9 +484,9 @@ type CommandRemoteWriteFileData struct {
type ConnKeywords struct {
ConnWshEnabled *bool `json:"conn:wshenabled,omitempty"`
ConnAskBeforeWshInstall *bool `json:"conn:askbeforewshinstall,omitempty"`
ConnOverrideConfig bool `json:"conn:overrideconfig,omitempty"`
ConnWshPath string `json:"conn:wshpath,omitempty"`
ConnShellPath string `json:"conn:shellpath,omitempty"`
ConnIgnoreSshConfig *bool `json:"conn:ignoresshconfig,omitempty"`
DisplayHidden *bool `json:"display:hidden,omitempty"`
DisplayOrder float32 `json:"display:order,omitempty"`