diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2021-10-15 13:20:48 +0300 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2021-10-19 19:02:57 +0300 |
| commit | 10314cef906fd9b73e003be69c2f6b7b3d66570c (patch) | |
| tree | 03e8b96ad97d3382d439725166f83c774dc999a4 /internal/ssh | |
| parent | b27fc108ecd6eead5c97cf6e894bf8d639fff75c (diff) | |
Can configure DTail client not to mess with ~/.ssh/known_hosts via env var - this is useful for running unit and integration tests in jenkins
Diffstat (limited to 'internal/ssh')
| -rw-r--r-- | internal/ssh/client/authmethods.go | 9 | ||||
| -rw-r--r-- | internal/ssh/client/knownhostscallback.go | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/internal/ssh/client/authmethods.go b/internal/ssh/client/authmethods.go index ced1fb9..089a66a 100644 --- a/internal/ssh/client/authmethods.go +++ b/internal/ssh/client/authmethods.go @@ -35,8 +35,7 @@ func initKnownHostsAuthMethods(trustAllHosts bool, throttleCh chan struct{}, if err != nil { dlog.Common.FatalPanic(knownHostsPath, err) } - dlog.Common.Debug("initKnownHostsAuthMethods", "Added known hosts file path", - knownHostsPath) + dlog.Common.Debug("initKnownHostsAuthMethods", "Added known hosts file path", knownHostsPath) if config.Common.ExperimentalFeaturesEnable { sshAuthMethods = append(sshAuthMethods, gossh.Password("experimental feature test")) dlog.Common.Debug("initKnownHostsAuthMethods", "Added experimental method to list of auth methods") @@ -88,7 +87,11 @@ func initKnownHostsAuthMethods(trustAllHosts bool, throttleCh chan struct{}, } dlog.Common.Debug("initKnownHostsAuthMethods", "Unable to use private key", privateKeyPath, err) - dlog.Common.FatalPanic("Unable to find private SSH key information") + + // This is only a panic when we expect to do something about it. + if !config.Client.SSHDontAddHostsToKnownHostsFile { + dlog.Common.FatalPanic("Unable to find private SSH key information") + } // Never reach this point. return sshAuthMethods, knownHostsCallback diff --git a/internal/ssh/client/knownhostscallback.go b/internal/ssh/client/knownhostscallback.go index 65a590a..2aa0168 100644 --- a/internal/ssh/client/knownhostscallback.go +++ b/internal/ssh/client/knownhostscallback.go @@ -10,6 +10,7 @@ import ( "sync" "time" + "github.com/mimecast/dtail/internal/config" "github.com/mimecast/dtail/internal/io/dlog" "github.com/mimecast/dtail/internal/io/prompt" @@ -214,6 +215,12 @@ func (c KnownHostsCallback) promptAddHosts(hosts []unknownHost) { func (c KnownHostsCallback) trustHosts(hosts []unknownHost) { tmpKnownHostsPath := fmt.Sprintf("%s.tmp", c.knownHostsPath) + + if config.Client.SSHDontAddHostsToKnownHostsFile { + dlog.Common.Verbose("Not adding hosts to known hosts file, as disabled by config") + return + } + newFd, err := os.OpenFile(tmpKnownHostsPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) if err != nil { panic(fmt.Sprintf("%s: %s", tmpKnownHostsPath, err.Error())) |
