vitess.io/vitess@v0.16.2/go/acl/read_only_policy.go (about) 1 /* 2 Copyright 2019 The Vitess 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 acl 18 19 import ( 20 "errors" 21 "net/http" 22 ) 23 24 var errReadOnly = errors.New("not allowed: read-only security_policy enforced") 25 26 // readOnlyPolicy allows DEBUGGING and MONITORING roles for everyone, 27 // while denying any other roles (e.g. ADMIN) for everyone. 28 type readOnlyPolicy struct{} 29 30 // CheckAccessActor disallows all actor access. 31 func (readOnlyPolicy) CheckAccessActor(actor, role string) error { 32 switch role { 33 case DEBUGGING, MONITORING: 34 return nil 35 default: 36 return errReadOnly 37 } 38 } 39 40 // CheckAccessHTTP disallows all HTTP access. 41 func (readOnlyPolicy) CheckAccessHTTP(req *http.Request, role string) error { 42 switch role { 43 case DEBUGGING, MONITORING: 44 return nil 45 default: 46 return errReadOnly 47 } 48 } 49 50 func init() { 51 RegisterPolicy("read-only", readOnlyPolicy{}) 52 }