model

package
v1.10.14 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultSep = ","

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	Key             string
	Value           string
	Tokens          []string
	ParamsTokens    []string
	Policy          [][]string
	PolicyMap       map[string]int
	RM              rbac.RoleManager
	CondRM          rbac.ConditionalRoleManager
	FieldIndexMap   map[string]int
	FieldIndexMutex sync.RWMutex
}

Assertion represents an expression in a section of the model. For example: r = sub, obj, act.

type AssertionMap

type AssertionMap map[string]*Assertion

AssertionMap is the collection of assertions, can be "r", "p", "g", "e", "m".

type Constraint added in v1.10.2

type Constraint struct {
	Key        string
	Type       ConstraintType
	Roles      []string
	Role       string
	MaxCount   int
	PreReqRole string
}

Constraint represents a policy constraint.

type ConstraintType added in v1.10.2

type ConstraintType int

ConstraintType represents the type of constraint.

const (
	ConstraintTypeSOD ConstraintType = iota
	ConstraintTypeSODMax
	ConstraintTypeRoleMax
	ConstraintTypeRolePre
)

type FunctionMap

type FunctionMap struct {
	// contains filtered or unexported fields
}

FunctionMap represents the collection of Function.

func LoadFunctionMap

func LoadFunctionMap() FunctionMap

LoadFunctionMap loads an initial function map.

func (*FunctionMap) AddFunction

func (fm *FunctionMap) AddFunction(name string, function govaluate.ExpressionFunction)

AddFunction adds an expression function.

func (*FunctionMap) GetFunctions added in v1.10.0

func (fm *FunctionMap) GetFunctions() map[string]govaluate.ExpressionFunction

GetFunctions return a map with all the functions.

type Model

type Model map[string]AssertionMap

Model represents the whole access control model.

func NewModel added in v1.10.0

func NewModel() Model

NewModel creates an empty model.

func NewModelFromFile added in v1.10.0

func NewModelFromFile(path string) (Model, error)

NewModelFromFile creates a model from a .CONF file.

func NewModelFromString added in v1.10.0

func NewModelFromString(text string) (Model, error)

NewModelFromString creates a model from a string which contains model text.

func (Model) AddDef added in v0.8.0

func (model Model) AddDef(sec string, key string, value string) bool

AddDef adds an assertion to the model.

func (Model) AddPolicies added in v1.10.0

func (model Model) AddPolicies(sec string, ptype string, rules [][]string) error

AddPolicies adds policy rules to the model.

func (Model) AddPoliciesWithAffected added in v1.10.0

func (model Model) AddPoliciesWithAffected(sec string, ptype string, rules [][]string) ([][]string, error)

AddPoliciesWithAffected adds policy rules to the model, and returns affected rules.

func (Model) AddPolicy

func (model Model) AddPolicy(sec string, ptype string, rule []string) error

AddPolicy adds a policy rule to the model.

func (model Model) BuildConditionalRoleLinks(condRmMap map[string]rbac.ConditionalRoleManager) error

BuildConditionalRoleLinks initializes the roles in RBAC.

func (model Model) BuildIncrementalConditionalRoleLinks(condRmMap map[string]rbac.ConditionalRoleManager, op PolicyOp, sec string, ptype string, rules [][]string) error

BuildIncrementalConditionalRoleLinks provides incremental build the role inheritance relations.

func (model Model) BuildIncrementalRoleLinks(rmMap map[string]rbac.RoleManager, op PolicyOp, sec string, ptype string, rules [][]string) error

BuildIncrementalRoleLinks provides incremental build the role inheritance relations.

func (model Model) BuildRoleLinks(rmMap map[string]rbac.RoleManager) error

BuildRoleLinks initializes the roles in RBAC.

func (Model) ClearPolicy

func (model Model) ClearPolicy()

ClearPolicy clears all current policy.

func (Model) Copy added in v1.10.0

func (model Model) Copy() Model

func (Model) GetAssertion added in v1.10.2

func (model Model) GetAssertion(sec string, ptype string) (*Assertion, error)

func (Model) GetFieldIndex added in v1.10.0

func (model Model) GetFieldIndex(ptype string, field string) (int, error)

