-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webhook: validate skipper annotations in ingress (#2493)
Introduce skipper ingress annotations eskip validation to `AdmissionValidationWebhook` and our webhook binary Signed-off-by: Mustafa Abdelrahman <[email protected]>
- Loading branch information
1 parent
2e836aa
commit 679e064
Showing
25 changed files
with
459 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package admission | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/zalando/skipper/dataclients/kubernetes/definitions" | ||
) | ||
|
||
type IngressAdmitter struct { | ||
IngressValidator *definitions.IngressV1Validator | ||
} | ||
|
||
func (iga *IngressAdmitter) name() string { | ||
return "ingress" | ||
} | ||
|
||
func (iga *IngressAdmitter) admit(req *admissionRequest) (*admissionResponse, error) { | ||
|
||
ingressItem := definitions.IngressV1Item{} | ||
err := json.Unmarshal(req.Object, &ingressItem) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = iga.IngressValidator.Validate(&ingressItem) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &admissionResponse{ | ||
UID: req.UID, | ||
Allowed: true, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package admission | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/zalando/skipper/dataclients/kubernetes/definitions" | ||
) | ||
|
||
type RouteGroupAdmitter struct { | ||
RouteGroupValidator *definitions.RouteGroupValidator | ||
} | ||
|
||
func (rga *RouteGroupAdmitter) name() string { | ||
return "routegroup" | ||
} | ||
|
||
func (rga *RouteGroupAdmitter) admit(req *admissionRequest) (*admissionResponse, error) { | ||
|
||
rgItem := definitions.RouteGroupItem{} | ||
err := json.Unmarshal(req.Object, &rgItem) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = rga.RouteGroupValidator.Validate(&rgItem) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &admissionResponse{ | ||
UID: req.UID, | ||
Allowed: true, | ||
}, nil | ||
} |
40 changes: 40 additions & 0 deletions
40
cmd/webhook/admission/testdata/ingress/invalid-filters-and-predicates.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "ing1", | ||
"namespace": "ing1", | ||
"annotations": { | ||
"zalando.org/skipper-filter": "this-is-invalid(10) -> inlineContent(\"This should work\")", | ||
"zalando.org/skipper-predicate": "Header(\"test\") & Path(\"/login\")" | ||
} | ||
}, | ||
"spec": { | ||
"rules": [ | ||
{ | ||
"host": "example.com", | ||
"http": { | ||
"paths": [ | ||
{ | ||
"backend": { | ||
"service": { | ||
"name": "example-service", | ||
"port": { | ||
"number": 80 | ||
} | ||
} | ||
}, | ||
"path": "/", | ||
"pathType": "Prefix" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
cmd/webhook/admission/testdata/ingress/invalid-filters.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "ing1", | ||
"namespace": "ing1", | ||
"annotations": { | ||
"zalando.org/skipper-filter": "this-is-invalid(10) -> inlineContent(\"This should't work\")" | ||
} | ||
}, | ||
"spec": { | ||
"rules": [ | ||
{ | ||
"host": "example.com", | ||
"http": { | ||
"paths": [ | ||
{ | ||
"backend": { | ||
"service": { | ||
"name": "example-service", | ||
"port": { | ||
"number": 80 | ||
} | ||
} | ||
}, | ||
"path": "/", | ||
"pathType": "Prefix" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
cmd/webhook/admission/testdata/ingress/invalid-predicates.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"request": { | ||
"uid": "req-uid", | ||
"name": "req1", | ||
"namespace": "n1", | ||
"object": { | ||
"metadata": { | ||
"name": "ing1", | ||
"namespace": "ing1", | ||
"annotations": { | ||
"zalando.org/skipper-predicate": "Header(\"test\") & Path(\"/login\")" | ||
} | ||
}, | ||
"spec": { | ||
"rules": [ | ||
{ | ||
"host": "example.com", | ||
"http": { | ||
"paths": [ | ||
{ | ||
"backend": { | ||
"service": { | ||
"name": "example-service", | ||
"port": { | ||
"number": 80 | ||
} | ||
} | ||
}, | ||
"path": "/", | ||
"pathType": "Prefix" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.