Skip to content

server host key lookup fails if a server has multiple keys #138

Open

Description

@timbertson

I'm not entirely sure that multiple keys of the same type per-host should be allowed, but openssh supports it so I'm reporting it in case it should be:

We have two servers in an active / inactive setup. We deploy to the inactive server, and then run a switch task to swap their IPs. This makes the previously inactive server active and vice versa.

The trouble is, we then need two SSH keys for the server address (since it might correspond to one of two physical machines). the ssh command-line client supports this if you list both in ~/.ssh/known_hosts, but paramiko does a lookup via hostname, so it will always return only one of the possible keys.

As a workaround, we're overriding the default rejection policy, since we're using fabric and that doesn't allow us to set a custom policy.

custom_hosts = hostkeys.HostKeys(os.path.join(env.project_path, "deployment", "known_hosts"))
class CustomRejectionPolicy(client.MissingHostKeyPolicy):
    def missing_host_key(self, client, hostname, key):
        if key is not None:
            all_keys = [entry.key for entry in custom_hosts._entries]
            if key in all_keys:
                return
        client._log(DEBUG, 'Rejecting %s host key for %s: %s' %
                    (key.get_name(), hostname, hexlify(key.get_fingerprint())))
        raise SSHException('Server %r not found in known_hosts' % hostname)
client.RejectPolicy = CustomRejectionPolicy

Activity

  1. bitprophet commented on Nov 24, 2014

    @bitprophet
    Member

    Very belatedly, this sounds legit to me offhand, and feels related to #166 and #437. Labeling for followup.

  2. bitprophet commented on May 5, 2016

    @bitprophet
    Member

    #737 seems to surface this same issue, with the specific use case being a virtual IP across 2 or more hosts.

    Suspecting we may be able to solve this just by making the known_hosts mechanism less naive / more in line with OpenSSH (as noted). Without having the code memorized I'd guess it's just lazy use of scalar-value dict keys where we may instead want to use tuples or similar (or a wholly separate structure and not a straight dict).

  3. added this to the milestone on May 5, 2016
  4. bitprophet commented on May 5, 2016

    @bitprophet
    Member

    Also noting to self: this strikes me as a straight up bug, so if we can solve it in a way that doesn't seem too disruptive, it should go into a bugfix or feature release and does not need to get thrown in with 3.0.

  5. modified the milestones: 1.16.2 / 1.17.1 / 2.0.1, on Jun 21, 2016
  6. modified the milestones: 1.17.3 et al, on Dec 9, 2016
  7. Jain281088 commented on May 3, 2017

    @Jain281088

    Any update on this issue... Are we fixing the issue to support Cluster or Active/DR server implementation. Its a very basic implementaion now a days and without this feature, we are unable to implement Host Key varification.

  8. scholich commented on Jan 27, 2021

    @scholich

    Hi, this seems to be open for quite a while already. Is there any progress on this? I would love to be able to have the option to provide multiple host keys for the same host to support failover switches

  9. bencroft commented on Aug 29, 2022

    @bencroft

    Hello there. Is there progress on this issue? It seems that it could be commonly-needed for load-balanced connections as well.

  10. bskinn commented on Aug 30, 2022

    @bskinn
    Contributor

    This will likely get wrapped into the overall key/auth overhaul of #387. Right now the next big piece of work is on a major release that drops Python 2 and old versions of 3.x. I believe #387 is still the priority after that.

    No specific timeline, unfortunately. bitprophet has to split his open-source time between paramiko, invoke and fabric, and that time has been reduced lately for various reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions