Skip to content

Commit

Permalink
* Fixed the bug with tools/striker-push-ssh where SSH on remote nodes…
Browse files Browse the repository at this point in the history
… with the same IP but different ports wasn't being configured properly.

Signed-off-by: Digimer <digimer@alteeve.ca>
  • Loading branch information
Digimer committed Dec 6, 2016
1 parent 249a57d commit 2b2f1d9
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 115 deletions.
92 changes: 62 additions & 30 deletions AN/Tools/Remote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,22 @@ sub add_target_to_known_hosts
my $self = shift;
my $parameter = shift;
my $an = $self->parent;
$an->Log->entry({log_level => 2, title_key => "tools_log_0001", title_variables => { function => "add_target_to_known_hosts" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__});
$an->Log->entry({log_level => 3, title_key => "tools_log_0001", title_variables => { function => "add_target_to_known_hosts" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__});

my $target = $parameter->{target};
my $port = $parameter->{port} ? $parameter->{port} : 22;
my $user = $parameter->{user} ? $parameter->{user} : $<;
my $delete_if_found = $parameter->{delete_if_found} ? $parameter->{delete_if_found} : 0;
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
name1 => "user", value1 => $user,
name2 => "target", value2 => $target,
name3 => "delete_if_found", value3 => $delete_if_found,
$an->Log->entry({log_level => 3, message_key => "an_variables_0004", message_variables => {
name1 => "target", value1 => $target,
name2 => "port", value2 => $port,
name3 => "user", value3 => $user,
name4 => "delete_if_found", value4 => $delete_if_found,
}, file => $THIS_FILE, line => __LINE__});

# Get the local user's home
my $users_home = $an->Get->users_home({user => $user});
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "users_home", value1 => $users_home,
}, file => $THIS_FILE, line => __LINE__});
if (not $users_home)
Expand All @@ -216,7 +218,7 @@ sub add_target_to_known_hosts

# I'll need to make sure I've seen the fingerprint before.
my $known_hosts = "$users_home/.ssh/known_hosts";
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "known_hosts", value1 => $known_hosts,
}, file => $THIS_FILE, line => __LINE__});

Expand All @@ -227,11 +229,12 @@ sub add_target_to_known_hosts
# Yup, see if the target is there already,
$known_machine = $an->Remote->_check_known_hosts_for_target({
target => $target,
port => $port,
known_hosts => $known_hosts,
user => $user,
delete_if_found => $delete_if_found,
});
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "known_machine", value1 => $known_machine,
}, file => $THIS_FILE, line => __LINE__});
}
Expand All @@ -240,26 +243,32 @@ sub add_target_to_known_hosts
if (not $known_machine)
{
# We don't know about this machine yet, so scan it.
my $added = $an->Remote->_call_ssh_keyscan({user => $user, target => $target, known_hosts => $known_hosts});
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
my $added = $an->Remote->_call_ssh_keyscan({
target => $target,
port => $port,
user => $user,
known_hosts => $known_hosts});
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "added", value1 => $added,
}, file => $THIS_FILE, line => __LINE__});

# Verify
$known_machine = $an->Remote->_check_known_hosts_for_target({
target => $target,
port => $port,
known_hosts => $known_hosts,
user => $user,
delete_if_found => $delete_if_found,
});
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "known_machine", value1 => $known_machine,
}, file => $THIS_FILE, line => __LINE__});
if ($known_machine)
{
# Successfully added!
$an->Log->entry({log_level => 2, message_key => "notice_message_0009", message_variables => {
target => $target,
port => $port,
user => $user,
}, file => $THIS_FILE, line => __LINE__});
}
Expand All @@ -268,6 +277,7 @@ sub add_target_to_known_hosts
# Failed to add. :(
$an->Alert->warning({message_key => "warning_title_0007", message_variables => {
target => $target,
port => $port,
user => $user,
}, quiet => 1, file => $THIS_FILE, line => __LINE__});
return(1);
Expand Down Expand Up @@ -764,7 +774,7 @@ sub wait_on_peer
port => $port,
});
my $count = @{$pids};
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "count", value1 => $count,
}, file => $THIS_FILE, line => __LINE__});
if ($count)
Expand Down Expand Up @@ -799,21 +809,27 @@ sub _call_ssh_keyscan
my $parameter = shift;
my $an = $self->parent;

