Просмотр исходного кода

fix(ssh): log the probe paths that never reach the pool (#1893) (#1926)

Nacho 4 недель назад
Родитель
Сommit
ef96238ac3

+ 7 - 0
server-go/internal/discover/discover.go

@@ -387,6 +387,10 @@ func Routers(ctx context.Context, db *sql.DB, keyPath string, force bool) Respon
 	if ctx.Err() != nil {
 		return Response{Subnet: &subnet, Results: []Result{}, Cached: false, Error: "cancelled"}
 	}
+	// #1893: el barrido abre y cierra TCP/22 en todo el /24 sin autenticar, que
+	// en dropbear aparece como "Exit before auth". Una sola línea por barrido
+	// basta para atribuir ese tráfico (y descartar que sea un sondeo de flota).
+	log.Printf("[netpulse:discover] barrido %s: %d de %d hosts con el 22 abierto", subnet, len(alive), len(hosts))
 
 	// #1895: "ya añadido" no puede ser una comparación de cadenas en crudo. El
 	// alta admite un nombre DNS o una IP con puerto y el barrido solo ve IPs,
@@ -414,6 +418,9 @@ func Routers(ctx context.Context, db *sql.DB, keyPath string, force bool) Respon
 			return Response{Subnet: &subnet, Results: []Result{}, Cached: false, Error: "cancelled"}
 		}
 		authorized, model := probeSsh(ctx, c.h, keyPath)
+		// #1893: deja rastro del probe openssh (una conexión TCP/22 por host), que
+		// de otro modo no aparece en el log del servidor.
+		log.Printf("[netpulse:ssh] %s: probe openssh autorizado=%v", c.h, authorized)
 		if authorized {
 			// Issue #651: pinar TODAS las host keys del router en known_hosts.
 			// El probe openssh (accept-new) solo registra la clave negociada

+ 2 - 0
server-go/internal/routerstore/routerstore.go

@@ -537,6 +537,8 @@ func probeGatewayModel(host, keyPath string) (model, typ string) {
 		return "", "openwrt"
 	case res := <-ch:
 		if res.err != nil {
+			// #1893: el bootstrap del gateway también diala SSH fuera del pool.
+			log.Printf("[netpulse:ssh] gateway %s: ssh falló (%v); se asume openwrt", host, res.err)
 			return "", "openwrt"
 		}
 		var board struct {

+ 9 - 1
server-go/internal/sshkey/sshkey.go

@@ -334,9 +334,17 @@ func scanHostKeys(host string) ([]khEntry, error) {
 	cmd := exec.Command("ssh-keyscan", "-T", "3", "-t", "ed25519,ecdsa,rsa", host)
 	out, err := cmd.Output()
 	if err != nil {
+		// #1893: ssh-keyscan abre una conexión por algoritmo y las cierra antes
+		// de autenticar, que en dropbear se ve como "Exit before auth: Exited
+		// normally". Sin esta línea ese tráfico no se podía atribuir a NetPulse.
+		log.Printf("[netpulse:ssh] ssh-keyscan %s: %v", host, err)
 		return nil, &ExecError{What: "ssh-keyscan", Err: err, Out: string(out)}
 	}
-	return parseKnownHosts(string(out))
+	entries, perr := parseKnownHosts(string(out))
+	if perr == nil {
+		log.Printf("[netpulse:ssh] ssh-keyscan %s: %d clave(s) de host", host, len(entries))
+	}
+	return entries, perr
 }
 
 func readKnownHosts(path string) ([]khEntry, error) {