Skip to content

Commit 705dcdb

Browse files
committed
remove OIDC checks from restrictusers admission plugin since it will be disabled
Signed-off-by: Bryce Palmer <[email protected]>
1 parent 61014ac commit 705dcdb

File tree

4 files changed

+7
-282
lines changed

4 files changed

+7
-282
lines changed

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@ package restrictusers
33
import (
44
"k8s.io/apiserver/pkg/admission"
55

6-
configv1informer "github.com/openshift/client-go/config/informers/externalversions"
76
userinformer "github.com/openshift/client-go/user/informers/externalversions"
87
)
98

10-
func NewInitializer(userInformer userinformer.SharedInformerFactory, configInformer configv1informer.SharedInformerFactory) admission.PluginInitializer {
11-
return &localInitializer{userInformer: userInformer, configInformer: configInformer}
9+
func NewInitializer(userInformer userinformer.SharedInformerFactory) admission.PluginInitializer {
10+
return &localInitializer{userInformer: userInformer}
1211
}
1312

1413
type WantsUserInformer interface {
1514
SetUserInformer(userinformer.SharedInformerFactory)
1615
admission.InitializationValidator
1716
}
1817

19-
type WantsConfigInformer interface {
20-
SetConfigInformer(configv1informer.SharedInformerFactory)
21-
}
22-
2318
type localInitializer struct {
2419
userInformer userinformer.SharedInformerFactory
25-
configInformer configv1informer.SharedInformerFactory
2620
}
2721

2822
// Initialize will check the initialization interfaces implemented by each plugin
@@ -31,8 +25,4 @@ func (i *localInitializer) Initialize(plugin admission.Interface) {
3125
if wants, ok := plugin.(WantsUserInformer); ok {
3226
wants.SetUserInformer(i.userInformer)
3327
}
34-
35-
if wants, ok := plugin.(WantsConfigInformer); ok {
36-
wants.SetConfigInformer(i.configInformer)
37-
}
3828
}

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

+4-55
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"time"
98

109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
kerrors "k8s.io/apimachinery/pkg/util/errors"
1211
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
13-
"k8s.io/apimachinery/pkg/util/wait"
1412
"k8s.io/apiserver/pkg/admission"
1513
"k8s.io/apiserver/pkg/admission/initializer"
1614
"k8s.io/client-go/kubernetes"
@@ -19,14 +17,11 @@ import (
1917
"k8s.io/klog/v2"
2018
"k8s.io/kubernetes/pkg/apis/rbac"
2119

22-
configv1 "github.com/openshift/api/config/v1"
2320
userv1 "github.com/openshift/api/user/v1"
2421
authorizationtypedclient "github.com/openshift/client-go/authorization/clientset/versioned/typed/authorization/v1"
25-
configv1informer "github.com/openshift/client-go/config/informers/externalversions"
2622
userclient "github.com/openshift/client-go/user/clientset/versioned"
2723
userinformer "github.com/openshift/client-go/user/informers/externalversions"
2824
"github.com/openshift/library-go/pkg/apiserver/admission/admissionrestconfig"
29-
"k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers/authncache"
3025
"k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers/usercache"
3126
)
3227

@@ -42,11 +37,6 @@ type GroupCache interface {
4237
HasSynced() bool
4338
}
4439

45-
type AuthnCache interface {
46-
Authn() (*configv1.Authentication, error)
47-
HasSynced() bool
48-
}
49-
5040
// restrictUsersAdmission implements admission.ValidateInterface and enforces
5141
// restrictions on adding rolebindings in a project to permit only designated
5242
// subjects.
@@ -58,7 +48,6 @@ type restrictUsersAdmission struct {
5848
kubeClient kubernetes.Interface
5949
groupCacheFunc func() (GroupCache, error)
6050
groupCache GroupCache
61-
authnCache AuthnCache
6251
}
6352

6453
var (
@@ -101,29 +90,11 @@ func (q *restrictUsersAdmission) SetRESTClientConfig(restClientConfig rest.Confi
10190
}
10291
}
10392

104-
func (q *restrictUsersAdmission) isAuthTypeOIDC() (bool, error) {
105-
err := wait.PollImmediate(1*time.Second, 10*time.Second, func() (bool, error) {
106-
return q.authnCache.HasSynced(), nil
107-
})
108-
if err != nil {
109-
return false, errors.New("authentications.config.openshift.io cache is not synchronized")
110-
}
111-
112-
auth, err := q.authnCache.Authn()
113-
if err == nil && auth != nil {
114-
return auth.Spec.Type == configv1.AuthenticationTypeOIDC, nil
115-
}
116-
return false, err
117-
}
118-
119-
func (q *restrictUsersAdmission) SetConfigInformer(configInformer configv1informer.SharedInformerFactory) {
120-
q.authnCache = authncache.NewAuthnCache(configInformer.Config().V1().Authentications())
121-
}
122-
12393
func (q *restrictUsersAdmission) SetUserInformer(userInformers userinformer.SharedInformerFactory) {
12494
// defer the allocation of the group cache until later in the process so we can
125-
// ensure we aren't creating informers for the Group resources if the authentication
126-
// type is OIDC.
95+
// ensure we aren't creating informers for the Group resources until this admission
96+
// plugin actually runs. If authentication type is OIDC, this plugin should be disabled
97+
// resulting in the Group informer never being configured and started.
12798
q.groupCacheFunc = func() (GroupCache, error) {
12899
if err := userInformers.User().V1().Groups().Informer().AddIndexers(cache.Indexers{
129100
usercache.ByUserIndexName: usercache.ByUserIndexKeys,
@@ -221,35 +192,16 @@ func (q *restrictUsersAdmission) Validate(ctx context.Context, a admission.Attri
221192
return nil
222193
}
223194

224-
isAuthOIDC, err := q.isAuthTypeOIDC()
225-
if err != nil {
226-
return admission.NewForbidden(a, fmt.Errorf("could not determine if authentication type is OIDC: %v", err))
227-
}
228-
229195
checkers := []SubjectChecker{}
230196
for _, rbr := range roleBindingRestrictionList.Items {
231-
// if the auth type is OIDC, the oauth-apiserver is down and as such
232-
// we cannot properly evaluate the user and/or group subjects. Fail fast
233-
// if the RBR has user and/or group restrictions applied if auth type is OIDC
234-
if isAuthOIDC {
235-
if rbr.Spec.UserRestriction != nil {
236-
return admission.NewForbidden(a, errors.New("authentication type is OIDC and rolebinding restriction specifies user restrictions. Unable to get user information due to OIDC configuration, rejecting"))
237-
}
238-
239-
if rbr.Spec.GroupRestriction != nil {
240-
return admission.NewForbidden(a, errors.New("authentication type is OIDC and rolebinding restriction specifies group restrictions. Unable to get group information due to OIDC configuration, rejecting"))
241-
}
242-
}
243197
checker, err := NewSubjectChecker(&rbr.Spec)
244198
if err != nil {
245199
return admission.NewForbidden(a, fmt.Errorf("could not create rolebinding restriction subject checker: %v", err))
246200
}
247201
checkers = append(checkers, checker)
248202
}
249203

250-
// If auth type is OIDC, we should never create checkers for the user/group restrictions
251-
// so it should be ok to provide a nil group cache
252-
if !isAuthOIDC && q.groupCache == nil && q.groupCacheFunc != nil {
204+
if q.groupCache == nil && q.groupCacheFunc != nil {
253205
q.groupCache, err = q.groupCacheFunc()
254206
if err != nil {
255207
return admission.NewForbidden(a, fmt.Errorf("could not create group cache: %v", err))
@@ -295,9 +247,6 @@ func (q *restrictUsersAdmission) ValidateInitialization() error {
295247
if q.userClient == nil {
296248
return errors.New("RestrictUsersAdmission plugin requires an OpenShift user client")
297249
}
298-
if q.authnCache == nil {
299-
return errors.New("RestrictUsersAdmission plugin requires an authentication cache")
300-
}
301250
if q.groupCache == nil && q.groupCacheFunc == nil {
302251
return errors.New("RestrictUsersAdmission plugin requires a group cache")
303252
}

0 commit comments

Comments
 (0)