mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-25 16:07:24 +00:00
fix(sec): corrects validation for regex objects (hostname and forbidden (#1983)
* fix(controller): decode old object for delete requests Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix: preserve ca-bundles injected from external providers Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix(sec): corrects validation for regex objects (hostname and forbidden metadata) Signed-off-by: Oliver Baehler <oliver@sudo-i.net> --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
This commit is contained in:
@@ -68,18 +68,27 @@ func (h *forbiddenAnnotationsRegexHandler) OnUpdate(
|
||||
}
|
||||
|
||||
func (h *forbiddenAnnotationsRegexHandler) validate(tnt *capsulev1beta2.Tenant, req admission.Request) *admission.Response {
|
||||
if tnt.Spec.NamespaceOptions == nil {
|
||||
if tnt == nil || tnt.Spec.NamespaceOptions == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
annotationsToCheck := map[string]string{
|
||||
regexesToCheck := map[string]string{
|
||||
"labels": tnt.Spec.NamespaceOptions.ForbiddenLabels.Regex,
|
||||
"annotations": tnt.Spec.NamespaceOptions.ForbiddenAnnotations.Regex,
|
||||
}
|
||||
|
||||
for scope, annotation := range annotationsToCheck {
|
||||
if _, err := regexp.Compile(tnt.Spec.NamespaceOptions.ForbiddenLabels.Regex); err != nil {
|
||||
return ad.Denyf("unable to compile %s regex for forbidden %s", annotation, scope)
|
||||
for scope, expression := range regexesToCheck {
|
||||
if expression == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := regexp.Compile(expression); err != nil {
|
||||
return ad.Denyf(
|
||||
"unable to compile regex %q for forbidden %s: %v",
|
||||
expression,
|
||||
scope,
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ func (h *hostnameRegexHandler) OnDelete(
|
||||
func (h *hostnameRegexHandler) OnUpdate(
|
||||
_ client.Client,
|
||||
_ client.Reader,
|
||||
old *capsulev1beta2.Tenant,
|
||||
tnt *capsulev1beta2.Tenant,
|
||||
_ *capsulev1beta2.Tenant,
|
||||
decoder admission.Decoder,
|
||||
_ events.EventRecorder,
|
||||
) handlers.Func {
|
||||
|
||||
Reference in New Issue
Block a user