Implement NKG-specific field validation #363
Labels
area/gateway/core
Relates to all Core features of Gateway
area/gatewayclass/core
Relates to all Core features of GatewayClass
area/httproute/core
Relates to all Core features of HTTPRoute
enhancement
New feature or request
Milestone
Parent issue -- #308
Background
NKG must prevent generating NGINX configuration with invalid or malicious values. See more context
in https://github.com/nginxinc/nginx-kubernetes-gateway/blob/6531ca1c51f1d552dae24c3b26939d2f29af8797/design/resource-validation.md
User Stories
Cluster admin and application developer = user
resource (according to Gateway API spec) and report the validation error in its status.
Requirements
Functional Requirements
We assume an invalid resource passed both the CRD and Webhook validations.
resource (according to Gateway API spec) and reports the error in its status.
resource (according to Gateway API spec), removing any previous NGINX config for those, and reports the error in its
status.
Resources and Fields to Validate
GatewayClass
spec
controllerName
- must be equal to the NKG controller nameparametersRef
- NKG does not support it.If
controllerName
doesn't match the controller name of NKG, NGK will:Note that the Webhook, if it is running properly, makes the field
controllerName
immutable.If
parameterRef
is set, NGK will:Accepted
, statusFalse
, reasonInvalidParameters
If it doesn't exist:
Gateway
spec
listeners
hostname
- gets into NGINX config.port
- NKG only supports 80 for HTTP and 443 for HTTPs.protocol
- NKG only supports HTTP and HTTPs.tls
- required for HTTPSmode
- onlyTerminate
certificateRefs
- only one ref, only Secret kind, only same namespace *1options
- NKG does not support any optionsallowedRoutes
- NKG does not support.addresses
- NGK does not support.*1 - validation of the TLS Secret content is covered in #359
If a listener is invalid, NKG will report in its status condition
Accepted
, statusFalse
and appropriate reasonfrom the Gateway API or an NGK-specific reason.
If
addresses
is set, NKG will report in the status of the listeners of the Gateway its status conditionAccepted
, statusFalse
, reasonUnsupportedAddress
.HTTPRoute
spec
parentRefs
port
- not supportedhostnames
- gets into NGINX config. Wildcard hostnames are not supported.rules
matches
path
type
- NKG does not support PathPrefix, RegularExpressionvalue
- gets into NGINX config *1headers
type
- NGK does not support RegularExpressionname
- gets into NGINX config.value
- gets into NGINX config.queryParams
type
- NGK does not support RegularExpressionname
- gets into NGINX config.value
- gets into NGINX config.method
- gets into NGINX config. NGINX does not support CONNECT, TRACE methods (itwill return 405 Not Allowed to clients). But no config reload failure though.
filters
type
- NKG only supports RequestRedirectrequestRedirect
scheme
- NKG must report unsupported valueshostname
- gets into NGINX config.path
- not supported.statusCode
- NKG must report unsupported values.backendRefs
reference
- NGK only supports Service in the same namespacefilters
- NKG does not support.*1 - for path validation, ensure whitespace is trimmed to prevent duplicate locations. See this
comment #356 (comment) (no longer relevant -- the webhook validation doesn't allow whitespace)
If field (of fields) is invalid, NKG will report it its status condition
Accepted
, statusFalse
with an appropriate reason. Except for field(s) of a backend ref. In that case, NKG will report conditionResovledRefs
statusFalse
.Edge Cases
If for some reason an invalid value is still propagates to NGINX config, NGINX will fail to reload. This means NGK validation or config generation has a bug. Such failures must be reported to the cluster admin. This will be covered in #292
Aha! Link: https://nginx.aha.io/features/NKG-27
The text was updated successfully, but these errors were encountered: