From 7cd2dc66611c21914adffc53a1ac6b836d2fe75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Loyet?= <822436+fatpat@users.noreply.github.com> Date: Wed, 12 Apr 2023 13:04:27 +0200 Subject: [PATCH] add --resolve-host flag to force DNS resolution to explode multiple A/AAAA records (#186) add --resolve-host and --shuffle-hosts hidden flags `--resolve-host`: to resolve the host(s) ip(s) (including multiple A/AAAA records). This can break SSL certificates, use --insecure if so --- cli/benchserver.go | 2 +- cli/client.go | 32 ++++++++++++++++++++++++++++---- cli/flags.go | 5 +++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/cli/benchserver.go b/cli/benchserver.go index 55d7402c..12bcba93 100644 --- a/cli/benchserver.go +++ b/cli/benchserver.go @@ -92,7 +92,7 @@ func runServerBenchmark(ctx *cli.Context, b bench.Benchmark) (bool, error) { return false, nil } - conns := newConnections(parseHosts(ctx.String("warp-client"))) + conns := newConnections(parseHosts(ctx.String("warp-client"), false)) if len(conns.hosts) == 0 { return true, errors.New("no hosts") } diff --git a/cli/client.go b/cli/client.go index d4e7981a..f7f3a65b 100644 --- a/cli/client.go +++ b/cli/client.go @@ -52,7 +52,7 @@ const ( ) func newClient(ctx *cli.Context) func() (cl *minio.Client, done func()) { - hosts := parseHosts(ctx.String("host")) + hosts := parseHosts(ctx.String("host"), ctx.Bool("resolve-host")) switch len(hosts) { case 0: fatalIf(probe.NewError(errors.New("no host defined")), "Unable to create MinIO client") @@ -220,7 +220,7 @@ func clientTransport(ctx *cli.Context) http.RoundTripper { } // parseHosts will parse the host parameter given. -func parseHosts(h string) []string { +func parseHosts(h string, resolveDNS bool) []string { hosts := strings.Split(h, ",") var dst []string for _, host := range hosts { @@ -238,7 +238,31 @@ func parseHosts(h string) []string { dst = append(dst, strings.Join(lbls, "")) } } - return dst + + if !resolveDNS { + return dst + } + + var resolved []string + for _, hostport := range dst { + host, port, _ := net.SplitHostPort(hostport) + if host == "" { + host = hostport + } + ips, err := net.LookupIP(host) + if err != nil { + fatalIf(probe.NewError(err), "Could not get IPs for "+hostport) + log.Fatal(err.Error()) + } + for _, ip := range ips { + if port == "" { + resolved = append(resolved, ip.String()) + } else { + resolved = append(resolved, ip.String()+":"+port) + } + } + } + return resolved } // mustGetSystemCertPool - return system CAs or empty pool in case of error (or windows) @@ -254,7 +278,7 @@ func mustGetSystemCertPool() *x509.CertPool { } func newAdminClient(ctx *cli.Context) *madmin.AdminClient { - hosts := parseHosts(ctx.String("host")) + hosts := parseHosts(ctx.String("host"), ctx.Bool("resolve-host")) if len(hosts) == 0 { fatalIf(probe.NewError(errors.New("no host defined")), "Unable to create MinIO admin client") } diff --git a/cli/flags.go b/cli/flags.go index bde5f4a5..784f184c 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -186,6 +186,11 @@ var ioFlags = []cli.Flag{ Value: string(hostSelectTypeWeighed), Usage: fmt.Sprintf("Host selection algorithm. Can be %q or %q", hostSelectTypeWeighed, hostSelectTypeRoundrobin), }, + cli.BoolFlag{ + Name: "resolve-host", + Usage: "Resolve the host(s) ip(s) (including multiple A/AAAA records). This can break SSL certificates, use --insecure if so", + Hidden: true, + }, cli.IntFlag{ Name: "concurrent", Value: 20,