Skip to content

Commit 8800674

Browse files
committed
just disable the plugin on configuration
Signed-off-by: Bryce Palmer <[email protected]>
1 parent edf1675 commit 8800674

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

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

+11-20
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ import (
2727
"k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers/usercache"
2828
)
2929

30+
const RestrictSubjectBindingsPluginName = "authorization.openshift.io/RestrictSubjectBindings"
31+
3032
func Register(plugins *admission.Plugins) {
31-
plugins.Register("authorization.openshift.io/RestrictSubjectBindings",
33+
plugins.Register(RestrictSubjectBindingsPluginName,
3234
func(config io.Reader) (admission.Interface, error) {
3335
cfg, err := readConfig(config)
3436
if err != nil {
3537
return nil, err
3638
}
3739

38-
return NewRestrictUsersAdmission(cfg)
40+
if cfg.OpenShiftOAuthDesiredState == v1alpha1.OpenShiftOAuthStateNotDesired {
41+
klog.Infof("Admission plugin %q configured to expect the OpenShift oauth-apiserver as not being available. This is effectively the same as disabling the plugin, so it will be disabled.", RestrictSubjectBindingsPluginName)
42+
return nil, nil
43+
}
44+
45+
return NewRestrictUsersAdmission()
3946
})
4047
}
4148

@@ -84,7 +91,6 @@ type restrictUsersAdmission struct {
8491
userClient userclient.Interface
8592
kubeClient kubernetes.Interface
8693
groupCache GroupCache
87-
oauthState v1alpha1.OpenShiftOAuthState
8894
}
8995

9096
var (
@@ -96,15 +102,9 @@ var (
96102

97103
// NewRestrictUsersAdmission configures an admission plugin that enforces
98104
// restrictions on adding role bindings in a project.
99-
func NewRestrictUsersAdmission(cfg *v1alpha1.RestrictSubjectBindingsAdmissionConfig) (admission.Interface, error) {
105+
func NewRestrictUsersAdmission() (admission.Interface, error) {
100106
return &restrictUsersAdmission{
101107
Handler: admission.NewHandler(admission.Create, admission.Update),
102-
oauthState: func() v1alpha1.OpenShiftOAuthState {
103-
if cfg != nil {
104-
return cfg.OpenShiftOAuthDesiredState
105-
}
106-
return v1alpha1.OpenShiftOAuthStateDesired
107-
}(),
108108
}, nil
109109
}
110110

@@ -134,10 +134,6 @@ func (q *restrictUsersAdmission) SetRESTClientConfig(restClientConfig rest.Confi
134134
}
135135

136136
func (q *restrictUsersAdmission) SetUserInformer(userInformers userinformer.SharedInformerFactory) {
137-
if q.oauthState == v1alpha1.OpenShiftOAuthStateNotDesired {
138-
return
139-
}
140-
141137
if err := userInformers.User().V1().Groups().Informer().AddIndexers(cache.Indexers{
142138
usercache.ByUserIndexName: usercache.ByUserIndexKeys,
143139
}); err != nil {
@@ -172,11 +168,6 @@ func subjectsDelta(elementsToIgnore, elements []rbac.Subject) []rbac.Subject {
172168
// each subject in the binding must be matched by some rolebinding restriction
173169
// in the namespace.
174170
func (q *restrictUsersAdmission) Validate(ctx context.Context, a admission.Attributes, _ admission.ObjectInterfaces) (err error) {
175-
if q.oauthState == v1alpha1.OpenShiftOAuthStateNotDesired {
176-
klog.V(2).Info("admission plugin authorization.openshift.io/RestrictSubjectBindings is configured to act as if the OpenShift oauth-apiserver is not present. This admission plugin relies on the OpenShift oauth-apiserver to function as expected and should be disabled when it is not present. Acting as if disabled and not enforcing subject bindings.")
177-
return nil
178-
}
179-
180171
// We only care about rolebindings
181172
if a.GetResource().GroupResource() != rbac.Resource("rolebindings") {
182173
return nil
@@ -286,7 +277,7 @@ func (q *restrictUsersAdmission) ValidateInitialization() error {
286277
if q.userClient == nil {
287278
return errors.New("RestrictUsersAdmission plugin requires an OpenShift user client")
288279
}
289-
if q.groupCache == nil && q.oauthState == v1alpha1.OpenShiftOAuthStateDesired {
280+
if q.groupCache == nil {
290281
return errors.New("RestrictUsersAdmission plugin requires a group cache")
291282
}
292283

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestAdmission(t *testing.T) {
359359
fakeUserClient := fakeuserclient.NewSimpleClientset(tc.userObjects...)
360360
fakeAuthorizationClient := fakeauthorizationclient.NewSimpleClientset(tc.authorizationObjects...)
361361

362-
plugin, err := NewRestrictUsersAdmission(nil)
362+
plugin, err := NewRestrictUsersAdmission()
363363
if err != nil {
364364
t.Errorf("unexpected error initializing admission plugin: %v", err)
365365
}

0 commit comments

Comments
 (0)