Skip to content

Commit

Permalink
Introduce wildcardhostname field to support differences between a wil…
Browse files Browse the repository at this point in the history
…dcard value and precise value.

Update the HTTPRequestRedirectFilter.Hostname to use a Hostname type which validates the value cannot
contain wildcard characters. Updates all other references which used Hostnaem to use WildcardHostname
which does allow for wildcard characters.

Signed-off-by: Steve Sloka <slokas@vmware.com>
  • Loading branch information
stevesloka committed Dec 7, 2021
1 parent 4c34b35 commit 55bb6b6
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 56 deletions.
2 changes: 1 addition & 1 deletion apis/v1alpha2/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ type Listener struct {
// Support: Core
//
// +optional
Hostname *Hostname `json:"hostname,omitempty"`
Hostname *WildcardHostname `json:"hostname,omitempty"`

// Port is the network port. Multiple listeners may use the
// same port, subject to the Listener compatibility rules.
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type HTTPRouteSpec struct {
//
// +optional
// +kubebuilder:validation:MaxItems=16
Hostnames []Hostname `json:"hostnames,omitempty"`
Hostnames []WildcardHostname `json:"hostnames,omitempty"`

// Rules are a list of HTTP matchers, filters and actions.
//
Expand Down
22 changes: 20 additions & 2 deletions apis/v1alpha2/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ type RouteStatus struct {
Parents []RouteParentStatus `json:"parents"`
}

// Hostname is the fully qualified domain name of a network host. This matches
// WildcardHostname is the fully qualified domain name of a network host. This matches
// the RFC 1123 definition of a hostname with 2 notable exceptions:
//
// 1. IPs are not allowed.
// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard
// label must appear by itself as the first label.
//
// Hostname can be "precise" which is a domain name without the terminating
// WildcardHostname can be "precise" which is a domain name without the terminating
// dot of a network host (e.g. "foo.example.com") or "wildcard", which is a
// domain name prefixed with a single wildcard label (e.g. `*.example.com`).
//
Expand All @@ -250,6 +250,24 @@ type RouteStatus struct {
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^(\*\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
type WildcardHostname string

// Hostname is the fully qualified domain name of a network host. This matches
// the RFC 1123 definition of a hostname with 2 notable exceptions:
//
// 1. IPs are not allowed.
// 2. A hostname may not be prefixed with a wildcard label (`*.`).
//
// Hostname can be "precise" which is a domain name without the terminating
// dot of a network host (e.g. "foo.example.com").
//
// Note that as per RFC1035 and RFC1123, a *label* must consist of lower case
// alphanumeric characters or '-', and must start and end with an alphanumeric
// character. No other punctuation is allowed.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
type Hostname string

// Group refers to a Kubernetes Group. It must either be an empty string or a
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha2/tlsroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type TLSRouteSpec struct {
//
// +optional
// +kubebuilder:validation:MaxItems=16
Hostnames []Hostname `json:"hostnames,omitempty"`
Hostnames []WildcardHostname `json:"hostnames,omitempty"`

// Rules are a list of TLS matchers and actions.
//
Expand Down
4 changes: 2 additions & 2 deletions apis/v1alpha2/validation/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ func TestValidateGateway(t *testing.T) {
},
"hostname present with tcp protocol": {
mutate: func(gw *gatewayv1a2.Gateway) {
hostname := gatewayv1a2.Hostname("foo.bar.com")
hostname := gatewayv1a2.WildcardHostname("foo.bar.com")
gw.Spec.Listeners[0].Hostname = &hostname
gw.Spec.Listeners[0].Protocol = gatewayv1a2.TCPProtocolType
},
expectErrsOnFields: []string{"spec.listeners[0].hostname"},
},
"hostname present with udp protocol": {
mutate: func(gw *gatewayv1a2.Gateway) {
hostname := gatewayv1a2.Hostname("foo.bar.com")
hostname := gatewayv1a2.WildcardHostname("foo.bar.com")
gw.Spec.Listeners[0].Hostname = &hostname
gw.Spec.Listeners[0].Protocol = gatewayv1a2.UDPProtocolType
},
Expand Down
6 changes: 3 additions & 3 deletions apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions config/crd/experimental/gateway.networking.k8s.io_tlsroutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions config/crd/stable/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions config/crd/stable/gateway.networking.k8s.io_tlsroutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: invalid-backend-port
spec:
rules:
- backendRefs:
- name: my-service
port: 8080
filters:
- type: RequestRedirect
requestRedirect:
hostname: "*.gateway.networking.k8s.io"

0 comments on commit 55bb6b6

Please sign in to comment.