Skip to content

Commit 79d9a40

Browse files
committed
Ignore updates related to Scheduling Gates
to allow the installation of external operators that manage pod scheduling. Scheduling Gates don't affect pod privileges, so there's no need to block them through SCC admission. Signed-off-by: bmordeha <[email protected]>
1 parent facc40c commit 79d9a40

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkg/securitycontextconstraints/sccadmission/admission.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"k8s.io/apimachinery/pkg/conversion"
78
"sort"
89
"strings"
910
"time"
@@ -552,8 +553,7 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
552553
// see if we are only updating the ownerRef. Garbage collection does this
553554
// and we should allow it in general, since you had the power to update and the power to delete.
554555
// The worst that happens is that you delete something, but you aren't controlling the privileged object itself
555-
res := rbacregistry.IsOnlyMutatingGCFields(newPodCopy, oldPod, kapihelper.Semantic)
556-
556+
res := IsOnlyMutatingGCFieldsOrSchedulingGates(newPod, oldPod, kapihelper.Semantic)
557557
return res
558558
}
559559

@@ -602,3 +602,9 @@ func logProviders(pod *coreapi.Pod, providers []sccmatching.SecurityContextConst
602602
klog.V(2).Infof("provider creation error: %v", err)
603603
}
604604
}
605+
606+
func IsOnlyMutatingGCFieldsOrSchedulingGates(pod, oldPod *coreapi.Pod, equalities conversion.Equalities) bool {
607+
pod.Spec.SchedulingGates = []coreapi.PodSchedulingGate{}
608+
oldPod.Spec.SchedulingGates = []coreapi.PodSchedulingGate{}
609+
return rbacregistry.IsOnlyMutatingGCFields(pod, oldPod, equalities)
610+
}

pkg/securitycontextconstraints/sccadmission/admission_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ func TestShouldIgnore(t *testing.T) {
268268
shouldIgnore: true,
269269
admissionAttributes: withStatusUpdate(goodPod()),
270270
},
271+
{
272+
description: "schedulingGates updates should be ignored",
273+
shouldIgnore: true,
274+
admissionAttributes: withUpdate(schedulingGatePod(), "",
275+
func(p *coreapi.Pod) *coreapi.Pod {
276+
p.Spec.SchedulingGates = []coreapi.PodSchedulingGate{}
277+
return p
278+
}),
279+
},
271280
{
272281
description: "don't ignore normal updates",
273282
shouldIgnore: false,
@@ -1724,6 +1733,14 @@ func goodPod() *coreapi.Pod {
17241733
}
17251734
}
17261735

1736+
// schedulingGatePod is empty pod with scheduling gate. schedulingGates modifications
1737+
// should be safely ignored.
1738+
func schedulingGatePod() *coreapi.Pod {
1739+
p := goodPod()
1740+
p.Spec.SchedulingGates = []coreapi.PodSchedulingGate{{"testGate"}}
1741+
return p
1742+
}
1743+
17271744
// windowsPod returns windows pod without any SCCs which are specific to Linux. The admission of Windows pod
17281745
// should be safely ignored.
17291746
func windowsPod() *coreapi.Pod {

0 commit comments

Comments
 (0)