Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 server entries are not handled correctly #1594

Open
verbit opened this issue Jun 3, 2023 · 1 comment
Open

IPv6 server entries are not handled correctly #1594

verbit opened this issue Jun 3, 2023 · 1 comment
Labels
bug Confirmed bugs

Comments

@verbit
Copy link

verbit commented Jun 3, 2023

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

( $server, $port ) = Rex::Helper::IP::get_server_and_port( $server, $port );

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

@verbit verbit added the triage needed A potential bug that needs to be reproduced and understood label Jun 3, 2023
@ferki ferki added bug Confirmed bugs and removed triage needed A potential bug that needs to be reproduced and understood labels Jun 9, 2023
@ferki
Copy link
Member

ferki commented Jun 9, 2023

Thanks for the report, @verbit!

At first glance it indeed looks like $server is not stringifed correctly when passed as an argument to is_ip* calls in Rex::Helper::IP.

I expect adding double quotes, forcing an early stringification, or changing what is being passed to get_server_and_port() in the first place may solve this. Perhaps get_server_and_port() may throw a warning or even error if it receives an unexpected argument format.

Either way, it certainly would need additional tests. t/issue/1008.t already has quite a few related tests, but not for the case when a server entry object is being passed to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs
Projects
None yet
Development

No branches or pull requests

2 participants