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

🐛 Handle ssh connection errors #1844

Merged
merged 1 commit into from
Sep 22, 2023
Merged

Conversation

czunker
Copy link
Contributor

@czunker czunker commented Sep 22, 2023

Fixes #1812

@czunker
Copy link
Contributor Author

czunker commented Sep 22, 2023

ssh connection errors now look like this:

cnquery run ssh -i ~/Downloads/christian\ \(1\).pem [email protected] -c "asset{ name title ids }" --verbose                                                              
! CLI pre-processing encountered an issue error="unknown shorthand flag: 'i' in -i"
DBG using provider os with connector ssh
! using builtin provider for os
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
DBG ssh> could not read ssh config error="open /home/christian/.ssh/config: no such file or directory" file=/home/christian/.ssh/config
DBG load ssh known_hosts file file=/home/christian/.ssh/known_hosts
DBG load ssh known_hosts file file=/home/christian/.ssh/google_compute_known_hosts
DBG enabled ssh private key authentication
DBG enabled ssh agent authentication
DBG ssh agent socket found socket=/run/user/1000/keyring/ssh
DBG connect to remote ssh methods=1 user=ec2-user
DBG could not establish ssh session error="dial tcp 52.59.216.198:22: connect: connection timed out" host=52.59.216.198 insecure=false port=22 provider=ssh
FTL failed to run query error="dial tcp 52.59.216.198:22: connect: connection timed out"

@czunker
Copy link
Contributor Author

czunker commented Sep 22, 2023

This also fixes #1814 :

cnquery run ssh [email protected] -c "asset{ name title ids }" --verbose                                                                                
! CLI pre-processing encountered an issue error="unknown flag: --verbose"
DBG using provider os with connector ssh
! using builtin provider for os
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
DBG ssh> could not read ssh config error="open /home/christian/.ssh/config: no such file or directory" file=/home/christian/.ssh/config
DBG load ssh known_hosts file file=/home/christian/.ssh/known_hosts
DBG load ssh known_hosts file file=/home/christian/.ssh/google_compute_known_hosts
DBG enabled ssh agent authentication
DBG ssh agent socket found socket=/run/user/1000/keyring/ssh
DBG connect to remote ssh methods=1 user=ec2-user
DBG skip hostkey check the hostkey since the algo is not supported yet
DBG could not establish ssh session error="ssh: handshake failed: ssh: disconnect, reason 2: Too many authentication failures" host=3.123.17.243 insecure=false port=22 provider=ssh
FTL failed to run query error="ssh: handshake failed: ssh: disconnect, reason 2: Too many authentication failures"

And w/o ssh-agent:

cnquery run ssh [email protected] -c "asset{ name title ids }" --verbose                                                                                   
! CLI pre-processing encountered an issue error="unknown flag: --verbose"
DBG using provider os with connector ssh
! using builtin provider for os
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
DBG ssh> could not read ssh config error="open /home/christian/.ssh/config: no such file or directory" file=/home/christian/.ssh/config
DBG load ssh known_hosts file file=/home/christian/.ssh/known_hosts
DBG load ssh known_hosts file file=/home/christian/.ssh/google_compute_known_hosts
DBG enabled ssh agent authentication
DBG could not find valid ssh agent authentication
DBG could not establish ssh session error="no authentication method defined" host=3.123.17.243 insecure=false port=22 provider=ssh
FTL failed to run query error="no authentication method defined"

Fixes #1812
Fixes #1814

Signed-off-by: Christian Zunker <[email protected]>
@czunker czunker force-pushed the christian/v9_handle_ssh_errs branch from d4345aa to 8801fe9 Compare September 22, 2023 05:43
@czunker czunker marked this pull request as ready for review September 22, 2023 05:44
@czunker
Copy link
Contributor Author

czunker commented Sep 22, 2023

This fixes also a panic for ssm connect, when connecting against a non-ssm instance:

cnquery run aws ec2 ssm ec2-user@i-08add0bfe5db56c47 --region eu-central-1 -c 'asset{ name title ids platform }'             
! CLI pre-processing encountered an issue error="unknown flag: --region"
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x12265f3]

goroutine 73 [running]:
go.mondoo.com/cnquery/providers/os/connection.(*SshConnection).RunCommand(0x0?, {0x1c90378?, 0x0?})
	/home/christian/workspace/mondoo/github.com/cnquery/providers/os/connection/ssh.go:138 +0x13
go.mondoo.com/cnquery/providers/os/detector.(*OSReleaseDetector).command(0x0?, {0x1c90378?, 0xc000014660?})
	/home/christian/workspace/mondoo/github.com/cnquery/providers/os/detector/os_release.go:27 +0x24
go.mondoo.com/cnquery/providers/os/detector.(*OSReleaseDetector).unames(...)
...

@vjeffrey vjeffrey merged commit 66756d7 into main Sep 22, 2023
@vjeffrey vjeffrey deleted the christian/v9_handle_ssh_errs branch September 22, 2023 14:58
@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws instance-connect panics when ssh connection problems exist
2 participants