netpolicy

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileEgressRuleset

func CompileEgressRuleset(policy model.NetPolicy, resolve NodeResolver, opts CompileOptions) (string, error)

CompileEgressRuleset renders a per-node egress policy into a deterministic nftables batch. It intentionally owns a separate lattice_policy table so this first committed path cannot conflict with the existing lattice_guard input table used by baseline node firewall inputs.

func CompileIngressInputRules

func CompileIngressInputRules(policy model.NetPolicy, resolve NodeResolver) ([]network.NFTInputRule, error)

CompileIngressInputRules extracts the ingress side of a per-node NetPolicy into typed lattice_guard input rules. It intentionally does not render nft syntax directly: the Network Guard renderer owns the single input chain so DNS/proxy/ACL providers cannot create competing default-drop hooks.

func ExpandGroupPolicies

func ExpandGroupPolicies(policies []model.GroupNetPolicy, resolved map[string][]string) map[string]model.NetPolicy

ExpandGroupPolicies materializes group-scoped policies into one per-node model.NetPolicy per node covered by any policy's scope group. A rule whose remote is a group (NetRefGroup) fans out to one node-ref rule per resolved remote member, so the UNCHANGED per-node compiler never sees a group ref.

Policies apply in (Priority, ID) order; within a policy, rule order is preserved. resolved maps a group ID to its resolved member node IDs (as produced by internal/groups.ResolveAll).

The returned policies are tagged GroupDerived=true and keyed by target node ID. Because they contain CONCRETE node refs, the compiled plan SHA changes whenever membership changes — closing the plan-staleness gap by construction (a node joining/leaving a remote group changes the rule set, hence the SHA).

func NormalizePolicy

func NormalizePolicy(policy model.NetPolicy, resolve NodeResolver) (model.NetPolicy, error)

Types

type CompileOptions

type CompileOptions struct {
	ControlPlaneIPv4 netip.Addr
	ControlPlaneIPv6 netip.Addr
	ControlPlaneHost string
	ControlPlanePort int
}

type DomainSet

type DomainSet struct {
	Host string `json:"host"`
	Set4 string `json:"set4"`
	Set6 string `json:"set6"`
}

type EgressPlan

type EgressPlan struct {
	Ruleset    string      `json:"ruleset"`
	DomainSets []DomainSet `json:"domain_sets,omitempty"`
}

func CompileEgressPlan

func CompileEgressPlan(policy model.NetPolicy, resolve NodeResolver, opts CompileOptions) (EgressPlan, error)

CompileEgressPlan returns the nftables batch plus the domain-backed named sets that must be populated on the node before the selfcheck runs.

type Graph

type Graph struct {
	Nodes     []GraphNode     `json:"nodes"`
	Edges     []GraphEdge     `json:"edges"`
	Externals []GraphExternal `json:"externals"`
}

func BuildGraph

func BuildGraph(nodes []model.Node, policies []model.NetPolicy) Graph

type GraphEdge

type GraphEdge struct {
	From      string `json:"from"`
	To        string `json:"to"`
	Action    string `json:"action"`
	Protocol  string `json:"protocol"`
	Ports     []int  `json:"ports,omitempty"`
	Direction string `json:"direction"`
	RuleID    string `json:"rule_id"`
}

type GraphExternal

type GraphExternal struct {
	TargetNodeID string `json:"target_node_id"`
	Action       string `json:"action"`
	Remote       string `json:"remote"`
	Protocol     string `json:"protocol"`
	Ports        []int  `json:"ports,omitempty"`
	Direction    string `json:"direction"`
	RuleID       string `json:"rule_id"`
}

type GraphNode

type GraphNode struct {
	ID     string         `json:"id"`
	Name   string         `json:"name"`
	Online bool           `json:"online"`
	Geo    *model.NodeGeo `json:"geo,omitempty"`
}

type NodeResolver

type NodeResolver func(id string) (model.Node, bool)

Jump to

Keyboard shortcuts

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