rules

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package rules loads and validates the postura policy ruleset. Rules are data: each rule carries CEL expressions that are evaluated against collected facts by the engine package. Nothing here touches GitHub or makes decisions on its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enterprises map[string]map[string]map[string]any `yaml:"enterprises"`
	Orgs        map[string]map[string]map[string]any `yaml:"orgs"`
	Repos       map[string]map[string]map[string]any `yaml:"repos"`
}

Config holds per-target rule overrides, layered most-specific-wins on top of each rule's built-in defaults:

rule.Config  ->  enterprises[slug]  ->  orgs[name]  ->  repos[owner/repo]

Each override block is keyed by rule id. Within a block the reserved keys `enabled` (bool) and `severity` (string) tune the rule itself; every other key is merged into the rule's `cfg` map available to its CEL expressions.

func LoadConfig

func LoadConfig(data []byte) (*Config, error)

LoadConfig parses a policy-config YAML file. An empty/nil input yields a zero Config (defaults only), which is valid.

func (*Config) Resolve

func (c *Config) Resolve(r Rule, enterprise, org, repo string) Resolved

Resolve computes the effective settings for rule r against a target located at (enterprise, org, repo). Empty location components are skipped. The most specific override present wins for each individual key.

type Resolved

type Resolved struct {
	Enabled  bool
	Severity string
	Cfg      map[string]any
}

Resolved is a rule's effective settings for one specific target.

type Rule

type Rule struct {
	ID       string         `yaml:"id"`
	Scope    Scope          `yaml:"scope"`
	Severity string         `yaml:"severity"`
	Title    string         `yaml:"title"`
	Pass     string         `yaml:"pass"`         // true => compliant
	Applies  string         `yaml:"applies_when"` // optional: false => skip (no row)
	Config   map[string]any `yaml:"config"`       // default knobs, overridable per target
	Enabled  *bool          `yaml:"enabled"`      // baseline on/off; nil => on. Config can override per target.
	FixHint  string         `yaml:"fix_hint"`
}

Rule is one policy check. The CEL expressions all evaluate to bool and read fact fields as top-level variables plus `cfg` (the rule's merged config).

type Ruleset

type Ruleset struct {
	Rules []Rule `yaml:"rules"`
}

Ruleset is the full ordered list of rules.

func Load

func Load(data []byte) (*Ruleset, error)

Load parses a ruleset from YAML and validates it structurally. CEL compilation happens in the engine, against a scope-specific environment.

func (*Ruleset) ByScope

func (rs *Ruleset) ByScope(s Scope) []Rule

ByScope returns the rules for one scope, in manifest order.

type Scope

type Scope string

Scope identifies which facts object a rule runs against.

const (
	ScopeEnterprise Scope = "enterprise"
	ScopeOrg        Scope = "org"
	ScopeRepo       Scope = "repo"
)

Jump to

Keyboard shortcuts

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