Documentation
¶
Overview ¶
Package firewall manages host ufw rules as declarative allow/deny records. Every rule it creates carries the Manager's comment prefix; Sync only ever adds or removes rules carrying that tag, never an operator's own ufw rules, never "ufw enable" or the default policy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultRequiredPorts = []int{8080, 9443, 80, 443}
DefaultRequiredPorts are the platform's own ports at default addresses: management API, agent mTLS gRPC, and the two ingress ports. Callers pass the actually configured ports to Validate; this is only the fallback.
var ErrWouldLockOut = errors.New("firewall: rule would lock out a required platform port")
ErrWouldLockOut is wrapped by Validate's error when a rule would deny, or narrow to a specific source, inbound access to one of the platform's own required ports. Refused unconditionally: a locked-out control plane has no way to fix itself back open.
Functions ¶
Types ¶
type Action ¶
type Action string
Action is the ufw action a Rule applies: allow lets traffic through, deny drops it silently.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager syncs a desired set of Rules against the local host's ufw.
func New ¶
New builds a Manager that shells out to the real "ufw" binary and only manages rules whose comment starts with prefix.
func NewFake ¶
NewFake builds a Manager over fake lookPath/run functions, exported so its callers' tests can exercise Sync without a real ufw binary, the same seam this package's own tests use.
func (*Manager) Report ¶
Report computes the current state of every rule in want without mutating anything: a pure read, safe to call from an HTTP GET handler.
func (*Manager) Sync ¶
Sync converges ufw to match want exactly, for every rule this package itself tagged: it applies every wanted rule not already present, and removes every prefix-tagged rule that's present but no longer wanted. It never touches a rule without that tag, never calls "ufw enable", and never changes ufw's default policy. Returns a nil error even when individual ufw invocations failed; see Result.Errors.
type Result ¶
type Result struct {
// Installed is false when the ufw binary itself isn't found. Managed
// is always empty and Applied/Removed are always zero in that case.
Installed bool
// Active is ufw's own "Status: active" flag. When false, rules
// cannot be meaningfully reported as applied (ufw isn't enforcing
// anything), so Managed still lists every wanted rule but every
// Applied is false and the Applied/Removed counters stay zero: Sync
// never calls "ufw enable" itself, see the package doc comment.
Active bool
// Managed is one RuleStatus per Rule passed to Report/Sync, in the
// same order.
Managed []RuleStatus
// Extra is every ufw rule this package tagged (the Manager prefix)
// that Report/Sync found active but that wasn't in the caller's want
// list, e.g. a rule a deleted record left behind because Sync
// hadn't run since. Sync removes these; Report only reports them.
Extra []RuleStatus
// Applied and Removed count the ufw commands Sync actually ran
// (never populated by Report, which never mutates).
Applied int
Removed int
// Errors carries one message per failed ufw invocation. Sync/Report
// still return a nil error and whatever partial Result it has when
// this is non-empty: one broken rule must not block every other
// rule from being read or applied correctly.
Errors []string
}
Result is Report's or Sync's outcome for one call.
type Rule ¶
type Rule struct {
// Port is the host port the rule applies to.
Port int
// Proto is "tcp" or "udp". Empty defaults to "tcp".
Proto string
// SourceCIDR restricts the rule to traffic from this CIDR. Empty
// means any source ("Anywhere" in ufw's own terminology).
SourceCIDR string
// Action is ActionAllow or ActionDeny.
Action Action
// Owner identifies what this rule is for (e.g. "rule:3",
// "app:myapp"), stored as the ufw rule's comment with the
// Manager's prefix prepended, and shown back in Report/Sync results
// so a caller can tell which resource a given rule belongs to.
Owner string
}
Rule is one host firewall rule this platform wants ufw to enforce.
type RuleStatus ¶
type RuleStatus struct {
Rule
// Applied is true when ufw's current rule set already has an entry
// matching this exact port/proto/source/action, whether this
// package's own Sync applied it or an operator had already set up
// the identical rule outside this package.
Applied bool
}
RuleStatus is one wanted Rule's actual state after Report or Sync.