Documentation
¶
Overview ¶
Package policy provides VORTEX's authorization policy engine (build plan M3.4): it embeds the Open Policy Agent (OPA) Rego evaluator so operators can express request-authorization rules as .rego policies, hot-reloaded without a restart. When no policy is supplied the engine falls back to a built-in allow-all policy, so policy enforcement is opt-in and never blocks a fresh install.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
NewMiddleware returns an HTTP middleware that evaluates engine's policy on every request. On allow it calls the next handler; on deny it returns 403; on an evaluation error it returns 500. Both error responses carry a JSON body.
func RouteNameFromContext ¶
RouteNameFromContext returns the route name stored by SetRouteName, or "" if none was set.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine evaluates Rego authorization policies. It is safe for concurrent use: Eval takes a read lock and Reload swaps the compiled query under a write lock, so evaluations never observe a half-built policy.
func NewEngine ¶
func NewEngine(cfg EngineConfig) (*Engine, error)
NewEngine builds an Engine, loading every .rego file under cfg.PolicyDir (and any JSON data under cfg.DataDir). If no policy files are found it compiles the built-in allow-all policy. A policy that fails to compile is a fatal error.
func (*Engine) DefaultPolicy ¶
DefaultPolicy returns the built-in allow-all policy text, useful for scaffolding a starter policy file.
func (*Engine) Eval ¶
Eval evaluates the policy query against input and reports whether the request is allowed. The decision is truthy: an explicit boolean true (or any non-false defined result) allows; false or an undefined/empty result denies. It returns an error only when evaluation itself fails, and never panics.
func (*Engine) Reload ¶
Reload re-reads the policy directory and recompiles. On success it atomically swaps in the new query; on failure it returns the error and leaves the previously-compiled policy in place, so a bad edit cannot take down enforcement.
func (*Engine) UsingDefault ¶
UsingDefault reports whether the built-in allow-all policy is currently in effect (i.e. no operator .rego files were loaded).
type EngineConfig ¶
type EngineConfig struct {
PolicyDir string // directory of .rego files; empty → built-in allow-all
DataDir string // optional directory of JSON data files
QueryPath string // query to evaluate; default "data.vortex.allow"
}
EngineConfig configures an Engine.