Skip to content

Commit

Permalink
fix(passwordless_login): login with ssh key only
Browse files Browse the repository at this point in the history
for security reason login with password is disabled for user created
during device onboarding
user created will able to login only using ssh key passed via
service info config.

Signed-off: Sayan Paul <[email protected]>
  • Loading branch information
say-paul authored and 7flying committed Dec 20, 2022
1 parent a3e0a47 commit 42ffa60
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions client-linuxapp/src/serviceinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ fn create_user(user: &str) -> Result<()> {
Ok(())
}

fn set_passwordless_login(user: &str) -> Result<()> {
let user_info = passwd::Passwd::from_name(user);
if user_info.is_none() {
bail!("User {} for passwordless login missing", user);
}
log::info!("Setting passwordless login for user: {}", user);
Command::new("passwd")
.arg("-d")
.arg(user)
.spawn()
.context("Error spawning passwordless setup command")?
.wait()
.context(format!(
"Error setting up passwordless login for user {}",
user
))?;
Ok(())
}

fn install_ssh_key(user: &str, key: &str) -> Result<()> {
let user_info = passwd::Passwd::from_name(user);
if user_info.is_none() {
Expand Down Expand Up @@ -627,6 +646,8 @@ async fn process_serviceinfo_in(si_in: &ServiceInfo, si_out: &mut ServiceInfo) -
))?;
install_ssh_key(sshkey_user.as_ref().unwrap(), sshkey_key.as_ref().unwrap())
.context("Error installing SSH key")?;
set_passwordless_login(sshkey_user.as_ref().unwrap())
.context("Error setting up passwordless login")?;
}

// Perform RHSM
Expand Down

0 comments on commit 42ffa60

Please sign in to comment.