Skip to content

Commit f6bc5b5

Browse files
Merge pull request #18468 from mfojtik/limit-openshift-ca-data
Automatic merge from submit-queue. apps: do not inject oversized env vars into deployer pod Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1535375 @deads2k @smarterclayton this will allow injecting reasonable sized vars into deployer, we can start deprecation process for `OPENSHIFT_CA_DATA` in 3.10?
2 parents 0f3cef4 + 7ce7e0e commit f6bc5b5

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

pkg/apps/controller/deployer/deployer_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import (
4343
// In most cases, we shouldn't need to retry up to maxRetryCount...
4444
const maxRetryCount = 15
4545

46+
// maxInjectedEnvironmentAllowedSize represents maximum size of a value of environment variable
47+
// that we will inject to a container. The default is 128Kb.
48+
const maxInjectedEnvironmentAllowedSize = 1000 * 128
49+
4650
// fatalError is an error which can't be retried.
4751
type fatalError string
4852

@@ -463,6 +467,12 @@ func (c *DeploymentController) makeDeployerContainer(strategy *appsapi.Deploymen
463467
if set.Has(env.Name) {
464468
continue
465469
}
470+
// TODO: The size of environment value should be probably validated in k8s api validation
471+
// as when the env var size is more than 128kb the execve calls will fail.
472+
if len(env.Value) > maxInjectedEnvironmentAllowedSize {
473+
glog.Errorf("failed to inject %s environment variable as the size exceed %d bytes", env.Name, maxInjectedEnvironmentAllowedSize)
474+
continue
475+
}
466476
environment = append(environment, env)
467477
}
468478

pkg/apps/controller/deployer/deployer_controller_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,48 @@ func okContainer() *v1.Container {
116116
}
117117
}
118118

119+
func TestMakeDeployerContainer(t *testing.T) {
120+
randSeq := func(n int) string {
121+
b := make([]byte, n)
122+
for i := range b {
123+
b[i] = '0'
124+
}
125+
return string(b)
126+
}
127+
client := &fake.Clientset{}
128+
controller := okDeploymentController(client, nil, nil, true, v1.PodUnknown)
129+
strategy := appstest.OkRollingStrategy()
130+
tests := []struct {
131+
name string
132+
environment []v1.EnvVar
133+
expected []v1.EnvVar
134+
}{
135+
{
136+
name: "simple var should be injected",
137+
environment: []v1.EnvVar{{Name: "FOO", Value: "BAR"}},
138+
expected: []v1.EnvVar{{Name: "FOO", Value: "BAR"}},
139+
},
140+
{
141+
name: "big vars should not be injected",
142+
environment: []v1.EnvVar{{Name: "FOO", Value: randSeq(1001 * 128)}},
143+
expected: []v1.EnvVar{},
144+
},
145+
}
146+
for _, test := range tests {
147+
controller.environment = test.environment
148+
container := controller.makeDeployerContainer(&strategy)
149+
if len(test.expected) == 0 {
150+
if len(container.Env) > 0 {
151+
t.Errorf("%s: expected no variables in container env vars, got %#v", test.name, container.Env)
152+
}
153+
continue
154+
}
155+
if !reflect.DeepEqual(container.Env, test.expected) {
156+
t.Errorf("%s: expected env vars (%#v) does match container env vars (%#v)", test.name, test.expected, container.Env)
157+
}
158+
}
159+
}
160+
119161
// TestHandle_createPodOk ensures that a deployer pod created in response
120162
// to a new deployment is valid.
121163
func TestHandle_createPodOk(t *testing.T) {

0 commit comments

Comments
 (0)