-
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: make sure Ingress/RouteGroup doesn't have duplicate hosts #2753
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "ing1", | ||
"namespace": "ing1", | ||
"annotations": { | ||
"zalando.org/skipper-filter": "status(200) -> inlineContent(\"This should work\")", | ||
"zalando.org/skipper-predicate": "Header(\"test\", \"test\") && Path(\"/login\")", | ||
"zalando.org/skipper-routes": "r1: Header(\"test2\", \"test2\") && Path(\"/login\") -> status(200) -> \"http://foo.test\"" | ||
} | ||
}, | ||
"spec": { | ||
"rules": [ | ||
{ | ||
"host": "example.com", | ||
"http": { | ||
"paths": [ | ||
{ | ||
"backend": { | ||
"service": { | ||
"name": "example-service", | ||
"port": { | ||
"number": 80 | ||
} | ||
} | ||
}, | ||
"path": "/", | ||
"pathType": "Prefix" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "rg1", | ||
"namespace": "n1" | ||
}, | ||
"spec": { | ||
"backends": [ | ||
{ | ||
"name": "backend", | ||
"type": "shunt" | ||
} | ||
], | ||
"defaultBackends": [ | ||
{ | ||
"backendName": "backend" | ||
} | ||
], | ||
"hosts": [ | ||
"example.org", | ||
"example.com", | ||
"example.org" | ||
] | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ func (igv *IngressV1Validator) Validate(item *IngressV1Item) error { | |
errs = append(errs, igv.validateFilterAnnotation(item.Metadata.Annotations)) | ||
errs = append(errs, igv.validatePredicateAnnotation(item.Metadata.Annotations)) | ||
errs = append(errs, igv.validateRoutesAnnotation(item.Metadata.Annotations)) | ||
errs = append(errs, igv.validateHosts(item)) | ||
|
||
return errorsJoin(errs...) | ||
} | ||
|
@@ -50,3 +51,15 @@ func (igv *IngressV1Validator) validateRoutesAnnotation(annotations map[string]s | |
} | ||
return nil | ||
} | ||
|
||
func (igv *IngressV1Validator) validateHosts(item *IngressV1Item) error { | ||
var errs []error | ||
uniqueHosts := make(map[string]struct{}, len(item.Spec.Rules)) | ||
for _, rule := range item.Spec.Rules { | ||
if _, ok := uniqueHosts[rule.Host]; ok { | ||
errs = append(errs, fmt.Errorf("duplicate host %q", rule.Host)) | ||
} | ||
uniqueHosts[rule.Host] = struct{}{} | ||
} | ||
Comment on lines
+58
to
+63
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 ingress rules may have the same host repeated with different rules, lets check 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. We agreed to disable duplicate hostname validation for ingress. 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. |
||
return errorsJoin(errs...) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
duplicate host \\\"example\.org\\\" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: zalando.org/v1 | ||
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 the test fixture for Ingress is missing 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. Right now we don't validate ingress in skipper we only do in ValidationWebhook, I think we will need another PR to migrate current ingress adhock validation to validator object. 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. What I mean by adhock validation https://github.com/zalando/skipper/blob/master/dataclients/kubernetes/ingress.go#L257C1-L269C2 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. |
||
kind: RouteGroup | ||
metadata: | ||
name: test-route-group | ||
spec: | ||
hosts: | ||
- example.org | ||
- example.org | ||
- example.com | ||
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 |
---|---|---|
@@ -1,7 +0,0 @@ | ||
kube_rg__default__myapp__all__0_0: | ||
Host("^(app[.]example[.]org[.]?(:[0-9]+)?|example[.]org[.]?(:[0-9]+)?)$") | ||
&& Path("/app") | ||
-> <roundRobin, "http://10.2.4.8:80", "http://10.2.4.16:80">; | ||
|
||
kube_rg____app_example_org__catchall__0_0: Host("^(app[.]example[.]org[.]?(:[0-9]+)?)$") -> <shunt>; | ||
kube_rg____example_org__catchall__0_0: Host("^(example[.]org[.]?(:[0-9]+)?)$") -> <shunt>; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
duplicate host \\\"app\.example\.org\\\" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +0,0 @@ | ||
kube_rg__default__myapp__all__0_0: Path("/articles") && Host(/^(example[.]org[.]?(:[0-9]+)?)$/) | ||
-> <roundRobin, "http://10.2.9.103:7272", "http://10.2.9.104:7272">; | ||
|
||
kube_rg__default__myapp__all__1_0: Path("/articles/shoes") && Host(/^(example[.]org[.]?(:[0-9]+)?)$/) | ||
-> <roundRobin, "http://10.2.9.103:7272", "http://10.2.9.104:7272">; | ||
|
||
kube_rg__default__myapp__all__2_0: Path("/order") && Host(/^(example[.]org[.]?(:[0-9]+)?)$/) | ||
-> <roundRobin, "http://10.2.9.103:7272", "http://10.2.9.104:7272">; | ||
|
||
kube_rg____example_org__catchall__0_0: Host(/^(example[.]org[.]?(:[0-9]+)?)$/) | ||
-> <shunt>; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
duplicate host \\\"example\.org\\\" |
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 still think we do not need to add tests for admission webhook when we change validator, its just increases size of PR but adds no value as webhook simply calls validator