hostfw

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostfw holds the controller's side of the locked-down host firewall (Phase 24): the built-in SSH access and its guard, the block list with auto-ban, and each node's listening ports with the firewall's verdict. The mesh manager adds what it returns to every node's firewall.

Index

Constants

View Source
const RuleSSH = "builtin:ssh"

RuleSSH is the built-in SSH rule's and guard's ID.

View Source
const SettingSSH = "firewall.ssh"

SettingSSH holds the SSH settings (JSON).

Variables

View Source
var ErrProtected = errors.New("protected address")

ErrProtected means the source covers an address that must stay reachable.

Functions

func SortBlocks

func SortBlocks(bs []store.FirewallBlock)

SortBlocks orders blocks newest first.

func Verdict

func Verdict(l *agentv1.Listener, fw *agentv1.Firewall, wireguardPort uint32) (verdict, rule string)

Verdict says how a listening socket is reached through the firewall.

Types

type BlockInput

type BlockInput struct {
	Source string
	Node   string        // "" = every node
	For    time.Duration // 0 = until removed
	Reason string
	By     string
	Auto   bool
}

BlockInput is a block to add.

type Listener

type Listener struct {
	Protocol string `json:"protocol"`
	Address  string `json:"address"`
	Port     uint32 `json:"port"`
	Process  string `json:"process"`
	// Verdict: open (to anyone), restricted (some sources), blocked (the
	// firewall drops it), local (loopback), private (the mesh only).
	Verdict string `json:"verdict"`
	// Rule is the rule that opens it ("" when blocked or not public).
	Rule string `json:"rule,omitempty"`
}

Listener is a listening socket on a node with the firewall's verdict.

type Manager

type Manager struct {

	// OnChange runs after anything that changes nodes' firewalls.
	OnChange func()
	// ProtectedIn reports whether a source range covers an address that may
	// never be blocked (cluster nodes, the controller).
	ProtectedIn func(p netip.Prefix) bool
	// AutoBan returns the ban for a source over a guard's limit on a port
	// other than SSH (nil: SSH only; Phase 25 adds load balancers).
	AutoBan func(node string, port uint32) (time.Duration, string, bool)
	// contains filtered or unexported fields
}

Manager keeps the settings and block list in memory: every node's firewall config asks for them.

func New

func New(st *store.Store, log *slog.Logger) *Manager

func (*Manager) Block

func (m *Manager) Block(ctx context.Context, in BlockInput) (store.FirewallBlock, error)

Block adds (or replaces) a block.

func (*Manager) Blocks

func (m *Manager) Blocks() []store.FirewallBlock

Blocks lists the blocks (expired ones are removed every 30 seconds).

func (*Manager) For

func (m *Manager) For(node string, clusterSources []string) (rules []*agentv1.FirewallRule, guards []*agentv1.FirewallGuard, blocks []*agentv1.FirewallBlock)

For returns what the host firewall adds to a node's firewall: the SSH rule, its guard and the node's blocks. clusterSources are the nodes' public addresses (never limited).

func (*Manager) Listeners

func (m *Manager) Listeners(node string, fw *agentv1.Firewall, wireguardPort uint32) ([]Listener, time.Time)

Listeners returns a node's listening sockets with the firewall's verdict for each, given the node's firewall (nil = no host firewall).

func (*Manager) Load

func (m *Manager) Load(ctx context.Context) error

Load reads the SSH settings and the block list. The first time, SSH rules of the original "default" policy move into the settings and that policy goes (it only held SSH).

func (*Manager) OnHeartbeat

func (m *Manager) OnHeartbeat(node store.Node, hb *agentv1.Heartbeat)

OnHeartbeat records a node's listening sockets and bans sources that went over a guard's limit.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run removes expired blocks every 30 seconds.

func (*Manager) SSH

func (m *Manager) SSH() SSH

SSH returns the SSH settings.

func (*Manager) SSHPorts

func (m *Manager) SSHPorts(node string) []int

SSHPorts are the ports SSH is open on for a node: 22, the extra ones and those sshd listens on there.

func (*Manager) SetSSH

func (m *Manager) SetSSH(ctx context.Context, s SSH) (SSH, error)

SetSSH saves the SSH settings.

func (*Manager) Unblock

func (m *Manager) Unblock(ctx context.Context, id string) error

Unblock removes a block.

type SSH

type SSH struct {
	// Ports are opened besides 22 and the detected sshd ports.
	Ports   []int    `json:"ports"`
	Sources []string `json:"sources"`
	// Rate limits new connections per source and minute (0 = no limit),
	// with Burst; Exempt sources are never limited.
	Rate   int      `json:"rate"`
	Burst  int      `json:"burst"`
	Exempt []string `json:"exempt"`
	// AutoBan blocks a source over the rate on that node for BanMinutes.
	AutoBan    bool `json:"autoBan"`
	BanMinutes int  `json:"banMinutes"`
}

SSH is how the nodes' SSH is reached: always open on port 22 and on every port sshd listens on, from Sources (empty = anywhere).

func DefaultSSH

func DefaultSSH() SSH

DefaultSSH is open to anyone, with a rate limit and auto-ban.

func (*SSH) Validate

func (s *SSH) Validate() error

Validate normalizes and checks the settings.

Jump to

Keyboard shortcuts

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