Skip to content

Commit 35a6c57

Browse files
committed
Use kube auth interfaces for union and group
Signed-off-by: Monis Khan <[email protected]>
1 parent 8eafb3d commit 35a6c57

File tree

7 files changed

+23
-248
lines changed

7 files changed

+23
-248
lines changed

pkg/auth/authenticator/request/unionrequest/union.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

pkg/auth/authenticator/request/unionrequest/unionauth_test.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

pkg/auth/group/group_adder.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

pkg/auth/group/group_adder_test.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

pkg/cmd/server/authenticator/remote.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,25 @@ import (
55
"time"
66

77
"k8s.io/kubernetes/pkg/auth/authenticator"
8+
"k8s.io/kubernetes/pkg/auth/group"
89
unversionedauthentication "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authentication/internalversion"
10+
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
911

10-
oauthenticator "github.com/openshift/origin/pkg/auth/authenticator"
1112
"github.com/openshift/origin/pkg/auth/authenticator/anonymous"
1213
"github.com/openshift/origin/pkg/auth/authenticator/request/bearertoken"
13-
"github.com/openshift/origin/pkg/auth/authenticator/request/unionrequest"
1414
"github.com/openshift/origin/pkg/auth/authenticator/request/x509request"
1515
authncache "github.com/openshift/origin/pkg/auth/authenticator/token/cache"
1616
authnremote "github.com/openshift/origin/pkg/auth/authenticator/token/remotetokenreview"
17-
"github.com/openshift/origin/pkg/auth/group"
18-
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
1917
)
2018

2119
// NewRemoteAuthenticator creates an authenticator that checks the provided remote endpoint for tokens, allows any linked clientCAs to be checked, and caches
2220
// responses as indicated. If no authentication is possible, the user will be system:anonymous.
2321
func NewRemoteAuthenticator(authenticationClient unversionedauthentication.TokenReviewsGetter, clientCAs *x509.CertPool, cacheTTL time.Duration, cacheSize int) (authenticator.Request, error) {
24-
authenticators := []oauthenticator.Request{}
22+
authenticators := []authenticator.Request{}
2523

2624
// API token auth
2725
var (
28-
tokenAuthenticator oauthenticator.Token
26+
tokenAuthenticator authenticator.Token
2927
err error
3028
)
3129
// Authenticate against the remote master
@@ -50,17 +48,12 @@ func NewRemoteAuthenticator(authenticationClient unversionedauthentication.Token
5048
authenticators = append(authenticators, certauth)
5149
}
5250

53-
ret := &unionrequest.Authenticator{
54-
// Anonymous requests will pass the token and cert checks without errors
55-
// Bad tokens or bad certs will produce errors, in which case we should not continue to authenticate them as "system:anonymous"
56-
FailOnError: true,
57-
Handlers: []oauthenticator.Request{
58-
// Add the "system:authenticated" group to users that pass token/cert authentication
59-
group.NewGroupAdder(unionrequest.NewUnionAuthentication(authenticators...), []string{bootstrappolicy.AuthenticatedGroup}),
60-
// Fall back to the "system:anonymous" user
61-
anonymous.NewAuthenticator(),
62-
},
63-
}
64-
65-
return ret, nil
51+
// Anonymous requests will pass the token and cert checks without errors
52+
// Bad tokens or bad certs will produce errors, in which case we should not continue to authenticate them as "system:anonymous"
53+
return union.NewFailOnError(
54+
// Add the "system:authenticated" group to users that pass token/cert authentication
55+
group.NewAuthenticatedGroupAdder(union.New(authenticators...)),
56+
// Fall back to the "system:anonymous" user
57+
anonymous.NewAuthenticator(),
58+
), nil
6659
}

pkg/cmd/server/origin/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import (
1717

1818
kapi "k8s.io/kubernetes/pkg/api"
1919
kerrs "k8s.io/kubernetes/pkg/api/errors"
20+
"k8s.io/kubernetes/pkg/auth/authenticator"
2021
kuser "k8s.io/kubernetes/pkg/auth/user"
2122
"k8s.io/kubernetes/pkg/client/retry"
2223
knet "k8s.io/kubernetes/pkg/util/net"
2324
"k8s.io/kubernetes/pkg/util/sets"
25+
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
2426

25-
"github.com/openshift/origin/pkg/auth/authenticator"
2627
"github.com/openshift/origin/pkg/auth/authenticator/challenger/passwordchallenger"
2728
"github.com/openshift/origin/pkg/auth/authenticator/challenger/placeholderchallenger"
2829
"github.com/openshift/origin/pkg/auth/authenticator/password/allowanypassword"
@@ -34,7 +35,6 @@ import (
3435
"github.com/openshift/origin/pkg/auth/authenticator/redirector"
3536
"github.com/openshift/origin/pkg/auth/authenticator/request/basicauthrequest"
3637
"github.com/openshift/origin/pkg/auth/authenticator/request/headerrequest"
37-
"github.com/openshift/origin/pkg/auth/authenticator/request/unionrequest"
3838
"github.com/openshift/origin/pkg/auth/authenticator/request/x509request"
3939
"github.com/openshift/origin/pkg/auth/ldaputil"
4040
"github.com/openshift/origin/pkg/auth/oauth/external"
@@ -739,7 +739,7 @@ func (c *AuthConfig) getAuthenticationRequestHandler() (authenticator.Request, e
739739
}
740740
}
741741

742-
authRequestHandler := unionrequest.NewUnionAuthentication(authRequestHandlers...)
742+
authRequestHandler := union.New(authRequestHandlers...)
743743
return authRequestHandler, nil
744744
}
745745