my $user = $parameter->{user};
my $target = $parameter->{target};
my $port = $parameter->{port};
my $user = $parameter->{user};
my $known_hosts = $parameter->{known_hosts};
$an->Log->entry({log_level => 3, title_key => "tools_log_0001", title_variables => { function => "_call_ssh_keyscan" }, message_key => "an_variables_0003", message_variables => {
name1 => "user", value1 => $user,
name2 => "target", value2 => $target,
name3 => "known_hosts", value3 => $known_hosts,
$an->Log->entry({log_level => 3, title_key => "tools_log_0001", title_variables => { function => "_call_ssh_keyscan" }, message_key => "an_variables_0004", message_variables => {
name1 => "target", value1 => $target,
name2 => "port", value2 => $port,
name3 => "user", value3 => $user,
name4 => "known_hosts", value4 => $known_hosts,
}, file => $THIS_FILE, line => __LINE__});

$an->Log->entry({log_level => 3, message_key => "notice_message_0010", message_variables => {
$an->Log->entry({log_level => 2, message_key => "notice_message_0010", message_variables => {
target => $target,
port => $port,
user => $user,
}, file => $THIS_FILE, line => __LINE__});
my $shell_call = $an->data->{path}{'ssh-keyscan'}." $target >> $known_hosts && ";
$shell_call .= $an->data->{path}{'chown'}." $user:$user $known_hosts";
my $shell_call = $an->data->{path}{'ssh-keyscan'}." $target >> $known_hosts";
if (($port) && ($port ne "22"))
{
$shell_call = $an->data->{path}{'ssh-keyscan'}." -p $port $target >> $known_hosts";
}
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "shell_call", value1 => $shell_call,
}, file => $THIS_FILE, line => __LINE__});
Expand All @@ -825,6 +841,19 @@ sub _call_ssh_keyscan
}
close $file_handle;

# Set the ownership
$shell_call = $an->data->{path}{'chown'}." $user:$user $known_hosts";
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "shell_call", value1 => $shell_call,
}, file => $THIS_FILE, line => __LINE__});
open ($file_handle, "$shell_call 2>&1 |") or $an->Alert->error({title_key => "an_0003", message_key => "error_title_0014", message_variables => { shell_call => $shell_call, error => $! }, code => 2, file => $THIS_FILE, line => __LINE__});
while(<$file_handle>)
{
chomp;
my $line = $_;
}
close $file_handle;

return(0);
}

Expand All @@ -837,36 +866,38 @@ sub _check_known_hosts_for_target
$an->Log->entry({log_level => 2, title_key => "tools_log_0001", title_variables => { function => "_check_known_hosts_for_target" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__});

my $target = $parameter->{target} ? $parameter->{target} : "";
my $port = $parameter->{port} ? $parameter->{port} : "";
my $known_hosts = $parameter->{known_hosts} ? $parameter->{known_hosts} : "";
my $user = $parameter->{user} ? $parameter->{user} : "";
my $delete_if_found = $parameter->{delete_if_found} ? $parameter->{delete_if_found} : 0;
$an->Log->entry({log_level => 2, message_key => "an_variables_0004", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0005", message_variables => {
name1 => "target", value1 => $target,
name2 => "known_hosts", value2 => $known_hosts,
name3 => "user", value3 => $user,
name4 => "delete_if_found", value4 => $delete_if_found,
name2 => "port", value2 => $port,
name3 => "known_hosts", value3 => $known_hosts,
name4 => "user", value4 => $user,
name5 => "delete_if_found", value5 => $delete_if_found,
}, file => $THIS_FILE, line => __LINE__});

