rbac

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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", "")
	GrantScraper        = NewGrant("scraper", "")
)

Functions

func IsScopedRole

func IsScopedRole(role Role) bool

func MatchNamespace

func MatchNamespace(selector, namespace string) bool

MatchNamespace says whether a namespace selector of a grant, a namespace name or a glob pattern as "prod*", matches the namespace. A malformed pattern matches its name only.

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) Covers

func (t Grants) Covers(g Grant) bool

Covers says whether these grants hold g, so whoever holds them may give g to another.

Root holds every grant. A role granted with no scope holds that role on every namespace, so it covers the role on any one. A role granted on a namespace covers that role on that namespace only, and a cluster role, like root or squatter, is covered by itself only.

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

Namespaces returns the namespace selectors of the grants of the roles, of every role with none: namespace names or glob patterns, which MatchNamespace matches against a namespace.

func (Grants) String

func (t Grants) String() string

func (Grants) Uncovered

func (t Grants) Uncovered(l ...Grant) (out Grants)

Uncovered returns the grants of l these grants do not cover.

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"
	RoleScraper        Role = "scraper"
)

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