Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to Ignore SSH Config File #1788

Merged
merged 8 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
63 changes: 49 additions & 14 deletions pkg/remote/sshclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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)

Expand Down Expand Up @@ -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 = strings.Split(ssh_config.Default("ProxyJump"), ",")
sshKeywords.SshUserKnownHostsFile = strings.Fields(ssh_config.Default("UserKnownHostsFile"))
sshKeywords.SshGlobalKnownHostsFile = strings.Fields(ssh_config.Default("GlobalKnownHostsFile"))
return sshKeywords, nil
oneirocosm marked this conversation as resolved.
Show resolved Hide resolved
}

type SSHOpts struct {
SSHHost string `json:"sshhost"`
SSHUser string `json:"sshuser"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/wshrpc/wshrpctypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Loading