diff --git a/crates/myfsio-server/src/handlers/admin.rs b/crates/myfsio-server/src/handlers/admin.rs index b317040..39b425b 100644 --- a/crates/myfsio-server/src/handlers/admin.rs +++ b/crates/myfsio-server/src/handlers/admin.rs @@ -345,6 +345,12 @@ pub async fn register_peer_site( .get("connection_id") .and_then(|v| v.as_str()) .map(|s| s.to_string()), + peer_inbound_access_key: payload + .get("peer_inbound_access_key") + .and_then(|v| v.as_str()) + .map(str::trim) + .filter(|s| !s.is_empty()) + .map(|s| s.to_string()), created_at: Some(chrono::Utc::now().to_rfc3339()), is_healthy: false, last_health_check: None, @@ -467,6 +473,16 @@ pub async fn update_peer_site( .and_then(|v| v.as_str()) .map(|s| s.to_string()) .or(existing.connection_id), + peer_inbound_access_key: if payload.get("peer_inbound_access_key").is_some() { + payload + .get("peer_inbound_access_key") + .and_then(|v| v.as_str()) + .map(str::trim) + .filter(|s| !s.is_empty()) + .map(|s| s.to_string()) + } else { + existing.peer_inbound_access_key + }, created_at: existing.created_at, is_healthy: existing.is_healthy, last_health_check: existing.last_health_check, @@ -1428,12 +1444,8 @@ fn require_admin_or_registered_peer(state: &AppState, principal: &Principal) -> } }; for peer in registry.list_peers() { - if let Some(conn_id) = peer.connection_id.as_deref() { - if let Some(conn) = state.connections.get(conn_id) { - if conn.access_key == principal.access_key { - return None; - } - } + if peer.peer_inbound_access_key.as_deref() == Some(principal.access_key.as_str()) { + return None; } } Some(json_error( diff --git a/crates/myfsio-server/src/handlers/ui_pages.rs b/crates/myfsio-server/src/handlers/ui_pages.rs index aa44e98..514c0fd 100644 --- a/crates/myfsio-server/src/handlers/ui_pages.rs +++ b/crates/myfsio-server/src/handlers/ui_pages.rs @@ -1192,6 +1192,7 @@ pub async fn sites_dashboard( "region": p.region, "priority": p.priority, "connection_id": p.connection_id, + "peer_inbound_access_key": p.peer_inbound_access_key, "is_healthy": p.is_healthy, "last_health_check": p.last_health_check, }) @@ -1496,6 +1497,8 @@ pub struct PeerSiteForm { #[serde(default)] pub connection_id: String, #[serde(default)] + pub peer_inbound_access_key: String, + #[serde(default)] pub csrf_token: String, } @@ -1657,6 +1660,14 @@ pub async fn add_peer_site( } let has_connection = connection_id.is_some(); + let peer_inbound_access_key = { + let value = form.peer_inbound_access_key.trim(); + if value.is_empty() { + None + } else { + Some(value.to_string()) + } + }; let peer = crate::services::site_registry::PeerSite { site_id: site_id.clone(), endpoint, @@ -1671,6 +1682,7 @@ pub async fn add_peer_site( } }, connection_id: connection_id.clone(), + peer_inbound_access_key, created_at: None, is_healthy: false, last_health_check: None, @@ -1755,6 +1767,14 @@ pub async fn update_peer_site( } } + let peer_inbound_access_key = { + let value = form.peer_inbound_access_key.trim(); + if value.is_empty() { + None + } else { + Some(value.to_string()) + } + }; let peer = crate::services::site_registry::PeerSite { site_id: site_id.clone(), endpoint: form.endpoint.trim().to_string(), @@ -1769,6 +1789,7 @@ pub async fn update_peer_site( } }, connection_id, + peer_inbound_access_key, created_at: existing.created_at, is_healthy: existing.is_healthy, last_health_check: existing.last_health_check, diff --git a/crates/myfsio-server/src/services/site_registry.rs b/crates/myfsio-server/src/services/site_registry.rs index 00ab5c5..c89c773 100644 --- a/crates/myfsio-server/src/services/site_registry.rs +++ b/crates/myfsio-server/src/services/site_registry.rs @@ -38,6 +38,8 @@ pub struct PeerSite { #[serde(default)] pub connection_id: Option, #[serde(default)] + pub peer_inbound_access_key: Option, + #[serde(default)] pub created_at: Option, #[serde(default)] pub is_healthy: bool, diff --git a/crates/myfsio-server/templates/sites.html b/crates/myfsio-server/templates/sites.html index 4f56864..892eec2 100644 --- a/crates/myfsio-server/templates/sites.html +++ b/crates/myfsio-server/templates/sites.html @@ -142,6 +142,11 @@
Link to a remote connection for health checks
+
+ + +
Access key the peer presents when calling this site (e.g. /admin/cluster/overview). Leave blank to require admin credentials.
+
+
+ + +
Access key the peer presents when calling this site (e.g. /admin/cluster/overview). Leave blank to require admin credentials.
+