Support SSH usernames which contain @ symbols (#25314)

Closes #25246

Release Notes:

- SSH: Improved handling of multiple `@` in connection strings: e.g.
`ssh jim.lv@es2@10.220.67.57@11.239.1.231` improving support of jump
hosts running JumpServer.

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Color Fuzzy 2025-03-17 13:10:21 +08:00 committed by GitHub
parent 8f560daec2
commit a0f995d2ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 4 deletions

View file

@ -39,6 +39,7 @@ shlex.workspace = true
smol.workspace = true
tempfile.workspace = true
thiserror.workspace = true
urlencoding.workspace = true
util.workspace = true
[dev-dependencies]

View file

@ -203,7 +203,8 @@ impl SshConnectionOptions {
anyhow::bail!("unsupported argument: {:?}", arg);
}
let mut input = &arg as &str;
if let Some((u, rest)) = input.split_once('@') {
// Destination might be: username1@username2@ip2@ip1
if let Some((u, rest)) = input.rsplit_once('@') {
input = rest;
username = Some(u.to_string());
}
@ -238,7 +239,9 @@ impl SshConnectionOptions {
pub fn ssh_url(&self) -> String {
let mut result = String::from("ssh://");
if let Some(username) = &self.username {
result.push_str(username);
// Username might be: username1@username2@ip2
let username = urlencoding::encode(username);
result.push_str(&username);
result.push('@');
}
result.push_str(&self.host);