Skip to content

🌱 validate group names in webhooks. #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
11 changes: 11 additions & 0 deletions pkg/webhook/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package webhook

import (
"fmt"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -448,6 +449,8 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
var mutatingWebhookCfgs admissionregv1.MutatingWebhookConfiguration
var validatingWebhookCfgs admissionregv1.ValidatingWebhookConfiguration

groupRegex := regexp.MustCompile(`^[a-z][-a-z0-9.]*[a-z0-9]$`)
Copy link
Member

Choose a reason for hiding this comment

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

maybe worth to have some positive and negative unit tests for this to ensure we (don't) error out on the right ones.


for _, root := range ctx.Roots {
markerSet, err := markers.PackageMarkers(ctx.Collector, root)
if err != nil {
Expand Down Expand Up @@ -493,6 +496,14 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
if err != nil {
return err
}
for _, group := range cfg.Groups {
if group == "" { // aka "core"
Copy link
Member

Choose a reason for hiding this comment

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

Why would we continue? There must be a groupname

continue
}
if !groupRegex.MatchString(group) {
Copy link
Member

Choose a reason for hiding this comment

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

This error will be very frustrating for anyone that runs into it - Please include the string of the regex used for validation

return fmt.Errorf("invalid group name: %s", group)
}
}
if cfg.Mutating {
w, err := cfg.ToMutatingWebhook()
if err != nil {
Expand Down