Skip to content

Commit

Permalink
bump russh
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang2821 committed Aug 19, 2024
1 parent d5ceede commit f627b9a
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 244 deletions.
306 changes: 173 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ sqlx = { version = "0.7.3", default-features = false, features = ["sqlx-postgres
sea-orm = { version = "0.12.12", features = [ "sqlx-postgres", "sqlx-sqlite", "runtime-tokio-rustls", "macros" ] }
sea-orm-migration = { version = "0.12.6", features = [ "sqlx-postgres", "runtime-tokio-rustls" ] }
uuid = { version = "1.6.1", features = ["v4", "serde"] }
russh = {version = "0.42.0", features = ["vendored-openssl"] }
russh-keys = { version = "0.42.0", features = ["vendored-openssl"] }
russh = {version = "0.44.1", features = ["vendored-openssl"] }
lapdev-api = { path = "./lapdev-api" }
lapdev-ws = { path = "./lapdev-ws" }
lapdev-db = { path = "./lapdev-db" }
Expand Down
2 changes: 1 addition & 1 deletion lapdev-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ oauth2.workspace = true
chrono.workspace = true
pasetors.workspace = true
git2.workspace = true
russh-keys.workspace = true
russh.workspace = true
axum.workspace = true
axum-extra.workspace = true
axum-client-ip.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions lapdev-api/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lapdev_common::{
};
use lapdev_db::{api::DbApi, entities};
use lapdev_rpc::error::ApiError;
use russh_keys::PublicKeyBase64;
use russh::keys::PublicKeyBase64;
use sea_orm::{prelude::Uuid, ActiveModelTrait, ActiveValue};

use crate::state::CoreState;
Expand Down Expand Up @@ -176,7 +176,7 @@ pub async fn create_ssh_key(
))
}
};
let parsed_key = russh_keys::parse_public_key_base64(key)
let parsed_key = russh::keys::parse_public_key_base64(key)
.map_err(|_| ApiError::InvalidRequest("The SSH public key is invalid".to_string()))?;
let parsed_key = parsed_key.public_key_base64();

Expand Down
30 changes: 15 additions & 15 deletions lapdev-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
mod account;
mod admin;
mod auth;
mod cert;
mod github;
mod gitlab;
mod machine_type;
mod organization;
mod prebuild;
mod project;
mod router;
pub mod account;
pub mod admin;
pub mod auth;
pub mod cert;
pub mod github;
pub mod gitlab;
pub mod machine_type;
pub mod organization;
pub mod prebuild;
pub mod project;
pub mod router;
pub mod server;
mod session;
mod state;
mod websocket;
mod workspace;
pub mod session;
pub mod state;
pub mod websocket;
pub mod workspace;
5 changes: 4 additions & 1 deletion lapdev-api/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct Cli {
/// The folder for putting logs
#[clap(short, long, action, value_hint = clap::ValueHint::AnyPath)]
logs_folder: Option<PathBuf>,
/// Don't run db migration on startup
#[clap(short, long, action)]
no_migration: bool,
}

