Documentation
¶
Index ¶
- Variables
- func MatchPolicy(p Policy, def []string, val string) (bool, error)
- func MatchRole(r *Role, val string) (bool, error)
- func NewErrRequestDeniedExplicit(err error) error
- func NewErrRequestDeniedImplicit(err error) error
- func NewRequestContext(ctx context.Context, meta ...map[string]interface{}) context.Context
- type Auditor
- type BoolCondition
- type Condition
- type ConditionBuilder
- type ConditionOptions
- type ConditionRegistry
- type Conditions
- type Enforcer
- type Error
- type IPWhitelistCondition
- type Matcher
- type Policy
- type PolicyEffect
- type PolicyManager
- type PolicyOption
- func PolicyAllow() PolicyOption
- func PolicyDeny() PolicyOption
- func PolicyDescription(d string) PolicyOption
- func PolicyName(n string) PolicyOption
- func SetActions(s ...string) PolicyOption
- func SetContext(ctx context.Context) PolicyOption
- func SetPolicyOptions(opts PolicyOptions) PolicyOption
- func SetResources(s ...string) PolicyOption
- func WithCondition(co ConditionOptions) PolicyOption
- func WithRole(r *Role) PolicyOption
- type PolicyOptions
- type Request
- type RequestMetadata
- type RequestMetadataKey
- type Role
- type RoleEqualsCondition
- type RoleManager
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultMatcher is a simple matcher DefaultMatcher = NewMatcher() // DefaultPolicyEffect is the policy effect to apply when no other matches can be found DefaultPolicyEffect = PolicyEffectDeny )
Functions ¶
func MatchPolicy ¶
MatchPolicy is a utility function that uses DefaultMatcher to evaluate whether p can be matched by val
func MatchRole ¶
MatchRole is a utility function that uses the DefaultMatcher to evaluate whether role val matches the effective roles of r
func NewErrRequestDeniedExplicit ¶
NewErrRequestDeniedExplicit returns an error with for explicit denials
func NewErrRequestDeniedImplicit ¶
NewErrRequestDeniedImplicit returns an error with for implicit denials (no policy)
Types ¶
type BoolCondition ¶
type BoolCondition struct {
Value bool `json:"value"`
}
BoolCondition matches a boolean value from context to the preconfigured value
func (*BoolCondition) Meets ¶
func (c *BoolCondition) Meets(val interface{}, _ *Request) bool
Meets evaluates whether parameter val matches the Condition Value
func (*BoolCondition) Name ¶
func (c *BoolCondition) Name() string
Name fulfills the Name method of Condition
type ConditionBuilder ¶
type ConditionBuilder func() Condition
ConditionBuilder is a typed function that returns a Condition
type ConditionOptions ¶
type ConditionOptions struct {
Name string `json:"name"`
Type string `json:"type"`
Options map[string]interface{} `json:"options"`
}
ConditionOptions contains the values used to build a Condition
type ConditionRegistry ¶
type ConditionRegistry map[string]ConditionBuilder
ConditionRegistry is a map contiaining named ConditionBuilders
func NewConditionRegistry ¶
func NewConditionRegistry(conds ...map[string]ConditionBuilder) ConditionRegistry
NewConditionRegistry returns a ConditionRegistry containing the default Conditions and accepts an array of map[string]ConditionBuilder to add custom conditions to the set
type Conditions ¶
Conditions is a map of named Conditions
func NewConditions ¶
func NewConditions(opts []ConditionOptions, reg ConditionRegistry) (Conditions, error)
NewConditions accepts an array of options and an optional ConditionRegistry and returns a Conditions map
type Enforcer ¶
Enforcer interface provides methods to enforce policies against a request
func NewDefaultEnforcer ¶ added in v0.1.2
func NewDefaultEnforcer(manager PolicyManager) (Enforcer, error)
func NewEnforcer ¶
func NewEnforcer(manager PolicyManager, matcher Matcher, auditor Auditor) (Enforcer, error)
NewEnforcer returns a default Enforcer combining a PolicyManager, Matcher, and Auditor
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a customized error implementation with additional context for policy evaluation
func (*Error) Reason ¶
Reason contains information about the policy decision that resulted in the error
func (*Error) StatusCode ¶
StatusCode can contain application or standard integer codes eg http 401
type IPWhitelistCondition ¶
type IPWhitelistCondition struct {
Networks []string `json:"networks" structs:"networks"`
}
IPWhitelistCondition performs CIDR matching for a range of Networks against a provided value
func (*IPWhitelistCondition) Meets ¶
func (c *IPWhitelistCondition) Meets(val interface{}, _ *Request) bool
Meets evaluates true when the network address in val is contained within one of the CIDR ranges of IPWhitelistCondition#Networks
func (*IPWhitelistCondition) Name ¶
func (c *IPWhitelistCondition) Name() string
Name fulfills the Name method of Condition
type Matcher ¶
type Matcher interface {
MatchPolicy(p Policy, def []string, val string) (bool, error)
MatchRole(r *Role, val string) (bool, error)
}
Matcher provides methods to facilitate matching policies to different request elements
func NewRegexMatcher ¶
func NewRegexMatcher() Matcher
NewRegexMatcher returns a Matcher using delimited regex for matching
type Policy ¶
type Policy interface {
ID() string
Description() string
Roles() []*Role
Resources() []string
Actions() []string
Scopes() []string
Conditions() Conditions
Effect() PolicyEffect
Context() context.Context
}
Policy provides methods to return data about a configured policy
func MustNewPolicy ¶
func MustNewPolicy(opts ...PolicyOption) Policy
MustNewPolicy returns a default policy implementation or panics on error
func NewPolicy ¶
func NewPolicy(opts ...PolicyOption) (Policy, error)
NewPolicy returns a default policy implementation from a set of provided options
type PolicyEffect ¶
type PolicyEffect string
PolicyEffect type is returned by Enforcer to describe the outcome of a policy evaluation
const ( // PolicyEffectAllow indicates explicit permission of the request PolicyEffectAllow PolicyEffect = "allow" // PolicyEffectDeny indicates explicti denial of the request PolicyEffectDeny PolicyEffect = "deny" )
func NewPolicyEffect ¶
func NewPolicyEffect(s string) PolicyEffect
NewPolicyEffect returns a PolicyEffect for a given string
type PolicyManager ¶
type PolicyManager interface {
Create(Policy) error
Update(Policy) error
Get(string) (Policy, error)
Delete(string) error
All(limit, offset int) ([]Policy, error)
FindByRequest(*Request) ([]Policy, error)
FindByRole(string) ([]Policy, error)
FindByResource(string) ([]Policy, error)
FindByScope(string) ([]Policy, error)
}
PolicyManager contains methods to allow query, update, and removal of policies
func NewManager ¶
func NewManager() PolicyManager
NewManager returns a default memory backed policy manager
type PolicyOption ¶
type PolicyOption func(*PolicyOptions)
PolicyOption is a typed function allowing updates to PolicyOptions through functional options
func PolicyDescription ¶
func PolicyDescription(d string) PolicyOption
PolicyDescription sets the policy description Option
func SetActions ¶
func SetActions(s ...string) PolicyOption
SetActions replaces the option Actions with the provided values
func SetContext ¶
func SetContext(ctx context.Context) PolicyOption
SetContext sets the Context option
func SetPolicyOptions ¶
func SetPolicyOptions(opts PolicyOptions) PolicyOption
SetPolicyOptions is a PolicyOption setting all PolicyOptions to the provided values
func SetResources ¶
func SetResources(s ...string) PolicyOption
SetResources replaces the option Resources with the provided values
func WithCondition ¶
func WithCondition(co ConditionOptions) PolicyOption
WithCondition adds a Condition to the Conditions option
type PolicyOptions ¶
type PolicyOptions struct {
Name string `json:"name"`
Description string `json:"description"`
Roles []*Role `json:"roles"`
Resources []string `json:"resources"`
Actions []string `json:"actions"`
Scopes []string `json:"scopes"`
Conditions []ConditionOptions `json:"conditions"`
Effect string `json:"effect"`
Context context.Context `json:"-"`
}
PolicyOptions struct allows different Policy implementations to be configured with marshalable data
func NewPolicyOptions ¶
func NewPolicyOptions(opts ...PolicyOption) PolicyOptions
NewPolicyOptions returns PolicyOptions configured with the provided functional options
type Request ¶
type Request struct {
Resource string `json:"resource"`
Action string `json:"action"`
Role string `json:"subject"`
Scope string `json:"scope"`
Context context.Context `json:"-"`
}
Request represents a request to be matched against a policy set
func NewRequest ¶
func NewRequestWithContext ¶ added in v0.1.2
func NewRequestWithContext(ctx context.Context, res, action, role, scope string, meta ...map[string]interface{}) *Request
NewRequestWithContext builds a request from the provided parameters
func (*Request) Metadata ¶
func (r *Request) Metadata() RequestMetadata
Metadata returns metadata stored in context or an empty set
type RequestMetadata ¶
type RequestMetadata map[string]interface{}
RequestMetadata is a helper type to allow type safe retrieval
func RequestMetadataFromContext ¶
func RequestMetadataFromContext(ctx context.Context) RequestMetadata
RequestMetadataFromContext extracts RequestMetadata from a given context or returns an empty metadata set
type RequestMetadataKey ¶
type RequestMetadataKey struct{}
RequestMetadataKey is a type to identify RequestMetadata embedded in context
type Role ¶
type Role struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Roles []*Role `json:"roles"`
}
Role represents a named association to a set of permissionable capability
func (*Role) EffectiveRoles ¶
EffectiveRoles returns a flattened slice of all roles embedded in the Role
type RoleEqualsCondition ¶
type RoleEqualsCondition struct{}
RoleEqualsCondition matches the Request role against the required role passed to the condition
func (*RoleEqualsCondition) Meets ¶
func (c *RoleEqualsCondition) Meets(val interface{}, r *Request) bool
Meets evaluates true when the role val matches Request#Role
func (*RoleEqualsCondition) Name ¶
func (c *RoleEqualsCondition) Name() string
Name fulfills the Name method of Condition
type RoleManager ¶
type RoleManager interface {
Create(*Role) error
Update(*Role) error
Get(string) (*Role, error)
GetByName(string) (*Role, error)
Delete(string) error
All(limit, offset int) ([]*Role, error)
GetMatching(string) ([]*Role, error)
}
RoleManager provides methods to store and retrieve role sets
func NewRoleManager ¶
func NewRoleManager() RoleManager