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
Copy file name to clipboardExpand all lines: design/resource-validation.md
+39-2
Original file line number
Diff line number
Diff line change
@@ -91,9 +91,36 @@ Design a validation mechanism for Gateway API resources.
91
91
92
92
## Design
93
93
94
+
We will introduce two validation methods to be run by NGF control plane:
95
+
96
+
1. Re-run of the Gateway API webhook validation
97
+
2. NGF-specific field validation
98
+
99
+
### Re-run of Webhook Validation
100
+
101
+
Before processing a resource, NGF will validate it using the functions from
102
+
the [validation package](https://github.com/kubernetes-sigs/gateway-api/tree/b241afc88e68c952cc0a59a5c72a51358dc2bada/apis/v1beta1/validation)
103
+
from the Gateway API. This will ensure that the webhook validation cannot be bypassed (it can be bypassed if the webhook
104
+
is not installed, misconfigured, or running a different version), and it will allow us to avoid repeating the same
105
+
validation in our code.
106
+
107
+
If a resource is invalid:
108
+
109
+
- NGF will not process it -- it will treat it as if the resource didn't exist. This also means that if the resource was
110
+
updated from a valid to an invalid state, NGF will also ignore any previous valid state. For example, it will remove
111
+
the generation configuration for an HTTPRoute resource.
| 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 |
122
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 |
123
151
124
152
@@ -128,6 +156,7 @@ following methods in order of their appearance in the table.
| 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. |
130
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. |
159
+
| Re-run of webhook validation | Go code | NGF control plane | Field values | Errors are reported as Event for the resource. | No |
131
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 |
132
161
133
162
@@ -153,6 +182,14 @@ We will not introduce any NGF webhook in the cluster (it adds operational comple
153
182
source of potential downtime -- a webhook failure disables CRUD operations on the relevant resources) unless we find
154
183
good reasons for that.
155
184
185
+
### Upgrades
186
+
187
+
Since NGF will use the validation package from the Gateway API project, when a new release happens, we will need to
188
+
upgrade the dependency and release a new version of NGF, provided that the validation code changed. However, if it did
189
+
not change, we do not need to release a new version. Note: other things from a new Gateway API release might prompt us
190
+
to release a new version like supporting a new field. See also
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
105
107
```
106
108
107
-
### Step 3 - Validation by NGF
109
+
> Bypassing this validation step is possible if the webhook is not running in the cluster.
110
+
> If this happens, Step 3 will reject the invalid values.
111
+
112
+
### Step 3 - Webhook validation by NGF
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.
116
+
117
+
Below is an example of how NGF rejects an invalid resource (a Gateway resource with a TCP listener that configures a
118
+
hostname) with a Kubernetes event:
119
+
120
+
```shell
121
+
kubectl describe gateway some-gateway
122
+
```
123
+
124
+
```text
125
+
. . .
126
+
Events:
127
+
Type Reason Age From Message
128
+
---- ------ ---- ---- -------
129
+
Warning Rejected 6s nginx-gateway-fabric-nginx the resource failed webhook validation, however the Gateway API webhook failed to reject it with the error; make sure the webhook is installed and running correctly; validation error: spec.listeners[1].hostname: Forbidden: should be empty for protocol TCP; NGF will delete any existing NGINX configuration that corresponds to the resource
130
+
```
131
+
132
+
> This validation step always runs and cannot be bypassed.
133
+
> NGF will ignore any resources that fail the webhook validation, like in the example above.
134
+
> If the resource previously existed, NGF will remove any existing NGINX configuration for that resource.
135
+
136
+
### Step 4 - Validation by NGF
108
137
109
138
This step catches the following cases of invalid values:
0 commit comments