Skip to content

Commit

Permalink
add --resolve-host flag to force DNS resolution to explode multiple A…
Browse files Browse the repository at this point in the history
…/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
  • Loading branch information
fatpat authored Apr 12, 2023
1 parent e491b46 commit 7cd2dc6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/benchserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
32 changes: 28 additions & 4 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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")
}
Expand Down
5 changes: 5 additions & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7cd2dc6

Please sign in to comment.