Files
one/share/ssh/etc/config-pre7.6
T
Petr Ospalý 2c36183a21 B OpenNebula/one#4935: Fix hashed known_hosts (#8)
This commit fixes problem when host key is already added in SSH
`known_hosts` file but SSH fails to validate this host key.

NOTE:
This problem manifests only when simulating 'accept-new' feature of the
newer SSH (>v7.6) via 'Match' with 'ssh-keygen -F'.

The cause of this problem is the fact that hostname is stored always
in lowercase even if the hostname had an upcase character.

It means that the record in `known_hosts` file for hostname `ABC`
becomes something like 'abc,10.0.0.10' - which in turn is hashed...

Therefore SSH with `HashKnownHosts=yes` is comparing wrong hashes:
    hash('ABC,10.0.0.10') vs hash('abc,10.0.0.10')

Most likely a bug or an oversight in SSH.

With this option disabled (`HashKnownHosts=no`) both upcased `ABC`
and lowercased `abc` work.

Example with *ENABLED* `HashKnownHosts=yes`:

    [oneadmin@ABC ~] hostname
    ABC
    [oneadmin@ABC ~] rm -f ~/.ssh/known_hosts
    [oneadmin@ABC ~] ssh-keyscan -H $(hostname) >> ~/.ssh/known_hosts
    [oneadmin@ABC ~]$ ssh ABC # this fails
    No ECDSA host key is known for abc and you have requested strict
    checking.
    Host key verification failed.
    [oneadmin@ABC ~]$ ssh abc # this works
    Warning: Permanently added 'abc,10.10.0.41' (ECDSA) to the list
    of known hosts.
    Last login: Mon Jun 15 04:32:38 2020 from ::1
    [oneadmin@ABC ~]$ # success with lowercase hostname

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>
2020-06-18 18:19:31 +02:00

45 lines
2.0 KiB
Plaintext

# Initial default configuration placed by opennebula-common
# package. Latest default configurations are located in
# /usr/share/one/ssh/.
###############################################################################
# WARNING: This configuration file is for OpenSSH before 7.6!
###############################################################################
# Workaround for OpenSSH version <7.6 which does not support:
# StrictHostKeyChecking accept-new
#
# We check if remote host key is not already in the known hosts and
# if NOT, we expect this is the very first access and accept the key.
# All further accesses already use strict host key checking.
Match !exec "ssh-keygen -F %h 2>/dev/null || ssh-keygen -F %h -f /etc/ssh/ssh_known_hosts 2>/dev/null"
HashKnownHosts no
StrictHostKeyChecking no
ServerAliveInterval 10
#############################################################################
# 'ControlMaster' is overriden by OpenNebula's drivers when needed
ControlMaster no
# The following options must be aligned with the accompanying timer/cronjob:
# opennebula-ssh-socks-cleaner (if present) which implements workaround for
# OpenSSH race condition during the closing of the master socket.
#
# 'ControlPersist' should be set to more than twice the period after which
# timer or cronjob is run - to offset the delay - e.g.: timer job is run each
# 30s then 'ControlPersist' should be at least one minute. It will also not
# change the behavior even if it set much higher or to the infinity (0) - it
# is limited by the timer/cronjob *AND* the command which is executed inside.
#
# (+) Add another 10s to give timer/cronjob a room for cleanup
ControlPersist 70s
# 'ControlPath' must be in-sync with the script run by timer/cronjob above!
ControlPath /run/one/ssh-socks/ctl-M-%C.sock
Host *
HashKnownHosts no
StrictHostKeyChecking yes
ServerAliveInterval 10
# IMPORTANT: set the following 'Control*' options the same way as above
ControlMaster no
ControlPersist 70s
ControlPath /run/one/ssh-socks/ctl-M-%C.sock