Skip to content

Commit 385d011

Browse files
authored
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
1 parent 2155ec3 commit 385d011

3 files changed

Lines changed: 51 additions & 16 deletions

File tree

frontend/types/gotypes.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ declare global {
309309
type ConnKeywords = {
310310
"conn:wshenabled"?: boolean;
311311
"conn:askbeforewshinstall"?: boolean;
312-
"conn:overrideconfig"?: boolean;
313312
"conn:wshpath"?: string;
314313
"conn:shellpath"?: string;
314+
"conn:ignoresshconfig"?: boolean;
315315
"display:hidden"?: boolean;
316316
"display:order"?: number;
317317
"term:*"?: boolean;

pkg/remote/sshclient.go

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,29 @@ func ConnectToClient(connCtx context.Context, opts *SSHOpts, currentClient *ssh.
699699
if jumpNum > SshProxyJumpMaxDepth {
700700
return nil, jumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: fmt.Errorf("ProxyJump %d exceeds Wave's max depth of %d", jumpNum, SshProxyJumpMaxDepth)}
701701
}
702-
// todo print final warning if logging gets turned off
703-
sshConfigKeywords, err := findSshConfigKeywords(opts.SSHHost)
704-
if err != nil {
705-
return nil, debugInfo.JumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: err}
702+
703+
rawName := opts.String()
704+
fullConfig := wconfig.GetWatcher().GetFullConfig()
705+
internalSshConfigKeywords, ok := fullConfig.Connections[rawName]
706+
if !ok {
707+
internalSshConfigKeywords = wshrpc.ConnKeywords{}
708+
}
709+
710+
var sshConfigKeywords *wshrpc.ConnKeywords
711+
if utilfn.SafeDeref(internalSshConfigKeywords.ConnIgnoreSshConfig) {
712+
var err error
713+
sshConfigKeywords, err = findSshDefaults(opts.SSHHost)
714+
if err != nil {
715+
err = fmt.Errorf("cannot determine default config keywords: %w", err)
716+
return nil, debugInfo.JumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: err}
717+
}
718+
} else {
719+
var err error
720+
sshConfigKeywords, err = findSshConfigKeywords(opts.SSHHost)
721+
if err != nil {
722+
err = fmt.Errorf("cannot determine config keywords: %w", err)
723+
return nil, debugInfo.JumpNum, ConnectionError{ConnectionDebugInfo: debugInfo, Err: err}
724+
}
706725
}
707726

708727
parsedKeywords := &wshrpc.ConnKeywords{}
@@ -713,19 +732,10 @@ func ConnectToClient(connCtx context.Context, opts *SSHOpts, currentClient *ssh.
713732
parsedKeywords.SshPort = &opts.SSHPort
714733
}
715734

716-
rawName := opts.String()
717-
fullConfig := wconfig.GetWatcher().GetFullConfig()
718-
internalSshConfigKeywords, ok := fullConfig.Connections[rawName]
719-
if !ok {
720-
internalSshConfigKeywords = wshrpc.ConnKeywords{}
721-
}
722-
723735
// cascade order:
724736
// ssh config -> (optional) internal config -> specified flag keywords -> parsed keywords
725737
partialMerged := sshConfigKeywords
726-
if internalSshConfigKeywords.ConnOverrideConfig {
727-
partialMerged = mergeKeywords(partialMerged, &internalSshConfigKeywords)
728-
}
738+
partialMerged = mergeKeywords(partialMerged, &internalSshConfigKeywords)
729739
partialMerged = mergeKeywords(partialMerged, connFlags)
730740
sshKeywords := mergeKeywords(partialMerged, parsedKeywords)
731741

@@ -910,6 +920,31 @@ func findSshConfigKeywords(hostPattern string) (connKeywords *wshrpc.ConnKeyword
910920
return sshKeywords, nil
911921
}
912922

923+
func findSshDefaults(hostPattern string) (connKeywords *wshrpc.ConnKeywords, outErr error) {
924+
sshKeywords := &wshrpc.ConnKeywords{}
925+
926+
userDetails, err := user.Current()
927+
if err != nil {
928+
return nil, err
929+
}
930+
sshKeywords.SshUser = &userDetails.Username
931+
sshKeywords.SshHostName = &hostPattern
932+
sshKeywords.SshPort = utilfn.Ptr(ssh_config.Default("Port"))
933+
sshKeywords.SshIdentityFile = ssh_config.DefaultAll("IdentityFile", hostPattern, ssh_config.DefaultUserSettings) // use the sshconfig here. should be different later
934+
sshKeywords.SshBatchMode = utilfn.Ptr(false)
935+
sshKeywords.SshPubkeyAuthentication = utilfn.Ptr(true)
936+
sshKeywords.SshPasswordAuthentication = utilfn.Ptr(true)
937+
sshKeywords.SshKbdInteractiveAuthentication = utilfn.Ptr(true)
938+
sshKeywords.SshPreferredAuthentications = strings.Split(ssh_config.Default("PreferredAuthentications"), ",")
939+
sshKeywords.SshAddKeysToAgent = utilfn.Ptr(false)
940+
sshKeywords.SshIdentitiesOnly = utilfn.Ptr(false)
941+
sshKeywords.SshIdentityAgent = utilfn.Ptr(ssh_config.Default("IdentityAgent"))
942+
sshKeywords.SshProxyJump = []string{}
943+
sshKeywords.SshUserKnownHostsFile = strings.Fields(ssh_config.Default("UserKnownHostsFile"))
944+
sshKeywords.SshGlobalKnownHostsFile = strings.Fields(ssh_config.Default("GlobalKnownHostsFile"))
945+
return sshKeywords, nil
946+
}
947+
913948
type SSHOpts struct {
914949
SSHHost string `json:"sshhost"`
915950
SSHUser string `json:"sshuser"`

pkg/wshrpc/wshrpctypes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ type CommandRemoteWriteFileData struct {
484484
type ConnKeywords struct {
485485
ConnWshEnabled *bool `json:"conn:wshenabled,omitempty"`
486486
ConnAskBeforeWshInstall *bool `json:"conn:askbeforewshinstall,omitempty"`
487-
ConnOverrideConfig bool `json:"conn:overrideconfig,omitempty"`
488487
ConnWshPath string `json:"conn:wshpath,omitempty"`
489488
ConnShellPath string `json:"conn:shellpath,omitempty"`
489+
ConnIgnoreSshConfig *bool `json:"conn:ignoresshconfig,omitempty"`
490490

491491
DisplayHidden *bool `json:"display:hidden,omitempty"`
492492
DisplayOrder float32 `json:"display:order,omitempty"`

0 commit comments

Comments
 (0)