k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/plugin/pkg/admission/deny/admission.go (about) 1 /* 2 Copyright 2014 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 deny 18 19 import ( 20 "context" 21 "errors" 22 "io" 23 24 "k8s.io/klog/v2" 25 26 "k8s.io/apiserver/pkg/admission" 27 ) 28 29 // PluginName indicates name of admission plugin. 30 const PluginName = "AlwaysDeny" 31 32 // Register registers a plugin 33 func Register(plugins *admission.Plugins) { 34 plugins.Register(PluginName, func(config io.Reader) (admission.Interface, error) { 35 return NewAlwaysDeny(), nil 36 }) 37 } 38 39 // alwaysDeny is an implementation of admission.Interface which always says no to an admission request. 40 type alwaysDeny struct{} 41 42 var _ admission.MutationInterface = alwaysDeny{} 43 var _ admission.ValidationInterface = alwaysDeny{} 44 45 // Admit makes an admission decision based on the request attributes. 46 func (alwaysDeny) Admit(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) { 47 return admission.NewForbidden(a, errors.New("admission control is denying all modifications")) 48 } 49 50 // Validate makes an admission decision based on the request attributes. It is NOT allowed to mutate. 51 func (alwaysDeny) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) { 52 return admission.NewForbidden(a, errors.New("admission control is denying all modifications")) 53 } 54 55 // Handles returns true if this admission controller can handle the given operation 56 // where operation can be one of CREATE, UPDATE, DELETE, or CONNECT 57 func (alwaysDeny) Handles(operation admission.Operation) bool { 58 return true 59 } 60 61 // NewAlwaysDeny creates an always deny admission handler 62 func NewAlwaysDeny() admission.Interface { 63 // DEPRECATED: AlwaysDeny denys all admission request, it is no use. 64 klog.Warningf("%s admission controller is deprecated. "+ 65 "Please remove this controller from your configuration files and scripts.", PluginName) 66 return new(alwaysDeny) 67 }