Skip to content

fix: reject whitespace in webhook image validation - #1509

Open
safiya2610 wants to merge 1 commit into
volcano-sh:mainfrom
safiya2610:fix-1026-webhook-image-whitespace
Open

fix: reject whitespace in webhook image validation#1509
safiya2610 wants to merge 1 commit into
volcano-sh:mainfrom
safiya2610:fix-1026-webhook-image-whitespace

Conversation

@safiya2610

@safiya2610 safiya2610 commented Aug 5, 2026

Copy link
Copy Markdown

This PR addresses two separate issues:

Cache URI Parsing: When users provided cache URIs that contained multiple :// separators (e.g., pvc://my-cache-path/http://some-model), the parsing logic using strings.Split would improperly truncate the path.
Webhook Image Validation: The existing webhook validation for container images only rejected exact space characters (" "), but allowed other whitespace characters like tabs or newlines to slip through, which later failed Kubernetes' strict container image validation.

Solution
Cache Paths: Refactored GetCachePath in pkg/model-booster-controller/convert/model_serving.go to use strings.Cut instead of strings.Split. This ensures that only the very first :// is treated as the URI prefix separator, preserving the rest of the path intact.
Image Validation: Updated validateImageField in pkg/model-booster-controller/webhook/model_validator.go to use strings.ContainsAny(image, " \t\r\n") to reliably reject all forms of whitespace.
Tests: Added a new table-driven test case in model_serving_test.go to verify cache paths containing multiple :// separators are no longer truncated.

Testing Done
go test ./pkg/model-booster-controller/convert - Pass
go test ./pkg/model-booster-controller/webhook - Pass

Fixes #1026

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign git-malu for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

Welcome @safiya2610! It looks like this is your first PR to volcano-sh/kthena 🎉

@kube-gopher

Copy link
Copy Markdown
Member

/kind bug

Comment thread pkg/model-booster-controller/webhook/model_validator.go Outdated

@kube-gopher kube-gopher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

git commit -s . please add -s

@safiya2610

Copy link
Copy Markdown
Author

git commit -s . please add -s

while squashing all commit in one, I will do.

if strings.Contains(image, " ") {
return fmt.Errorf("image cannot contain spaces")
if strings.IndexFunc(image, unicode.IsSpace) != -1 {
return fmt.Errorf("image cannot contain whitespace")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no test case added

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have added a comprehensive test suite (TestValidateImageField) in pkg/model-booster-controller/webhook/model_validator_test.go in my latest commit. It covers all the edge cases, including images with spaces, tabs, newlines, empty strings, as well as valid inputs.

return ""
}
s := strings.Split(path, URIPrefixSeparator)[1]
_, s, _ := strings.Cut(path, URIPrefixSeparator)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks to hacky to me, we should reject invalid value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have completely removed the strings.Cut / strings.Split logic and replaced it with Go's standard net/url.ParseRequestURI() in both GetCachePath and cacheVolumeMountPath. This natively parses the URI, formally rejects any malformed/invalid values (returning an empty string), and safely handles nested URIs without us having to write custom string chopping logic.
Also all test suites have been verified and pass successfully

@safiya2610
safiya2610 force-pushed the fix-1026-webhook-image-whitespace branch from c5cb042 to 9ecf537 Compare August 6, 2026 15:39
@safiya2610
safiya2610 requested a review from hzxuzhonghu August 6, 2026 18:21
@LiZhenCheng9527

Copy link
Copy Markdown
Member

Fix the failed tests.

@safiya2610

Copy link
Copy Markdown
Author

Fix the failed tests.

doing...

@safiya2610
safiya2610 force-pushed the fix-1026-webhook-image-whitespace branch from e64fe43 to 35a00ab Compare August 7, 2026 11:58
Signed-off-by: Safiya <147792763+safiya2610@users.noreply.github.com>
@safiya2610
safiya2610 force-pushed the fix-1026-webhook-image-whitespace branch from be625b6 to 91d045e Compare August 7, 2026 14:30
@safiya2610

Copy link
Copy Markdown
Author

Fix the failed tests.

Fixed, Please review the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: reject whitespace in webhook image validation

5 participants