-
Notifications
You must be signed in to change notification settings - Fork 352
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: prevent multiple filters/predicates per yaml item #2691
Changes from 1 commit
7b9e20b
1edc372
936b026
0adbfd9
1c98c74
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"operation": "create", | ||
"kind": { | ||
"group": "zalando", | ||
"version": "v1", | ||
"kind": "RouteGroup" | ||
}, | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "rg1", | ||
"namespace": "n1" | ||
}, | ||
"spec": { | ||
"backends": [ | ||
{ | ||
"name": "backend", | ||
"type": "shunt" | ||
} | ||
], | ||
"defaultBackends": [ | ||
{ | ||
"backendName": "backend" | ||
} | ||
], | ||
"routes": [ | ||
{ | ||
"backends": [ | ||
{ | ||
"backendName": "backend" | ||
} | ||
], | ||
"filters": [ | ||
"status(201) -> inlineContent(\"hi\")" | ||
], | ||
"path": "/", | ||
"predicates": [ | ||
"Method(\"GET\")" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"operation": "create", | ||
"kind": { | ||
"group": "zalando", | ||
"version": "v1", | ||
"kind": "RouteGroup" | ||
}, | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "rg1", | ||
"namespace": "n1" | ||
}, | ||
"spec": { | ||
"backends": [ | ||
{ | ||
"name": "backend", | ||
"type": "shunt" | ||
} | ||
], | ||
"defaultBackends": [ | ||
{ | ||
"backendName": "backend" | ||
} | ||
], | ||
"routes": [ | ||
{ | ||
"backends": [ | ||
{ | ||
"backendName": "backend" | ||
} | ||
], | ||
"filters": [ | ||
"status(201)" | ||
], | ||
"path": "/", | ||
"predicates": [ | ||
"Method(\"GET\") && Path(\"/\")" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package definitions | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/zalando/skipper/eskip" | ||
) | ||
|
||
type RouteGroupValidator struct{} | ||
|
||
var ( | ||
errMultipleFilters = errors.New("multiple filters per yaml/json array item is not supported") | ||
errMultiplePredicates = errors.New("multiple predicates per yaml/json array item is not supported") | ||
) | ||
|
||
var defaultRouteGroupValidator = &RouteGroupValidator{} | ||
|
||
// ValidateRouteGroup validates a RouteGroupItem | ||
|
@@ -56,7 +63,10 @@ func (rgv *RouteGroupValidator) filtersValidation(item *RouteGroupItem) error { | |
var errs []error | ||
for _, r := range item.Spec.Routes { | ||
for _, f := range r.Filters { | ||
_, err := eskip.ParseFilters(f) | ||
filters, err := eskip.ParseFilters(f) | ||
if len(filters) > 1 { | ||
errs = append(errs, errMultipleFilters) | ||
} | ||
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. I think we can check I also think we should not mention json/yaml in the error message as it is ambiguous and also routegroup could be created programmatically. 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. for empty string we already validate with https://github.com/zalando/skipper/blob/master/dataclients/kubernetes/definitions/routegroupvalidator.go#L134-L140 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. Since we check empty first 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. Then maybe we should move empty check here to have filter validation in one place. Note that value might also contain only whitespaces |
||
errs = append(errs, err) | ||
} | ||
} | ||
|
@@ -68,7 +78,10 @@ func (rgv *RouteGroupValidator) predicatesValidation(item *RouteGroupItem) error | |
var errs []error | ||
for _, r := range item.Spec.Routes { | ||
for _, p := range r.Predicates { | ||
_, err := eskip.ParsePredicates(p) | ||
predicates, err := eskip.ParsePredicates(p) | ||
if len(predicates) > 1 { | ||
errs = append(errs, errMultiplePredicates) | ||
} | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
route group without name | ||
error in route group default/rg1: route group without backend | ||
multiple predicates per yaml/json array item is not supported | ||
multiple filters per yaml/json array item is not supported |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
multiple filters per yaml/json array item is not supported |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: zalando.org/v1 | ||
kind: RouteGroup | ||
metadata: | ||
name: test-route-group | ||
spec: | ||
hosts: | ||
- example.org | ||
backends: | ||
- name: app | ||
type: service | ||
serviceName: app-svc | ||
servicePort: 80 | ||
defaultBackends: | ||
- backendName: app | ||
routes: | ||
- path: / | ||
methods: | ||
- GET | ||
- HEAD | ||
predicates: | ||
- Foo("X-Bar", "42") | ||
filters: | ||
- foo(42) -> bar(24) | ||
backends: | ||
- backendName: app |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
multiple predicates per yaml/json array item is not supported |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: zalando.org/v1 | ||
kind: RouteGroup | ||
metadata: | ||
name: test-route-group | ||
spec: | ||
hosts: | ||
- example.org | ||
backends: | ||
- name: app | ||
type: service | ||
serviceName: app-svc | ||
servicePort: 80 | ||
defaultBackends: | ||
- backendName: app | ||
routes: | ||
- path: / | ||
methods: | ||
- GET | ||
- HEAD | ||
predicates: | ||
- Foo("X-Bar", "42") && Bar("X-Foo", "24") | ||
filters: | ||
- foo(42) | ||
- bar(24) | ||
backends: | ||
- backendName: app |
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.
I think we should check number of filters only when err is 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.
Why? I think we should send both errors to decrease roundtrips of fixes
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.
Lets add a test case for empty value, maybe eskip.Parse already handles it
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.
there is one already
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.
without validation
ParseFilter/predicate
return no error for empty string