Skip to content

Commit 3de8e52

Browse files
committed
Separate serviceaccount and secret storage config
1 parent 227f52e commit 3de8e52

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

cmd/kube-apiserver/app/server.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,20 @@ func BuildAuthenticator(s *options.ServerRunOptions, storageFactory serverstorag
469469
if s.Authentication.ServiceAccounts.Lookup {
470470
// we have to go direct to storage because the clientsets fail when they're initialized with some API versions excluded
471471
// we should stop trying to control them like that.
472-
storageConfig, err := storageFactory.NewConfig(api.Resource("serviceaccounts"))
472+
storageConfigServiceAccounts, err := storageFactory.NewConfig(api.Resource("serviceaccounts"))
473473
if err != nil {
474474
return nil, nil, fmt.Errorf("unable to get serviceaccounts storage: %v", err)
475475
}
476-
authenticatorConfig.ServiceAccountTokenGetter = serviceaccountcontroller.NewGetterFromStorageInterface(storageConfig, storageFactory.ResourcePrefix(api.Resource("serviceaccounts")), storageFactory.ResourcePrefix(api.Resource("secrets")))
476+
storageConfigSecrets, err := storageFactory.NewConfig(api.Resource("secrets"))
477+
if err != nil {
478+
return nil, nil, fmt.Errorf("unable to get secrets storage: %v", err)
479+
}
480+
authenticatorConfig.ServiceAccountTokenGetter = serviceaccountcontroller.NewGetterFromStorageInterface(
481+
storageConfigServiceAccounts,
482+
storageFactory.ResourcePrefix(api.Resource("serviceaccounts")),
483+
storageConfigSecrets,
484+
storageFactory.ResourcePrefix(api.Resource("secrets")),
485+
)
477486
}
478487
if client == nil || reflect.ValueOf(client).IsNil() {
479488
// TODO: Remove check once client can never be nil.

pkg/controller/serviceaccount/tokengetter.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@ func (r *registryGetter) GetSecret(namespace, name string) (*v1.Secret, error) {
8585

8686
// NewGetterFromStorageInterface returns a ServiceAccountTokenGetter that
8787
// uses the specified storage to retrieve service accounts and secrets.
88-
func NewGetterFromStorageInterface(config *storagebackend.Config, saPrefix, secretPrefix string) serviceaccount.ServiceAccountTokenGetter {
89-
saOpts := generic.RESTOptions{StorageConfig: config, Decorator: generic.UndecoratedStorage, ResourcePrefix: saPrefix}
90-
secretOpts := generic.RESTOptions{StorageConfig: config, Decorator: generic.UndecoratedStorage, ResourcePrefix: secretPrefix}
88+
func NewGetterFromStorageInterface(
89+
saConfig *storagebackend.Config,
90+
saPrefix string,
91+
secretConfig *storagebackend.Config,
92+
secretPrefix string) serviceaccount.ServiceAccountTokenGetter {
93+
94+
saOpts := generic.RESTOptions{StorageConfig: saConfig, Decorator: generic.UndecoratedStorage, ResourcePrefix: saPrefix}
95+
secretOpts := generic.RESTOptions{StorageConfig: secretConfig, Decorator: generic.UndecoratedStorage, ResourcePrefix: secretPrefix}
9196
return NewGetterFromRegistries(
9297
serviceaccountregistry.NewRegistry(serviceaccountstore.NewREST(saOpts)),
9398
secret.NewRegistry(secretstore.NewREST(secretOpts)),

0 commit comments

Comments
 (0)