func (Model) GetFilteredPolicy

func (model Model) GetFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) ([][]string, error)

GetFilteredPolicy gets rules based on field filters from a policy.

func (Model) GetPolicy

func (model Model) GetPolicy(sec string, ptype string) ([][]string, error)

GetPolicy gets all rules in a policy.

func (Model) GetValuesForFieldInPolicy

func (model Model) GetValuesForFieldInPolicy(sec string, ptype string, fieldIndex int) ([]string, error)

GetValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.

func (Model) GetValuesForFieldInPolicyAllTypes added in v1.10.0

func (model Model) GetValuesForFieldInPolicyAllTypes(sec string, fieldIndex int) ([]string, error)

GetValuesForFieldInPolicyAllTypes gets all values for a field for all rules in a policy of all ptypes, duplicated values are removed.

func (Model) GetValuesForFieldInPolicyAllTypesByName added in v1.10.2

func (model Model) GetValuesForFieldInPolicyAllTypesByName(sec string, field string) ([]string, error)

GetValuesForFieldInPolicyAllTypesByName gets all values for a field for all rules in a policy of all ptypes, duplicated values are removed.

func (Model) HasPolicies added in v1.10.0

func (model Model) HasPolicies(sec string, ptype string, rules [][]string) (bool, error)

HasPolicies determines whether a model has any of the specified policies. If one is found we return true.

func (Model) HasPolicy

func (model Model) HasPolicy(sec string, ptype string, rule []string) (bool, error)

HasPolicy determines whether a model has the specified policy rule.

func (Model) HasPolicyEx added in v1.10.0

func (model Model) HasPolicyEx(sec string, ptype string, rule []string) (bool, error)

HasPolicyEx determines whether a model has the specified policy rule with error.

func (Model) LoadModel added in v0.9.0

func (model Model) LoadModel(path string) error

LoadModel loads the model from model CONF file.

func (Model) LoadModelFromText added in v0.9.0

func (model Model) LoadModelFromText(text string) error

LoadModelFromText loads the model from the text.

func (Model) PrintModel

func (model Model) PrintModel()

PrintModel prints the model to the log.

func (Model) PrintPolicy

func (model Model) PrintPolicy()

PrintPolicy prints the policy to log.

func (Model) RemoveFilteredPolicy

func (model Model) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) (bool, [][]string, error)

RemoveFilteredPolicy removes policy rules based on field filters from the model.

func (Model) RemovePolicies added in v1.10.0

func (model Model) RemovePolicies(sec string, ptype string, rules [][]string) (bool, error)

RemovePolicies removes policy rules from the model.

func (Model) RemovePoliciesWithAffected added in v1.10.0

func (model Model) RemovePoliciesWithAffected(sec string, ptype string, rules [][]string) ([][]string, error)

RemovePoliciesWithAffected removes policy rules from the model, and returns affected rules.

func (Model) RemovePolicy

func (model Model) RemovePolicy(sec string, ptype string, rule []string) (bool, error)

RemovePolicy removes a policy rule from the model. Deprecated: Using AddPoliciesWithAffected instead.

func (Model) SortPoliciesByPriority added in v1.10.0

func (model Model) SortPoliciesByPriority() error

func (Model) SortPoliciesBySubjectHierarchy added in v1.10.0

func (model Model) SortPoliciesBySubjectHierarchy() error

func (Model) ToText added in v1.10.0

func (model Model) ToText() string

func (Model) UpdatePolicies added in v1.10.0

func (model Model) UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) (bool, error)

UpdatePolicies updates a policy rule from the model.

func (Model) UpdatePolicy added in v1.10.0

func (model Model) UpdatePolicy(sec string, ptype string, oldRule []string, newRule []string) (bool, error)

UpdatePolicy updates a policy rule from the model.

func (Model) ValidateConstraints added in v1.10.2

func (model Model) ValidateConstraints() error

ValidateConstraints validates all constraints against the current policy.

type PolicyOp added in v1.10.0

type PolicyOp int
const (
	PolicyAdd PolicyOp = iota
	PolicyRemove
)

Jump to

Keyboard shortcuts

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