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

sshforwarding: exit on ssh errors without printing any further errors #9

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ pub enum Error {

#[error("malformed destination address {0}")]
BadDestinationAddress(String),

// Used to silently terminate the SSH tunnel without logging any further errors
// this allows the last `ssh: ` log to be reported as the main error to the user
#[error("")]
SilentError
}
20 changes: 11 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async fn main() -> io::Result<()> {
init_logging(&log_args);

if let Err(err) = run(command).await.as_ref() {
tracing::error!(error = ?err, "network tunnel failed.");
if !matches!(err, Error::SilentError) {
tracing::error!(error = ?err, "network tunnel failed.");
}
std::process::exit(1);
}
Ok(())
Expand All @@ -64,15 +66,15 @@ async fn run_and_cleanup(tunnel: &mut Box<dyn NetworkTunnel>) -> Result<(), Erro
let tunnel_block = {
let prep = tunnel.prepare().await;

// Write "READY" to stdio to unblock Go logic.
// The current workflow assumes that
// 1. After tunnel.prepare() is called, the network tunnel is able to accept requests from clients without sending errors back to clients.
// 2. The network tunnel is able to process client requests immediately after `tunnel.start_serve` is called.
// If either of the assumptions is invalid for any new tunnel type, the READY-logic need to be moved to a separate task, which
// sends out the "READY" signal after making sure the network tunnel is started and working properly.
println!("READY");

future::ready(prep).and_then(|()| {
// Write "READY" to stdio to unblock Go logic.
// The current workflow assumes that
// 1. After tunnel.prepare() is called, the network tunnel is able to accept requests from clients without sending errors back to clients.
// 2. The network tunnel is able to process client requests immediately after `tunnel.start_serve` is called.
// If either of the assumptions is invalid for any new tunnel type, the READY-logic need to be moved to a separate task, which
// sends out the "READY" signal after making sure the network tunnel is started and working properly.
println!("READY");

tunnel.start_serve()
}).await
};
Expand Down
14 changes: 10 additions & 4 deletions src/sshforwarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ impl NetworkTunnel for SshForwarding {
if line.starts_with("debug1:") {
tracing::debug!("ssh: {}", &line);
} else if line.starts_with("Warning: Permanently added") {
tracing::debug!("ssh: {}", &line);
tracing::debug!("{}", &line);
} else if line.contains("Permission denied") {
tracing::error!("ssh: {}", &line);
tracing::error!("{}", &line);
return Err(Error::SilentError)
} else if line.contains("Network is unreachable") {
tracing::error!("ssh: {}", &line);
tracing::error!("{}", &line);
mdibaiee marked this conversation as resolved.
Show resolved Hide resolved
return Err(Error::SilentError)
} else if line.contains("Connection timed out") {
tracing::error!("ssh: {}", &line);
tracing::error!("{}", &line);
return Err(Error::SilentError)
} else if line.contains("Operation timed out") {
tracing::error!("n{}", &line);
return Err(Error::SilentError)
} else {
tracing::info!("ssh: {}", &line);
}
Expand Down
Loading