浏览代码

Block nebula ssh server from listening on port 22 (#266)

Port 22 is blocked as a safety mechanism. In a case where nebula is
started before sshd, a system may be rendered unreachable if nebula
is holding the system ssh port and there is no other connectivity.

This commit enforces the restriction, which could previously be worked
around by listening on an IPv6 address, e.g.  "[::]:22".
forfuncsake 4 年之前
父节点
当前提交
50b04413c7
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      ssh.go

+ 5 - 4
ssh.go

@@ -66,10 +66,11 @@ func configSSH(ssh *sshd.SSHServer, c *Config) error {
 		return fmt.Errorf("sshd.listen must be provided")
 		return fmt.Errorf("sshd.listen must be provided")
 	}
 	}
 
 
-	port := strings.Split(listen, ":")
-	if len(port) < 2 {
-		return fmt.Errorf("sshd.listen does not have a port")
-	} else if port[1] == "22" {
+	_, port, err := net.SplitHostPort(listen)
+	if err != nil {
+		return fmt.Errorf("invalid sshd.listen address: %s", err)
+	}
+	if port == "22" {
 		return fmt.Errorf("sshd.listen can not use port 22")
 		return fmt.Errorf("sshd.listen can not use port 22")
 	}
 	}