# read it in and search.
my $known_machine = 0;
my $shell_call = $known_hosts;
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "shell_call", value1 => $shell_call,
}, file => $THIS_FILE, line => __LINE__});
open (my $file_handle, "<$shell_call") or $an->Alert->error({title_key => "an_0003", message_key => "error_title_0016", message_variables => { shell_call => $shell_call, error => $! }, code => 2, file => $THIS_FILE, line => __LINE__});
while(<$file_handle>)
{
chomp;
my $line = $_;
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "line", value1 => $line,
}, file => $THIS_FILE, line => __LINE__});
if ($line =~ /$target ssh-rsa /)
if (($line =~ /$target ssh-rsa /) or ($line =~ /\[$target\]:$port ssh-rsa /))
{
# We already know this machine (or rather, we already have a fingerprint for
# this machine).
$known_machine = 1;
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "known_machine", value1 => $known_machine,
}, file => $THIS_FILE, line => __LINE__});
}
Expand All @@ -875,21 +906,22 @@ sub _check_known_hosts_for_target

if ($delete_if_found)
{
### NOTE: It appears the port is not needed.
# If we have a non-digit user, run this through 'su.
my $shell_call = $an->data->{path}{'ssh-keygen'}." -R $target";
if (($user) && ($user =~ /\D/))
{
$shell_call = $an->data->{path}{su}." - $user -c '".$an->data->{path}{'ssh-keygen'}." -R $target'";
}
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "shell_call", value1 => $shell_call,
}, file => $THIS_FILE, line => __LINE__});
open (my $file_handle, "$shell_call 2>&1 |") or $an->Alert->error({title_key => "an_0003", message_key => "error_title_0014", message_variables => { shell_call => $shell_call, error => $! }, code => 2, file => $THIS_FILE, line => __LINE__});
while(<$file_handle>)
{
chomp;
my $line = $_;
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
name1 => "line", value1 => $line,
}, file => $THIS_FILE, line => __LINE__});
}
Expand Down
42 changes: 19 additions & 23 deletions AN/Tools/Striker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -913,27 +913,30 @@ sub scan_node
if ($cached_access)
{
# If this fails, we'll walk our various connections.
my $target = $cached_access;
my $port = 22;
$an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => {
name1 => "target", value1 => $target,
name2 => "port", value2 => $port,
}, file => $THIS_FILE, line => __LINE__});

my $target = $cached_access;
my $port = 22;
my $password = $an->data->{sys}{anvil}{$node_key}{password};
if ($target =~ /^(.*?):(\d+)$/)
{
$target = $1;
$port = $2;
$an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => {
$an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => {
name1 => "target", value1 => $target,
name2 => "port", value2 => $port,
}, file => $THIS_FILE, line => __LINE__});
}

$an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => {
name1 => "target", value1 => $target,
name2 => "port", value2 => $port,
}, file => $THIS_FILE, line => __LINE__});
$an->Log->entry({log_level => 4, message_key => "an_variables_0001", message_variables => {
name1 => "password", value1 => $password,
}, file => $THIS_FILE, line => __LINE__});
my $access = $an->Check->access({
target => $target,
port => $port,
password => $an->data->{sys}{anvil}{$node_key}{password},
password => $password,
});
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
name1 => "access", value1 => $access,
Expand All @@ -943,8 +946,7 @@ sub scan_node
$an->data->{sys}{anvil}{$node_key}{use_ip} = $target;
$an->data->{sys}{anvil}{$node_key}{use_port} = $port;
$an->data->{sys}{anvil}{$node_key}{online} = 1;
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0003", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
name1 => "sys::anvil::${node_key}::use_ip", value1 => $an->data->{sys}{anvil}{$node_key}{use_ip},
name2 => "sys::anvil::${node_key}::use_port", value2 => $an->data->{sys}{anvil}{$node_key}{use_port},
name3 => "sys::anvil::${node_key}::online", value3 => $an->data->{sys}{anvil}{$node_key}{online},
Expand All @@ -953,8 +955,7 @@ sub scan_node
}

