Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/querier/tenantfederation/regex_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ func (r *RegexValidator) TenantID(ctx context.Context) (string, error) {
return "", errInvalidRegex
}

if err := tenant.CheckTenantIDLength(id); err != nil {
return "", err
}

if err := tenant.CheckTenantIDIsSupported(id); err != nil {
return "", err
}

return id, nil
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/querier/tenantfederation/regex_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tenantfederation

import (
"context"
"errors"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -120,6 +122,31 @@ func Test_RegexValidator(t *testing.T) {
orgID: "[a-z",
expectedErr: errInvalidRegex,
},
{
description: "tenant ID is too long",
orgID: strings.Repeat("a", 151),
expectedErr: errors.New("tenant ID is too long: max 150 characters"),
},
{
description: ".",
orgID: ".",
expectedErr: errors.New("tenant ID is '.' or '..'"),
},
{
description: "..",
orgID: "..",
expectedErr: errors.New("tenant ID is '.' or '..'"),
},
{
description: "__markers__",
orgID: "__markers__",
expectedErr: errors.New("tenant ID '__markers__' is not allowed"),
},
{
description: "user-index.json.gz",
orgID: "user-index.json.gz",
expectedErr: errors.New("tenant ID 'user-index.json.gz' is not allowed"),
},
}

for _, tc := range tests {
Expand Down
18 changes: 17 additions & 1 deletion pkg/tenant/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NormalizeTenantIDs(tenantIDs []string) []string {
return tenantIDs[0:posOut]
}

// ValidTenantID
// ValidTenantID validate tenantID
func ValidTenantID(s string) error {
// check if it contains invalid runes
for pos, r := range s {
Expand All @@ -66,10 +66,26 @@ func ValidTenantID(s string) error {
}
}

if err := CheckTenantIDLength(s); err != nil {
return err
}

if err := CheckTenantIDIsSupported(s); err != nil {
return err
}

return nil
}

func CheckTenantIDLength(s string) error {
if len(s) > 150 {
return errTenantIDTooLong
}

return nil
}

func CheckTenantIDIsSupported(s string) error {
// check tenantID is "__markers__"
if s == GlobalMarkersDir {
return errTenantIDMarkers
Expand Down
Loading