From 424b44c2475838796c2600eda8381af0947951f7 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 28 Apr 2022 16:27:53 -0700 Subject: [PATCH] allow changing server command line from http->https (#14832) this is allowed as long as order is preserved as is on an existing setup, the new command line is updated in `pool.bin` to facilitate future decommission's on these pools. --- cmd/erasure-server-pool-decom.go | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/cmd/erasure-server-pool-decom.go b/cmd/erasure-server-pool-decom.go index c2892d853..ce66b9dfa 100644 --- a/cmd/erasure-server-pool-decom.go +++ b/cmd/erasure-server-pool-decom.go @@ -25,6 +25,7 @@ import ( "net/http" "sort" "strconv" + "strings" "sync" "time" @@ -309,9 +310,31 @@ func (p *poolMeta) validate(pools []*erasureSets) (bool, error) { specifiedPools[pool.endpoints.CmdLine] = idx } + replaceScheme := func(k string) string { + // This is needed as fallback when users are changeing + // from http->https or https->http, we need to verify + // both because MinIO remembers the command-line in + // "exact" order - as long as this order is not disturbed + // we allow changing the "scheme" i.e internode communication + // from plain-text to TLS or from TLS to plain-text. + if strings.HasPrefix(k, "http://") { + k = strings.ReplaceAll(k, "http://", "https://") + } else if strings.HasPrefix(k, "https://") { + k = strings.ReplaceAll(k, "https://", "http://") + } + return k + } + + var update bool // Check if specified pools need to remove decommissioned pool. for k := range specifiedPools { pi, ok := rememberedPools[k] + if !ok { + pi, ok = rememberedPools[replaceScheme(k)] + if ok { + update = true // Looks like user is changing from http->https or https->http + } + } if ok && pi.completed { return false, fmt.Errorf("pool(%s) = %s is decommissioned, please remove from server command line", humanize.Ordinal(pi.position+1), k) } @@ -323,6 +346,12 @@ func (p *poolMeta) validate(pools []*erasureSets) (bool, error) { continue } _, ok := specifiedPools[k] + if !ok { + _, ok = specifiedPools[replaceScheme(k)] + if ok { + update = true // Looks like user is changing from http->https or https->http + } + } if !ok { return false, fmt.Errorf("pool(%s) = %s is not specified, please specify on server command line", humanize.Ordinal(pi.position+1), k) } @@ -332,6 +361,12 @@ func (p *poolMeta) validate(pools []*erasureSets) (bool, error) { if len(rememberedPools) == len(specifiedPools) { for k, pi := range rememberedPools { pos, ok := specifiedPools[k] + if !ok { + pos, ok = specifiedPools[replaceScheme(k)] + if ok { + update = true // Looks like user is changing from http->https or https->http + } + } if !ok { return false, fmt.Errorf("pool(%s) = %s is not specified, please specify on server command line", humanize.Ordinal(pi.position+1), k) } @@ -341,7 +376,9 @@ func (p *poolMeta) validate(pools []*erasureSets) (bool, error) { } } - update := len(rememberedPools) != len(specifiedPools) + if !update { + update = len(rememberedPools) != len(specifiedPools) + } if update { for k, pi := range rememberedPools { if pi.decomStarted && !pi.completed {