Skip to content

Commit 5592a48

Browse files
committed
UPSTREAM: <carry>: Move Group informer configuration into RestrictSubjectBindings
admission plugin initialization to prevent Group informers being configured when the plugin is disabled. This is necessary for when the OpenShift OAuth stack is not present and the plugin is disabled as part of that. Signed-off-by: Bryce Palmer <[email protected]>
1 parent 8ac36bf commit 5592a48

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

openshift-kube-apiserver/admission/authorization/restrictusers/restrictusers.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/apiserver/pkg/admission/initializer"
1414
"k8s.io/client-go/kubernetes"
1515
"k8s.io/client-go/rest"
16+
"k8s.io/client-go/tools/cache"
1617
"k8s.io/klog/v2"
1718
"k8s.io/kubernetes/pkg/apis/rbac"
1819

@@ -48,10 +49,12 @@ type restrictUsersAdmission struct {
4849
groupCache GroupCache
4950
}
5051

51-
var _ = admissionrestconfig.WantsRESTClientConfig(&restrictUsersAdmission{})
52-
var _ = WantsUserInformer(&restrictUsersAdmission{})
53-
var _ = initializer.WantsExternalKubeClientSet(&restrictUsersAdmission{})
54-
var _ = admission.ValidationInterface(&restrictUsersAdmission{})
52+
var (
53+
_ = admissionrestconfig.WantsRESTClientConfig(&restrictUsersAdmission{})
54+
_ = WantsUserInformer(&restrictUsersAdmission{})
55+
_ = initializer.WantsExternalKubeClientSet(&restrictUsersAdmission{})
56+
_ = admission.ValidationInterface(&restrictUsersAdmission{})
57+
)
5558

5659
// NewRestrictUsersAdmission configures an admission plugin that enforces
5760
// restrictions on adding role bindings in a project.
@@ -87,6 +90,12 @@ func (q *restrictUsersAdmission) SetRESTClientConfig(restClientConfig rest.Confi
8790
}
8891

8992
func (q *restrictUsersAdmission) SetUserInformer(userInformers userinformer.SharedInformerFactory) {
93+
if err := userInformers.User().V1().Groups().Informer().AddIndexers(cache.Indexers{
94+
usercache.ByUserIndexName: usercache.ByUserIndexKeys,
95+
}); err != nil {
96+
utilruntime.HandleError(err)
97+
return
98+
}
9099
q.groupCache = usercache.NewGroupCache(userInformers.User().V1().Groups())
91100
}
92101

@@ -116,7 +125,6 @@ func subjectsDelta(elementsToIgnore, elements []rbac.Subject) []rbac.Subject {
116125
// each subject in the binding must be matched by some rolebinding restriction
117126
// in the namespace.
118127
func (q *restrictUsersAdmission) Validate(ctx context.Context, a admission.Attributes, _ admission.ObjectInterfaces) (err error) {
119-
120128
// We only care about rolebindings
121129
if a.GetResource().GroupResource() != rbac.Resource("rolebindings") {
122130
return nil

openshift-kube-apiserver/openshiftkubeapiserver/patch.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import (
2727
clientgoinformers "k8s.io/client-go/informers"
2828
corev1informers "k8s.io/client-go/informers/core/v1"
2929
"k8s.io/client-go/rest"
30-
"k8s.io/client-go/tools/cache"
3130
"k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers"
32-
"k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers/usercache"
3331
"k8s.io/kubernetes/openshift-kube-apiserver/admission/autoscaling/managednode"
3432
"k8s.io/kubernetes/openshift-kube-apiserver/admission/autoscaling/managementcpusoverride"
3533
"k8s.io/kubernetes/openshift-kube-apiserver/admission/scheduler/nodeenv"
@@ -109,7 +107,8 @@ func OpenShiftKubeAPIServerConfigPatch(genericConfig *genericapiserver.Config, k
109107
// END HANDLER CHAIN
110108

111109
openshiftAPIServiceReachabilityCheck := newOpenshiftAPIServiceReachabilityCheck(genericConfig.PublicAddress)
112-
oauthAPIServiceReachabilityCheck := newOAuthPIServiceReachabilityCheck(genericConfig.PublicAddress)
110+
oauthAPIServiceReachabilityCheck := newOAuthAPIServiceReachabilityCheck(genericConfig.PublicAddress)
111+
113112
genericConfig.ReadyzChecks = append(genericConfig.ReadyzChecks, openshiftAPIServiceReachabilityCheck, oauthAPIServiceReachabilityCheck)
114113

115114
genericConfig.AddPostStartHookOrDie("openshift.io-startkubeinformers", func(context genericapiserver.PostStartHookContext) error {
@@ -176,11 +175,6 @@ func newInformers(loopbackClientConfig *rest.Config) (*kubeAPIServerInformers, e
176175
OpenshiftUserInformers: userinformer.NewSharedInformerFactory(userClient, defaultInformerResyncPeriod),
177176
OpenshiftConfigInformers: configv1informer.NewSharedInformerFactory(configClient, defaultInformerResyncPeriod),
178177
}
179-
if err := ret.OpenshiftUserInformers.User().V1().Groups().Informer().AddIndexers(cache.Indexers{
180-
usercache.ByUserIndexName: usercache.ByUserIndexKeys,
181-
}); err != nil {
182-
return nil, err
183-
}
184178

185179
return ret, nil
186180
}
@@ -195,12 +189,15 @@ type kubeAPIServerInformers struct {
195189
func (i *kubeAPIServerInformers) getOpenshiftQuotaInformers() quotainformer.SharedInformerFactory {
196190
return i.OpenshiftQuotaInformers
197191
}
192+
198193
func (i *kubeAPIServerInformers) getOpenshiftSecurityInformers() securityv1informer.SharedInformerFactory {
199194
return i.OpenshiftSecurityInformers
200195
}
196+
201197
func (i *kubeAPIServerInformers) getOpenshiftUserInformers() userinformer.SharedInformerFactory {
202198
return i.OpenshiftUserInformers
203199
}
200+
204201
func (i *kubeAPIServerInformers) getOpenshiftInfraInformers() configv1informer.SharedInformerFactory {
205202
return i.OpenshiftConfigInformers
206203
}

openshift-kube-apiserver/openshiftkubeapiserver/sdn_readyz_wait.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func newOpenshiftAPIServiceReachabilityCheck(ipForKubernetesDefaultService net.I
2222
return newAggregatedAPIServiceReachabilityCheck(ipForKubernetesDefaultService, "openshift-apiserver", "api")
2323
}
2424

25-
func newOAuthPIServiceReachabilityCheck(ipForKubernetesDefaultService net.IP) *aggregatedAPIServiceAvailabilityCheck {
25+
func newOAuthAPIServiceReachabilityCheck(ipForKubernetesDefaultService net.IP) *aggregatedAPIServiceAvailabilityCheck {
2626
return newAggregatedAPIServiceReachabilityCheck(ipForKubernetesDefaultService, "openshift-oauth-apiserver", "api")
2727
}
2828

0 commit comments

Comments
 (0)