Documentation
¶
Overview ¶
Package firewaller defines an interface that can be used to manipulate firewall configuration for a bridge network.
Index ¶
- type Config
- type Firewaller
- type IPVersion
- type Network
- type NetworkConfig
- type NetworkConfigFam
- type StubFirewaller
- type StubFirewallerNetwork
- func (nw *StubFirewallerNetwork) AddEndpoint(_ context.Context, epIPv4, epIPv6 netip.Addr) error
- func (nw *StubFirewallerNetwork) AddLink(_ context.Context, parentIP, childIP netip.Addr, ports []types.TransportPort) error
- func (nw *StubFirewallerNetwork) AddPorts(_ context.Context, pbs []types.PortBinding) error
- func (nw *StubFirewallerNetwork) DelEndpoint(_ context.Context, epIPv4, epIPv6 netip.Addr) error
- func (nw *StubFirewallerNetwork) DelLink(_ context.Context, parentIP, childIP netip.Addr, ports []types.TransportPort)
- func (nw *StubFirewallerNetwork) DelNetworkLevelRules(_ context.Context) error
- func (nw *StubFirewallerNetwork) DelPorts(_ context.Context, pbs []types.PortBinding) error
- func (nw *StubFirewallerNetwork) LinkExists(parentIP, childIP netip.Addr, ports []types.TransportPort) bool
- func (nw *StubFirewallerNetwork) PortExists(pb types.PortBinding) bool
- func (nw *StubFirewallerNetwork) ReapplyNetworkLevelRules(_ context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// IPv4 true means IPv4 firewalling is required.
IPv4 bool
// IPv6 true means IPv4 firewalling is required.
IPv6 bool
// Hairpin means the userland proxy will not be running.
Hairpin bool
// AllowDirectRouting means packets addressed directly to a container's IP address will be
// accepted, regardless of which network interface they are from.
AllowDirectRouting bool
// WSL2Mirrored is true if running under WSL2 with mirrored networking enabled.
WSL2Mirrored bool
}
Config contains top-level settings for the firewaller.
type Firewaller ¶
type Firewaller interface {
// NewNetwork returns an object that can be used to add published ports and legacy
// links for a bridge network.
NewNetwork(ctx context.Context, nc NetworkConfig) (Network, error)
// FilterForwardDrop sets the default policy of the FORWARD chain in the filter
// table to DROP.
FilterForwardDrop(ctx context.Context, ipv IPVersion) error
}
Firewaller implements firewall rules for bridge networks.
type Network ¶
type Network interface {
// ReapplyNetworkLevelRules re-creates the initial set of network-level rules
// created by [Firewaller.NewNetwork]. It can be called after, for example, a
// firewalld reload has deleted the rules. Rules for port mappings and legacy
// links are not re-created.
ReapplyNetworkLevelRules(ctx context.Context) error
// DelNetworkLevelRules deletes any configuration set up by [Firewaller.NewNetwork].
// It does not delete per-port or per-link rules. The caller is responsible for tracking
// those and deleting them when the network is removed.
DelNetworkLevelRules(ctx context.Context) error
// AddEndpoint is used to notify the firewaller about a new container on the
// network, with its IP addresses.
AddEndpoint(ctx context.Context, epIPv4, epIPv6 netip.Addr) error
// DelEndpoint undoes configuration applied by AddEndpoint.
DelEndpoint(ctx context.Context, epIPv4, epIPv6 netip.Addr) error
// AddPorts adds the configuration needed for published ports.
AddPorts(ctx context.Context, pbs []types.PortBinding) error
// DelPorts deletes the configuration needed for published ports.
DelPorts(ctx context.Context, pbs []types.PortBinding) error
// AddLink adds the configuration needed for a legacy link.
AddLink(ctx context.Context, parentIP, childIP netip.Addr, ports []types.TransportPort) error
// DelLink deletes the configuration needed for a legacy link.
DelLink(ctx context.Context, parentIP, childIP netip.Addr, ports []types.TransportPort)
}
Network can be used to manipulate firewall rules for a bridge network.
type NetworkConfig ¶
type NetworkConfig struct {
// IfName is the name of the bridge device.
IfName string
// Internal is true if the network should have no access to networks outside the Docker host.
Internal bool
// ICC is false if containers on the bridge should not be able to communicate (unless it's the
// default bridge, and legacy-links are set up).
ICC bool
// Masquerade is true if the network should use masquerading/SNAT.
Masquerade bool
// TrustedHostInterfaces are interfaces that must be treated as part of the network (like the
// bridge itself). In particular, these are not external interfaces for the purpose of
// blocking direct-routing to a container's IP address.
TrustedHostInterfaces []string
// Config4 contains IPv4-specific configuration for the network.
Config4 NetworkConfigFam
// Config6 contains IPv6-specific configuration for the network.
Config6 NetworkConfigFam
}
NetworkConfig contains settings for a single bridge network.
type NetworkConfigFam ¶
type NetworkConfigFam struct {
// HostIP is the address to use for SNAT. If unset, masquerading will be used instead.
HostIP netip.Addr
// Prefix is the bridge network's subnet.
Prefix netip.Prefix
// Routed is true if containers should be directly addressable, no NAT from the host.
Routed bool
// Unprotected is true if no rules to filter unpublished ports or direct access from
// any remote host are required.
Unprotected bool
}
NetworkConfigFam contains network configuration for a single address family.
type StubFirewaller ¶
type StubFirewaller struct {
Config
Networks map[string]*StubFirewallerNetwork
FFD map[IPVersion]bool // filter forward drop
}
StubFirewaller implements a Firewaller for unit tests. It just tracks what it's been asked for.
func NewStubFirewaller ¶
func NewStubFirewaller(config Config) *StubFirewaller
func (*StubFirewaller) FilterForwardDrop ¶
func (fw *StubFirewaller) FilterForwardDrop(_ context.Context, ipv IPVersion) error
func (*StubFirewaller) NewNetwork ¶
func (fw *StubFirewaller) NewNetwork(_ context.Context, nc NetworkConfig) (Network, error)
type StubFirewallerNetwork ¶
type StubFirewallerNetwork struct {
NetworkConfig
Deleted bool
Endpoints map[stubEndpoint]struct{}
Ports []types.PortBinding
Links []stubFirewallerLink
// contains filtered or unexported fields
}
func (*StubFirewallerNetwork) AddEndpoint ¶
func (*StubFirewallerNetwork) AddLink ¶
func (nw *StubFirewallerNetwork) AddLink(_ context.Context, parentIP, childIP netip.Addr, ports []types.TransportPort) error
func (*StubFirewallerNetwork) AddPorts ¶
func (nw *StubFirewallerNetwork) AddPorts(_ context.Context, pbs []types.PortBinding) error
func (*StubFirewallerNetwork) DelEndpoint ¶
func (*StubFirewallerNetwork) DelLink ¶
func (nw *StubFirewallerNetwork) DelLink(_ context.Context, parentIP, childIP netip.Addr, ports []types.TransportPort)
func (*StubFirewallerNetwork) DelNetworkLevelRules ¶
func (nw *StubFirewallerNetwork) DelNetworkLevelRules(_ context.Context) error
func (*StubFirewallerNetwork) DelPorts ¶
func (nw *StubFirewallerNetwork) DelPorts(_ context.Context, pbs []types.PortBinding) error
func (*StubFirewallerNetwork) LinkExists ¶
func (nw *StubFirewallerNetwork) LinkExists(parentIP, childIP netip.Addr, ports []types.TransportPort) bool
func (*StubFirewallerNetwork) PortExists ¶
func (nw *StubFirewallerNetwork) PortExists(pb types.PortBinding) bool
func (*StubFirewallerNetwork) ReapplyNetworkLevelRules ¶
func (nw *StubFirewallerNetwork) ReapplyNetworkLevelRules(_ context.Context) error
Click to show internal directories.
Click to hide internal directories.