RexOps / RexOps/Rex

IPv6 server entries are not handled correctly

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

Nobody has claimed this yet.

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

Description

Describe the bug

When using an IPv6 as a server entry, the hostname/port is not parsed correctly (see rex -d output below). For example, with 2001:db8::1 it uses 2001 as the host and db8 as the port.

Expected behavior

I expect it to use 2001:db8::1 as the address and 23 as the port (default).

How to reproduce it

A code sample to reproduce the issue is attached.

Code example
use Rex -feature => [ '1.4', 'exec_autodie' ];

group myservers => '2001:db8::1';

task 'uptime', group => 'myservers', sub { run 'uptime'; };
Additional context
rex -d logs
me@mymachine rextest % rex -d uptime
[2023-06-03 19:03:42] DEBUG - This is Rex version: 1.14.2
[2023-06-03 19:03:42] DEBUG - Command Line Parameters
[2023-06-03 19:03:42] DEBUG - 	d = 1
[2023-06-03 19:03:42] DEBUG - Creating lock-file (Rexfile.lock)
[2023-06-03 19:03:42] DEBUG - Loading Rexfile
[2023-06-03 19:03:42] DEBUG - Enabling task_chaining_cmdline_args feature
[2023-06-03 19:03:42] DEBUG - Activating new template engine.
[2023-06-03 19:03:42] DEBUG - Disabling usage of a tty
[2023-06-03 19:03:42] DEBUG - Activating autodie.
[2023-06-03 19:03:42] DEBUG - Using Net::OpenSSH if present.
[2023-06-03 19:03:42] DEBUG - Add service check.
[2023-06-03 19:03:42] DEBUG - Setting set() to not append data.
[2023-06-03 19:03:42] DEBUG - Registering CMDB as template variables.
[2023-06-03 19:03:42] DEBUG - activating featureset >= 0.51
[2023-06-03 19:03:42] DEBUG - activating featureset >= 0.40
[2023-06-03 19:03:42] DEBUG - activating featureset >= 0.35
[2023-06-03 19:03:42] DEBUG - activating featureset >= 0.31
[2023-06-03 19:03:42] DEBUG - Enabling exec_autodie
[2023-06-03 19:03:42] DEBUG - Creating new distribution class of type: Base
[2023-06-03 19:03:42] DEBUG - new distribution class of type Rex::TaskList::Base created.
[2023-06-03 19:03:42] DEBUG - Creating task: uptime
[2023-06-03 19:03:42] DEBUG - Found Net::OpenSSH and Net::SFTP::Foreign - using it as default
[2023-06-03 19:03:42] DEBUG - Registering task: uptime
[2023-06-03 19:03:42] DEBUG - Initializing Logger from parameters found in Rexfile
[2023-06-03 19:03:42] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2023-06-03 19:03:42] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2023-06-03 19:03:42] INFO - Running task uptime on 2001:db8::1
[2023-06-03 19:03:42] DEBUG - Rex::Group::Entry::Server (private_key): returning
[2023-06-03 19:03:42] DEBUG - Rex::Group::Entry::Server (public_key): returning
[2023-06-03 19:03:42] DEBUG - $VAR1 = '';

[2023-06-03 19:03:42] DEBUG - Auth-Information inside Task:
[2023-06-03 19:03:42] DEBUG - public_key => [[]]
[2023-06-03 19:03:42] DEBUG - password => [[%s]]
[2023-06-03 19:03:42] DEBUG - sudo_password => [[**********]]
[2023-06-03 19:03:42] DEBUG - auth_type => [[try]]
[2023-06-03 19:03:42] DEBUG - private_key => [[]]
[2023-06-03 19:03:42] DEBUG - sudo => [[]]
[2023-06-03 19:03:42] DEBUG - user => [[me]]
[2023-06-03 19:03:42] DEBUG - port => [[]]
[2023-06-03 19:03:42] DEBUG - Using Net::OpenSSH for connection
[2023-06-03 19:03:42] DEBUG - Using user: me
[2023-06-03 19:03:42] DEBUG - Connecting to 2001:db8 (me)
[2023-06-03 19:03:42] DEBUG - get_openssh_opt()
[2023-06-03 19:03:42] DEBUG - $VAR1 = {};

[2023-06-03 19:03:42] DEBUG - OpenSSH: key_auth or not defined: 2001:db8 - me
[2023-06-03 19:03:42] DEBUG - OpenSSH options:
[2023-06-03 19:03:42] DEBUG - $VAR1 = [
          '2001',
          'user',
          'me',
          'port',
          'db8',
          'master_opts',
          [
            '-o',
            'ConnectTimeout=2',
            '-o',
            'LogLevel=QUIET'
          ],
          'default_ssh_opts',
          $VAR1->[6]
        ];

[2023-06-03 19:03:42] DEBUG - OpenSSH constructor options:
[2023-06-03 19:03:42] DEBUG - $VAR1 = {};

[2023-06-03 19:03:42] DEBUG - Trying following auth types:
[2023-06-03 19:03:42] DEBUG - $VAR1 = [
          'key',
          'pass'
        ];

Bad port 'db8'
Bad port 'db8'
Bad port 'db8'
Bad port 'db8'
Bad port 'db8'
Bad port 'db8'
[2023-06-03 19:03:42] WARN - Can't authenticate against 2001 (unable to establish master SSH connection: master process exited unexpectedly)
[2023-06-03 19:03:42] DEBUG - Connections in queue: 1
[2023-06-03 19:03:42] DEBUG - Destroying all cached os information
[2023-06-03 19:03:43] DEBUG - Waiting for children to finish
[2023-06-03 19:03:43] DEBUG - Need to reinitialize connections.
[2023-06-03 19:03:43] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base
[2023-06-03 19:03:43] ERROR - 1 out of 1 task(s) failed:
[2023-06-03 19:03:43] ERROR - 	uptime failed on 2001:db8::1
[2023-06-03 19:03:43] ERROR - 		Couldn't authenticate against 2001:db8::1. It may be caused by one or more of:
[2023-06-03 19:03:43] ERROR - 		 - wrong username, password, key or passphrase
[2023-06-03 19:03:43] ERROR - 		 - changed remote host key
[2023-06-03 19:03:43] ERROR - 		 at /Users/me/perl5/lib/perl5/Rex/TaskList/Base.pm line 340.
[2023-06-03 19:03:43] DEBUG - Removing lockfile
[2023-06-03 19:03:43] DEBUG - Returning existing distribution class of type: Rex::TaskList::Base

My suspicion is that the error lies here https://github.com/RexOps/Rex/blob/6fe5da1832927b22ad940248fa15cc393c224169/lib/Rex/Interface/Connection/OpenSSH.pm#L67

Rex::Helper::IP::get_server_and_port expects a string for the $server but gets a server entry object instead which makes all the is_ip functions inside get_server_and_port fail. Maybe passing "$server" would solve the issue?

Rex version

(R)?ex 1.14.2

Perl version

This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level

Operating system running rex

macOS 12.0.1 (21A559)

Operating system managed by rex

none

How rex was installed?

cpan client

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

Start at lib/Rex/Interface/Connection/OpenSSH.pm around line 67 and trace how the server entry reaches Rex::Helper::IP::get_server_and_port. Reproduce the IPv6 example from the issue and verify that the full address is preserved and the default port remains 23. Done means the connection no longer splits 2001:db8::1 into a host and port.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.