rules

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package rules provides a CEL-based security rules engine for MongoRPC.

Package rules provides middleware for rules enforcement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RulesInterceptor

func RulesInterceptor(engine *Engine) grpc.UnaryServerInterceptor

RulesInterceptor creates a gRPC interceptor that enforces security rules.

func StreamRulesInterceptor

func StreamRulesInterceptor(engine *Engine) grpc.StreamServerInterceptor

StreamRulesInterceptor creates a streaming interceptor for rules enforcement.

Types

type Config

type Config struct {
	Rules []RuleConfig `json:"rules" yaml:"rules"`
}

Config represents rules configuration.

type Engine

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

Engine is the rules evaluation engine.

func LoadFromFile

func LoadFromFile(path string) (*Engine, error)

LoadFromFile loads rules from a YAML file.

func NewEngine

func NewEngine() (*Engine, error)

NewEngine creates a new rules engine.

func (*Engine) AddRule

func (e *Engine) AddRule(path, operation, expression string) error

AddRule adds a rule to the engine.

func (*Engine) Evaluate

func (e *Engine) Evaluate(ctx context.Context, req *Request) (bool, error)

Evaluate evaluates rules for a request.

func (*Engine) LoadConfig

func (e *Engine) LoadConfig(config *Config) error

LoadConfig loads rules from a configuration.

func (*Engine) SetDefaultAllow

func (e *Engine) SetDefaultAllow(op Operation, allow bool)

SetDefaultAllow sets the default allow/deny for an operation.

type Operation

type Operation string

Operation represents the type of database operation.

const (
	OpRead   Operation = "read"
	OpWrite  Operation = "write"
	OpCreate Operation = "create"
	OpUpdate Operation = "update"
	OpDelete Operation = "delete"
	OpList   Operation = "list"
)

type Request

type Request struct {
	// Auth information
	UserID    string
	UserEmail string
	IsAdmin   bool
	Claims    map[string]interface{}

	// Resource information
	Database   string
	Collection string
	DocumentID string

	// Operation
	Operation Operation

	// Document data (for write operations)
	IncomingData map[string]interface{}
	ExistingData map[string]interface{}
}

Request represents a request context for rule evaluation.

type Rule

type Rule struct {
	// Path pattern (e.g., "databases/{database}/collections/{collection}")
	Path string
	// CEL expression for the rule
	Allow string
}

Rule represents a security rule.

type RuleConfig

type RuleConfig struct {
	Path      string `json:"path" yaml:"path"`
	Operation string `json:"operation" yaml:"operation"`
	Allow     string `json:"allow" yaml:"allow"`
}

RuleConfig represents a single rule configuration.

Jump to

Keyboard shortcuts

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