opa

package
v0.0.0-...-e308f56 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package opa provides OPA-based HTTP request authorization middleware.

Index

Constants

View Source
const DefaultPolicy = `` /* 145-byte string literal not displayed */

DefaultPolicy allows all requests from localhost and restricts remote access to non-admin paths.

Variables

This section is empty.

Functions

func Middleware

func Middleware(ctx context.Context, cfg Config, next http.Handler) (http.Handler, error)

Middleware returns an http.Handler that evaluates OPA policy before delegating to next. The policy must define a boolean "allow" rule under package cachew.authz. If allow is true the request proceeds; otherwise it is rejected with 403.

Types

type Config

type Config struct {
	Policy     string `hcl:"policy,optional" help:"Inline Rego policy."`
	PolicyFile string `hcl:"policy-file,optional" help:"Path to a Rego policy file."`
	Data       string `hcl:"data,optional" help:"Inline JSON object loaded as OPA data.*"`
	DataFile   string `hcl:"data-file,optional" help:"Path to a JSON file loaded as OPA data.*"`
}

Config for OPA policy evaluation. If neither Policy nor PolicyFile is set, a default policy allowing only GET and HEAD requests is used.

Jump to

Keyboard shortcuts

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