Skip to content
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

validator: ensure no network backend path #2719

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cmd/webhook/admission/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestRouteGroupAdmitter(t *testing.T) {
{
name: "routegroup with invalid backends",
inputFile: "rg-with-invalid-backend-path.json",
message: `backend address \"http://example.com/foo\" contains path\nbackend address \"http://example.com/foo/bar\" contains path\nbackend address \"http://example.com/foo/\" contains path\nbackend address \"/foo\" contains path\nbackend address \"http://example.com/\" contains path\nbackend address \"example.com/\" contains path\nbackend address \"example.com/foo\" contains path`,
message: `backend address \"http://example.com/foo\" contains path\nbackend address \"http://example.com/foo/bar\" contains path\nbackend address \"http://example.com/foo/\" contains path\nbackend address \"/foo\" contains path\nbackend address \"http://example.com/\" contains path\nbackend address \"example.com/\" contains path\nbackend address \"example.com/foo\" contains path\nbackend address \"http://example.com?foo=bar\" contains path`,
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
"name" : "invalid-backend8",
"type" : "network",
"address" : "example.com/foo"
},
{
"name" : "invalid-backend9",
"type" : "network",
"address" : "http://example.com?foo=bar"
}
],
"defaultBackends": [
Expand Down
2 changes: 1 addition & 1 deletion dataclients/kubernetes/definitions/routegroupvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (rgv *RouteGroupValidator) validateBackends(item *RouteGroupItem) error {
address, err := url.Parse(backend.Address)
if err != nil {
errs = append(errs, fmt.Errorf("failed to parse backend address %q: %w", backend.Address, err))
} else if address.Path != "" {
} else if address.Path != "" || address.RawQuery != "" {
errs = append(errs, fmt.Errorf("backend address %q contains path", backend.Address))
MustafaSaber marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ backend address "http://example.com/foo/bar" contains path
backend address "http://example.com/foo/" contains path
MustafaSaber marked this conversation as resolved.
Show resolved Hide resolved
backend address "/foo" contains path
backend address "example.com/" contains path
backend address "http://example.com?foo=bar" contains path
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
"type": "network",
"address": "http://user:[email protected]"
},
{
"name": "backend8",
"type": "network",
"address": "http://example.com?foo=bar"
},
{
"name": "shunt",
"type": "shunt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ backend address \\\"/foo\\\" contains path
backend address \\\"/foo/bar\\\" contains path
backend address \\\"example\.com/foo\\\" contains path
backend address \\\"http://example\.com/\\\" contains path
backend address \\\"http://example\.com\?foo=bar\\\" contains path
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ spec:
- name: backend8
type: network
address: http://user:[email protected]
- name: backend9
type: network
address: http://example.com?foo=bar
defaultBackends:
- backendName: app
routes:
Expand Down