Documentation
¶
Overview ¶
Package policy implements network policy enforcement for plexd mesh nodes.
Index ¶
- Constants
- Variables
- func DispatchHandler(enforcer *Enforcer, iface string) reconcile.DispatchHandler
- func HandlePolicyUpdated(trigger ReconcileTrigger) api.EventHandler
- type Config
- type ConnDir
- type ConnEvent
- type ConnLogger
- func (c *ConnLogger) Event(ev ConnEvent)
- func (c *ConnLogger) ForwardTo(fn func(ts time.Time, severity, message string))
- func (c *ConnLogger) Lost(n int)
- func (c *ConnLogger) Revert()
- func (c *ConnLogger) Run(ctx context.Context)
- func (c *ConnLogger) SetRuleset(revisionID string, rules []FirewallRule)
- type ConnReporter
- type ConnSink
- type DropCounter
- type Enforcer
- func (e *Enforcer) AdmitsTCPDial(src netip.Addr, dst netip.AddrPort) (admitted, enforced bool)
- func (e *Enforcer) ApplyFirewallRules(policy *api.PolicySnapshot, iface string) (bool, error)
- func (e *Enforcer) Changed() <-chan struct{}
- func (e *Enforcer) ConnLogger() *ConnLogger
- func (e *Enforcer) DropCounts() (packets, bytes uint64, ok bool)
- func (e *Enforcer) Preflight() error
- func (e *Enforcer) Status() Status
- func (e *Enforcer) Sync(desired *api.PolicySnapshot, iface string)
- func (e *Enforcer) Teardown() error
- type FirewallController
- type FirewallRule
- type NftablesController
- func (c *NftablesController) ApplyRules(chain string, rules []FirewallRule) error
- func (c *NftablesController) DeleteChain(chain string) error
- func (c *NftablesController) DropCounts(chain string) (packets, bytes uint64, err error)
- func (c *NftablesController) EnsureChain(chain string) error
- func (c *NftablesController) FlushChain(chain string) error
- func (c *NftablesController) Probe() error
- func (c *NftablesController) SetConnSink(sink ConnSink)
- type PolicyEngine
- type ReconcileTrigger
- type Status
- type StatusClient
- type StatusReporter
Constants ¶
const DefaultChainName = "plexd-mesh"
DefaultChainName is the default iptables chain name for policy enforcement.
const RelayProbePort = 9
RelayProbePort is the UDP port of plexd's relay liveness probe (relayProbePort in internal/wireguard/dial.go).
DECISION: every backend lets the node send UDP to this port over the mesh interface without a rule, ahead of the policy rules (author, 2026-11-12, #178). Any local process can do so, to any address the mesh routes, and the receiving node's inbound rules still apply. Without the exemption a narrow policy fails every probe send, and plexd notices a dead relay only once the handshake goes stale.
Variables ¶
var ErrInvalidRuleset = errors.New("policy: invalid ruleset")
ErrInvalidRuleset marks a policy revision the engine cannot translate into firewall rules. It is a permanent property of the revision's rules, not a transient backend failure: retrying the identical revision can never succeed, so callers must not hold state back waiting for it to clear.
Functions ¶
func DispatchHandler ¶ added in v0.31.0
func DispatchHandler(enforcer *Enforcer, iface string) reconcile.DispatchHandler
DispatchHandler returns a reconcile.DispatchHandler that hands the policy block of every successful pull to enforcer.Sync, which applies it when it is not the installed ruleset and records the outcome for the policy status report and the node API.
DECISION: the apply runs on the dispatch seam, on every pull, rather than as a reconcile handler behind the differ's PolicyChanged. A reconcile handler could not retry a rejected revision: the differ stores the pulled block once the cycle completes and never offers its fingerprint again, and returning the error instead would hold back every other block of the snapshot. On this seam a failed apply never holds anything back, and Sync compares the pull with what is installed itself, so a rejected block is applied again on the next pull and a pull with policy: null can be recorded as applied over the startup baseline. The differ still reports policy drift in the cycle log.
func HandlePolicyUpdated ¶
func HandlePolicyUpdated(trigger ReconcileTrigger) api.EventHandler
HandlePolicyUpdated returns an api.EventHandler that triggers reconciliation when a policy_updated SSE event is received.
Types ¶
type Config ¶
type Config struct {
// Enabled controls whether policy enforcement is active. A pointer, so an
// unset key stays distinguishable from an explicit false: enforcement is the
// deny-by-default posture and its absence is fatal at startup, so
// `enabled: false` is the operator's only way to run a node without it and
// must survive ApplyDefaults exactly as written.
// Default: true (nil reads as enabled).
Enabled *bool `yaml:"enabled"`
// ChainName is the iptables chain name for firewall rules.
// Default: plexd-mesh.
ChainName string `yaml:"chain_name"`
}
Config holds the configuration for network policy enforcement.
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults sets default values for zero-valued fields. Enabled is left untouched — nil already means enabled, and writing a value into it would erase the difference between an omitted key and an operator's `false`.
type ConnDir ¶ added in v0.30.0
type ConnDir int
ConnDir is the direction of a connection a logged rule admitted, as the node sees it.
type ConnEvent ¶ added in v0.30.0
type ConnEvent struct {
Tag string
Dir ConnDir
Src, Dst netip.Addr
Protocol uint8
SrcPort, DstPort uint16
}
ConnEvent is one connection a logged rule admitted, as a backend's kernel reported it. SrcPort and DstPort are 0 unless Protocol is TCP or UDP.
type ConnLogger ¶ added in v0.30.0
type ConnLogger struct {
// contains filtered or unexported fields
}
ConnLogger turns what the backends' readers report into one line in plexd's own log per connection a logged rule admitted. It knows the tags of the ruleset the Enforcer applied last and of the one before, so an event the kernel produced just before or after an apply still finds its rule. It bounds the rate of its lines with a token bucket and reports what it dropped once a minute.
All methods are safe for concurrent use.
func NewConnLogger ¶ added in v0.30.0
func NewConnLogger(logger *slog.Logger) *ConnLogger
NewConnLogger returns a ConnLogger that writes to logger.
func (*ConnLogger) Event ¶ added in v0.30.0
func (c *ConnLogger) Event(ev ConnEvent)
Event logs the connection ev reports, when its tag names a rule of the current or the previous ruleset, the rule admits it, and the rate allows it. It implements ConnSink.
func (*ConnLogger) ForwardTo ¶ added in v0.30.0
func (c *ConnLogger) ForwardTo(fn func(ts time.Time, severity, message string))
ForwardTo makes every line and every summary also go to fn, with severity info or warning and the record as plexd's text handler renders it. A nil fn stops forwarding.
func (*ConnLogger) Lost ¶ added in v0.30.0
func (c *ConnLogger) Lost(n int)
Lost counts n records a reader knows it missed. It implements ConnSink.
func (*ConnLogger) Revert ¶ added in v0.30.0
func (c *ConnLogger) Revert()
Revert undoes the last SetRuleset after its apply failed: the previous ruleset, the one still in the kernel, becomes current again. It does nothing when there is no previous ruleset.
func (*ConnLogger) Run ¶ added in v0.30.0
func (c *ConnLogger) Run(ctx context.Context)
Run logs, once a minute, how many lines the rate limit dropped and how many records the readers lost since the last summary, when either is above 0. It returns when ctx ends.
func (*ConnLogger) SetRuleset ¶ added in v0.30.0
func (c *ConnLogger) SetRuleset(revisionID string, rules []FirewallRule)
SetRuleset records the tagged rules of a ruleset about to be applied for revisionID. The rules it held become the previous ruleset, and the ones before that are forgotten. A tag is "<generation>/<index>", and a rule whose tag carries no index after the slash is ignored.
type ConnReporter ¶ added in v0.30.0
type ConnReporter interface {
SetConnSink(sink ConnSink)
}
ConnReporter is implemented by a FirewallController that can report the connections its logged rules admit.
type ConnSink ¶ added in v0.30.0
ConnSink receives what a backend's reader produces. Lost counts records the reader knows it missed.
type DropCounter ¶ added in v0.31.0
DropCounter is implemented by a FirewallController that counts what the deny rules of a chain dropped since the chain was last loaded. The engine's only deny is the default deny, so the count is what the default deny dropped. The Enforcer reports it to the control plane; a backend without it reports no drops.
type Enforcer ¶
type Enforcer struct {
// contains filtered or unexported fields
}
Enforcer combines a PolicyEngine with a FirewallController to enforce network policies on the local node.
func NewEnforcer ¶
func NewEnforcer(engine *PolicyEngine, firewall FirewallController, cfg Config, logger *slog.Logger) *Enforcer
NewEnforcer creates an Enforcer. The firewall parameter may be nil if no firewall backend is available; in that case ApplyFirewallRules is a no-op. When the firewall can report the connections its logged rules admit, its reports go to the Enforcer's ConnLogger.
func (*Enforcer) AdmitsTCPDial ¶ added in v0.35.0
AdmitsTCPDial reports whether the ruleset the backend holds lets a socket of the node send TCP from src, the node's mesh address, to dst. enforced is false, and admitted true, while enforcement is disabled, no backend exists, no ruleset is installed, or the Enforcer is closed.
It enforces nothing: the kernel does, and a caller uses the answer only to name why a dial it already made failed. A ruleset admits the dial when one of its allow rules matches the dial's addresses, protocol and destination port, as FirewallRule.admits matches a connection event; the default deny alone, which the startup baseline and a pull with policy: null install, admits nothing.
func (*Enforcer) ApplyFirewallRules ¶
ApplyFirewallRules builds firewall rules from the merged policy and applies them via the FirewallController. A nil policy yields a default-deny-only ruleset — deny-by-default is plexd's documented posture.
The bool reports whether the ruleset actually reached the kernel. Enforcement being disabled and the absence of a firewall backend are no-ops that return (false, nil), so callers cannot mistake either for a successful apply and claim an enforcement that never happened.
A ruleset the engine refuses to translate is reported as ErrInvalidRuleset so callers can tell a permanently broken revision from a transient netlink failure.
Every rule with log: true gets the tag "<generation>/<index>", the index being the rule's position in the policy's rules. The ConnLogger learns the tags before the firewall does, so an event the kernel produces right after the apply finds its rule, and forgets them again when the apply fails, so repeated failures never push the installed ruleset's tags out of it.
DECISION: the logged rules go ahead of the unlogged ones, each group in the order given, and the default deny stays last. Every rule is an allow and order carries no verdict, so the move changes nothing that passes or drops. It makes every backend's first match a logged rule whenever one allows the connection, so a narrow logged rule still logs behind a Project's allow-all policy. A connection is named after the first logged rule in revision order that allows it. The backends see the reordered list, so a WFP filter's #<i> and a pf line's position follow it, while a line's rule stays the revision index.
A successful apply records the policy as the one the backend holds, which Sync compares the next pull against. It does not count as applying a pull's block: the startup baseline, ApplyFirewallRules(nil, iface), leaves Status's HasApplied false until Sync adopts a pull.
func (*Enforcer) Changed ¶ added in v0.31.0
func (e *Enforcer) Changed() <-chan struct{}
Changed returns the channel Sync signals on when it ran for the first time or changed the enforcement, the applied block or the rejection. It has a capacity of one: several changes before the reader wakes collapse into one signal, and the reader then reads the latest Status.
func (*Enforcer) ConnLogger ¶ added in v0.30.0
func (e *Enforcer) ConnLogger() *ConnLogger
ConnLogger returns the logger that writes a line for each connection a logged rule admits. plexd up runs its summary loop and, where no platform log source reads plexd's output, forwards its lines.
func (*Enforcer) DropCounts ¶ added in v0.31.0
DropCounts returns what the installed ruleset's deny rules dropped since it was installed, and whether there is such a count. It is false while enforcement is not on, while nothing is installed, and for a backend that does not implement DropCounter.
A failed read returns the counts read last for the same install, so a report keeps carrying drops through a passing failure: the control plane counts the whole value of a report that follows one without counters, and a gap would count the same drops twice. Without such counts it returns false. The failure is logged at Warn once per run of failures.
An install is an apply the backend accepted. A failed apply leaves the chain and its counters as they were, so it keeps the counts read last. The read holds the Enforcer's lock, so the counts always belong to the install they are remembered with; on macOS that is one pfctl run.
func (*Enforcer) Preflight ¶ added in v0.3.0
Preflight reports whether this node can enforce policy at all, without changing any kernel state. It answers the question the first ApplyFirewallRules would otherwise answer — but that call happens after registration has spent a redemption of its bootstrap token, so a node that can never install a chain has to learn it here instead.
The two no-op paths of ApplyFirewallRules are no-ops here as well: with enforcement disabled or no firewall backend compiled in, there is no enforcement to be unable to perform. A backend that fails the probe is an error — that node was told to enforce and cannot.
func (*Enforcer) Status ¶ added in v0.31.0
Status returns a copy of the Enforcer's record. Before the first Sync it is the zero Status.
func (*Enforcer) Sync ¶ added in v0.31.0
func (e *Enforcer) Sync(desired *api.PolicySnapshot, iface string)
Sync brings the firewall to the policy block of a pull and records the outcome in Status. The reconciler runs it on every successful pull through DispatchHandler. It decides in this order:
- The block becomes Status.Received.
- With enforcement disabled (policy.enabled: false) or no firewall backend, it records the enforcement as disabled or unavailable, clears the applied and the rejected block, and touches nothing.
- When a ruleset is installed and desired is the same block (both nil, or the same non-empty fingerprint), it makes no kernel call and adopts desired as applied: a first pull with policy: null applies over the startup baseline, and a pull that changes only revision_id or revisions under an unchanged fingerprint is taken as it is.
- With nothing installed and a nil desired, it does nothing: the node whose startup skipped the baseline stays as it was.
- Otherwise it applies desired. On success desired is applied and the rejection cleared.
- On failure the applied block stays, because every backend replaces a chain whole or leaves it. A block with a fingerprint becomes Rejected, with Attempts counting the failures in a row of that fingerprint and reason. A nil block or one without a fingerprint cannot be echoed, so its failure clears Rejected instead.
DECISION: the retry is the next pull. A block that is not installed is applied again on every pull, every reconcile interval and on every trigger, without a backoff: a ruleset the engine refuses costs one pass over its rules and no kernel call, and a backend failure was retried every cycle before.
The first failure of a fingerprint and reason logs at Error, a repeat at Debug, so a revision stuck behind the retry does not repeat its Error every minute. Sync signals Changed when it ran for the first time or changed what sameReportedState compares.
func (*Enforcer) Teardown ¶
Teardown removes the firewall chain and its rules. It is safe to call when the firewall backend is nil. It clears the record of what is installed and applied, so Status no longer claims a ruleset the backend dropped, and closes the Enforcer: Sync and ApplyFirewallRules touch the backend no more.
DECISION: plexd up tears the chain down before it waits for the reconciler, which can still be inside a cycle whose pull it fetched before the shutdown. The dispatch handler syncs every pull, so without the close that cycle would install the chain again after Teardown removed it.
type FirewallController ¶
type FirewallController interface {
// Probe reports whether the backend is usable, without changing any kernel
// state. It must exercise the same privileged path the mutating calls take,
// so a missing capability or an unavailable subsystem surfaces here rather
// than on the first EnsureChain.
Probe() error
// EnsureChain creates the named iptables chain if it does not already exist.
EnsureChain(chain string) error
// ApplyRules replaces all rules of the named chain atomically, for
// traffic in both directions: what arrives on a rule's interface and what
// the node itself sends over it.
ApplyRules(chain string, rules []FirewallRule) error
// FlushChain removes all rules from the named chain.
FlushChain(chain string) error
// DeleteChain deletes the named chain.
// Implementations must be idempotent: deleting a non-existent chain must return nil.
DeleteChain(chain string) error
}
FirewallController abstracts OS-level iptables operations for testability.
type FirewallRule ¶
type FirewallRule struct {
Interface string // network interface name
SrcIP string // source IP (CIDR or single IP); "" matches every address
DstIP string // destination IP (CIDR or single IP); "" matches every address
Port int // destination port (0 = any)
PortTo int // inclusive end of a destination port range, 0 means single-Port match
Protocol string // "tcp", "udp", "icmp", or "" (any)
Action string // "allow" or "deny"
// LogTag, when set, asks the backend to report the connections this rule
// admits, carrying the tag. Only an allow carries one.
LogTag string
}
FirewallRule describes a single packet filter rule. An address field holds a prefix or a single address of either family; both fields together name one family, and a rule with both empty matches both.
A backend applies each rule to what arrives on Interface, delivered to the node or forwarded through it, and to what the node's own sockets send over Interface. A rule matches by its addresses. The control plane compiles every authored rule for both ends (plexsphere/plexsphere#1056): the destination node gets a copy naming the source as sender, the source node one naming itself, so each copy matches one direction.
DECISION: a rule carries no direction. The rejected alternative, the engine tagging each rule inbound or outbound, needs the node's own mesh address, which the engine does not receive.
func (*FirewallRule) Validate ¶
func (r *FirewallRule) Validate() error
Validate checks the rule for semantic correctness and returns an error if any field contains an invalid value.
type NftablesController ¶
type NftablesController struct {
// contains filtered or unexported fields
}
NftablesController implements FirewallController using the Linux nftables subsystem via the google/nftables netlink library. It manages one inet filter table ("plexd"), which matches IPv4 and IPv6 alike, and gives every configured chain name three base chains in it: one on the input hook for traffic addressed to the node, one on the forward hook for traffic it routes, and one on the output hook for traffic the node's own sockets send. All three hold the same rules. The input and forward chains match them against the interface a packet arrives on, and the output chain against the interface a packet leaves through, behind the foreign-source rule and the relay probe exemption.
A rule with a LogTag gets a log rule in front of it, which sends the first packet of each connection it admits to NFLOG group nflogGroup. The controller reads that group and hands each record to the sink SetConnSink set.
func NewNftablesController ¶
func NewNftablesController(logger *slog.Logger) *NftablesController
NewNftablesController returns a new NftablesController.
func (*NftablesController) ApplyRules ¶
func (c *NftablesController) ApplyRules(chain string, rules []FirewallRule) error
ApplyRules replaces all rules in the three base chains of the named chain atomically. It builds two lists from the rules before it touches the batch: one for the input and forward chains, which matches the interface a packet arrives on, and one for the output chain, which matches the interface a packet leaves through. Each list opens with the connection tracking rules of every interface the rules name, which the output list follows with that interface's foreign-source rule and relay probe rule, and then holds each FirewallRule as an nftables rule with its match expressions and verdict, behind its log rule when it carries a LogTag. It flushes the three chains and writes the lists into them in one batch, so the three change together or not at all.
Before it builds the lists, prepareLogging opens the NFLOG reader a logged rule needs, or takes the log tags off when it cannot. A host whose kernel cannot load nfnetlink_log fails the open, not the batch.
DECISION: only packets in the reply direction of a tracked connection bypass the rules, in all three chains. Every packet in a connection's original direction is matched against the rules, so a revoked rule cuts an established connection at its next packet, as a stateless chain would: an inbound or forwarded one in the input or forward chain, and one the node's own sockets opened in the output chain. The replies pass without a rule of their own: those that arrive for a connection the node or a host behind it opened, and those the node sends for a connection the policy let in. Accepting every established packet instead would keep a revoked connection alive until conntrack forgets it.
DECISION: the output chain filters only what the node itself sends from an address of the mesh interface (author, 2026-11-12): the packets of its own sockets, and the ICMP errors and TCP resets its kernel generates, which pass as related or reply traffic. A packet the node forwards into the mesh, from a user-access client, a site-to-site peer, a host behind a bridge, or a container or Pod masqueraded onto the node's address, takes the forward hook, whose chain matches the interface the packet arrived on, so it is not filtered on its way out. Some packets reach the output chain with another source: IPVS sends a Pod's packet to a Service endpoint behind the mesh through the output hook with the Pod's address, and a socket can bind another address of the node. Masquerade gives such a packet the mesh address only after this hook, at postrouting, so no rule could match it; the foreign-source rule (foreignSourceExprs) lets it out unfiltered, as forwarded traffic leaves. A packet that leaves with a foreign source is dropped by the receiving peer's WireGuard, which accepts from a peer only the addresses it allows for that peer. kube-proxy's DNAT of a host-network connection to a Service never meets the output chain as plexd0 traffic: the filter chains of the output hook see the interface of the route the connection started on, and the DNAT reroutes it only for postrouting.
The batch's netlink socket gets buffers sized to the number of rules it adds (applyBufferBytes), because the default ones cannot hold the echoes of a ruleset of a few dozen policy rules written into three chains.
func (*NftablesController) DeleteChain ¶
func (c *NftablesController) DeleteChain(chain string) error
DeleteChain deletes the three base chains of the named chain. It is idempotent: a chain that does not exist is skipped, and deleting a chain none of whose base chains exists returns nil. It closes the NFLOG reader first, also when no chain exists.
func (*NftablesController) DropCounts ¶ added in v0.31.0
func (c *NftablesController) DropCounts(chain string) (packets, bytes uint64, err error)
DropCounts returns the packets and bytes the drop rules in the three base chains of the named chain dropped. It implements DropCounter. buildRuleExprs ends every rule in a counter and a verdict, and the default deny is the only rule the engine gives a drop verdict, so the sum is what the default deny dropped. The counters restart when ApplyRules replaces the chain: it flushes the three chains and adds every rule again with a counter at zero. It reads the counters with one rule dump per base chain.
func (*NftablesController) EnsureChain ¶
func (c *NftablesController) EnsureChain(chain string) error
EnsureChain creates the three base chains of the named chain in one batch if they do not already exist: one on the input hook, so the kernel evaluates its rules for traffic addressed to the node, one on the forward hook, for traffic the node routes, and one on the output hook, for traffic the node's own sockets send.
func (*NftablesController) FlushChain ¶
func (c *NftablesController) FlushChain(chain string) error
FlushChain removes all rules from those of the three base chains of the named chain that exist. A chain that does not exist is skipped, and a chain none of whose base chains exists returns nil, so Enforcer.Teardown reaches DeleteChain also where only some of them exist, such as the two chains of a plexd before the output chain.
func (*NftablesController) Probe ¶ added in v0.3.0
func (c *NftablesController) Probe() error
Probe reports whether the nftables backend is usable, without changing any kernel state. It dumps the inet table list: nfnetlink gates every message on CAP_NET_ADMIN, dumps included, so a dropped capability or an nf_tables subsystem the kernel does not offer is reported here rather than on the first EnsureChain — which by then has already added a table to its batch.
A read is deliberate: the caller runs this before registration, so it must not leave a table behind on a node that goes on to fail startup for another reason.
func (*NftablesController) SetConnSink ¶ added in v0.30.0
func (c *NftablesController) SetConnSink(sink ConnSink)
SetConnSink sets the sink the NFLOG reader hands the connections of logged rules to. Without a sink ApplyRules installs no log rule. A reader opened for an earlier sink is closed, and the next ApplyRules with a logged rule opens one for this sink.
type PolicyEngine ¶
type PolicyEngine struct {
// contains filtered or unexported fields
}
PolicyEngine translates the control plane's merged policy rules into concrete firewall rules for the local node.
func NewPolicyEngine ¶
func NewPolicyEngine(logger *slog.Logger) *PolicyEngine
NewPolicyEngine creates a PolicyEngine with the given logger.
func (*PolicyEngine) BuildFirewallRules ¶
func (e *PolicyEngine) BuildFirewallRules(rules []api.PolicyRule, iface string) ([]FirewallRule, error)
BuildFirewallRules converts the merged policy's rules into concrete FirewallRule entries for the local node.
Every rule is an allow and rule order carries no meaning: a packet passes when any rule allows it, and the default deny appended last drops the rest. A rule that still carries the action key of the format before plexsphere/plexsphere#1058 passes only when that action is allow. Any other value, a deny from a control plane that predates the allow-only model included, rejects the set, since enforcing it as an allow would open what the operator denied.
DECISION: one untranslatable rule rejects the whole set, and the caller keeps the previously installed ruleset. Under allow-only, skipping the rule would only narrow the ruleset, but the node would then enforce a ruleset that matches no revision, and a revision is reported as either applied or rejected (plexd#177).
Protocols tcp/udp/icmp are kept and any maps to "" (match all). Both CIDRs must be parseable prefixes of one family, IPv4 or IPv6. An empty string reaches the backends as "match any address" and would silently widen the rule, and an IPv4-mapped IPv6 prefix would match no packet the operator meant. Ports are valid only for tcp/udp and must be a bounded, non-inverted range; a zero or out-of-range port would drop the port match entirely (widening the rule to every port) or wrap through uint16 onto an unrelated port.
The result holds one FirewallRule per policy rule, in the order given, and then the default deny. A rule's Log flag does not change its FirewallRule: the Enforcer tags the logged rules by that order, since a tag names the apply, which the engine does not know.
The trailing default-deny rule is always appended — including when rules is empty or nil — for a deny-by-default posture. It carries no addresses, so every backend applies it to both families.
type ReconcileTrigger ¶
type ReconcileTrigger interface {
TriggerReconcile()
}
ReconcileTrigger is satisfied by *reconcile.Reconciler.
type Status ¶ added in v0.31.0
type Status struct {
// Enforcement is one of the api.PolicyEnforcement* constants.
Enforcement string
// Synced tells whether Sync ran at least once.
Synced bool
// HasApplied tells whether a pull's block is applied.
HasApplied bool
// Applied is that block; nil when the applied pull carried policy: null.
Applied *api.PolicySnapshot
// Received is the block of the latest pull; nil for policy: null.
Received *api.PolicySnapshot
// Rejected is the block the latest apply failed on; nil when it did not
// fail.
Rejected *api.PolicySnapshot
// Reason is why Rejected failed, as rejectionReason renders the error;
// empty without Rejected.
Reason string
// Attempts counts the applies of Rejected that failed in a row with the
// same reason; 0 without Rejected.
Attempts int
}
Status is the Enforcer's record of what it did with the policy blocks of the pulls, which the policy status report and the node API read.
type StatusClient ¶ added in v0.31.0
type StatusClient interface {
ReportPolicyStatus(ctx context.Context, nodeID string, req api.PolicyStatusRequest) (*api.PolicyStatusResponse, error)
}
StatusClient sends policy status reports. *api.ControlPlane satisfies it.
type StatusReporter ¶ added in v0.31.0
type StatusReporter struct {
// contains filtered or unexported fields
}
StatusReporter sends the Enforcer's record to PUT /v1/nodes/{node_id}/policy-status: what the node enforces, the ruleset it applied, the one its latest apply failed on and why, and the drop counters of its default deny. The control plane derives the node's policy status from it and logs every change in what the node enforces.
It sends when the Enforcer signals a change of the enforcement, the applied block or the rejection. On each tick of the interval it sends only when no report of the current state was accepted yet, which is the case after a failed send, or when the drop counters moved since the last accepted one, so a quiet node sends nothing (the author chose this on 2026-11-13).
DECISION: the reporter sends from a goroutine of its own, one report at a time, never from inside the dispatch handler, so a slow control plane never delays a reconcile cycle. This follows bridge.RelayStatusReporter.
DECISION: nothing is sent before the Enforcer's first Sync, because until then plexd has seen no pull and could only report the startup baseline, which is no ruleset of the control plane's. Nothing is sent at shutdown either: the contract defines no such report, and the control plane keeps the last one.
func NewStatusReporter ¶ added in v0.31.0
func NewStatusReporter(interval time.Duration, nodeID string, client StatusClient, enforcer *Enforcer, logger *slog.Logger) *StatusReporter
NewStatusReporter creates a StatusReporter that reports what enforcer records for nodeID through client. A non-positive interval becomes 30 s, the value of agent.DefaultHeartbeatInterval: the contract asks for an unchanged report at most once per heartbeat interval.