# If I don't have access (no cache or cache didn't work), walk through the networks.
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
name1 => "sys::anvil::${node_key}::online", value1 => $an->data->{sys}{anvil}{$node_key}{online},
}, file => $THIS_FILE, line => __LINE__});
if ($an->data->{sys}{anvil}{$node_key}{online})
Expand Down Expand Up @@ -987,8 +988,7 @@ sub scan_node
$an->data->{sys}{anvil}{$node_key}{use_ip} = $an->data->{sys}{anvil}{$node_key}{bcn_ip};
$an->data->{sys}{anvil}{$node_key}{use_port} = 22;
$an->data->{sys}{anvil}{$node_key}{online} = 1;
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0003", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
name1 => "sys::anvil::${node_key}::use_ip", value1 => $an->data->{sys}{anvil}{$node_key}{use_ip},
name2 => "sys::anvil::${node_key}::use_port", value2 => $an->data->{sys}{anvil}{$node_key}{use_port},
name3 => "sys::anvil::${node_key}::online", value3 => $an->data->{sys}{anvil}{$node_key}{online},
Expand All @@ -1011,8 +1011,7 @@ sub scan_node
$an->data->{sys}{anvil}{$node_key}{use_ip} = $an->data->{sys}{anvil}{$node_key}{ifn_ip};
$an->data->{sys}{anvil}{$node_key}{use_port} = 22;
$an->data->{sys}{anvil}{$node_key}{online} = 1;
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0003", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
name1 => "sys::anvil::${node_key}::use_ip", value1 => $an->data->{sys}{anvil}{$node_key}{use_ip},
name2 => "sys::anvil::${node_key}::use_port", value2 => $an->data->{sys}{anvil}{$node_key}{use_port},
name3 => "sys::anvil::${node_key}::online", value3 => $an->data->{sys}{anvil}{$node_key}{online},
Expand All @@ -1037,8 +1036,7 @@ sub scan_node
$an->data->{sys}{anvil}{$node_key}{use_ip} = $an->data->{sys}{anvil}{$node_key}{remote_ip};
$an->data->{sys}{anvil}{$node_key}{use_port} = $an->data->{sys}{anvil}{$node_key}{remote_port};
$an->data->{sys}{anvil}{$node_key}{online} = 1;
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0003", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
name1 => "sys::anvil::${node_key}::use_ip", value1 => $an->data->{sys}{anvil}{$node_key}{use_ip},
name2 => "sys::anvil::${node_key}::use_port", value2 => $an->data->{sys}{anvil}{$node_key}{use_port},
name3 => "sys::anvil::${node_key}::online", value3 => $an->data->{sys}{anvil}{$node_key}{online},
Expand All @@ -1059,8 +1057,7 @@ sub scan_node
# No luck.
$an->data->{sys}{anvil}{$node_key}{online} = 0;
$an->data->{sys}{anvil}{$node_key}{power} = $an->ScanCore->target_power({target => $node_uuid});
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
name1 => "sys::anvil::${node_key}::power", value1 => $an->data->{sys}{anvil}{$node_key}{power},
}, file => $THIS_FILE, line => __LINE__});
}
Expand All @@ -1069,8 +1066,7 @@ sub scan_node
}

# If I connected, cache the data.
### NOTE: Customer requested, move to 2 before v2.0 release
$an->Log->entry({log_level => 1, message_key => "an_variables_0001", message_variables => {
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
name1 => "sys::anvil::${node_key}::online", value1 => $an->data->{sys}{anvil}{$node_key}{online},
}, file => $THIS_FILE, line => __LINE__});
if ($an->data->{sys}{anvil}{$node_key}{online})
Expand Down
Loading

0 comments on commit 2b2f1d9

Please sign in to comment.