rules

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package rules implements Interseptor's rule-pack format: a signed-intent tarball of Starlark checks (passive and active) plus a manifest, so a community can author, share, install, and remove whole bundles of checks — the "OhMy" ecosystem layer over the per-check authoring API.

A pack is a .tar.gz containing:

manifest.json              — name, version, author, entries[] with per-file sha256
checks/<id>.star           — passive checks
active-checks/<id>.star    — active checks

Integrity: every file's sha256 is recorded in the manifest at build time and verified on read, so a corrupted or tampered pack is rejected before any check is written to disk. (Detached minisign/ed25519 signing is the next layer; the manifest+sha256 gate is the foundation it rides on.)

Index

Constants

View Source
const (
	KindPassive = "passive"
	KindActive  = "active"
)

KindPassive / KindActive are the two check categories a pack can carry.

Variables

This section is empty.

Functions

func ReadPack

func ReadPack(r io.Reader) (Manifest, []File, error)

ReadPack decodes a pack tarball from r, parses its manifest, and verifies that every check file's sha256 matches the manifest. A missing manifest, an unknown member, or any hash mismatch is an error — nothing is returned partial.

Types

type CatalogPack

type CatalogPack struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`
	Author      string `json:"author"`
	Checks      int    `json:"checks"`
}

CatalogPack describes a bundled pack available for one-click install.

func ListCatalog

func ListCatalog() ([]CatalogPack, error)

ListCatalog returns bundled packs (sorted by name) with check counts.

type Entry

type Entry struct {
	Kind   string `json:"kind"`
	ID     string `json:"id"`
	SHA256 string `json:"sha256"`
}

Entry is one check in a pack manifest: its category, id, and the sha256 of the file bytes — verified before install so a tampered file aborts the pack.

type File

type File struct {
	Kind string
	ID   string
	Data []byte
}

File is one decoded check from a pack: its category, id, and source bytes.

type InstallRecord

type InstallRecord struct {
	Name      string   `json:"name"`
	Version   string   `json:"version"`
	Installed string   `json:"installed"`
	Source    string   `json:"source,omitempty"`
	IDs       []string `json:"ids"`
}

InstallRecord is one pack the operator has installed: its manifest identity plus the check ids it owns (so `rules remove` can delete exactly those files).

type Manifest

type Manifest struct {
	Name        string  `json:"name"`
	Version     string  `json:"version"`
	Description string  `json:"description,omitempty"`
	Author      string  `json:"author,omitempty"`
	Homepage    string  `json:"homepage,omitempty"`
	License     string  `json:"license,omitempty"`
	Created     string  `json:"created,omitempty"`
	Entries     []Entry `json:"entries"`
}

Manifest is the pack's front matter plus its file index.

func BuildCatalogPack

func BuildCatalogPack(name string, w *bytes.Buffer) (Manifest, error)

BuildCatalogPack writes a verified pack tarball for the named catalog entry into w. Sources are embedded; install uses the same sha256 gate as community packs.

func BuildPack

func BuildPack(srcDir string, meta Manifest, w io.Writer) (Manifest, error)

BuildPack writes a pack tarball to w from the checks found under srcDir (expected layout: srcDir/checks/*.star and srcDir/active-checks/*.star). The supplied meta fills the manifest's descriptive fields; entries + hashes are computed from the files. Files are written in a stable (sorted) order so two builds of the same source are byte-identical.

type Registry

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

Registry tracks installed packs in <root>/packs/registry.json. It is the source of truth for `rules list` / `rules remove` and for the REST/MCP pack surfaces. Filesystem layout for installed checks: passive → <root>/checks, active → <root>/active-checks (same dirs the engines already read), so an installed pack's checks run immediately with everything else.

func NewRegistry

func NewRegistry(root string) *Registry

NewRegistry opens (or creates) the pack registry rooted at root (the global interseptor data dir, e.g. ~/.interseptor).

func (*Registry) Get

func (r *Registry) Get(name string) (InstallRecord, bool, error)

Get returns one installed pack by name.

func (*Registry) InstallFile

func (r *Registry) InstallFile(path, checksDir, activeChecksDir string) (Manifest, int, error)

InstallFile installs a pack from a local .tar.gz path.

func (*Registry) InstallStream

func (r *Registry) InstallStream(rdr readSeekFree, checksDir, activeChecksDir, source string) (Manifest, int, error)

InstallStream reads a pack from r, verifies it, writes its checks to disk, and records it in the registry. source is stored for provenance (e.g. a URL).

func (*Registry) List

func (r *Registry) List() ([]InstallRecord, error)

List returns installed packs, sorted by name.

func (*Registry) Remove

func (r *Registry) Remove(name, checksDir, activeChecksDir string) (int, error)

Remove deletes a pack's check files and drops its registry entry. Files a user hand-edited are left in place (an entry only owns ids it recorded).

Jump to

Keyboard shortcuts

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