mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 09:09:17 +00:00
Fix credential ospf logic, fix udp subnet proxy loop protection (#2315)
This commit is contained in:
@@ -3,6 +3,7 @@ use axum::http::StatusCode;
|
||||
use axum::routing::{delete, post};
|
||||
use axum::{Json, Router, extract::State, routing::get};
|
||||
use axum_login::AuthUser;
|
||||
use easytier::common::config::ConfigSource as RuntimeConfigSource;
|
||||
use easytier::launcher::NetworkConfig;
|
||||
use easytier::proto::common::Void;
|
||||
use easytier::proto::{api::manage::*, web::*};
|
||||
@@ -60,6 +61,7 @@ struct SaveNetworkJsonReq {
|
||||
struct RunNetworkJsonReq {
|
||||
config: NetworkConfig,
|
||||
save: bool,
|
||||
source: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
@@ -82,6 +84,17 @@ struct RemoveNetworkJsonReq {
|
||||
inst_ids: Vec<uuid::Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct ManagedNetworkConfigJson {
|
||||
instance_id: uuid::Uuid,
|
||||
network_config: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct ReconcileManagedNetworkConfigsJsonReq {
|
||||
managed_network_configs: Vec<ManagedNetworkConfigJson>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct ListMachineItem {
|
||||
client_url: Option<url::Url>,
|
||||
@@ -130,10 +143,11 @@ impl NetworkApi {
|
||||
Json(payload): Json<RunNetworkJsonReq>,
|
||||
) -> Result<Json<Void>, HttpHandleError> {
|
||||
client_mgr
|
||||
.handle_run_network_instance(
|
||||
.handle_run_network_instance_with_source(
|
||||
(Self::get_user_id(&auth_session)?, machine_id),
|
||||
payload.config,
|
||||
payload.save,
|
||||
RuntimeConfigSource::Web,
|
||||
)
|
||||
.await
|
||||
.map_err(convert_error)?;
|
||||
@@ -274,10 +288,11 @@ impl NetworkApi {
|
||||
));
|
||||
}
|
||||
client_mgr
|
||||
.handle_save_network_config(
|
||||
.handle_save_network_config_with_source(
|
||||
(Self::get_user_id(&auth_session)?, machine_id),
|
||||
inst_id,
|
||||
payload.config,
|
||||
RuntimeConfigSource::Web,
|
||||
)
|
||||
.await
|
||||
.map_err(convert_error)
|
||||
@@ -302,8 +317,17 @@ impl NetworkApi {
|
||||
Path((user_id, machine_id)): Path<(UserIdInDb, uuid::Uuid)>,
|
||||
Json(payload): Json<RunNetworkJsonReq>,
|
||||
) -> Result<Json<Void>, HttpHandleError> {
|
||||
let source = payload
|
||||
.source
|
||||
.and_then(RuntimeConfigSource::from_rpc)
|
||||
.unwrap_or(RuntimeConfigSource::Web);
|
||||
client_mgr
|
||||
.handle_run_network_instance((user_id, machine_id), payload.config, payload.save)
|
||||
.handle_run_network_instance_with_source(
|
||||
(user_id, machine_id),
|
||||
payload.config,
|
||||
payload.save,
|
||||
source,
|
||||
)
|
||||
.await
|
||||
.map_err(convert_error)?;
|
||||
Ok(Void::default().into())
|
||||
@@ -319,6 +343,31 @@ impl NetworkApi {
|
||||
.map_err(convert_error)
|
||||
}
|
||||
|
||||
async fn handle_reconcile_managed_network_configs_internal(
|
||||
State(client_mgr): AppState,
|
||||
Path((user_id, machine_id)): Path<(UserIdInDb, uuid::Uuid)>,
|
||||
Json(payload): Json<ReconcileManagedNetworkConfigsJsonReq>,
|
||||
) -> Result<Json<Void>, HttpHandleError> {
|
||||
let desired = payload
|
||||
.managed_network_configs
|
||||
.into_iter()
|
||||
.map(|item| crate::webhook::ManagedNetworkConfig {
|
||||
instance_id: item.instance_id.to_string(),
|
||||
network_config: item.network_config,
|
||||
})
|
||||
.collect();
|
||||
client_mgr
|
||||
.reconcile_managed_network_configs(user_id, machine_id, desired)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
other_error(err.to_string()).into(),
|
||||
)
|
||||
})?;
|
||||
Ok(Void::default().into())
|
||||
}
|
||||
|
||||
async fn handle_list_network_instance_ids_internal(
|
||||
State(client_mgr): AppState,
|
||||
Path((user_id, machine_id)): Path<(UserIdInDb, uuid::Uuid)>,
|
||||
@@ -347,6 +396,7 @@ impl NetworkApi {
|
||||
.route(
|
||||
"/api/internal/users/:user-id/machines/:machine-id/networks",
|
||||
post(Self::handle_run_network_instance_internal)
|
||||
.put(Self::handle_reconcile_managed_network_configs_internal)
|
||||
.get(Self::handle_list_network_instance_ids_internal),
|
||||
)
|
||||
.route(
|
||||
|
||||
@@ -16,6 +16,7 @@ pub struct ProxyRpcRequest {
|
||||
pub service_name: String,
|
||||
pub method_name: String,
|
||||
pub payload: serde_json::Value,
|
||||
pub scope: Option<String>,
|
||||
}
|
||||
|
||||
macro_rules! match_service {
|
||||
@@ -35,6 +36,7 @@ async fn handle_proxy_rpc_by_session(
|
||||
service_name,
|
||||
method_name,
|
||||
payload,
|
||||
scope,
|
||||
} = req;
|
||||
|
||||
let resp = match service_name.as_str() {
|
||||
@@ -74,12 +76,20 @@ async fn handle_proxy_rpc_by_session(
|
||||
payload,
|
||||
session
|
||||
),
|
||||
"api.instance.TcpProxyRpcService" => match_service!(
|
||||
easytier::proto::api::instance::TcpProxyRpcClientFactory<BaseController>,
|
||||
method_name,
|
||||
payload,
|
||||
session
|
||||
),
|
||||
"api.instance.TcpProxyRpcService" => {
|
||||
let client = if let Some(ref domain) = scope {
|
||||
session.scoped_client_with_domain::<
|
||||
easytier::proto::api::instance::TcpProxyRpcClientFactory<BaseController>,
|
||||
>(domain.clone())
|
||||
} else {
|
||||
session.scoped_client::<
|
||||
easytier::proto::api::instance::TcpProxyRpcClientFactory<BaseController>,
|
||||
>()
|
||||
};
|
||||
client
|
||||
.json_call_method(BaseController::default(), &method_name, payload)
|
||||
.await
|
||||
}
|
||||
"api.instance.AclManageRpcService" => match_service!(
|
||||
easytier::proto::api::instance::AclManageRpcClientFactory<BaseController>,
|
||||
method_name,
|
||||
|
||||
Reference in New Issue
Block a user