@@ -5,12 +5,10 @@ import (
5
5
"errors"
6
6
"fmt"
7
7
"io"
8
- "time"
9
8
10
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
10
kerrors "k8s.io/apimachinery/pkg/util/errors"
12
11
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
13
- "k8s.io/apimachinery/pkg/util/wait"
14
12
"k8s.io/apiserver/pkg/admission"
15
13
"k8s.io/apiserver/pkg/admission/initializer"
16
14
"k8s.io/client-go/kubernetes"
@@ -19,14 +17,11 @@ import (
19
17
"k8s.io/klog/v2"
20
18
"k8s.io/kubernetes/pkg/apis/rbac"
21
19
22
- configv1 "github.com/openshift/api/config/v1"
23
20
userv1 "github.com/openshift/api/user/v1"
24
21
authorizationtypedclient "github.com/openshift/client-go/authorization/clientset/versioned/typed/authorization/v1"
25
- configv1informer "github.com/openshift/client-go/config/informers/externalversions"
26
22
userclient "github.com/openshift/client-go/user/clientset/versioned"
27
23
userinformer "github.com/openshift/client-go/user/informers/externalversions"
28
24
"github.com/openshift/library-go/pkg/apiserver/admission/admissionrestconfig"
29
- "k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers/authncache"
30
25
"k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers/usercache"
31
26
)
32
27
@@ -42,11 +37,6 @@ type GroupCache interface {
42
37
HasSynced () bool
43
38
}
44
39
45
- type AuthnCache interface {
46
- Authn () (* configv1.Authentication , error )
47
- HasSynced () bool
48
- }
49
-
50
40
// restrictUsersAdmission implements admission.ValidateInterface and enforces
51
41
// restrictions on adding rolebindings in a project to permit only designated
52
42
// subjects.
@@ -58,7 +48,6 @@ type restrictUsersAdmission struct {
58
48
kubeClient kubernetes.Interface
59
49
groupCacheFunc func () (GroupCache , error )
60
50
groupCache GroupCache
61
- authnCache AuthnCache
62
51
}
63
52
64
53
var (
@@ -101,29 +90,11 @@ func (q *restrictUsersAdmission) SetRESTClientConfig(restClientConfig rest.Confi
101
90
}
102
91
}
103
92
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
-
123
93
func (q * restrictUsersAdmission ) SetUserInformer (userInformers userinformer.SharedInformerFactory ) {
124
94
// 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.
127
98
q .groupCacheFunc = func () (GroupCache , error ) {
128
99
if err := userInformers .User ().V1 ().Groups ().Informer ().AddIndexers (cache.Indexers {
129
100
usercache .ByUserIndexName : usercache .ByUserIndexKeys ,
@@ -221,35 +192,16 @@ func (q *restrictUsersAdmission) Validate(ctx context.Context, a admission.Attri
221
192
return nil
222
193
}
223
194
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
-
229
195
checkers := []SubjectChecker {}
230
196
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
- }
243
197
checker , err := NewSubjectChecker (& rbr .Spec )
244
198
if err != nil {
245
199
return admission .NewForbidden (a , fmt .Errorf ("could not create rolebinding restriction subject checker: %v" , err ))
246
200
}
247
201
checkers = append (checkers , checker )
248
202
}
249
203
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 {
253
205
q .groupCache , err = q .groupCacheFunc ()
254
206
if err != nil {
255
207
return admission .NewForbidden (a , fmt .Errorf ("could not create group cache: %v" , err ))
@@ -295,9 +247,6 @@ func (q *restrictUsersAdmission) ValidateInitialization() error {
295
247
if q .userClient == nil {
296
248
return errors .New ("RestrictUsersAdmission plugin requires an OpenShift user client" )
297
249
}
298
- if q .authnCache == nil {
299
- return errors .New ("RestrictUsersAdmission plugin requires an authentication cache" )
300
- }
301
250
if q .groupCache == nil && q .groupCacheFunc == nil {
302
251
return errors .New ("RestrictUsersAdmission plugin requires a group cache" )
303
252
}
0 commit comments