浏览代码

Merge pull request #8466 from heyitsanthony/tls-srv-mismatch

srv: if a host matches a peer, only use if url schemes match
Anthony Romano 8 年之前
父节点
当前提交
7d4a8a6935
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. 2 1
      pkg/srv/srv.go
  2. 8 1
      pkg/srv/srv_test.go

+ 2 - 1
pkg/srv/srv.go

@@ -71,9 +71,10 @@ func GetCluster(service, name, dns string, apurls types.URLs) ([]string, error)
 			// SRV records have a trailing dot but URL shouldn't.
 			shortHost := strings.TrimSuffix(srv.Target, ".")
 			urlHost := net.JoinHostPort(shortHost, port)
-			stringParts = append(stringParts, fmt.Sprintf("%s=%s://%s", n, scheme, urlHost))
 			if ok && url.Scheme != scheme {
 				err = fmt.Errorf("bootstrap at %s from DNS for %s has scheme mismatch with expected peer %s", scheme+"://"+urlHost, service, url.String())
+			} else {
+				stringParts = append(stringParts, fmt.Sprintf("%s=%s://%s", n, scheme, urlHost))
 			}
 		}
 		if len(stringParts) == 0 {

+ 8 - 1
pkg/srv/srv_test.go

@@ -86,7 +86,14 @@ func TestSRVGetCluster(t *testing.T) {
 
 			"dnsClusterTest=https://1.example.com:2480,0=https://2.example.com:2480,1=https://3.example.com:2480",
 		},
-		// invalid
+		// reject if apurls are TLS but SRV is only http
+		{
+			nil,
+			srvAll,
+			[]string{"https://10.0.0.1:2480"},
+
+			"0=http://2.example.com:2480,1=http://3.example.com:2480",
+		},
 	}
 
 	resolveTCPAddr = func(network, addr string) (*net.TCPAddr, error) {