policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package policy is the deny-by-default access engine. It decides whether a client may call a tool and filters the catalog a client may see.

Rules are explicit allow lists per client. A bare entry ("github__create_issue") allows exactly that tool. A wildcard ("github__*") allows the tools of that downstream, but only those observed at the last explicit Sync: a tool that appears at runtime is denied until a re-sync admits it, so a downstream cannot widen a client's access by exposing a new tool (design §6.5, ADR-0009).

The engine satisfies domain.Decider and domain.CatalogFilter and is safe for concurrent use: rules are immutable after New, and the synced wildcard expansion is guarded by a read-write mutex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine evaluates access decisions and catalog filtering. Its rule set is hot-reloadable: New builds it, Reload atomically swaps it, and every read takes the read lock, so a SIGHUP reload never drops a live evaluation (design §5).

func New

func New(defaultAllow bool, rules []Rule) *Engine

New builds an engine from compiled rules. defaultAllow makes every call allowed (used when the configured default is "allow"); otherwise the engine is deny-by-default and only explicit allows pass. Input is assumed already validated by the config layer.

func (*Engine) Decide

func (e *Engine) Decide(client domain.Identity, t domain.ToolRef) domain.Decision

Decide reports whether the client may call the tool. It reads the rule set under the read lock so a concurrent Reload swap is observed atomically.

func (*Engine) Filter

func (e *Engine) Filter(client domain.Identity, full domain.Catalog) domain.Catalog

Filter returns the subset of the catalog the client is permitted to see. Filtering is security-load-bearing: a tool the client may not call is omitted entirely, including its schema and description (design §8).

func (*Engine) Reload

func (e *Engine) Reload(defaultAllow bool, rules []Rule)

Reload atomically swaps the engine's default and rule set, for a SIGHUP/file- watch config reload (design §5). It clears the wildcard pins computed for the old rules, so a wildcard admits nothing until the caller re-Syncs against the current catalog — a fail-closed transient (deny during reload), never an over-permit. It is safe to call concurrently with Decide and Filter.

func (*Engine) Sync

func (e *Engine) Sync(catalog domain.Catalog)

Sync pins each client's wildcards to the tools present in the catalog. After Sync, a wildcard admits exactly the matching tools observed here; tools that appear later are denied until the next Sync. It holds the write lock across the computation so it reads a consistent rule set even if a Reload runs concurrently.

type Rule

type Rule struct {
	Client string
	Allow  []string
}

Rule is a client's allow list. Each entry is a namespaced tool name ("downstream__tool") or a downstream wildcard ("downstream__*").

Jump to

Keyboard shortcuts

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