forked from DGNum/colmena
Do not use an explicit user for ssh when deploymentUser is null
This commit is contained in:
parent
429a0f5aa1
commit
e937eb8faa
4 changed files with 8 additions and 23 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -162,7 +162,6 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tokio-test",
|
"tokio-test",
|
||||||
"users",
|
|
||||||
"uuid",
|
"uuid",
|
||||||
"validator",
|
"validator",
|
||||||
]
|
]
|
||||||
|
@ -986,16 +985,6 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "users"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|
|
@ -33,7 +33,6 @@ sys-info = "0.9.0"
|
||||||
snafu = "0.7.0"
|
snafu = "0.7.0"
|
||||||
tempfile = "3.1.0"
|
tempfile = "3.1.0"
|
||||||
tokio-stream = "0.1.8"
|
tokio-stream = "0.1.8"
|
||||||
users = "0.11.0"
|
|
||||||
uuid = { version = "1.0.0", features = ["serde", "v4"] }
|
uuid = { version = "1.0.0", features = ["serde", "v4"] }
|
||||||
validator = { version = "0.15.0", features = ["derive"] }
|
validator = { version = "0.15.0", features = ["derive"] }
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use super::{CopyDirection, CopyOptions, RebootOptions, Host, key_uploader};
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Ssh {
|
pub struct Ssh {
|
||||||
/// The username to use to connect.
|
/// The username to use to connect.
|
||||||
user: String,
|
user: Option<String>,
|
||||||
|
|
||||||
/// The hostname or IP address to connect to.
|
/// The hostname or IP address to connect to.
|
||||||
host: String,
|
host: String,
|
||||||
|
@ -166,7 +166,7 @@ impl Host for Ssh {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ssh {
|
impl Ssh {
|
||||||
pub fn new(user: String, host: String) -> Self {
|
pub fn new(user: Option<String>, host: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
user,
|
user,
|
||||||
host,
|
host,
|
||||||
|
@ -197,7 +197,7 @@ impl Ssh {
|
||||||
pub fn ssh(&self, command: &[&str]) -> Command {
|
pub fn ssh(&self, command: &[&str]) -> Command {
|
||||||
let options = self.ssh_options();
|
let options = self.ssh_options();
|
||||||
let options_str = options.join(" ");
|
let options_str = options.join(" ");
|
||||||
let privilege_escalation_command = if self.user != "root" {
|
let privilege_escalation_command = if self.user.as_deref() != Some("root") {
|
||||||
self.privilege_escalation_command.as_slice()
|
self.privilege_escalation_command.as_slice()
|
||||||
} else {
|
} else {
|
||||||
&[]
|
&[]
|
||||||
|
@ -224,7 +224,10 @@ impl Ssh {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ssh_target(&self) -> String {
|
fn ssh_target(&self) -> String {
|
||||||
format!("{}@{}", self.user, self.host)
|
match &self.user {
|
||||||
|
Some(n) => format!("{}@{}", n, self.host),
|
||||||
|
None => self.host.clone(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nix_copy_closure(&self, path: &StorePath, direction: CopyDirection, options: CopyOptions) -> Command {
|
fn nix_copy_closure(&self, path: &StorePath, direction: CopyDirection, options: CopyOptions) -> Command {
|
||||||
|
|
|
@ -5,7 +5,6 @@ use std::path::Path;
|
||||||
|
|
||||||
use serde::de;
|
use serde::de;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use users::get_current_username;
|
|
||||||
use validator::{Validate, ValidationError as ValidationErrorType};
|
use validator::{Validate, ValidationError as ValidationErrorType};
|
||||||
|
|
||||||
use crate::error::{ColmenaResult, ColmenaError};
|
use crate::error::{ColmenaResult, ColmenaError};
|
||||||
|
@ -164,12 +163,7 @@ impl NodeConfig {
|
||||||
|
|
||||||
pub fn to_ssh_host(&self) -> Option<Ssh> {
|
pub fn to_ssh_host(&self) -> Option<Ssh> {
|
||||||
self.target_host.as_ref().map(|target_host| {
|
self.target_host.as_ref().map(|target_host| {
|
||||||
let username =
|
let mut host = Ssh::new(self.target_user.clone(), target_host.clone());
|
||||||
match &self.target_user {
|
|
||||||
Some(uname) => uname.clone(),
|
|
||||||
None => get_current_username().unwrap().into_string().unwrap(),
|
|
||||||
};
|
|
||||||
let mut host = Ssh::new(username, target_host.clone());
|
|
||||||
host.set_privilege_escalation_command(self.privilege_escalation_command.clone());
|
host.set_privilege_escalation_command(self.privilege_escalation_command.clone());
|
||||||
|
|
||||||
if let Some(target_port) = self.target_port {
|
if let Some(target_port) = self.target_port {
|
||||||
|
|
Loading…
Reference in a new issue