mirror of
https://github.com/versity/versitygw.git
synced 2026-01-08 04:35:15 +00:00
feat: add option to disable strict bucket name checks
Some systems may choose to allow non-aws compliant bucket names and/or handle the bucket naem validation in the backend instead. This adds the option to turn off the strict bucket name validation checks in the frontend API handlers. When frontend bucket name validation is disabled, we need to do sanity checks for posix compliant names in the posix/scoutfs backends. This is automatically enabled when strict bucket name validation is disabled. Fixes #1564
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
@@ -41,6 +42,16 @@ var (
|
||||
bucketNameIpRegexp = regexp.MustCompile(`^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`)
|
||||
)
|
||||
|
||||
var strictBucketNameValidation atomic.Bool
|
||||
|
||||
func init() {
|
||||
strictBucketNameValidation.Store(true)
|
||||
}
|
||||
|
||||
func SetBucketNameValidationStrict(strict bool) {
|
||||
strictBucketNameValidation.Store(strict)
|
||||
}
|
||||
|
||||
func GetUserMetaData(headers *fasthttp.RequestHeader) (metadata map[string]string) {
|
||||
metadata = make(map[string]string)
|
||||
headers.DisableNormalizing()
|
||||
@@ -209,6 +220,10 @@ func StreamResponseBody(ctx *fiber.Ctx, rdr io.ReadCloser, bodysize int) {
|
||||
}
|
||||
|
||||
func IsValidBucketName(bucket string) bool {
|
||||
if !strictBucketNameValidation.Load() {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(bucket) < 3 || len(bucket) > 63 {
|
||||
debuglogger.Logf("bucket name length should be in 3-63 range, got: %v\n", len(bucket))
|
||||
return false
|
||||
|
||||
@@ -231,6 +231,28 @@ func TestIsValidBucketName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetBucketNameValidationStrict(t *testing.T) {
|
||||
SetBucketNameValidationStrict(true)
|
||||
t.Cleanup(func() {
|
||||
SetBucketNameValidationStrict(true)
|
||||
})
|
||||
|
||||
invalidBucket := "Invalid_Bucket"
|
||||
if IsValidBucketName(invalidBucket) {
|
||||
t.Fatalf("expected %q to be invalid with strict validation", invalidBucket)
|
||||
}
|
||||
|
||||
SetBucketNameValidationStrict(false)
|
||||
if !IsValidBucketName(invalidBucket) {
|
||||
t.Fatalf("expected %q to be accepted when strict validation disabled", invalidBucket)
|
||||
}
|
||||
|
||||
SetBucketNameValidationStrict(true)
|
||||
if IsValidBucketName(invalidBucket) {
|
||||
t.Fatalf("expected %q to be invalid after re-enabling strict validation", invalidBucket)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUint(t *testing.T) {
|
||||
type args struct {
|
||||
str string
|
||||
|
||||
Reference in New Issue
Block a user