mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
sync ssh keys on add
This commit is contained in:
@@ -15,6 +15,7 @@ use crate::db::model::ServerStatus;
|
|||||||
use crate::disk::mount::util::unmount;
|
use crate::disk::mount::util::unmount;
|
||||||
use crate::middleware::auth::LOCAL_AUTH_COOKIE_PATH;
|
use crate::middleware::auth::LOCAL_AUTH_COOKIE_PATH;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::ssh::SSH_AUTHORIZED_KEYS_FILE;
|
||||||
use crate::util::cpupower::{get_available_governors, get_preferred_governor, set_governor};
|
use crate::util::cpupower::{get_available_governors, get_preferred_governor, set_governor};
|
||||||
use crate::util::Invoke;
|
use crate::util::Invoke;
|
||||||
use crate::{Error, ARCH};
|
use crate::{Error, ARCH};
|
||||||
@@ -212,7 +213,7 @@ pub async fn init(cfg: &ServerConfig) -> Result<InitResult, Error> {
|
|||||||
|
|
||||||
crate::ssh::sync_keys(
|
crate::ssh::sync_keys(
|
||||||
&peek.as_private().as_ssh_pubkeys().de()?,
|
&peek.as_private().as_ssh_pubkeys().de()?,
|
||||||
"/home/start9/.ssh/authorized_keys",
|
SSH_AUTHORIZED_KEYS_FILE,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
tracing::info!("Synced SSH Keys");
|
tracing::info!("Synced SSH Keys");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::prelude::*;
|
|||||||
use crate::util::clap::FromStrParser;
|
use crate::util::clap::FromStrParser;
|
||||||
use crate::util::serde::{display_serializable, HandlerExtSerde, WithIoFormat};
|
use crate::util::serde::{display_serializable, HandlerExtSerde, WithIoFormat};
|
||||||
|
|
||||||
static SSH_AUTHORIZED_KEYS_FILE: &str = "/home/start9/.ssh/authorized_keys";
|
pub const SSH_AUTHORIZED_KEYS_FILE: &str = "/home/start9/.ssh/authorized_keys";
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct SshKeys(BTreeMap<InternedString, WithTimeData<SshPubKey>>);
|
pub struct SshKeys(BTreeMap<InternedString, WithTimeData<SshPubKey>>);
|
||||||
@@ -113,20 +113,26 @@ pub struct AddParams {
|
|||||||
pub async fn add(ctx: RpcContext, AddParams { key }: AddParams) -> Result<SshKeyResponse, Error> {
|
pub async fn add(ctx: RpcContext, AddParams { key }: AddParams) -> Result<SshKeyResponse, Error> {
|
||||||
let mut key = WithTimeData::new(key);
|
let mut key = WithTimeData::new(key);
|
||||||
let fingerprint = InternedString::intern(key.0.fingerprint_md5());
|
let fingerprint = InternedString::intern(key.0.fingerprint_md5());
|
||||||
ctx.db
|
let (keys, res) = ctx
|
||||||
|
.db
|
||||||
.mutate(move |m| {
|
.mutate(move |m| {
|
||||||
m.as_private_mut()
|
m.as_private_mut()
|
||||||
.as_ssh_pubkeys_mut()
|
.as_ssh_pubkeys_mut()
|
||||||
.insert(&fingerprint, &key)?;
|
.insert(&fingerprint, &key)?;
|
||||||
|
|
||||||
Ok(SshKeyResponse {
|
Ok((
|
||||||
|
m.as_private().as_ssh_pubkeys().de()?,
|
||||||
|
SshKeyResponse {
|
||||||
alg: key.0.keytype().to_owned(),
|
alg: key.0.keytype().to_owned(),
|
||||||
fingerprint,
|
fingerprint,
|
||||||
hostname: key.0.comment.take().unwrap_or_default(),
|
hostname: key.0.comment.take().unwrap_or_default(),
|
||||||
created_at: key.created_at.to_rfc3339(),
|
created_at: key.created_at.to_rfc3339(),
|
||||||
|
},
|
||||||
|
))
|
||||||
})
|
})
|
||||||
})
|
.await?;
|
||||||
.await
|
sync_keys(&keys, SSH_AUTHORIZED_KEYS_FILE).await?;
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Parser)]
|
#[derive(Deserialize, Serialize, Parser)]
|
||||||
|
|||||||
Reference in New Issue
Block a user