Documentation
¶
Index ¶
- Constants
- Variables
- func RequestAuthorizer(authorizer Authorizer, actions func(*http.Request) []string) func(*http.Request) error
- func WithAssertions(ctx context.Context, assertions ...Assertion) context.Context
- func WithClaims(ctx context.Context, claims *Claims) context.Context
- func WithRequestInfo(ctx context.Context, info RequestInfo) context.Context
- func WithTarget(ctx context.Context, target *Target) context.Context
- type AccessConfig
- type Assertion
- type AssertionFunc
- type AuthorizationChecker
- type Authorizer
- type Claims
- type Config
- type Decision
- type DefaultAuthorizer
- type DefaultRole
- func (r *DefaultRole) AddChild(child Role) error
- func (r *DefaultRole) AddParent(parent Role) error
- func (r *DefaultRole) AddPermissions(permission string, rest ...string)
- func (r *DefaultRole) Children() []Role
- func (r *DefaultRole) HasAncestor(role Role) bool
- func (r *DefaultRole) HasDescendant(role Role) bool
- func (r *DefaultRole) HasPermission(permission string) bool
- func (r *DefaultRole) Name() string
- func (r *DefaultRole) Parents() []Role
- func (r *DefaultRole) Permissions(children bool) []string
- func (r *DefaultRole) RePermissions(children bool) []*regexp.Regexp
- func (r *DefaultRole) String() string
- type RBAC
- func (rbac *RBAC) AddRole(role any, parents ...any) error
- func (rbac *RBAC) Apply(cfg Config) error
- func (rbac *RBAC) CreateMissingRoles() bool
- func (rbac *RBAC) HasRole(role any) (bool, error)
- func (rbac *RBAC) IsGranted(ctx context.Context, role any, permission string, assertions ...Assertion) bool
- func (rbac *RBAC) IsGrantedE(ctx context.Context, role any, permission string, assertions ...Assertion) (bool, error)
- func (rbac *RBAC) Role(name string) (Role, error)
- func (rbac *RBAC) Roles() []Role
- func (rbac *RBAC) SetCreateMissingRoles(createMissingRoles bool) *RBAC
- type RequestInfo
- type Role
- type RoleConfig
- type Subject
- type Target
Constants ¶
View Source
const ( DecisionDeny = iota + 1 DecisionAllow )
Variables ¶
View Source
var ( ErrRoleNotFound = errors.New("role not found") ErrInvalidRole = errors.New("role must be a string or implement the Role interface") )
View Source
var ErrCircularReference = errors.New("circular reference detected")
View Source
var ErrDeny = errors.New("deny")
Functions ¶
func RequestAuthorizer ¶
func WithAssertions ¶
func WithRequestInfo ¶ added in v0.0.3
func WithRequestInfo(ctx context.Context, info RequestInfo) context.Context
Types ¶
type AccessConfig ¶
type Assertion ¶
type Assertion interface {
Assert(ctx context.Context, role Role, permission string) (bool, error)
}
func CtxAssertions ¶
type AssertionFunc ¶
type AuthorizationChecker ¶
type Authorizer ¶
type Config ¶
type Config struct { CreateMissingRoles bool `json:"createMissingRoles,omitempty" yaml:"createMissingRoles,omitempty"` RoleHierarchy []RoleConfig `json:"roleHierarchy,omitempty" yaml:"roleHierarchy,omitempty"` AccessControl []AccessConfig `json:"accessControl,omitempty" yaml:"accessControl,omitempty"` }
type DefaultAuthorizer ¶
type DefaultAuthorizer struct {
// contains filtered or unexported fields
}
func NewDefaultAuthorizer ¶
func NewDefaultAuthorizer(rbac *RBAC) *DefaultAuthorizer
type DefaultRole ¶
type DefaultRole struct {
// contains filtered or unexported fields
}
func NewRole ¶
func NewRole(name string) *DefaultRole
func (*DefaultRole) AddChild ¶
func (r *DefaultRole) AddChild(child Role) error
func (*DefaultRole) AddParent ¶
func (r *DefaultRole) AddParent(parent Role) error
func (*DefaultRole) AddPermissions ¶
func (r *DefaultRole) AddPermissions(permission string, rest ...string)
func (*DefaultRole) Children ¶
func (r *DefaultRole) Children() []Role
func (*DefaultRole) HasAncestor ¶
func (r *DefaultRole) HasAncestor(role Role) bool
func (*DefaultRole) HasDescendant ¶
func (r *DefaultRole) HasDescendant(role Role) bool
func (*DefaultRole) HasPermission ¶
func (r *DefaultRole) HasPermission(permission string) bool
func (*DefaultRole) Name ¶
func (r *DefaultRole) Name() string
func (*DefaultRole) Parents ¶
func (r *DefaultRole) Parents() []Role
func (*DefaultRole) Permissions ¶
func (r *DefaultRole) Permissions(children bool) []string
func (*DefaultRole) RePermissions ¶ added in v0.0.5
func (r *DefaultRole) RePermissions(children bool) []*regexp.Regexp
func (*DefaultRole) String ¶
func (r *DefaultRole) String() string
type RBAC ¶
type RBAC struct {
// contains filtered or unexported fields
}
func NewWithConfig ¶
func (*RBAC) CreateMissingRoles ¶
func (*RBAC) IsGrantedE ¶
func (*RBAC) SetCreateMissingRoles ¶
type RequestInfo ¶ added in v0.0.3
type RequestInfo struct { Method string Host string RequestURI string Pattern string RemoteAddr string Header http.Header URL url.URL IsTLS bool }
func CtxRequestInfo ¶ added in v0.0.3
func CtxRequestInfo(ctx context.Context) RequestInfo
type Role ¶
type Role interface { fmt.Stringer Name() string AddPermissions(permission string, rest ...string) HasPermission(permission string) bool Permissions(children bool) []string RePermissions(children bool) []*regexp.Regexp AddParent(Role) error Parents() []Role AddChild(Role) error Children() []Role HasAncestor(role Role) bool HasDescendant(role Role) bool }
type RoleConfig ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.