rbac

package
v3.0.0-rc21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GrantRoot           = NewGrant("root", "")
	GrantSquatter       = NewGrant("squatter", "")
	GrantHeartbeat      = NewGrant("heartbeat", "")
	GrantBlacklistAdmin = NewGrant("blacklistadmin", "")
	GrantJoin           = NewGrant("join", "")
	GrantLeave          = NewGrant("leave", "")
	GrantPrioritizer    = NewGrant("prioritizer", "")
)

Functions

func IsScopedRole

func IsScopedRole(role Role) bool

func Roles

func Roles() []string

Roles returns list of defined roles

Types

type Grant

type Grant string

Grant is <role>:<scope>

func NewGrant

func NewGrant(role Role, scope string) Grant

func (*Grant) Role

func (t *Grant) Role() Role

func (*Grant) Scope

func (t *Grant) Scope() string

func (*Grant) Split

func (t *Grant) Split() (string, string)

func (*Grant) String

func (t *Grant) String() string

type Grants

type Grants []Grant

Grants is a list of Grant

func FilterGrantStrings

func FilterGrantStrings(allowed []string, roles []Role, scope string) Grants

FilterGrantStrings return a subset of allowed grants capped by the requested role and scope.

1/ with no role and no scope,

return all user grants.

Request    Request   User                             Returned
Role       Scope     Grants                           Grants
---        ---       ---                              ---
                     root                             root
                     admin                            admin
                     admin:ns1,admin:ns2,guest:ns3    admin:ns1,admin:ns2,guest:ns3

2/ with roles and scope,

Request    Request   User                             Returned
Role       Scope     Grants                           Grants
---        ---       ---                              ---
admin      ns2       root                             admin:ns2
admin      ns2       admin                            admin:ns2
guest      ns2       admin                            guest:ns2
admin      ns2       admin:ns1,admin:ns2,guest:ns3    admin:ns2
admin      ns3       admin:ns1,admin:ns2,guest:ns3
guest      ns2       admin:ns1,admin:ns2,guest:ns3    guest:ns2

3/ with roles and no scope,

Role       Scope     Grants                           Filtered Grants
---        ---       ---                              ---
root                 root                             root
admin                root                             admin
root                 admin
admin                admin                            admin
guest                admin                            guest
root                 admin:ns1,admin:ns2,guest:ns3
admin                admin:ns1,admin:ns2,guest:ns3    admin:ns1,admin:ns2
guest                admin:ns1,admin:ns2,guest:ns3    guest:ns3

4/ with scope and no role,

Role       Scope     Grants                           Filtered Grants
---        ---       ---                              ---
           ns1       root                             admin:ns1
           ns1       guest                            guest:ns1
           ns1       admin:ns1,admin:ns2,guest:ns3    admin:ns1
           ns3       admin:ns1,admin:ns2,guest:ns3    guest:ns3

func NewGrants

func NewGrants(l ...string) Grants

func (Grants) AsStringList

func (t Grants) AsStringList() []string

func (Grants) AssertRoleOn

func (t Grants) AssertRoleOn(scope string, roles ...Role) bool

func (Grants) Has

func (t Grants) Has(role Role, scope string) bool

func (Grants) HasGrant

func (t Grants) HasGrant(grants ...Grant) bool

HasGrant returns true if any grant of the variadic grants is found.

func (Grants) HasRole

func (t Grants) HasRole(roles ...Role) bool

HasRole returns true if any role of the variadic roles is found.

func (Grants) HasRoleOn

func (t Grants) HasRoleOn(scope string, roles ...Role) bool

HasRoleOn checks if any of the specified roles with the given scope exist in the Grants.

func (Grants) Namespaces

func (t Grants) Namespaces(roles ...Role) []string

func (Grants) String

func (t Grants) String() string

func (Grants) WithRole

func (t Grants) WithRole(roles ...Role) (grants Grants)

type Role

type Role string
const (
	RoleUndef          Role = ""
	RoleRoot           Role = "root"
	RoleAdmin          Role = "admin"
	RoleOperator       Role = "operator"
	RolePrioritizer    Role = "prioritizer"
	RoleGuest          Role = "guest"
	RoleSquatter       Role = "squatter"
	RoleBlacklistAdmin Role = "blacklistadmin"
	RoleHeartbeat      Role = "heartbeat"
	RoleJoin           Role = "join"
	RoleLeave          Role = "leave"
)

func ParseRole

func ParseRole(s string) Role

func SplitGrant

func SplitGrant(grant Grant) (r Role, ns string)

SplitGrant extract role and scope from a grant

func (*Role) String

func (t *Role) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL