RexOps / RexOps/Rex

Hostname used withing Host entries in ssh config

Open
#1,458 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage needed
Dominant language
Perl
Stars
737
Forks
214
PR merge metrics
No merged PRs in 30d

Description

On Debian 10 "buster", amd64, using rex from backports, version "(R)?ex 1.12.2".
Those points where discussed on IRC.

Describe the bug

Rex uses the Hostname sub-key of a Host section in ~/.ssh/config

How to reproduce it

Steps to reproduce the behavior:

  1. Create 1 proxy machine "proxy" with 2 NICs and a running ssh-server instance;
    1.1 connect 1 NIC so that it can be reached from LAN, and give it, for example, IP 192.168.1.200/16
    1.2 connect the other one so that it can not be reached from LAN and give it IP 10.0.0.1/16
    1.3 create a user "bouncer", with no password and nologin shell;
    1.4 give "bouncer" a file ~bouncer/.ssh/authorized_keys filled with a public key "vmproxy";
  2. Create 1 target machine "target" which only NIC is only reachable by "proxy";
    2.1 create a normal user "user"
    2.2 give "user" a file ~user/.ssh/authorized_keys filled with a public key "vmlan";
    2.3 give NIC the IP 10.0.0.10/16
  3. on host, create a ~/.ssh/config file such as:
Host proxy
  Hostname 192.168.1.200
  User bouncer
  IdentityFile ~/.ssh/vmproxy

Host target
  Hostname 10.0.0.10
  User user
  IdentityFile ~/.ssh/vmlan
  ProxyJump proxy
  1. connect to proxy via ssh. It should work.
  2. connect to target via ssh. It should also work.
  3. run rex -H target -u u user -e say run uptime <= will fail
  4. on host, modify a ~/.ssh/config file such as:
Host proxy
  Hostname 192.168.1.200
  User bouncer
  IdentityFile ~/.ssh/vmproxy

Host target
  Hostname 10.0.0.10
Host 10.0.0.10
  User user
  IdentityFile ~/.ssh/vmlan
  ProxyJump proxy
  1. run rex -H target -u u user -e say run uptime <= will work

Expected behavior

step 6 should behave the same as step 8

Circumstances

  • Rex version: (R)?ex 1.12.2
  • Perl version: This is perl 5, version 28, subversion 1 (v5.28.1) built for x86_64-linux-gnu-thread-multi
    (with 65 registered patches, see perl -V for more detail)
  • OS running rex: Debian 10 buster, amd64
  • OS managed by rex: same.
  • How rex was installed: apt-get

Debug log

[2020-12-13 21:23:18] DEBUG - This is Rex version: 1.12.2
[2020-12-13 21:23:18] DEBUG - Command Line Parameters
[2020-12-13 21:23:18] DEBUG - 	e = say
[2020-12-13 21:23:18] DEBUG - 	u = user
[2020-12-13 21:23:18] DEBUG - 	H = sfiles
[2020-12-13 21:23:18] DEBUG - 	d = 1
[2020-12-13 21:23:18] DEBUG - Creating lock-file (Rexfile.lock)
[2020-12-13 21:23:18] DEBUG - Loading Rexfile
[2020-12-13 21:23:18] DEBUG - Creating new distribution class of type: Base
[2020-12-13 21:23:18] DEBUG - new distribution class of type Rex::TaskList::Base created.
[2020-12-13 21:23:18] DEBUG - Initializing Logger from parameters found in Rexfile
[2020-12-13 21:23:18] DEBUG - Executing command line code
[2020-12-13 21:23:18] DEBUG - 	say
[2020-12-13 21:23:18] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2020-12-13 21:23:18] DEBUG - Creating task: eval-line
[2020-12-13 21:23:18] DEBUG - 	server: sfiles
[2020-12-13 21:23:18] DEBUG - Found Net::OpenSSH and Net::SFTP::Foreign - using it as default
[2020-12-13 21:23:18] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2020-12-13 21:23:18] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2020-12-13 21:23:18] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2020-12-13 21:23:18] INFO - Running task eval-line on sfiles
[2020-12-13 21:23:18] DEBUG - Checking for a private key in .ssh/config
[2020-12-13 21:23:18] DEBUG - Rex::Group::Entry::Server (private_key): returning ~/.ssh/vmlan
[2020-12-13 21:23:18] DEBUG - Checking for a public key in .ssh/config
[2020-12-13 21:23:18] DEBUG - Rex::Group::Entry::Server (public_key): returning ~/.ssh/vmlan.pub
[2020-12-13 21:23:18] DEBUG - $VAR1 = '';

[2020-12-13 21:23:18] DEBUG - Auth-Information inside Task:
[2020-12-13 21:23:18] DEBUG - public_key => [[~/.ssh/vmlan.pub]]
[2020-12-13 21:23:18] DEBUG - port => [[]]
[2020-12-13 21:23:18] DEBUG - sudo_password => [[**********]]
[2020-12-13 21:23:18] DEBUG - password => [[%s]]
[2020-12-13 21:23:18] DEBUG - auth_type => [[try]]
[2020-12-13 21:23:18] DEBUG - user => [[user]]
[2020-12-13 21:23:18] DEBUG - sudo => [[]]
[2020-12-13 21:23:18] DEBUG - private_key => [[~/.ssh/vmlan]]
[2020-12-13 21:23:18] DEBUG - Using Net::OpenSSH for connection
[2020-12-13 21:23:18] DEBUG - Using user: user
[2020-12-13 21:23:18] DEBUG - Connecting to 10.0.1.10:22 (user)
[2020-12-13 21:23:18] DEBUG - get_openssh_opt()
[2020-12-13 21:23:18] DEBUG - $VAR1 = {};

[2020-12-13 21:23:18] DEBUG - OpenSSH: key_auth or not defined: 10.0.1.10:22 - user
[2020-12-13 21:23:18] DEBUG - OpenSSH options: 
[2020-12-13 21:23:18] DEBUG - $VAR1 = [
          '10.0.1.10',
          'user',
          'user',
          'port',
          22,
          'master_opts',
          [
            '-o',
            'ConnectTimeout=2',
            '-o',
            'LogLevel=QUIET'
          ],
          'default_ssh_opts',
          $VAR1->[6]
        ];

[2020-12-13 21:23:18] DEBUG - OpenSSH constructor options: 
[2020-12-13 21:23:18] DEBUG - $VAR1 = {};

[2020-12-13 21:23:18] DEBUG - Trying following auth types:
[2020-12-13 21:23:18] DEBUG - $VAR1 = [
          'key',
          'pass'
        ];

[2020-12-13 21:23:31] WARN - Can't authenticate against 10.0.1.10 (unable to establish master SSH connection: master process exited unexpectedly)
[2020-12-13 21:23:31] DEBUG - Connections in queue: 1
[2020-12-13 21:23:31] DEBUG - Destroying all cached os information
[2020-12-13 21:23:31] DEBUG - Waiting for children to finish
[2020-12-13 21:23:31] DEBUG - Need to reinitialize connections.
[2020-12-13 21:23:31] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2020-12-13 21:23:31] ERROR - 1 out of 1 task(s) failed:
[2020-12-13 21:23:31] ERROR - 	eval-line failed on sfiles
[2020-12-13 21:23:31] ERROR - 		Couldn't authenticate against sfiles. It may be caused by one or more of:
[2020-12-13 21:23:31] ERROR - 		 - wrong username, password, key or passphrase
[2020-12-13 21:23:31] ERROR - 		 - changed remote host key
[2020-12-13 21:23:31] ERROR - 		 at /usr/share/perl5/Rex/TaskList/Base.pm line 342.
[2020-12-13 21:23:31] DEBUG - Removing lockfile
[2020-12-13 21:23:31] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with rex -H target -u user -e say run uptime and compare it with the working SSH configuration. Start at /usr/share/perl5/Rex/TaskList/Base.pm around line 342, then trace Rex's SSH configuration handling and Net::OpenSSH connection setup. Done means a Host entry using Hostname and ProxyJump behaves like the equivalent address-based entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.