-
Notifications
You must be signed in to change notification settings - Fork 440
🌱 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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ package webhook | |
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"sort" | ||
"strings" | ||
|
||
|
@@ -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]$`) | ||
|
||
for _, root := range ctx.Roots { | ||
markerSet, err := markers.PackageMarkers(ctx.Collector, root) | ||
if err != nil { | ||
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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.