You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update documents to cover CEL validation on CRDs (#1212)
Update resource validation docs to cover CEL validation.
Problem: Gateway API 0.8.0 introduced CEL based-validation and the shift away from webhook validation.
Solution: Updated the resource validation docs to cover CEL validation for supported Kubernetes versions and kept webhook validation for older versions.
| CRD validation | OpenAPI and CEL validation | Kubernetes API server | Structure, field values | Kubernetes API server returns any errors a response for an API call. | Yes, if the CRDs are modified. |
149
+
| Re-run of webhook validation | Go code | NGF control plane | Field values | Errors are reported as Event for the resource. | No |
150
+
| NGF-specific validation | Go code | NGF control plane | Field values | Errors are reported in the status of a resource after its creation/modification. | No |
151
+
152
+
153
+
#### For Kubernetes 1.23 and 1.24
154
+
133
155
| Name | Type | Component | Scope | Feedback loop for errors | Can be bypassed? |
| CRD validation | OpenAPI | Kubernetes API server | Structure, field values | Kubernetes API server returns any errors a response for an API call. | Yes, if the CRDs are modified. |
136
158
| Webhook validation | Go code | Gateway API webhook | Field values | Kubernetes API server returns any errors a response for an API call. | Yes, if the webhook is not installed, misconfigured, or running a different version. |
137
159
| Re-run of webhook validation | Go code | NGF control plane | Field values | Errors are reported as Event for the resource. | No |
138
160
| NGF-specific validation | Go code | NGF control plane | Field values | Errors are reported in the status of a resource after its creation/modification. | No |
139
161
162
+
140
163
Notes:
141
164
142
165
- The amount and the extent of the validation should allow multiple application developers to share a single NGF (User
@@ -148,7 +171,7 @@ Notes:
148
171
149
172
NGF will support more resources:
150
173
151
-
- More Gateway API resources. For those, NGF will use the four validation methods from the table in the previous
174
+
- More Gateway API resources. For those, NGF will use the validation methods from the table in the previous
152
175
section.
153
176
- Introduce NGF resources. For those, NGF will use CRD validation (the rules of which are fully controlled by us). The
154
177
CRD validation will include the validation to prevent invalid NGINX configuration values and malicious values. Because
Copy file name to clipboardExpand all lines: docs/resource-validation.md
+34-8
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,15 @@ created.
15
15
16
16
A Gateway API resource (a new resource or an update for the existing one) is validated by the following steps:
17
17
18
+
### For Kubernetes 1.25+
19
+
20
+
1. OpenAPI schema validation by the Kubernetes API server.
21
+
2. CEL validation by the Kubernetes API server.
22
+
3. Webhook validation by NGF.
23
+
4. Validation by NGF.
24
+
25
+
### For Kubernetes 1.23 and 1.24
26
+
18
27
1. OpenAPI schema validation by the Kubernetes API server.
19
28
2. Webhook validation by the Gateway API webhook.
20
29
3. Webhook validation by NGF.
@@ -64,35 +73,52 @@ The HTTPRoute "coffee" is invalid: spec.hostnames[0]: Invalid value: "cafe.!@#$%
64
73
> While unlikely, bypassing this validation step is possible if the Gateway API CRDs are modified to remove the validation.
65
74
> If this happens, Step 4 will reject any invalid values (from NGINX perspective).
66
75
67
-
### Step 2 - Webhook Validation by Gateway API Webhook
76
+
### Step 2 - For Kubernetes 1.25+ - CEL Validation by Kubernetes API Server
77
+
78
+
The Kubernetes API server validates Gateway API resources using CEL validation embedded in the Gateway API CRDs.
79
+
It validates Gateway API resources using advanced rules unavailable in the OpenAPI schema validation.
80
+
For example, if you create a Gateway resource with a TCP listener that configures a hostname, the CEL validation will
81
+
reject it with the following error:
82
+
83
+
84
+
```shell
85
+
kubectl apply -f some-gateway.yaml
86
+
```
87
+
88
+
```text
89
+
The Gateway "some-gateway" is invalid: spec.listeners: Invalid value: "array": hostname must not be specified for protocols ['TCP', 'UDP']
90
+
```
91
+
92
+
More information on CEL in Kubernetes can be found [here](https://kubernetes.io/docs/reference/using-api/cel/).
93
+
94
+
### Step 2 - For Kubernetes 1.23 and 1.24 - Webhook Validation by Gateway API Webhook
68
95
69
96
The Gateway API comes with a validating webhook which is enabled by default in the Gateway API installation manifests.
70
97
It validates Gateway API resources using advanced rules unavailable in the OpenAPI schema validation. For example, if
71
98
you create a Gateway resource with a TCP listener that configures a hostname, the webhook will reject it with the
72
99
following error:
73
100
74
101
```shell
75
-
kubectl apply -f prod-gateway.yaml
102
+
kubectl apply -f some-gateway.yaml
76
103
```
77
104
78
105
```text
79
-
Error from server: error when creating "prod-gateway.yaml": admission webhook "validate.gateway.networking.k8s.io" denied the request: spec.listeners[1].hostname: Forbidden: should be empty for protocol TCP
106
+
Error from server: error when creating "some-gateway.yaml": admission webhook "validate.gateway.networking.k8s.io" denied the request: spec.listeners[1].hostname: Forbidden: should be empty for protocol TCP
80
107
```
81
108
82
109
> Bypassing this validation step is possible if the webhook is not running in the cluster.
83
110
> If this happens, Step 3 will reject the invalid values.
84
111
85
112
### Step 3 - Webhook validation by NGF
86
-
87
-
The previous step relies on the Gateway API webhook running in the cluster. To ensure that the resources are validated
88
-
with the webhook validation rules, even if the webhook is not running, NGF performs the same validation. However, NGF
89
-
performs the validation *after* the Kubernetes API server accepts the resource.
113
+
To ensure that the resources are validated with the webhook validation rules, even if the webhook is not running,
114
+
NGF performs the same validation. However, NGF performs the validation *after* the Kubernetes API server accepts
115
+
the resource.
90
116
91
117
Below is an example of how NGF rejects an invalid resource (a Gateway resource with a TCP listener that configures a
0 commit comments