Skip to content

Commit 0a9373b

Browse files
authored
Merge pull request kubernetes#78885 from liggitt/procmount-1.15
1.15: Fix incorrect procMount defaulting
2 parents 8de1569 + 899d00a commit 0a9373b

File tree

17 files changed

+47
-155
lines changed

17 files changed

+47
-155
lines changed

pkg/api/pod/util.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,22 @@ func dropDisabledProcMountField(podSpec, oldPodSpec *api.PodSpec) {
447447
defaultProcMount := api.DefaultProcMount
448448
for i := range podSpec.Containers {
449449
if podSpec.Containers[i].SecurityContext != nil {
450-
podSpec.Containers[i].SecurityContext.ProcMount = &defaultProcMount
450+
if podSpec.Containers[i].SecurityContext.ProcMount != nil {
451+
// The ProcMount field was improperly forced to non-nil in 1.12.
452+
// If the feature is disabled, and the existing object is not using any non-default values, and the ProcMount field is present in the incoming object, force to the default value.
453+
// Note: we cannot force the field to nil when the feature is disabled because it causes a diff against previously persisted data.
454+
podSpec.Containers[i].SecurityContext.ProcMount = &defaultProcMount
455+
}
451456
}
452457
}
453458
for i := range podSpec.InitContainers {
454459
if podSpec.InitContainers[i].SecurityContext != nil {
455-
podSpec.InitContainers[i].SecurityContext.ProcMount = &defaultProcMount
460+
if podSpec.InitContainers[i].SecurityContext.ProcMount != nil {
461+
// The ProcMount field was improperly forced to non-nil in 1.12.
462+
// If the feature is disabled, and the existing object is not using any non-default values, and the ProcMount field is present in the incoming object, force to the default value.
463+
// Note: we cannot force the field to nil when the feature is disabled because it causes a diff against previously persisted data.
464+
podSpec.InitContainers[i].SecurityContext.ProcMount = &defaultProcMount
465+
}
456466
}
457467
}
458468
}
@@ -514,7 +524,7 @@ func runtimeClassInUse(podSpec *api.PodSpec) bool {
514524
return false
515525
}
516526

517-
// procMountInUse returns true if the pod spec is non-nil and has a SecurityContext's ProcMount field set
527+
// procMountInUse returns true if the pod spec is non-nil and has a SecurityContext's ProcMount field set to a non-default value
518528
func procMountInUse(podSpec *api.PodSpec) bool {
519529
if podSpec == nil {
520530
return false

pkg/api/pod/util_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ func TestDropProcMount(t *testing.T) {
616616
},
617617
}
618618
}
619-
podWithoutProcMount := func() *api.Pod {
619+
podWithDefaultProcMount := func() *api.Pod {
620620
return &api.Pod{
621621
Spec: api.PodSpec{
622622
RestartPolicy: api.RestartPolicyNever,
@@ -625,6 +625,15 @@ func TestDropProcMount(t *testing.T) {
625625
},
626626
}
627627
}
628+
podWithoutProcMount := func() *api.Pod {
629+
return &api.Pod{
630+
Spec: api.PodSpec{
631+
RestartPolicy: api.RestartPolicyNever,
632+
Containers: []api.Container{{Name: "container1", Image: "testimage", SecurityContext: &api.SecurityContext{ProcMount: nil}}},
633+
InitContainers: []api.Container{{Name: "container1", Image: "testimage", SecurityContext: &api.SecurityContext{ProcMount: nil}}},
634+
},
635+
}
636+
}
628637

629638
podInfo := []struct {
630639
description string
@@ -636,6 +645,11 @@ func TestDropProcMount(t *testing.T) {
636645
hasProcMount: true,
637646
pod: podWithProcMount,
638647
},
648+
{
649+
description: "has default ProcMount",
650+
hasProcMount: false,
651+
pod: podWithDefaultProcMount,
652+
},
639653
{
640654
description: "does not have ProcMount",
641655
hasProcMount: false,
@@ -683,8 +697,8 @@ func TestDropProcMount(t *testing.T) {
683697
t.Errorf("new pod was not changed")
684698
}
685699
// new pod should not have ProcMount
686-
if !reflect.DeepEqual(newPod, podWithoutProcMount()) {
687-
t.Errorf("new pod had ProcMount: %v", diff.ObjectReflectDiff(newPod, podWithoutProcMount()))
700+
if procMountInUse(&newPod.Spec) {
701+
t.Errorf("new pod had ProcMount: %#v", &newPod.Spec)
688702
}
689703
default:
690704
// new pod should not need to be changed

pkg/apis/apps/v1/zz_generated.defaults.go

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/apps/v1beta1/zz_generated.defaults.go

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/apps/v1beta2/zz_generated.defaults.go

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/batch/v1/zz_generated.defaults.go

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/batch/v1beta1/zz_generated.defaults.go

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/batch/v2alpha1/zz_generated.defaults.go

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/core/fuzzer/fuzzer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,6 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
354354
c.Fuzz(&sc.Capabilities.Add)
355355
c.Fuzz(&sc.Capabilities.Drop)
356356
}
357-
if sc.ProcMount == nil {
358-
defProcMount := core.DefaultProcMount
359-
sc.ProcMount = &defProcMount
360-
}
361357
},
362358
func(s *core.Secret, c fuzz.Continue) {
363359
c.FuzzNoCustom(s) // fuzz self without calling this function again

0 commit comments

Comments
 (0)