Skip to content

fix(sec): corrects validation for regex objects (hostname and forbidden#1983

Merged
oliverbaehler merged 26 commits into
projectcapsule:mainfrom
oliverbaehler:feat/sec
Jun 24, 2026
Merged

fix(sec): corrects validation for regex objects (hostname and forbidden#1983
oliverbaehler merged 26 commits into
projectcapsule:mainfrom
oliverbaehler:feat/sec

Conversation

@oliverbaehler

Copy link
Copy Markdown
Collaborator

No description provided.

oliverbaehler and others added 26 commits December 10, 2025 06:50
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>
Copilot AI review requested due to automatic review settings June 24, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.OnUpdate parameter 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())
@oliverbaehler oliverbaehler merged commit 8d89d68 into projectcapsule:main Jun 24, 2026
18 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants