From 3673c110c252d73ce08c764f39c8a73ca168f4e2 Mon Sep 17 00:00:00 2001 From: parth-gr Date: Thu, 3 Nov 2022 19:56:36 +0530 Subject: [PATCH] core: validate crd name size from admission controller Closes: https://github.com/rook/rook/issues/11212 Signed-off-by: parth-gr (cherry picked from commit 7bd863d5abbc20e541a69c25101ddd125687df67) --- pkg/apis/ceph.rook.io/v1/object.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/apis/ceph.rook.io/v1/object.go b/pkg/apis/ceph.rook.io/v1/object.go index 903bacf54..07186dbd4 100644 --- a/pkg/apis/ceph.rook.io/v1/object.go +++ b/pkg/apis/ceph.rook.io/v1/object.go @@ -28,6 +28,11 @@ var _ webhook.Validator = &CephObjectStore{} const ServiceServingCertKey = "service.beta.openshift.io/serving-cert-secret-name" +// 38 is the max length of a ceph store name as total length of the resource name cannot be more than 63 characters limit +// and there is a configmap which is formed by appending `rook-ceph-rgw--mime-types` +// so over all it brings up to (63-14-11 = 38) characters for the store name +const objectStoreNameMaxLen = 38 + func (s *ObjectStoreSpec) IsMultisite() bool { return s.Zone.Name != "" } @@ -76,6 +81,9 @@ func ValidateObjectSpec(gs *CephObjectStore) error { if gs.Namespace == "" { return errors.New("missing namespace") } + if len(gs.Name) > objectStoreNameMaxLen { + return errors.New("object store name cannot be longer than 38 characters") + } securePort := gs.Spec.Gateway.SecurePort if securePort < 0 || securePort > 65535 { return errors.Errorf("securePort value of %d must be between 0 and 65535", securePort)