pkg/cmd/server/origin/master_config.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
kapierrors "k8s.io/kubernetes/pkg/api/errors"
1919
"k8s.io/kubernetes/pkg/api/unversioned"
2020
"k8s.io/kubernetes/pkg/apiserver/request"
21+
"k8s.io/kubernetes/pkg/auth/authenticator"
2122
"k8s.io/kubernetes/pkg/auth/group"
2223
"k8s.io/kubernetes/pkg/client/cache"
2324
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
@@ -35,12 +36,11 @@ import (
3536
saadmit "k8s.io/kubernetes/plugin/pkg/admission/serviceaccount"
3637
storageclassdefaultadmission "k8s.io/kubernetes/plugin/pkg/admission/storageclass/default"
3738
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/headerrequest"
39+
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
3840

39-
"github.com/openshift/origin/pkg/auth/authenticator"
4041
"github.com/openshift/origin/pkg/auth/authenticator/anonymous"
4142
"github.com/openshift/origin/pkg/auth/authenticator/request/bearertoken"
4243
"github.com/openshift/origin/pkg/auth/authenticator/request/paramtoken"
43-
"github.com/openshift/origin/pkg/auth/authenticator/request/unionrequest"
4444
"github.com/openshift/origin/pkg/auth/authenticator/request/x509request"
4545
authnregistry "github.com/openshift/origin/pkg/auth/oauth/registry"
4646
"github.com/openshift/origin/pkg/auth/userregistry/identitymapper"
@@ -648,11 +648,11 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
648648
tokenAuthenticators = append(tokenAuthenticators,
649649
// if you have a bearer token, you're a human (usually)
650650
// if you change this, have a look at the impersonationFilter where we attach groups to the impersonated user
651-
group.NewGroupAdder(unionrequest.NewUnionAuthentication(oauthTokenRequestAuthenticators...), []string{bootstrappolicy.AuthenticatedOAuthGroup}))
651+
group.NewGroupAdder(union.New(oauthTokenRequestAuthenticators...), []string{bootstrappolicy.AuthenticatedOAuthGroup}))
652652
}
653653

654654
if len(tokenAuthenticators) > 0 {
655-
authenticators = append(authenticators, unionrequest.NewUnionAuthentication(tokenAuthenticators...))
655+
authenticators = append(authenticators, union.New(tokenAuthenticators...))
656656
}
657657

658658
if configapi.UseTLS(config.ServingInfo.ServingInfo) {
@@ -665,10 +665,10 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
665665
authenticators = append(authenticators, certauth)
666666
}
667667

668-
resultingAuthenticator := &unionrequest.Authenticator{FailOnError: true, Handlers: authenticators}
668+
resultingAuthenticator := union.NewFailOnError(authenticators...)
669669

670670
topLevelAuthenticators := []authenticator.Request{}
671-
// if we have a front proxy providing authentication configuration, wire it up and it should come first
671+
// if we have a front proxy providing authentication configuration, wire it up and it should come first
672672
if config.AuthConfig.RequestHeader != nil {
673673
requestHeaderAuthenticator, err := headerrequest.NewSecure(
674674
config.AuthConfig.RequestHeader.ClientCA,
@@ -680,10 +680,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
680680
if err != nil {
681681
return nil, fmt.Errorf("Error building front proxy auth config: %v", err)
682682
}
683-
topLevelAuthenticators = append(topLevelAuthenticators, &unionrequest.Authenticator{
684-
FailOnError: false,
685-
Handlers: []authenticator.Request{requestHeaderAuthenticator, resultingAuthenticator},
686-
})
683+
topLevelAuthenticators = append(topLevelAuthenticators, union.New(requestHeaderAuthenticator, resultingAuthenticator))
687684

688685
} else {
689686
topLevelAuthenticators = append(topLevelAuthenticators, resultingAuthenticator)
@@ -692,10 +689,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
692689

693690
topLevelAuthenticators = append(topLevelAuthenticators, anonymous.NewAuthenticator())
694691

695-
return group.NewAuthenticatedGroupAdder(&unionrequest.Authenticator{
696-
FailOnError: true,
697-
Handlers: topLevelAuthenticators,
698-
}), nil
692+
return group.NewAuthenticatedGroupAdder(union.NewFailOnError(topLevelAuthenticators...)), nil
699693
}
700694

701695
func newProjectAuthorizationCache(authorizer authorizer.Authorizer, kubeClient *kclientset.Clientset, informerFactory shared.InformerFactory) *projectauth.AuthorizationCache {

0 commit comments

Comments
 (0)