Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reference utils rego relative to policy lib #3

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
"strings"

"github.com/open-policy-agent/opa/storage"
"github.com/open-policy-agent/opa/storage/inmem"
"strings"

"github.com/PaloAltoNetworks/rbac-police/pkg/collect"
"github.com/PaloAltoNetworks/rbac-police/pkg/utils"
Expand All @@ -25,12 +27,16 @@ var (
"ignore": {},
"utils": {},
}
severityMap = map[string]int{"Low": 1, "Medium": 2, "High": 3, "Critical": 4, "": 5}
builtinsLibPath = "lib/utils/builtins.rego" // TODO: move out of eval.go / make configurable / go-bindata
severityMap = map[string]int{"Low": 1, "Medium": 2, "High": 3, "Critical": 4, "": 5}
builtinsLibPath string
builtinsLibSuffix = "utils/builtins.rego" // TODO: move out of eval.go / make configurable / go-bindata
)

// Evaluates RBAC permissions using Rego policies
func Eval(policyPath string, collectResult collect.CollectResult, evalConfig EvalConfig) *PolicyResults {
builtinsLibPath = filepath.Join(policyPath, builtinsLibSuffix)
wrapperFilePath = filepath.Join(policyPath, wrapperFileSuffix)

// Set debug mode
if evalConfig.DebugMode {
log.SetLevel(log.DebugLevel)
Expand Down Expand Up @@ -196,7 +202,7 @@ func evaluatePolicy(policyFile string, input interface{}, policyConfig string, e

// Wrap policy if needed
if policyNeedsWrapping(policy) {
regoFiles = append([]string{wrapperFile}, regoFiles...)
regoFiles = append([]string{wrapperFilePath}, regoFiles...)
queryStr = "data.wrapper.main[_]"
} else {
queryStr = "data.policy.main[_]"
Expand Down
5 changes: 3 additions & 2 deletions pkg/eval/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
)

const (
wrapperFile = "lib/utils/wrapper.rego" // TODO: move elsewhere / make configurable / go-bindata
wrapperFileSuffix = "utils/wrapper.rego" // TODO: move elsewhere / make configurable / go-bindata
)

var (
wrappedPattern = `(?m)^\s*main\s*\[\s*\{.*\}\s*\].*$`
wrapperFilePath string
wrappedPattern = `(?m)^\s*main\s*\[\s*\{.*\}\s*\].*$`
)

// Checks if policy needs wrapping (doesn't define main rule)
Expand Down
Loading