From 55aa431578ddc6c9b57b873bf39ebe9d3ee10239 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 10 Jun 2024 20:13:30 -0700 Subject: [PATCH] fix: on windows avoid ':' as part of the object name (#19907) fixes #18865 avoid-colon --- cmd/batch-handlers.go | 2 +- cmd/batch-job-common-types.go | 10 ---------- cmd/bucket-listobjects-handlers.go | 2 +- cmd/object-api-utils.go | 12 ++++++++++++ cmd/sts-handlers.go | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cmd/batch-handlers.go b/cmd/batch-handlers.go index 044e27a41..0e87cc795 100644 --- a/cmd/batch-handlers.go +++ b/cmd/batch-handlers.go @@ -1633,7 +1633,7 @@ func (a adminAPIHandlers) StartBatchJob(w http.ResponseWriter, r *http.Request) return } - job.ID = fmt.Sprintf("%s%s%d", shortuuid.New(), getBatchJobIDSeparator(), GetProxyEndpointLocalIndex(globalProxyEndpoints)) + job.ID = fmt.Sprintf("%s%s%d", shortuuid.New(), getKeySeparator(), GetProxyEndpointLocalIndex(globalProxyEndpoints)) job.User = user job.Started = time.Now() diff --git a/cmd/batch-job-common-types.go b/cmd/batch-job-common-types.go index 661bc8628..83e1c554b 100644 --- a/cmd/batch-job-common-types.go +++ b/cmd/batch-job-common-types.go @@ -19,7 +19,6 @@ package cmd import ( "fmt" - "runtime" "strings" "time" @@ -289,12 +288,3 @@ func (s *BatchJobSize) UnmarshalYAML(unmarshal func(interface{}) error) error { *s = BatchJobSize(sz) return nil } - -// getBatchJobIDSeparator - returns the separator to be used in the batch job ID -// windows requires `_` as the separator `:` will be an invalid one -func getBatchJobIDSeparator() string { - if runtime.GOOS == globalWindowsOSName { - return "_" - } - return ":" -} diff --git a/cmd/bucket-listobjects-handlers.go b/cmd/bucket-listobjects-handlers.go index 82d0fab56..1dafdfb5a 100644 --- a/cmd/bucket-listobjects-handlers.go +++ b/cmd/bucket-listobjects-handlers.go @@ -231,7 +231,7 @@ func parseRequestToken(token string) (subToken string, nodeIndex int) { if token == "" { return token, -1 } - i := strings.Index(token, getBatchJobIDSeparator()) + i := strings.Index(token, getKeySeparator()) if i < 0 { return token, -1 } diff --git a/cmd/object-api-utils.go b/cmd/object-api-utils.go index d58acc887..d095ddb6b 100644 --- a/cmd/object-api-utils.go +++ b/cmd/object-api-utils.go @@ -80,6 +80,18 @@ const ( compMinIndexSize = 8 << 20 ) +// getkeyeparator - returns the separator to be used for +// persisting on drive. +// +// - ":" is used on non-windows platforms +// - "_" is used on windows platforms +func getKeySeparator() string { + if runtime.GOOS == globalWindowsOSName { + return "_" + } + return ":" +} + // isMinioBucket returns true if given bucket is a MinIO internal // bucket and false otherwise. func isMinioMetaBucketName(bucket string) bool { diff --git a/cmd/sts-handlers.go b/cmd/sts-handlers.go index fe46f6feb..aac928d99 100644 --- a/cmd/sts-handlers.go +++ b/cmd/sts-handlers.go @@ -865,7 +865,7 @@ func (sts *stsAPIHandlers) AssumeRoleWithCertificate(w http.ResponseWriter, r *h } // Associate any service accounts to the certificate CN - parentUser := "tls:" + certificate.Subject.CommonName + parentUser := "tls" + getKeySeparator() + certificate.Subject.CommonName claims[expClaim] = UTCNow().Add(expiry).Unix() claims[subClaim] = certificate.Subject.CommonName @@ -990,7 +990,7 @@ func (sts *stsAPIHandlers) AssumeRoleWithCustomToken(w http.ResponseWriter, r *h expiry = requestedDuration } - parentUser := "custom:" + res.Success.User + parentUser := "custom" + getKeySeparator() + res.Success.User // metadata map claims[expClaim] = UTCNow().Add(time.Duration(expiry) * time.Second).Unix()