Allow passing some configuration for user/password on SSH
With some real integration testing it looks like the "set an environment variable" approach is not really going to work effectively. I think the script {} will need to be treated like a template instead, since different shells require different ways of setting env variables and it doesn't appear that there's a good ssh2-based way to set these environment variables.
This commit is contained in:
parent
7b9066d096
commit
754fd428f8
|
@ -17,11 +17,21 @@ pub struct Group {
|
||||||
pub struct Target {
|
pub struct Target {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub uri: String,
|
pub uri: String,
|
||||||
|
pub config: Option<Config>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
#[serde(default = "default_transport")]
|
||||||
pub transport: Transport,
|
pub transport: Transport,
|
||||||
|
pub ssh: Option<SshConfig>,
|
||||||
|
}
|
||||||
|
fn default_transport() -> Transport { Transport::Ssh }
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub struct SshConfig {
|
||||||
|
pub user: String,
|
||||||
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
|
|
@ -36,8 +36,20 @@ impl Transport for Ssh {
|
||||||
let mut sess = Session::new().unwrap();
|
let mut sess = Session::new().unwrap();
|
||||||
sess.set_tcp_stream(tcp);
|
sess.set_tcp_stream(tcp);
|
||||||
sess.handshake().unwrap();
|
sess.handshake().unwrap();
|
||||||
sess.userauth_agent(&std::env::var("USER").unwrap())
|
|
||||||
.unwrap();
|
let mut authenticated = false;
|
||||||
|
|
||||||
|
if let Some(config) = &target.config {
|
||||||
|
if let Some(sshconfig) = &config.ssh {
|
||||||
|
// requires PasswordAuthentication yes
|
||||||
|
sess.userauth_password(&sshconfig.user, &sshconfig.password).unwrap();
|
||||||
|
authenticated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ! authenticated {
|
||||||
|
sess.userauth_agent(&std::env::var("USER").unwrap())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let mut channel = sess.channel_session().unwrap();
|
let mut channel = sess.channel_session().unwrap();
|
||||||
|
|
||||||
|
@ -45,6 +57,7 @@ impl Transport for Ssh {
|
||||||
|
|
||||||
if let Some(env) = env {
|
if let Some(env) = env {
|
||||||
for (key, val) in env.iter() {
|
for (key, val) in env.iter() {
|
||||||
|
channel.setenv(key, val);
|
||||||
segments.push(format!("export ZAP_{}=\"{}\"", key.to_uppercase(), val));
|
segments.push(format!("export ZAP_{}=\"{}\"", key.to_uppercase(), val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,12 @@ targets:
|
||||||
uri: 192.168.1.41
|
uri: 192.168.1.41
|
||||||
- name: gopher
|
- name: gopher
|
||||||
uri: 192.168.1.41
|
uri: 192.168.1.41
|
||||||
|
- name: zap-freebsd
|
||||||
|
uri: 192.168.1.224
|
||||||
|
config:
|
||||||
|
ssh:
|
||||||
|
user: root
|
||||||
|
password: root
|
||||||
|
|
||||||
config:
|
config:
|
||||||
transport: ssh
|
transport: ssh
|
||||||
|
|
|
@ -7,6 +7,6 @@ task Echo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
script {
|
script {
|
||||||
inline = "echo ${ZAP_MSG}"
|
inline = "env; echo ${ZAP_MSG}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue