Skip to content

Commit 00a718e

Browse files
steveslokarobscott
authored andcommitted
Introduce PreciseHostname field to support differences between a wildcard value and precise value for hostnames.
Updates the HTTPRequestRedirectFilter.Hostname to use the new PreciseHostname type which validates the value cannot contain wildcard characters. Signed-off-by: Steve Sloka <[email protected]>
1 parent ff9883d commit 00a718e

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

apis/v1alpha2/httproute_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ type HTTPRequestRedirectFilter struct {
683683
// Support: Core
684684
//
685685
// +optional
686-
Hostname *Hostname `json:"hostname,omitempty"`
686+
Hostname *PreciseHostname `json:"hostname,omitempty"`
687687

688688
// Port is the port to be used in the value of the `Location`
689689
// header in the response.

apis/v1alpha2/shared_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ type RouteStatus struct {
252252
// +kubebuilder:validation:Pattern=`^(\*\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
253253
type Hostname string
254254

255+
// PreciseHostname is the fully qualified domain name of a network host. This matches
256+
// the RFC 1123 definition of a hostname with 2 notable exceptions:
257+
//
258+
// 1. IPs are not allowed.
259+
// 2. A hostname may not be prefixed with a wildcard label (`*.`).
260+
//
261+
// Hostname can be "precise" which is a domain name without the terminating
262+
// dot of a network host (e.g. "foo.example.com").
263+
//
264+
// Note that as per RFC1035 and RFC1123, a *label* must consist of lower case
265+
// alphanumeric characters or '-', and must start and end with an alphanumeric
266+
// character. No other punctuation is allowed.
267+
//
268+
// +kubebuilder:validation:MinLength=1
269+
// +kubebuilder:validation:MaxLength=253
270+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
271+
type PreciseHostname string
272+
255273
// Group refers to a Kubernetes Group. It must either be an empty string or a
256274
// RFC 1123 subdomain.
257275
//

apis/v1alpha2/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/v1alpha2/gateway.networking.k8s.io_httproutes.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: gateway.networking.k8s.io/v1alpha2
2+
kind: HTTPRoute
3+
metadata:
4+
name: invalid-backend-port
5+
spec:
6+
rules:
7+
- backendRefs:
8+
- name: my-service
9+
port: 8080
10+
filters:
11+
- type: RequestRedirect
12+
requestRedirect:
13+
hostname: "*.gateway.networking.k8s.io"
14+

0 commit comments

Comments
 (0)