Skip to content

Commit

Permalink
internal/eval: remove the inCache
Browse files Browse the repository at this point in the history
We don't currently have a benchmark that's telling us that we need this cache. In fact, several of our benchmarks show that for large, shallow entity graphs, the inCache actually slows down authorizations and batch evaluations because of all the extra allocation that goes on to build the map.

For deep entity graphs, such a cache might be useful, but I think instead that we'll try to put such a cache in the entity graph itself by keeping track of the transitive closure of every entity's parents. That way, the cache will be effective across multiple authorizations.

Signed-off-by: Patrick Jakubowski <[email protected]>
  • Loading branch information
patjakdev committed Oct 1, 2024
1 parent 609f098 commit 163a095
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 121 deletions.
6 changes: 3 additions & 3 deletions authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const (
// IsAuthorized uses the combination of the PolicySet and Entities to determine
// if the given Request to determine Decision and Diagnostic.
func (p PolicySet) IsAuthorized(entityMap Entities, req Request) (Decision, Diagnostic) {
c := eval.InitEnv(&eval.Env{
env := eval.Env{
Entities: entityMap,
Principal: req.Principal,
Action: req.Action,
Resource: req.Resource,
Context: req.Context,
})
}
var diag Diagnostic
var forbids []DiagnosticReason
var permits []DiagnosticReason
Expand All @@ -35,7 +35,7 @@ func (p PolicySet) IsAuthorized(entityMap Entities, req Request) (Decision, Diag
// - For permit, all permits must be run to collect annotations
// - For forbid, forbids must be run to collect annotations
for id, po := range p.policies {
result, err := po.eval.Eval(c)
result, err := po.eval.Eval(env)
if err != nil {
diag.Errors = append(diag.Errors, DiagnosticError{PolicyID: id, Position: po.Position(), Message: err.Error()})
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BoolEvaler struct {
eval Evaler
}

func (e *BoolEvaler) Eval(env *Env) (types.Boolean, error) {
func (e *BoolEvaler) Eval(env Env) (types.Boolean, error) {
v, err := e.eval.Eval(env)
if err != nil {
return false, err
Expand Down
Loading

0 comments on commit 163a095

Please sign in to comment.