-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dataplane): move DataPlane ports validation to ValidationAdmissi…
…onPolicy and ValidationAdmissionPolicyBinding
- Loading branch information
Showing
11 changed files
with
85 additions
and
255 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 |
---|---|---|
|
@@ -9034,6 +9034,7 @@ spec: | |
required: | ||
- port | ||
type: object | ||
maxItems: 4 | ||
type: array | ||
type: | ||
default: LoadBalancer | ||
|
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 |
---|---|---|
|
@@ -9034,6 +9034,7 @@ spec: | |
required: | ||
- port | ||
type: object | ||
maxItems: 4 | ||
type: array | ||
type: | ||
default: LoadBalancer | ||
|
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
73 changes: 73 additions & 0 deletions
73
config/default/validation_policies/dataplane_validation_policies.yaml
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,73 @@ | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingAdmissionPolicy | ||
metadata: | ||
name: ports.dataplane.gateway-operator.konghq.com | ||
spec: | ||
matchConstraints: | ||
resourceRules: | ||
- apiGroups: | ||
- "gateway-operator.konghq.com" | ||
apiVersions: | ||
- "v1beta1" | ||
operations: | ||
- "CREATE" | ||
- "UPDATE" | ||
resources: | ||
- "dataplanes" | ||
variables: | ||
- name: ingressPorts | ||
expression: object.spec.network.services.ingress.ports | ||
- name: podTemplateSpec | ||
expression: object.spec.deployment.podTemplateSpec | ||
- name: proxyContainer | ||
expression: | | ||
variables.podTemplateSpec.spec.containers.exists(c, c.name == 'proxy') ? | ||
variables.podTemplateSpec.spec.containers.filter(c, c.name == 'proxy')[0] : | ||
null | ||
- name: envFilteredPortMaps | ||
expression: | | ||
variables.proxyContainer.env.filter(e, e.name == "KONG_PORT_MAPS") | ||
- name: envFilteredProxyListen | ||
expression: | | ||
variables.proxyContainer.env.filter(e, e.name == "KONG_PROXY_LISTEN") | ||
- name: envPortMaps | ||
expression: | | ||
variables.envFilteredPortMaps.size() > 0 ? variables.envFilteredPortMaps[0] : null | ||
- name: envProxyListen | ||
expression: | | ||
variables.envFilteredProxyListen.size() > 0 ? variables.envFilteredProxyListen[0] : null | ||
# Using string functions from: https://pkg.go.dev/github.com/google/cel-go/ext | ||
validations: | ||
- messageExpression: "'Each port from spec.network.services.ingress.ports has to have an accompanying port in KONG_PORT_MAPS env'" | ||
expression: | | ||
variables.ingressPorts == null || | ||
variables.envPortMaps == null || | ||
variables.ingressPorts.all(p, variables.envPortMaps.value. | ||
split(","). | ||
exists(pm, | ||
pm.split(":")[1].trim() == string(p.targetPort) | ||
) | ||
) | ||
reason: Invalid | ||
- messageExpression: "'Each port from spec.network.services.ingress.ports has to have an accompanying port in KONG_PROXY_LISTEN env'" | ||
expression: | | ||
variables.ingressPorts == null || | ||
variables.envProxyListen == null || | ||
variables.ingressPorts.all(p, variables.envProxyListen.value. | ||
split(","). | ||
exists(pm, | ||
pm.trim().split(" ")[0].split(":")[1].trim() == string(p.targetPort) | ||
) | ||
) | ||
reason: Invalid | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingAdmissionPolicyBinding | ||
metadata: | ||
name: binding-ports.dataplane.gateway-operator.konghq.com | ||
spec: | ||
policyName: ports.dataplane.gateway-operator.konghq.com | ||
validationActions: | ||
- Deny | ||
--- |
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,5 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- dataplane_validation_policies.yaml |
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 |
---|---|---|
|
@@ -44,4 +44,3 @@ spec: | |
- name: https | ||
port: 8083 | ||
targetPort: 9443 | ||
|
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
Oops, something went wrong.