1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-27 11:00:48 +00:00
steve/pkg/accesscontrol/access_control.go

47 lines
1.3 KiB
Go
Raw Normal View History

2019-08-04 17:41:32 +00:00
package accesscontrol
import (
apiserver "github.com/rancher/apiserver/pkg/server"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/steve/pkg/attributes"
"github.com/rancher/wrangler/v3/pkg/kv"
"k8s.io/apimachinery/pkg/runtime/schema"
2019-08-04 17:41:32 +00:00
)
type AccessControl struct {
apiserver.SchemaBasedAccess
2019-08-04 17:41:32 +00:00
}
func NewAccessControl() *AccessControl {
return &AccessControl{}
}
func (a *AccessControl) CanDo(apiOp *types.APIRequest, resource, verb, namespace, name string) error {
apiSchema := apiOp.Schemas.LookupSchema(resource)
if apiSchema != nil && attributes.GVK(apiSchema).Kind != "" {
access := GetAccessListMap(apiSchema)
if access[verb].Grants(namespace, name) {
return nil
}
}
group, resource := kv.Split(resource, "/")
accessSet := apiOp.Schemas.Attributes["accessSet"].(*AccessSet)
if accessSet.Grants(verb, schema.GroupResource{
Group: group,
Resource: resource,
}, namespace, name) {
return nil
}
return a.SchemaBasedAccess.CanDo(apiOp, resource, verb, namespace, name)
}
2020-01-31 05:37:59 +00:00
func (a *AccessControl) CanWatch(apiOp *types.APIRequest, schema *types.APISchema) error {
if attributes.GVK(schema).Kind != "" {
access := GetAccessListMap(schema)
if _, ok := access["watch"]; ok {
return nil
}
2019-08-04 17:41:32 +00:00
}
return a.SchemaBasedAccess.CanWatch(apiOp, schema)
2019-08-04 17:41:32 +00:00
}