Skip to content

Commit 0302807

Browse files
committed
KEP-4427: Relaxed DNS search validation
Add additional validation relaxation requirements Related to kubernetes/kubernetes#125883
1 parent 37ab844 commit 0302807

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

keps/sig-network/4427-relaxed-dns-search-validation/README.md

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
8686
## Summary
8787

8888
Currently, Kubernetes validates search string in the `dnsConfig.searches` according to [RFC-1123](https://datatracker.ietf.org/doc/html/rfc1123)
89-
which defines restrictions for hostnames. While most DNS names identify hosts, there are record types (like SRV) that don't. For these, it's less clear
89+
which defines restrictions for hostnames. However, there are reasons why this validation is too strict for the use in `dnsConfig.searches`.
90+
91+
Firstly, while most DNS names identify hosts, there are record types (like SRV) that don't. For these, it's less clear
9092
whether hostname restrictions apply, for example [RFC-1035 Section 2.3.1](https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.1) points out
9193
that it's better to stick with valid host names but also states that labels must meet the hostname requirements.
9294

9395
In practice, legacy workloads sometimes include an underscore (`_`) in DNS names and DNS servers will generally allow this.
9496

97+
Secondly, users may require setting `dnsConfig.searches` to a single dot character (`.`) should they wish to avoid unnessesary DNS lookup calls to internal Kubernetes domain names.
98+
9599
This KEP proposes relaxing the checks on DNS search strings only. Allowing these values in the `searches` field of `dnsConfig` allows pods to
96-
resolve short names properly in cases where the search string contains an underscore.
100+
resolve short names properly in cases where the search string contains an underscore or is a single dot character.
97101

98102
## Motivation
99103

@@ -131,15 +135,47 @@ Allowing underscores in the search string allows integration with legacy workloa
131135
these names within Kubernetes. Since having underscores in a name creates other issues (such as inability to obtain a publicly trusted TLS certificate),
132136
search strings seem like the only area where this is likely to occur.
133137

138+
Should a user require a DNS query to resolve to an external domain first (before the internal Kubernetes domain names) they would require adding a dot to the `dnsConfig.searches` list.
139+
140+
An example of this configuration could look like this:
141+
142+
```
143+
apiVersion: v1
144+
kind: Pod
145+
metadata:
146+
namespace: default
147+
name: dns-example
148+
spec:
149+
containers:
150+
- name: test
151+
image: nginx
152+
dnsPolicy: "None"
153+
dnsConfig:
154+
nameservers:
155+
- 1.2.3.4
156+
searches:
157+
- .
158+
- default.svc.cluster.local
159+
- svc.cluster.local
160+
- cluster.local
161+
```
162+
163+
Applying the above Pod spec will result in the following error:
164+
165+
```
166+
The Pod "dns-example" is invalid: spec.dnsConfig.searches[0]: Invalid value: "": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
167+
```
168+
134169
### Goals
135170

136171
- Support workloads that need to resolve DNS short names where the full DNS name includes an underscore (`_`).
172+
- Allow users to use a single dot character `.` as a search string
137173

138174
## Proposal
139175

140176
Introduce a RelaxedDNSSearchValidation feature gate which is disabled by default. When the feature gate is enabled,
141177
a new DNS name validation function will be used, which keeps the existing validation logic but also allows an underscore (`_`) in any place
142-
where a dash (`-`) would be allowed currently.
178+
where a dash (`-`) would be allowed currently and allowing a single dot (`.`) character.
143179

144180
Since the relaxed check allows previously invalid values, care must be taken to support cluster downgrades safely. To accomplish this, the validation will distinguish between new resources and updates to existing resources:
145181
- When the feature gate is disabled:
@@ -199,20 +235,20 @@ with a value that contains an underscore.
199235

200236
- Gate On
201237
- New value
202-
- Underscore (expect validation to pass)
203-
- No Underscore (expect validation to pass)
238+
- Underscore and/or dot (expect validation to pass)
239+
- No Underscore and/or dot (expect validation to pass)
204240
- Existing value
205-
- Underscore (expect validation to pass)
206-
- No Underscore (expect validation to pass)
241+
- Underscore and/or dot (expect validation to pass)
242+
- No Underscore and/or dot (expect validation to pass)
207243
- Gate Off
208244
- New value
209-
- Underscore (expect validation to fail)
210-
- No Underscore (expect validation to pass)
245+
- Underscore and/or dot (expect validation to fail)
246+
- No Underscore and/or dot (expect validation to pass)
211247
- Existing value
212-
- Underscore (expect validation to pass)
213-
- No Underscore (expect validation to pass)
248+
- Underscore and/or dot (expect validation to pass)
249+
- No Underscore and/or dot (expect validation to pass)
214250
- Ratcheting
215-
- Turn gate on, write search string with underscore, turn gate off, change unrelated property on the object and verify that it passes validation, remove search value with the underscore, verify that saving a search string with an underscore is now prevented
251+
- Turn gate on, write search string with underscore and/or dot, turn gate off, change unrelated property on the object and verify that it passes validation, remove search value with the underscore and/or dot, verify that saving a search string with an underscore and/or dot is now prevented
216252

217253
In addition to the Pod itself, each integration test should be repeated with objects that contain a pod spec template:
218254
- Deployment
@@ -221,7 +257,7 @@ In addition to the Pod itself, each integration test should be repeated with obj
221257

222258
##### e2e tests
223259

224-
- Add a test that verifies successful creation of a pod whose `dnsConfig.searches` contains an underscore
260+
- Add a test that verifies successful creation of a pod whose `dnsConfig.searches` contains an underscore and/or dot
225261
- Add tests that verify successful creation of objects with a podTemplate whose `dnsConfig.searches`
226262
contains an underscore
227263

keps/sig-network/4427-relaxed-dns-search-validation/kep.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ title: Relaxed DNS search string validation
22
kep-number: 4427
33
authors:
44
- "@sethev"
5+
- "@adrianmoisey"
56
owning-sig: sig-network
67
status: implementable
78
creation-date: 2024-01-22
@@ -15,13 +16,13 @@ stage: alpha
1516
# The most recent milestone for which work toward delivery of this KEP has been
1617
# done. This can be the current (upcoming) milestone, if it is being actively
1718
# worked on.
18-
latest-milestone: "v1.30"
19+
latest-milestone: "v1.32"
1920

2021
# The milestone at which this feature was, or is targeted to be, at each stage.
2122
milestone:
22-
alpha: "v1.30"
23-
beta: "v1.31"
24-
stable: "v1.32"
23+
alpha: "v1.32"
24+
beta: "v1.33"
25+
stable: "v1.34"
2526

2627
# The following PRR answers are required at alpha release
2728
# List the feature gate name and the components for which it must be enabled

0 commit comments

Comments
 (0)