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
- Variables
- func SortBlocks(bs []store.FirewallBlock)
- func Verdict(l *agentv1.Listener, fw *agentv1.Firewall, wireguardPort uint32) (verdict, rule string)
- type BlockInput
- type Listener
- type Manager
- func (m *Manager) Block(ctx context.Context, in BlockInput) (store.FirewallBlock, error)
- func (m *Manager) Blocks() []store.FirewallBlock
- func (m *Manager) For(node string, clusterSources []string) (rules []*agentv1.FirewallRule, guards []*agentv1.FirewallGuard, ...)
- func (m *Manager) Holders(node string) map[string]string
- func (m *Manager) Listeners(node string, fw *agentv1.Firewall, wireguardPort uint32) ([]Listener, time.Time)
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) OnHeartbeat(node store.Node, hb *agentv1.Heartbeat)
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) SSH() SSH
- func (m *Manager) SSHPorts(node string) []int
- func (m *Manager) SetSSH(ctx context.Context, s SSH) (SSH, error)
- func (m *Manager) Unblock(ctx context.Context, id string) error
- type SSH
Constants ¶
const RuleSSH = "builtin:ssh"
RuleSSH is the built-in SSH rule's and guard's ID.
const SettingSSH = "firewall.ssh"
SettingSSH holds the SSH settings (JSON).
Variables ¶
var ErrProtected = errors.New("protected address")
ErrProtected means the source covers an address that must stay reachable.
Functions ¶
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 (*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) Holders ¶ added in v0.4.0
Holders are the ports something other than Traefik listens on, on one node ("tcp/25" -> process), from its last listener report. A port held there can't become a public port: Traefik could not bind it.
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 ¶
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 ¶
OnHeartbeat records a node's listening sockets and bans sources that went over a guard's limit.
func (*Manager) SSHPorts ¶
SSHPorts are the ports SSH is open on for a node: 22, the extra ones and those sshd listens on there.
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.