API-avain -autentikaatio natiivisolmuille
Natiivisolmujen (node_type: native) auth-viesti vaatii api_key-kentän joka vastaa hubin NODE_API_KEY-ympäristömuuttujaa. Virheellinen avain sulkee WebSocket-yhteyden. Selainsolmut eivät vaadi avainta (Origin-validointi suojaa niitä). Jos NODE_API_KEY ei ole asetettu, kaikki natiivisolmut hyväksytään (kehitysympäristö). Käyttö: Hub: NODE_API_KEY=kpn_sk_abc123 cargo run Node: NODE_API_KEY=kpn_sk_abc123 cargo run Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -691,6 +691,18 @@ async fn handle_socket(socket: WebSocket, state: Arc<AppState>, ip: IpAddr) {
|
|||||||
let allocated = json.get("allocated_gb").and_then(|v| v.as_u64()).unwrap_or(4) as u32;
|
let allocated = json.get("allocated_gb").and_then(|v| v.as_u64()).unwrap_or(4) as u32;
|
||||||
let node_type = json.get("node_type").and_then(|v| v.as_str()).unwrap_or("browser");
|
let node_type = json.get("node_type").and_then(|v| v.as_str()).unwrap_or("browser");
|
||||||
|
|
||||||
|
// API-avain vaaditaan natiivisolmuilta (ei selaimilta)
|
||||||
|
if node_type == "native" {
|
||||||
|
let required_key = std::env::var("NODE_API_KEY").unwrap_or_default();
|
||||||
|
if !required_key.is_empty() {
|
||||||
|
let provided_key = json.get("api_key").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
|
if provided_key != required_key {
|
||||||
|
tracing::warn!("Solmu {} ({}) hylätty: virheellinen API-avain", node_id, ip);
|
||||||
|
break; // Suljetaan WebSocket
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut map = state.nodes_vram.lock().unwrap();
|
let mut map = state.nodes_vram.lock().unwrap();
|
||||||
map.insert(node_id, allocated);
|
map.insert(node_id, allocated);
|
||||||
|
|||||||
Reference in New Issue
Block a user