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

feat(kgo): added ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding for validating DataPlane ports #1215

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export GOLDEN_TEST_FAILURE_MSG
_chartsnap: _chartsnap.deps
helm chartsnap -c ./charts/$(CHART) -f ./charts/$(CHART)/ci/ $(CHARTSNAP_ARGS) \
-- \
--api-versions gateway.networking.k8s.io/v1
--api-versions gateway.networking.k8s.io/v1 \
--api-versions admissionregistration.k8s.io/v1/ValidatingAdmissionPolicy \
--api-versions admissionregistration.k8s.io/v1/ValidatingAdmissionPolicyBinding

.PHONY: _chartsnap.deps
_chartsnap.deps: chartsnap
Expand Down
8 changes: 8 additions & 0 deletions charts/gateway-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.4.3

### Changes

- Added `ValidatingAdmissionPolicy` and ``ValidatingAdmissionPolicyBinding` for
pmalek marked this conversation as resolved.
Show resolved Hide resolved
pmalek marked this conversation as resolved.
Show resolved Hide resolved
validating `DataPlane` ports.
[#1215](https://github.com/Kong/charts/pull/1215)

## 0.4.2

### Changes
Expand Down
2 changes: 1 addition & 1 deletion charts/gateway-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ maintainers:
name: gateway-operator
sources:
- https://github.com/Kong/charts/tree/main/charts/gateway-operator
version: 0.4.2
version: 0.4.3
appVersion: "1.4"
annotations:
artifacthub.io/prerelease: "false"
Expand Down
96 changes: 94 additions & 2 deletions charts/gateway-operator/ci/__snapshots__/affinity-values.snap
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ kind: Deployment
metadata:
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.2
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
app.kubernetes.io/component: kgo
Expand All @@ -716,7 +716,7 @@ spec:
labels:
control-plane: controller-manager
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.2
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
app.kubernetes.io/component: kgo
Expand Down Expand Up @@ -808,3 +808,95 @@ spec:
- name: chartsnap-gateway-operator-certs-dir
emptyDir:
sizeLimit: 256Mi
---
# Source: gateway-operator/templates/validation-policy-dataplane.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: ports.dataplane.gateway-operator.konghq.com
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
spec:
matchConstraints:
resourceRules:
- apiGroups:
- "gateway-operator.konghq.com"
apiVersions:
- "v1beta1"
operations:
- "CREATE"
- "UPDATE"
resources:
- "dataplanes"
variables:
- name: network
expression: object.spec.network
- name: services
expression: variables.network.services
- name: ingressPorts
expression: variables.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].value : null
- name: envProxyListen
expression: |
variables.envFilteredProxyListen.size() > 0 ? variables.envFilteredProxyListen[0].value : 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: |
!has(object.spec.network) ||
!has(object.spec.network.services) ||
variables.ingressPorts == null ||
variables.envPortMaps == null ||
variables.ingressPorts.all(p, variables.envPortMaps.
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: |
!has(object.spec.network) ||
!has(object.spec.network.services) ||
variables.ingressPorts == null ||
variables.envProxyListen == null ||
variables.ingressPorts.all(p, variables.envProxyListen.
split(",").
exists(pm,
pm.trim().split(" ")[0].split(":")[1].trim() == string(p.targetPort)
)
)
reason: Invalid
---
# Source: gateway-operator/templates/validation-policy-dataplane.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: binding-ports.dataplane.gateway-operator.konghq.com
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
spec:
policyName: ports.dataplane.gateway-operator.konghq.com
validationActions:
- Deny
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ kind: Deployment
metadata:
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.2
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
app.kubernetes.io/component: kgo
Expand All @@ -716,7 +716,7 @@ spec:
labels:
control-plane: controller-manager
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.2
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
app.kubernetes.io/component: kgo
Expand Down Expand Up @@ -800,3 +800,95 @@ spec:
- name: chartsnap-gateway-operator-certs-dir
emptyDir:
sizeLimit: 256Mi
---
# Source: gateway-operator/templates/validation-policy-dataplane.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: ports.dataplane.gateway-operator.konghq.com
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
spec:
matchConstraints:
resourceRules:
- apiGroups:
- "gateway-operator.konghq.com"
apiVersions:
- "v1beta1"
operations:
- "CREATE"
- "UPDATE"
resources:
- "dataplanes"
variables:
- name: network
expression: object.spec.network
- name: services
expression: variables.network.services
- name: ingressPorts
expression: variables.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].value : null
- name: envProxyListen
expression: |
variables.envFilteredProxyListen.size() > 0 ? variables.envFilteredProxyListen[0].value : 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: |
!has(object.spec.network) ||
!has(object.spec.network.services) ||
variables.ingressPorts == null ||
variables.envPortMaps == null ||
variables.ingressPorts.all(p, variables.envPortMaps.
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: |
!has(object.spec.network) ||
!has(object.spec.network.services) ||
variables.ingressPorts == null ||
variables.envProxyListen == null ||
variables.ingressPorts.all(p, variables.envProxyListen.
split(",").
exists(pm,
pm.trim().split(" ")[0].split(":")[1].trim() == string(p.targetPort)
)
)
reason: Invalid
---
# Source: gateway-operator/templates/validation-policy-dataplane.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: binding-ports.dataplane.gateway-operator.konghq.com
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
spec:
policyName: ports.dataplane.gateway-operator.konghq.com
validationActions:
- Deny
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ kind: Deployment
metadata:
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.2
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
app.kubernetes.io/component: kgo
Expand All @@ -716,7 +716,7 @@ spec:
labels:
control-plane: controller-manager
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.2
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
app.kubernetes.io/component: kgo
Expand Down Expand Up @@ -800,3 +800,95 @@ spec:
- name: chartsnap-gateway-operator-certs-dir
emptyDir:
sizeLimit: 256Mi
---
# Source: gateway-operator/templates/validation-policy-dataplane.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: ports.dataplane.gateway-operator.konghq.com
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
spec:
matchConstraints:
resourceRules:
- apiGroups:
- "gateway-operator.konghq.com"
apiVersions:
- "v1beta1"
operations:
- "CREATE"
- "UPDATE"
resources:
- "dataplanes"
variables:
- name: network
expression: object.spec.network
- name: services
expression: variables.network.services
- name: ingressPorts
expression: variables.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].value : null
- name: envProxyListen
expression: |
variables.envFilteredProxyListen.size() > 0 ? variables.envFilteredProxyListen[0].value : 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: |
!has(object.spec.network) ||
!has(object.spec.network.services) ||
variables.ingressPorts == null ||
variables.envPortMaps == null ||
variables.ingressPorts.all(p, variables.envPortMaps.
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: |
!has(object.spec.network) ||
!has(object.spec.network.services) ||
variables.ingressPorts == null ||
variables.envProxyListen == null ||
variables.ingressPorts.all(p, variables.envProxyListen.
split(",").
exists(pm,
pm.trim().split(" ")[0].split(":")[1].trim() == string(p.targetPort)
)
)
reason: Invalid
---
# Source: gateway-operator/templates/validation-policy-dataplane.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: binding-ports.dataplane.gateway-operator.konghq.com
labels:
app.kubernetes.io/name: gateway-operator
helm.sh/chart: gateway-operator-0.4.3
app.kubernetes.io/instance: "chartsnap"
app.kubernetes.io/version: "1.4"
spec:
policyName: ports.dataplane.gateway-operator.konghq.com
validationActions:
- Deny
Loading
Loading