k8s.io/kubernetes@v1.29.3/pkg/registry/authentication/rest/storage_authentication.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package rest 18 19 import ( 20 authenticationv1 "k8s.io/api/authentication/v1" 21 authenticationv1alpha1 "k8s.io/api/authentication/v1alpha1" 22 authenticationv1beta1 "k8s.io/api/authentication/v1beta1" 23 "k8s.io/apiserver/pkg/authentication/authenticator" 24 "k8s.io/apiserver/pkg/registry/generic" 25 "k8s.io/apiserver/pkg/registry/rest" 26 genericapiserver "k8s.io/apiserver/pkg/server" 27 serverstorage "k8s.io/apiserver/pkg/server/storage" 28 "k8s.io/kubernetes/pkg/api/legacyscheme" 29 "k8s.io/kubernetes/pkg/apis/authentication" 30 "k8s.io/kubernetes/pkg/registry/authentication/selfsubjectreview" 31 "k8s.io/kubernetes/pkg/registry/authentication/tokenreview" 32 ) 33 34 type RESTStorageProvider struct { 35 Authenticator authenticator.Request 36 APIAudiences authenticator.Audiences 37 } 38 39 func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, error) { 40 // TODO figure out how to make the swagger generation stable, while allowing this endpoint to be disabled. 41 // if p.Authenticator == nil { 42 // return genericapiserver.APIGroupInfo{}, false 43 // } 44 45 apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(authentication.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs) 46 // If you add a version here, be sure to add an entry in `k8s.io/kubernetes/cmd/kube-apiserver/app/aggregator.go with specific priorities. 47 // TODO refactor the plumbing to provide the information in the APIGroupInfo 48 49 if storageMap := p.v1alpha1Storage(apiResourceConfigSource, restOptionsGetter); len(storageMap) > 0 { 50 apiGroupInfo.VersionedResourcesStorageMap[authenticationv1alpha1.SchemeGroupVersion.Version] = storageMap 51 } 52 53 if storageMap := p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter); len(storageMap) > 0 { 54 apiGroupInfo.VersionedResourcesStorageMap[authenticationv1beta1.SchemeGroupVersion.Version] = storageMap 55 } 56 57 if storageMap := p.v1Storage(apiResourceConfigSource, restOptionsGetter); len(storageMap) > 0 { 58 apiGroupInfo.VersionedResourcesStorageMap[authenticationv1.SchemeGroupVersion.Version] = storageMap 59 } 60 61 return apiGroupInfo, nil 62 } 63 64 func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage { 65 storage := map[string]rest.Storage{} 66 67 // tokenreviews 68 if resource := "tokenreviews"; apiResourceConfigSource.ResourceEnabled(authenticationv1.SchemeGroupVersion.WithResource(resource)) { 69 tokenReviewStorage := tokenreview.NewREST(p.Authenticator, p.APIAudiences) 70 storage[resource] = tokenReviewStorage 71 } 72 if resource := "selfsubjectreviews"; apiResourceConfigSource.ResourceEnabled(authenticationv1.SchemeGroupVersion.WithResource(resource)) { 73 selfSRStorage := selfsubjectreview.NewREST() 74 storage[resource] = selfSRStorage 75 } 76 77 return storage 78 } 79 80 func (p RESTStorageProvider) v1alpha1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage { 81 storage := map[string]rest.Storage{} 82 83 // selfsubjectreviews 84 if resource := "selfsubjectreviews"; apiResourceConfigSource.ResourceEnabled(authenticationv1alpha1.SchemeGroupVersion.WithResource(resource)) { 85 selfSRStorage := selfsubjectreview.NewREST() 86 storage[resource] = selfSRStorage 87 } 88 return storage 89 } 90 91 func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage { 92 storage := map[string]rest.Storage{} 93 94 // selfsubjectreviews 95 if resource := "selfsubjectreviews"; apiResourceConfigSource.ResourceEnabled(authenticationv1beta1.SchemeGroupVersion.WithResource(resource)) { 96 selfSRStorage := selfsubjectreview.NewREST() 97 storage[resource] = selfSRStorage 98 } 99 return storage 100 } 101 102 func (p RESTStorageProvider) GroupName() string { 103 return authentication.GroupName 104 }