Skip to content

Commit ff669dc

Browse files
authored
Merge pull request kubernetes#4373 from HirazawaUi/special-characters-environment
Allow almost all printable ASCII characters in environment variables
2 parents 2e7663f + 53c565c commit ff669dc

File tree

2 files changed

+370
-0
lines changed

2 files changed

+370
-0
lines changed
Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
# KEP-4369: Allow special characters in environment variables
2+
3+
<!-- toc -->
4+
- [Release Signoff Checklist](#release-signoff-checklist)
5+
- [Summary](#summary)
6+
- [Motivation](#motivation)
7+
- [Goals](#goals)
8+
- [Non-Goals](#non-goals)
9+
- [Proposal](#proposal)
10+
- [User Stories (Optional)](#user-stories-optional)
11+
- [Story 1](#story-1)
12+
- [Risks and Mitigations](#risks-and-mitigations)
13+
- [Design Details](#design-details)
14+
- [Test Plan](#test-plan)
15+
- [Prerequisite testing updates](#prerequisite-testing-updates)
16+
- [Unit tests](#unit-tests)
17+
- [Integration tests](#integration-tests)
18+
- [e2e tests](#e2e-tests)
19+
- [Graduation Criteria](#graduation-criteria)
20+
- [Alpha](#alpha)
21+
- [Beta](#beta)
22+
- [GA](#ga)
23+
- [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy)
24+
- [Upgrade](#upgrade)
25+
- [Downgrade](#downgrade)
26+
- [Version Skew Strategy](#version-skew-strategy)
27+
- [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire)
28+
- [Feature Enablement and Rollback](#feature-enablement-and-rollback)
29+
- [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning)
30+
- [Monitoring Requirements](#monitoring-requirements)
31+
- [Dependencies](#dependencies)
32+
- [Scalability](#scalability)
33+
- [Troubleshooting](#troubleshooting)
34+
- [Implementation History](#implementation-history)
35+
- [Drawbacks](#drawbacks)
36+
- [Alternatives](#alternatives)
37+
- [Infrastructure Needed (Optional)](#infrastructure-needed-optional)
38+
<!-- /toc -->
39+
40+
## Release Signoff Checklist
41+
42+
<!--
43+
**ACTION REQUIRED:** In order to merge code into a release, there must be an
44+
issue in [kubernetes/enhancements] referencing this KEP and targeting a release
45+
milestone **before the [Enhancement Freeze](https://git.k8s.io/sig-release/releases)
46+
of the targeted release**.
47+
48+
For enhancements that make changes to code or processes/procedures in core
49+
Kubernetes—i.e., [kubernetes/kubernetes], we require the following Release
50+
Signoff checklist to be completed.
51+
52+
Check these off as they are completed for the Release Team to track. These
53+
checklist items _must_ be updated for the enhancement to be released.
54+
-->
55+
56+
Items marked with (R) are required *prior to targeting to a milestone / release*.
57+
58+
- [ ] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR)
59+
- [ ] (R) KEP approvers have approved the KEP status as `implementable`
60+
- [ ] (R) Design details are appropriately documented
61+
- [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
62+
- [ ] e2e Tests for all Beta API Operations (endpoints)
63+
- [ ] (R) Ensure GA e2e tests meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
64+
- [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free
65+
- [ ] (R) Graduation criteria is in place
66+
- [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
67+
- [ ] (R) Production readiness review completed
68+
- [ ] (R) Production readiness review approved
69+
- [ ] "Implementation History" section is up-to-date for milestone
70+
- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io]
71+
- [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
72+
73+
[kubernetes.io]: https://kubernetes.io/
74+
[kubernetes/enhancements]: https://git.k8s.io/enhancements
75+
[kubernetes/kubernetes]: https://git.k8s.io/kubernetes
76+
[kubernetes/website]: https://git.k8s.io/website
77+
78+
## Summary
79+
80+
Allows all printable ASCII characters except "=" to be set as environment variables, the range of printable ASCII characters is 32-126.
81+
82+
## Motivation
83+
84+
Kubernetes should not restrict which environment variable names can be used, because it has no way of knowing what the application may need, and people can't always choose their own variable names, which may limit the adoption of Kubernetes.
85+
86+
### Goals
87+
88+
* Allows users to set all ASCII characters with serial numbers in the range of 32-126 except "=" as environment variables.
89+
90+
### Non-Goals
91+
92+
## Proposal
93+
94+
* Implements relaxed validation at the top level validation method when validating API create requests, all ASCII characters in the range 32-126 except "=" can be verified.
95+
* Allow users to set `Configmap` keys and secret keys outside the `C_IDENTIFIER` scope as environment variables using EnvFrom
96+
* Document rules for setting environment variables.
97+
98+
### User Stories (Optional)
99+
100+
#### Story 1
101+
102+
I am a .NET Core development engineer, .Net Core applications are using ":" when working with application settings loaded from appsettings.json file. When running .net core app in containers typically overwrite this settings by specifying environmental variable.
103+
such as:
104+
`"Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Warning" } }`
105+
override like this `-e Logging:LogLevel:Default=Debug`
106+
107+
### Risks and Mitigations
108+
109+
Relaxed validation can break upgrade and rollback scenarios, but our use of feature gate to control whether it's enabled or not will make it a manageable risk, with the user having the autonomy to choose whether or not to enable it.
110+
111+
## Design Details
112+
113+
- A feature gate name `RelaxedEnvironmentVariableValidation` controlling the loosening of the envvar name validation, initially in alpha state and defaulting to false
114+
115+
- Two sets of validation logic for envvar names:
116+
117+
* Strict validation
118+
* Strict validation follows the current design, which only allows envvar names passed the regular expression `[-._a-zA-Z][-._a-zA-Z0-9]*`.
119+
120+
- Relaxed validation
121+
* Relaxed verification allows all ASCII characters in the range 32-126 as envvar name, and its regular expression is `^[ -<>-~]+$`, matches a string containing ASCII characters from `space` to `<` and from `>` to `~`, ignore `=`, and has a length of at least 1.
122+
123+
- Everywhere we validate envvar names in API objects, plumbing a parameter whether we want the strict or relaxed validation
124+
- At the top level validation method when validating API create requests, use the strict validation if the feature gate is off
125+
- At the top level validation method when validating API update requests, use the strict validation if the feature gate is off and the old object passes strict envvar name validation
126+
127+
### Test Plan
128+
129+
[x] I/we understand the owners of the involved components may require updates to
130+
existing tests to make this code solid enough prior to committing the changes necessary
131+
to implement this enhancement.
132+
133+
##### Prerequisite testing updates
134+
135+
##### Unit tests
136+
137+
Currently coverages:
138+
139+
* pkg/apis/core/validation/validation_test.go: `2023-12-21` - `83.9%`
140+
* pkg/kubelet/kubelet_pods_test.go: `2023-12-21` - `67.2%`
141+
* staging/src/k8s.io/apimachinery/pkg/util/validation/validation_test.go: `2023-12-21` - `94.8%`
142+
143+
These tests will be added:
144+
145+
* New tests will be added to ensure environment variable fields can be correctly validated `pkg/apis/core/validation/validation_test.go`
146+
* Add a new test that sets special character environment variables for pods in a given namespace `pkg/kubelet/kubelet_pods_test.go`
147+
* A new test will be added to ensure that the environment variable name field is valid `staging/src/k8s.io/apimachinery/pkg/util/validation/validation_test.go`
148+
149+
##### Integration tests
150+
151+
- N/A
152+
153+
##### e2e tests
154+
155+
* Add a test to `test/e2e/common/node/configmap.go` to test that the special characters in configmap are consumed by the environment variable.
156+
157+
* Add a test to `test/e2e/common/node/secret.go` to test that the special characters in secret are consumed by the environment variable.
158+
159+
* Add a test to `test/e2e/common/node/expansion` to test environment variable can contain special characters.
160+
161+
### Graduation Criteria
162+
163+
#### Alpha
164+
165+
- Created the feature gate and implement the feature, disabled by default.
166+
- Add unit and e2e tests for the feature.
167+
168+
#### Beta
169+
170+
- Solicit feedback from the Alpha.
171+
- Ensure tests are stable and passing.
172+
173+
#### GA
174+
175+
- No issues reported during two releases.
176+
177+
### Upgrade / Downgrade Strategy
178+
179+
#### Upgrade
180+
181+
Environment variables previously set by the user will not change. To use this enhancement, users need to enable the feature gate
182+
183+
#### Downgrade
184+
185+
users need to reset their environment variables for special characters to normal characters.
186+
187+
### Version Skew Strategy
188+
189+
kube-apiserver will need to enable feature gates to use this feature.
190+
191+
If kube-apiserver is not enabled feature gate will use strict validation.
192+
193+
If the feature gate is disabled and the existing object passes strict validation, strict validation on update will be used.
194+
195+
196+
## Production Readiness Review Questionnaire
197+
198+
### Feature Enablement and Rollback
199+
200+
###### How can this feature be enabled / disabled in a live cluster?
201+
202+
- [x] Feature gate (also fill in values in `kep.yaml`)
203+
- Feature gate name: RelaxedEnvironmentVariableValidation
204+
- Components depending on the feature gate: kube-apiserver
205+
206+
###### Does enabling the feature change any default behavior?
207+
208+
No
209+
210+
###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)?
211+
212+
If close the feature gate, already running workloads will not be affected in any way,
213+
but cannot create workloads that use special characters as environment variables.
214+
215+
###### What happens if we reenable the feature if it was previously rolled back?
216+
217+
The feature should continue to work just fine.
218+
219+
###### Are there any tests for feature enablement/disablement?
220+
221+
Yes.
222+
223+
### Rollout, Upgrade and Rollback Planning
224+
225+
###### How can a rollout or rollback fail? Can it impact already running workloads?
226+
227+
When a feature gate is closed, already running workloads are not affected in any way, but update fields for workload will cause the workload to fail.
228+
229+
###### What specific metrics should inform a rollback?
230+
231+
N/A
232+
233+
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
234+
235+
N/A
236+
237+
###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.?
238+
239+
No.
240+
241+
### Monitoring Requirements
242+
243+
- N/A
244+
245+
### Dependencies
246+
247+
N/A
248+
249+
###### Does this feature depend on any specific services running in the cluster?
250+
251+
No.
252+
253+
### Scalability
254+
255+
###### Will enabling / using this feature result in any new API calls?
256+
257+
No
258+
259+
###### Will enabling / using this feature result in introducing new API types?
260+
261+
No
262+
263+
###### Will enabling / using this feature result in any new calls to the cloud provider?
264+
265+
No
266+
267+
###### Will enabling / using this feature result in increasing size or count of the existing API objects?
268+
269+
No
270+
271+
###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs?
272+
273+
No
274+
275+
###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components?
276+
277+
No
278+
279+
###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)?
280+
281+
No
282+
283+
### Troubleshooting
284+
285+
###### How does this feature react if the API server and/or etcd is unavailable?
286+
287+
###### What are other known failure modes?
288+
289+
###### What steps should be taken if SLOs are not being met to determine the problem?
290+
291+
## Implementation History
292+
293+
\- 2023-12-21: Initial draft KEP
294+
295+
## Drawbacks
296+
297+
If the envvar name character set is extended, all the things currently consuming and using envvar names from the API will have an impact and may break or be unsafe.
298+
299+
For example:
300+
301+
* If a third party uses an envvar name as a filename and assumes that it is currently safe, then if it contains characters that cannot be used as a filename (like `:`) or characters that break the assumptions of a flat directory structure (like `/`), then unexpected results will occur.
302+
303+
## Alternatives
304+
305+
- do nothing (leave it as-is)
306+
307+
- relax the rule, but with a long beta period where the existing rule remains the default.
308+
Ensure that the beta period doesn't end until ValidatingAdmissionPolicy is GA and has been for 2 minor releases.
309+
*Clearly* document how to use a ValidatingAdmissionPolicy to get behavior equivalent to the legacy checking,
310+
and signpost people to these docs when graduating the looser validation to be the Kubernetes default.
311+
312+
- define a label or annotation for each namespace that controls how Pod environment variables are validated in that namespace
313+
314+
- [more complex!]
315+
add an API kind to specify the validation rules for Pods
316+
317+
Create a new API kind, eg PodValidationRule. It's **namespaced**. Within the `.spec` of each object, define:
318+
319+
- a Pod selector
320+
- an optional CEL validation rule for environment variable keys
321+
- an optional CEL validation rule for environment variable values
322+
323+
If any of the selected validation rules don't pass for a Pod, reject it at admission time. Set up a defaulting
324+
mechanism to
325+
Also, define how Pod templates interact with this new API (eg: you get a `Warning:` when you create
326+
a Deployment where the PodTemplate inside the Deployment wouldn't pass validation)
327+
328+
## Infrastructure Needed (Optional)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
title: Allow special characters environment variable
2+
kep-number: 4369
3+
authors:
4+
- "@HirazawaUi"
5+
owning-sig: sig-node
6+
participating-sigs:
7+
- sig-api-machinery
8+
status: provisional
9+
creation-date: 2023-12-21
10+
reviewers:
11+
- "@liggitt"
12+
- "@thockin"
13+
- TBD
14+
approvers:
15+
- "@liggitt"
16+
- "@thockin"
17+
18+
see-also: []
19+
replaces: []
20+
21+
# The target maturity stage in the current dev cycle for this KEP.
22+
stage: alpha
23+
24+
# The most recent milestone for which work toward delivery of this KEP has been
25+
# done. This can be the current (upcoming) milestone, if it is being actively
26+
# worked on.
27+
latest-milestone: "v1.30"
28+
29+
# The milestone at which this feature was, or is targeted to be, at each stage.
30+
milestone:
31+
alpha: "v1.30"
32+
33+
# The following PRR answers are required at alpha release
34+
# List the feature gate name and the components for which it must be enabled
35+
feature-gates:
36+
- name: RelaxedEnvironmentVariableValidation
37+
components:
38+
- kube-apiserver
39+
disable-supported: true
40+
41+
# The following PRR answers are required at beta release
42+
metrics: []

0 commit comments

Comments
 (0)