Documentation
¶
Overview ¶
Package hostfw reads the host firewall (ufw, firewalld, nftables, iptables) and opens exactly ports 80 and 443 in it, nothing else. It never enables a disabled firewall, never edits or deletes a rule it did not add, and every change it makes has a printed undo.
Index ¶
- Constants
- Variables
- func InputFiltered(ctx context.Context, run Runner, b Backend) (filtered, known bool)
- func IptablesInputFiltered(dump string) bool
- func NftInputFiltered(ruleset string) bool
- func OpenFix(b Backend, ports []int) string
- func ValidPort(p int) bool
- type Backend
- type Command
- type DNSFinding
- type DNSRules
- func (r DNSRules) Backend() Backend
- func (r DNSRules) Diagnose(ctx context.Context, ifaces []string) []DNSFinding
- func (r DNSRules) Ensure(ctx context.Context, ifaces []string) error
- func (r DNSRules) Present(ctx context.Context, ifaces []string) (map[string]bool, error)
- func (r DNSRules) Remove(ctx context.Context) error
- type Deps
- type OpenCommand
- type Plan
- type Result
- type Runner
- type Status
Constants ¶
const ( CodeManagedFirewalld = "dns_firewall_managed_firewalld" CodeManagedUFW = "dns_firewall_managed_ufw" CodeRuleShadowed = "dns_firewall_rule_shadowed" CodeNftNoTable = "dns_firewall_nft_no_table" )
Finding codes for a host firewall that would still drop DNS from a bridge.
Variables ¶
var ( // ErrNoDNSTool means neither iptables nor nft is on the host. ErrNoDNSTool = errors.New("hostfw: no iptables or nft found") // ErrBadInterface means a bridge name failed validation and was not passed to any tool. ErrBadInterface = errors.New("hostfw: invalid interface name") )
var ErrRefused = errors.New("hostfw: refused")
ErrRefused is wrapped by Apply when the change is not safe to make here.
var WebPorts = []int{80, 443}
WebPorts are the only ports this package ever opens.
Functions ¶
func InputFiltered ¶
InputFiltered classifies whether the backend's input path drops traffic, with the same helpers the doctor check uses. known is false for backends that are not read as a raw ruleset or when the dump cannot be read.
func IptablesInputFiltered ¶
IptablesInputFiltered reports whether `iptables -S` output drops inbound traffic on INPUT by policy, by rule, or through a user chain INPUT jumps to.
func NftInputFiltered ¶
NftInputFiltered reports whether an `nft list ruleset` dump has an input hook that drops by policy or by rule. Docker's NAT, raw and forward rules do not count.
Types ¶
type DNSFinding ¶
type DNSFinding struct {
Code string `json:"code"`
Message string `json:"message"`
Command string `json:"command"`
}
DNSFinding is one detected problem plus the command an operator can run. We only ever print it.
type DNSRules ¶
type DNSRules struct {
Deps Deps
// Tag is the comment on every rule this type owns; rules without it are never touched.
Tag string
}
DNSRules keeps an INPUT accept for udp and tcp 53 from the managed bridges, tagged so it can be removed.
func (DNSRules) Backend ¶
Backend reports which tool the rules go through: iptables first, then nft.
func (DNSRules) Diagnose ¶
func (r DNSRules) Diagnose(ctx context.Context, ifaces []string) []DNSFinding
Diagnose reports firewall states that make a present accept rule useless. It never changes the host.
func (DNSRules) Ensure ¶
Ensure makes exactly the wanted interfaces accept udp and tcp 53, and drops tagged rules for others.
type OpenCommand ¶
type OpenCommand struct {
Port int `json:"port"`
Backend Backend `json:"backend"`
Command string `json:"command"`
Note string `json:"note,omitempty"`
}
OpenCommand is text for the operator to run; this package never executes it.
func OpenCommands ¶
func OpenCommands(b Backend, ports []int) []OpenCommand
OpenCommands returns one command per valid port for backend b, or one per backend and port when b is BackendNone. Invalid ports are dropped, and the command string is built from integers only.
type Plan ¶
type Plan struct {
Backend Backend `json:"backend"`
Ports []int `json:"ports"`
Add []Command `json:"add"`
Undo []Command `json:"undo"`
// Persistent is false when the rule is lost on reboot unless the operator saves the ruleset.
Persistent bool `json:"persistent"`
Note string `json:"note,omitempty"`
// Refusal is set when the change must not be made from here; Add is then empty.
Refusal string `json:"refusal,omitempty"`
}
Plan is exactly what opening the web ports would run and how to reverse it.
type Result ¶
type Result struct {
Plan Plan `json:"plan"`
Status Status `json:"status"`
// Undo are the commands that reverse exactly what was added.
Undo []Command `json:"undo"`
}
Result is what Apply did.
type Status ¶
type Status struct {
Backend Backend `json:"backend"`
// Installed is true when a firewall tool exists on the host.
Installed bool `json:"installed"`
// Active is true when the firewall filters incoming traffic.
Active bool `json:"active"`
// Unknown is true when a tool exists but could not be read, usually for lack of privileges.
Unknown bool `json:"unknown"`
// Open reports, per web port, whether incoming TCP is allowed.
Open map[int]bool `json:"open"`
Detail string `json:"detail"`
// contains filtered or unexported fields
}
Status is what the host firewall does with ports 80 and 443 right now.
func Detect ¶
Detect reads every installed firewall tool and reports the one that is enforcing, else the first that is installed, else BackendNone.
func (Status) MissingPorts ¶
MissingPorts lists the web ports an active firewall does not allow.