fix(sec): corrects validation for regex objects (hostname and forbidden#1983
Merged
Conversation
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
…en metadata) Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Tenant webhook validation around regex fields by ensuring the new Tenant object is validated on update (Ingress allowed hostnames), and by correctly compiling/validating forbidden labels/annotations regex expressions (with improved error messaging). It also adds/extends e2e coverage for invalid regex inputs.
Changes:
- Fix
hostnameRegexHandler.OnUpdateparameter ordering so update validation runs against the updated Tenant spec. - Fix forbidden labels/annotations regex validation to compile the correct expression(s), skip empty regexes, and include compile errors in the denial message.
- Add e2e tests that cover invalid forbidden labels/annotations regexes and invalid allowed hostnames regex updates.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/webhook/tenant/validation/hostname_regex.go | Fixes update handler parameter ordering so invalid regex updates are actually validated. |
| internal/webhook/tenant/validation/forbidden_annotations_regex.go | Correctly validates both forbidden labels and annotations regex expressions (and improves denial message). |
| e2e/tenant_forbidden_annotations_regex_test.go | Adds e2e coverage for invalid forbidden labels/annotations regexes being denied. |
| e2e/ingress_hostnames_test.go | Adds e2e coverage for denying updates that set an invalid allowed hostnames regex. |
Comment on lines
+313
to
+335
| Eventually(func() error { | ||
| current := &capsulev1beta2.Tenant{} | ||
| if err := k8sClient.Get( | ||
| context.TODO(), | ||
| client.ObjectKeyFromObject(tnt), | ||
| current, | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if current.Spec.IngressOptions.AllowedHostnames == nil { | ||
| current.Spec.IngressOptions.AllowedHostnames = &api.AllowedListSpec{} | ||
| } | ||
|
|
||
| current.Spec.IngressOptions.AllowedHostnames.Regex = invalidRegex | ||
|
|
||
| err := k8sClient.Update(context.TODO(), current) | ||
| if err == nil { | ||
| return fmt.Errorf("expected tenant update with invalid allowed hostname regex %q to be denied", invalidRegex) | ||
| } | ||
|
|
||
| return nil | ||
| }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) |
Svarrogh1337
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.