Repository navigation
Closed
Labels
area/networkingNetworkingarea/networking/d/bridgeNetworkingkind/featureFunctionality or other elements that the project doesn't currently have. Features are new and shiny
Description
Description
The bridge driver currently manages its iptables rules inline with the rest of its logic ... extract that code and put it behind an interface, so that nftables/firewalld code can be swapped in at runtime.
The interface should be abstract ("add network") rather than low level ("create isolation rules"). it also needs to fit in with the bridge driver's current structure, where possible.
The current proposal is:
type IPVersion uint8
const (
IPv4 IPVersion = 4
IPv6 IPVersion = 6
)
// Config contains top-level settings for the firewaller.
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
}
// NetworkConfig contains settings for a single bridge network.
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
// Config4 contains IPv4-specific configuration for the network.
Config4 NetworkConfigFam
// Config6 contains IPv6-specific configuration for the network.
Config6 NetworkConfigFam
}
// NetworkConfigFam contains network configuration for a single address family.
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
}
// Firewaller implements firewall rules for bridge networks.
type Firewaller interface {
// NewNetwork returns an object that can be used to add published ports and legacy
// links for a bridge network.
NewNetwork(nc NetworkConfig) (Network, error)
// FilterForwardDrop sets the default policy of the FORWARD chain in the filter
// table to DROP.
FilterForwardDrop(ipv IPVersion) error
}
// Network can be used to manipulate firewall rules for a bridge network.
//
// If the rules for a network are all deleted (for example, by a firewalld reload), there
// is no need to call the delete methods, the object can just be dropped. Construction of
// a new Network will re-create the rules.
type Network interface {
// 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() 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)
}Metadata
Metadata
Assignees
Labels
area/networkingNetworkingarea/networking/d/bridgeNetworkingkind/featureFunctionality or other elements that the project doesn't currently have. Features are new and shiny
Activity