pub async fn start(additional_router: Option<Router<CoreState>>) {
Expand All @@ -64,7 +67,7 @@ async fn run(cli: &Cli, additional_router: Option<Router<CoreState>>) -> Result<
.db
.ok_or_else(|| anyhow!("can't find database url in your config file"))?;

let db = DbApi::new(&db_url).await?;
let db = DbApi::new(&db_url, cli.no_migration).await?;
let conductor = Conductor::new(LAPDEV_VERSION, db.clone()).await?;

let ssh_proxy_port = config.ssh_proxy_port.unwrap_or(2222);
Expand Down
2 changes: 1 addition & 1 deletion lapdev-conductor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true

[dependencies]
data-encoding.workspace = true
russh-keys.workspace = true
russh.workspace = true
itertools.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
14 changes: 7 additions & 7 deletions lapdev-conductor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use lapdev_enterprise::enterprise::Enterprise;
use lapdev_rpc::{
error::ApiError, long_running_context, spawn_twoway, ConductorService, WorkspaceServiceClient,
};
use russh_keys::{
use russh::keys::{
key::{KeyPair, PublicKey, SignatureHash},
pkcs8, PublicKeyBase64,
};
Expand Down Expand Up @@ -1039,12 +1039,12 @@ impl Conductor {
fn generate_key_pair(&self) -> Result<(String, String)> {
let key = KeyPair::generate_rsa(4096, SignatureHash::SHA2_512)
.ok_or_else(|| anyhow!("can't generate ssh key pair"))?;
let id_rsa = encode_pkcs8_pem(&key);
let id_rsa = encode_pkcs8_pem(&key)?;
let public_key = key.clone_public_key()?;
let public_key = format!(
"{} {}",
match public_key {
PublicKey::RSA { .. } | PublicKey::P256(_) | PublicKey::P521(_) => "ssh-rsa",
PublicKey::RSA { .. } | PublicKey::EC { .. } => "ssh-rsa",
PublicKey::Ed25519(_) => "ssh-ed25519",
},
public_key.public_key_base64()
Expand Down Expand Up @@ -3094,12 +3094,12 @@ impl Conductor {
}
}

pub fn encode_pkcs8_pem(key: &KeyPair) -> String {
let x = pkcs8::encode_pkcs8(key);
format!(
pub fn encode_pkcs8_pem(key: &KeyPair) -> Result<String> {
let x = pkcs8::encode_pkcs8(key)?;
Ok(format!(
"-----BEGIN PRIVATE KEY-----\n{}\n-----END PRIVATE KEY-----\n",
BASE64_MIME.encode(&x)
)
))
}

fn repo_branches(repo: &Repository) -> Result<Vec<GitBranch>> {
Expand Down
8 changes: 5 additions & 3 deletions lapdev-db/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ async fn connect_db(conn_url: &str) -> Result<sqlx::PgPool> {
}

impl DbApi {
pub async fn new(conn_url: &str) -> Result<Self> {
pub async fn new(conn_url: &str, no_migration: bool) -> Result<Self> {
let pool = connect_db(conn_url).await?;
let conn = sea_orm::SqlxPostgresConnector::from_sqlx_postgres_pool(pool.clone());
let db = DbApi {
conn,
pool: Some(pool),
};
db.init().await?;
if !no_migration {
db.migrate().await?;
}
Ok(db)
}

async fn init(&self) -> Result<()> {
async fn migrate(&self) -> Result<()> {
Migrator::up(&self.conn, None).await?;
Ok(())
}
Expand Down
36 changes: 18 additions & 18 deletions lapdev-db/src/migration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
pub use sea_orm_migration::prelude::*;
use sea_orm_migration::prelude::*;

mod m20231105_152940_create_machine_type_table;
mod m20231105_193627_create_workspace_host_table;
mod m20231106_100019_create_user_table;
mod m20231106_100804_create_workspace_table;
mod m20231109_171859_create_project_table;
mod m20231113_170211_create_ssh_public_key_table;
mod m20231114_110943_create_config_table;
mod m20231130_151650_create_organization_table;
mod m20231130_151937_create_organization_member_table;
mod m20231213_143210_create_prebuild_table;
mod m20240125_135149_create_quota_table;
mod m20240129_215530_create_usage_table;
mod m20240205_113409_create_audit_log_table;
mod m20240228_141013_create_user_invitation_table;
mod m20240311_220708_create_prebuild_replica_table;
mod m20240312_175753_create_table_update_trigger;
mod m20240316_194115_create_workspace_port_table;
pub mod m20231105_152940_create_machine_type_table;
pub mod m20231105_193627_create_workspace_host_table;
pub mod m20231106_100019_create_user_table;
pub mod m20231106_100804_create_workspace_table;
pub mod m20231109_171859_create_project_table;
pub mod m20231113_170211_create_ssh_public_key_table;
pub mod m20231114_110943_create_config_table;
pub mod m20231130_151650_create_organization_table;
pub mod m20231130_151937_create_organization_member_table;
pub mod m20231213_143210_create_prebuild_table;
pub mod m20240125_135149_create_quota_table;
pub mod m20240129_215530_create_usage_table;
pub mod m20240205_113409_create_audit_log_table;
pub mod m20240228_141013_create_user_invitation_table;
pub mod m20240311_220708_create_prebuild_replica_table;
pub mod m20240312_175753_create_table_update_trigger;
pub mod m20240316_194115_create_workspace_port_table;

pub struct Migrator;

Expand Down
1 change: 0 additions & 1 deletion lapdev-proxy-ssh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition.workspace = true
[dependencies]
data-encoding.workspace = true
russh.workspace = true
russh-keys.workspace = true
async-trait.workspace = true
serde_json.workspace = true
tracing.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions lapdev-proxy-ssh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::Arc;

use anyhow::{anyhow, Result};
use async_trait::async_trait;
use russh::keys::key::KeyPair;
use russh::{Channel, ChannelId, ChannelMsg};
use russh_keys::key::KeyPair;
use tracing::debug;

pub struct SshProxyClient {}
Expand All @@ -17,10 +17,10 @@ impl russh::client::Handler for SshProxyClient {
type Error = anyhow::Error;

async fn check_server_key(
self,
_server_public_key: &russh_keys::key::PublicKey,
) -> Result<(Self, bool), Self::Error> {
Ok((self, true))
&mut self,
_server_public_key: &russh::keys::key::PublicKey,
) -> Result<bool, Self::Error> {
Ok(true)
}
}

Expand Down
4 changes: 2 additions & 2 deletions lapdev-proxy-ssh/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use lapdev_conductor::server::encode_pkcs8_pem;
use lapdev_db::{api::DbApi, entities};
use russh_keys::{
use russh::keys::{
decode_secret_key,
key::{KeyPair, SignatureHash},
};
Expand All @@ -20,7 +20,7 @@ pub async fn load_key(kind: &str, db: &DbApi) -> Result<KeyPair> {
.ok_or_else(|| anyhow!("can't generate server key"))?,
_ => return Err(anyhow!("don't support {kind} host key")),
};
let secret = encode_pkcs8_pem(&key);
let secret = encode_pkcs8_pem(&key)?;
entities::config::ActiveModel {
name: ActiveValue::Set(kind.to_string()),
value: ActiveValue::Set(secret),
Expand Down
Loading

0 comments on commit f627b9a

Please sign in to comment.