mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
fix: ignore the match statement in ssh config (#1155)
This change will skip over match statements in the ssh config without panicking. Note that this change still does not add match statement parsing--it merely makes it possible to continue parsing if the match keyword is present.
This commit is contained in:
parent
d0d9095c92
commit
94eb165346
2
go.mod
2
go.mod
@ -47,6 +47,6 @@ require (
|
|||||||
golang.org/x/net v0.29.0 // indirect
|
golang.org/x/net v0.29.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/kevinburke/ssh_config => github.com/wavetermdev/ssh_config v0.0.0-20240306041034-17e2087ebde2
|
replace github.com/kevinburke/ssh_config => github.com/wavetermdev/ssh_config v0.0.0-20241027232332-ed124367682d
|
||||||
|
|
||||||
replace github.com/creack/pty => github.com/photostorm/pty v1.1.19-0.20230903182454-31354506054b
|
replace github.com/creack/pty => github.com/photostorm/pty v1.1.19-0.20230903182454-31354506054b
|
||||||
|
4
go.sum
4
go.sum
@ -88,8 +88,8 @@ github.com/ubuntu/gowsl v0.0.0-20240906163211-049fd49bd93b h1:wFBKF5k5xbJQU8bYgc
|
|||||||
github.com/ubuntu/gowsl v0.0.0-20240906163211-049fd49bd93b/go.mod h1:N1CYNinssZru+ikvYTgVbVeSi21thHUTCoJ9xMvWe+s=
|
github.com/ubuntu/gowsl v0.0.0-20240906163211-049fd49bd93b/go.mod h1:N1CYNinssZru+ikvYTgVbVeSi21thHUTCoJ9xMvWe+s=
|
||||||
github.com/wavetermdev/htmltoken v0.1.0 h1:RMdA9zTfnYa5jRC4RRG3XNoV5NOP8EDxpaVPjuVz//Q=
|
github.com/wavetermdev/htmltoken v0.1.0 h1:RMdA9zTfnYa5jRC4RRG3XNoV5NOP8EDxpaVPjuVz//Q=
|
||||||
github.com/wavetermdev/htmltoken v0.1.0/go.mod h1:5FM0XV6zNYiNza2iaTcFGj+hnMtgqumFHO31Z8euquk=
|
github.com/wavetermdev/htmltoken v0.1.0/go.mod h1:5FM0XV6zNYiNza2iaTcFGj+hnMtgqumFHO31Z8euquk=
|
||||||
github.com/wavetermdev/ssh_config v0.0.0-20240306041034-17e2087ebde2 h1:onqZrJVap1sm15AiIGTfWzdr6cEF0KdtddeuuOVhzyY=
|
github.com/wavetermdev/ssh_config v0.0.0-20241027232332-ed124367682d h1:ArHaUBaiQWUqBzM2G/oLlm3Be0kwUMDt9vTNOWIfOd0=
|
||||||
github.com/wavetermdev/ssh_config v0.0.0-20240306041034-17e2087ebde2/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
|
github.com/wavetermdev/ssh_config v0.0.0-20241027232332-ed124367682d/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||||
|
@ -554,7 +554,7 @@ func resolveSshConfigPatterns(configFiles []string) ([]string, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, _ := ssh_config.Decode(fd)
|
cfg, _ := ssh_config.Decode(fd, true)
|
||||||
for _, host := range cfg.Hosts {
|
for _, host := range cfg.Hosts {
|
||||||
// for each host, find the first good alias
|
// for each host, find the first good alias
|
||||||
for _, hostPattern := range host.Patterns {
|
for _, hostPattern := range host.Patterns {
|
||||||
@ -620,7 +620,7 @@ func GetConnectionsFromConfig() ([]string, error) {
|
|||||||
localConfig := filepath.Join(home, ".ssh", "config")
|
localConfig := filepath.Join(home, ".ssh", "config")
|
||||||
systemConfig := filepath.Join("/etc", "ssh", "config")
|
systemConfig := filepath.Join("/etc", "ssh", "config")
|
||||||
sshConfigFiles := []string{localConfig, systemConfig}
|
sshConfigFiles := []string{localConfig, systemConfig}
|
||||||
ssh_config.ReloadConfigs()
|
remote.WaveSshConfigUserSettings().ReloadConfigs()
|
||||||
|
|
||||||
return resolveSshConfigPatterns(sshConfigFiles)
|
return resolveSshConfigPatterns(sshConfigFiles)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kevinburke/ssh_config"
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -339,14 +338,14 @@ func IsPowershell(shellPath string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NormalizeConfigPattern(pattern string) string {
|
func NormalizeConfigPattern(pattern string) string {
|
||||||
userName, err := ssh_config.GetStrict(pattern, "User")
|
userName, err := WaveSshConfigUserSettings().GetStrict(pattern, "User")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
localUser, err := user.Current()
|
localUser, err := user.Current()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userName = localUser.Username
|
userName = localUser.Username
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
port, err := ssh_config.GetStrict(pattern, "Port")
|
port, err := WaveSshConfigUserSettings().GetStrict(pattern, "Port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
port = "22"
|
port = "22"
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kevinburke/ssh_config"
|
"github.com/kevinburke/ssh_config"
|
||||||
@ -34,6 +35,17 @@ import (
|
|||||||
|
|
||||||
const SshProxyJumpMaxDepth = 10
|
const SshProxyJumpMaxDepth = 10
|
||||||
|
|
||||||
|
var waveSshConfigUserSettingsInternal *ssh_config.UserSettings
|
||||||
|
var configUserSettingsOnce = &sync.Once{}
|
||||||
|
|
||||||
|
func WaveSshConfigUserSettings() *ssh_config.UserSettings {
|
||||||
|
configUserSettingsOnce.Do(func() {
|
||||||
|
waveSshConfigUserSettingsInternal = ssh_config.DefaultUserSettings
|
||||||
|
waveSshConfigUserSettingsInternal.IgnoreMatchDirective = true
|
||||||
|
})
|
||||||
|
return waveSshConfigUserSettingsInternal
|
||||||
|
}
|
||||||
|
|
||||||
type UserInputCancelError struct {
|
type UserInputCancelError struct {
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
@ -724,54 +736,54 @@ func combineSshKeywords(opts *SSHOpts, configKeywords *SshKeywords) (*SshKeyword
|
|||||||
// but `var != "no"` will default to true
|
// but `var != "no"` will default to true
|
||||||
// when given unexpected strings
|
// when given unexpected strings
|
||||||
func findSshConfigKeywords(hostPattern string) (*SshKeywords, error) {
|
func findSshConfigKeywords(hostPattern string) (*SshKeywords, error) {
|
||||||
ssh_config.ReloadConfigs()
|
WaveSshConfigUserSettings().ReloadConfigs()
|
||||||
sshKeywords := &SshKeywords{}
|
sshKeywords := &SshKeywords{}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
userRaw, err := ssh_config.GetStrict(hostPattern, "User")
|
userRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "User")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.User = trimquotes.TryTrimQuotes(userRaw)
|
sshKeywords.User = trimquotes.TryTrimQuotes(userRaw)
|
||||||
|
|
||||||
hostNameRaw, err := ssh_config.GetStrict(hostPattern, "HostName")
|
hostNameRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "HostName")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.HostName = trimquotes.TryTrimQuotes(hostNameRaw)
|
sshKeywords.HostName = trimquotes.TryTrimQuotes(hostNameRaw)
|
||||||
|
|
||||||
portRaw, err := ssh_config.GetStrict(hostPattern, "Port")
|
portRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "Port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.Port = trimquotes.TryTrimQuotes(portRaw)
|
sshKeywords.Port = trimquotes.TryTrimQuotes(portRaw)
|
||||||
|
|
||||||
identityFileRaw := ssh_config.GetAll(hostPattern, "IdentityFile")
|
identityFileRaw := WaveSshConfigUserSettings().GetAll(hostPattern, "IdentityFile")
|
||||||
for i := 0; i < len(identityFileRaw); i++ {
|
for i := 0; i < len(identityFileRaw); i++ {
|
||||||
identityFileRaw[i] = trimquotes.TryTrimQuotes(identityFileRaw[i])
|
identityFileRaw[i] = trimquotes.TryTrimQuotes(identityFileRaw[i])
|
||||||
}
|
}
|
||||||
sshKeywords.IdentityFile = identityFileRaw
|
sshKeywords.IdentityFile = identityFileRaw
|
||||||
|
|
||||||
batchModeRaw, err := ssh_config.GetStrict(hostPattern, "BatchMode")
|
batchModeRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "BatchMode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.BatchMode = (strings.ToLower(trimquotes.TryTrimQuotes(batchModeRaw)) == "yes")
|
sshKeywords.BatchMode = (strings.ToLower(trimquotes.TryTrimQuotes(batchModeRaw)) == "yes")
|
||||||
|
|
||||||
// we currently do not support host-bound or unbound but will use yes when they are selected
|
// we currently do not support host-bound or unbound but will use yes when they are selected
|
||||||
pubkeyAuthenticationRaw, err := ssh_config.GetStrict(hostPattern, "PubkeyAuthentication")
|
pubkeyAuthenticationRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "PubkeyAuthentication")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.PubkeyAuthentication = (strings.ToLower(trimquotes.TryTrimQuotes(pubkeyAuthenticationRaw)) != "no")
|
sshKeywords.PubkeyAuthentication = (strings.ToLower(trimquotes.TryTrimQuotes(pubkeyAuthenticationRaw)) != "no")
|
||||||
|
|
||||||
passwordAuthenticationRaw, err := ssh_config.GetStrict(hostPattern, "PasswordAuthentication")
|
passwordAuthenticationRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "PasswordAuthentication")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.PasswordAuthentication = (strings.ToLower(trimquotes.TryTrimQuotes(passwordAuthenticationRaw)) != "no")
|
sshKeywords.PasswordAuthentication = (strings.ToLower(trimquotes.TryTrimQuotes(passwordAuthenticationRaw)) != "no")
|
||||||
|
|
||||||
kbdInteractiveAuthenticationRaw, err := ssh_config.GetStrict(hostPattern, "KbdInteractiveAuthentication")
|
kbdInteractiveAuthenticationRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "KbdInteractiveAuthentication")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -779,18 +791,18 @@ func findSshConfigKeywords(hostPattern string) (*SshKeywords, error) {
|
|||||||
|
|
||||||
// these are parsed as a single string and must be separated
|
// these are parsed as a single string and must be separated
|
||||||
// these are case sensitive in openssh so they are here too
|
// these are case sensitive in openssh so they are here too
|
||||||
preferredAuthenticationsRaw, err := ssh_config.GetStrict(hostPattern, "PreferredAuthentications")
|
preferredAuthenticationsRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "PreferredAuthentications")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.PreferredAuthentications = strings.Split(trimquotes.TryTrimQuotes(preferredAuthenticationsRaw), ",")
|
sshKeywords.PreferredAuthentications = strings.Split(trimquotes.TryTrimQuotes(preferredAuthenticationsRaw), ",")
|
||||||
addKeysToAgentRaw, err := ssh_config.GetStrict(hostPattern, "AddKeysToAgent")
|
addKeysToAgentRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "AddKeysToAgent")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshKeywords.AddKeysToAgent = (strings.ToLower(trimquotes.TryTrimQuotes(addKeysToAgentRaw)) == "yes")
|
sshKeywords.AddKeysToAgent = (strings.ToLower(trimquotes.TryTrimQuotes(addKeysToAgentRaw)) == "yes")
|
||||||
|
|
||||||
identityAgentRaw, err := ssh_config.GetStrict(hostPattern, "IdentityAgent")
|
identityAgentRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "IdentityAgent")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -815,7 +827,7 @@ func findSshConfigKeywords(hostPattern string) (*SshKeywords, error) {
|
|||||||
sshKeywords.IdentityAgent = agentPath
|
sshKeywords.IdentityAgent = agentPath
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyJumpRaw, err := ssh_config.GetStrict(hostPattern, "ProxyJump")
|
proxyJumpRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "ProxyJump")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -827,9 +839,9 @@ func findSshConfigKeywords(hostPattern string) (*SshKeywords, error) {
|
|||||||
}
|
}
|
||||||
sshKeywords.ProxyJump = append(sshKeywords.ProxyJump, proxyJumpName)
|
sshKeywords.ProxyJump = append(sshKeywords.ProxyJump, proxyJumpName)
|
||||||
}
|
}
|
||||||
rawUserKnownHostsFile, _ := ssh_config.GetStrict(hostPattern, "UserKnownHostsFile")
|
rawUserKnownHostsFile, _ := WaveSshConfigUserSettings().GetStrict(hostPattern, "UserKnownHostsFile")
|
||||||
sshKeywords.UserKnownHostsFile = strings.Fields(rawUserKnownHostsFile) // TODO - smarter splitting escaped spaces and quotes
|
sshKeywords.UserKnownHostsFile = strings.Fields(rawUserKnownHostsFile) // TODO - smarter splitting escaped spaces and quotes
|
||||||
rawGlobalKnownHostsFile, _ := ssh_config.GetStrict(hostPattern, "GlobalKnownHostsFile")
|
rawGlobalKnownHostsFile, _ := WaveSshConfigUserSettings().GetStrict(hostPattern, "GlobalKnownHostsFile")
|
||||||
sshKeywords.GlobalKnownHostsFile = strings.Fields(rawGlobalKnownHostsFile) // TODO - smarter splitting escaped spaces and quotes
|
sshKeywords.GlobalKnownHostsFile = strings.Fields(rawGlobalKnownHostsFile) // TODO - smarter splitting escaped spaces and quotes
|
||||||
|
|
||||||
return sshKeywords, nil
|
return sshKeywords, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user