Separate serviceaccount and secret storage config

This commit is contained in:
Jordan Liggitt 2017-06-20 23:49:10 -04:00
parent 227f52e0cb
commit 3de8e52c8a
No known key found for this signature in database
GPG Key ID: 24E7ADF9A3B42012
2 changed files with 19 additions and 5 deletions

View File

@ -469,11 +469,20 @@ func BuildAuthenticator(s *options.ServerRunOptions, storageFactory serverstorag
if s.Authentication.ServiceAccounts.Lookup { if s.Authentication.ServiceAccounts.Lookup {
// we have to go direct to storage because the clientsets fail when they're initialized with some API versions excluded // we have to go direct to storage because the clientsets fail when they're initialized with some API versions excluded
// we should stop trying to control them like that. // we should stop trying to control them like that.
storageConfig, err := storageFactory.NewConfig(api.Resource("serviceaccounts")) storageConfigServiceAccounts, err := storageFactory.NewConfig(api.Resource("serviceaccounts"))
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("unable to get serviceaccounts storage: %v", err) return nil, nil, fmt.Errorf("unable to get serviceaccounts storage: %v", err)
} }
authenticatorConfig.ServiceAccountTokenGetter = serviceaccountcontroller.NewGetterFromStorageInterface(storageConfig, storageFactory.ResourcePrefix(api.Resource("serviceaccounts")), storageFactory.ResourcePrefix(api.Resource("secrets"))) storageConfigSecrets, err := storageFactory.NewConfig(api.Resource("secrets"))
if err != nil {
return nil, nil, fmt.Errorf("unable to get secrets storage: %v", err)
}
authenticatorConfig.ServiceAccountTokenGetter = serviceaccountcontroller.NewGetterFromStorageInterface(
storageConfigServiceAccounts,
storageFactory.ResourcePrefix(api.Resource("serviceaccounts")),
storageConfigSecrets,
storageFactory.ResourcePrefix(api.Resource("secrets")),
)
} }
if client == nil || reflect.ValueOf(client).IsNil() { if client == nil || reflect.ValueOf(client).IsNil() {
// TODO: Remove check once client can never be nil. // TODO: Remove check once client can never be nil.

View File

@ -85,9 +85,14 @@ func (r *registryGetter) GetSecret(namespace, name string) (*v1.Secret, error) {
// NewGetterFromStorageInterface returns a ServiceAccountTokenGetter that // NewGetterFromStorageInterface returns a ServiceAccountTokenGetter that
// uses the specified storage to retrieve service accounts and secrets. // uses the specified storage to retrieve service accounts and secrets.
func NewGetterFromStorageInterface(config *storagebackend.Config, saPrefix, secretPrefix string) serviceaccount.ServiceAccountTokenGetter { func NewGetterFromStorageInterface(
saOpts := generic.RESTOptions{StorageConfig: config, Decorator: generic.UndecoratedStorage, ResourcePrefix: saPrefix} saConfig *storagebackend.Config,
secretOpts := generic.RESTOptions{StorageConfig: config, Decorator: generic.UndecoratedStorage, ResourcePrefix: secretPrefix} saPrefix string,
secretConfig *storagebackend.Config,
secretPrefix string) serviceaccount.ServiceAccountTokenGetter {
saOpts := generic.RESTOptions{StorageConfig: saConfig, Decorator: generic.UndecoratedStorage, ResourcePrefix: saPrefix}
secretOpts := generic.RESTOptions{StorageConfig: secretConfig, Decorator: generic.UndecoratedStorage, ResourcePrefix: secretPrefix}
return NewGetterFromRegistries( return NewGetterFromRegistries(
serviceaccountregistry.NewRegistry(serviceaccountstore.NewREST(saOpts)), serviceaccountregistry.NewRegistry(serviceaccountstore.NewREST(saOpts)),
secret.NewRegistry(secretstore.NewREST(secretOpts)), secret.NewRegistry(secretstore.NewREST(secretOpts)),