Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurability to Netavark firewall driver #1750

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ and __$HOME/.config/cni/net.d__ as rootless.
For the netavark backend "/etc/containers/networks" is used as root
and "$graphroot/networks" as rootless.

**firewall_driver**=""

The firewall driver to be used by netavark.
The default is empty which means netavark will pick one accordingly. Current supported
drivers are "iptables", "none" (no firewall rules will be created) and "firewalld" (firewalld is
experimental at the moment and not recommend outside of testing). In the future we are
planning to add support for a "nftables" driver.

**dns_bind_port**=53

Port to use for dns forwarding daemon with netavark in rootful bridge
Expand Down
3 changes: 3 additions & 0 deletions libnetwork/netavark/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (n *netavarkNetwork) execNetavark(args []string, needPlugin bool, stdin, re
if n.dnsBindPort != 0 {
env = append(env, "NETAVARK_DNS_PORT="+strconv.Itoa(int(n.dnsBindPort)))
}
if n.firewallDriver != "" {
env = append(env, "NETAVARK_FW="+n.firewallDriver)
}
return n.execBinary(n.netavarkBinary, append(n.getCommonNetavarkOptions(needPlugin), args...), stdin, result, env)
}

Expand Down
7 changes: 7 additions & 0 deletions libnetwork/netavark/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type netavarkNetwork struct {
// aardvarkBinary is the path to the aardvark binary.
aardvarkBinary string

// firewallDriver sets the firewall driver to use
firewallDriver string

// defaultNetwork is the name for the default network.
defaultNetwork string
// defaultSubnet is the default subnet for the default network.
Expand Down Expand Up @@ -79,6 +82,9 @@ type InitConfig struct {
// NetworkRunDir is where temporary files are stored, i.e.the ipam db, aardvark config
NetworkRunDir string

// FirewallDriver sets the firewall driver to use
FirewallDriver string

// DefaultNetwork is the name for the default network.
DefaultNetwork string
// DefaultSubnet is the default subnet for the default network.
Expand Down Expand Up @@ -146,6 +152,7 @@ func NewNetworkInterface(conf *InitConfig) (types.ContainerNetwork, error) {
aardvarkBinary: conf.AardvarkBinary,
networkRootless: unshare.IsRootless(),
ipamDBPath: filepath.Join(conf.NetworkRunDir, "ipam.db"),
firewallDriver: conf.FirewallDriver,
defaultNetwork: defaultNetworkName,
defaultSubnet: defaultNet,
defaultsubnetPools: defaultSubnetPools,
Expand Down
1 change: 1 addition & 0 deletions libnetwork/network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NetworkBackend(store storage.Store, conf *config.Config, syslog bool) (type
NetavarkBinary: netavarkBin,
AardvarkBinary: aardvarkBin,
PluginDirs: conf.Network.NetavarkPluginDirs.Get(),
FirewallDriver: conf.Network.FirewallDriver,
DefaultNetwork: conf.Network.DefaultNetwork,
DefaultSubnet: conf.Network.DefaultSubnet,
DefaultsubnetPools: conf.Network.DefaultSubnetPools,
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ type NetworkConfig struct {
// NetavarkPluginDirs is a list of directories which contain netavark plugins.
NetavarkPluginDirs attributedstring.Slice `toml:"netavark_plugin_dirs,omitempty"`

// FirewallDriver is the firewall driver to be used
FirewallDriver string `toml:"firewall_driver,omitempty"`

// DefaultNetwork is the network name of the default network
// to attach pods to.
DefaultNetwork string `toml:"default_network,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/config_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ var _ = Describe("Config Local", func() {
gomega.Expect(config2.Network.DNSBindPort).To(gomega.Equal(uint16(1153)))
})

It("test firewall", func() {
// Given
config, err := New(nil)
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Network.FirewallDriver).To(gomega.Equal(string("")))
// When
config2, err := NewConfig("testdata/containers_default.conf")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config2.Network.FirewallDriver).To(gomega.Equal("none"))
})

It("parse pasta_options", func() {
// Given
config, err := New(nil)
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ default_sysctls = [
# "/usr/lib/netavark",
#]

# The firewall driver to be used by netavark.
# The default is empty which means netavark will pick one accordingly. Current supported
# drivers are "iptables", "none" (no firewall rules will be created) and "firewalld" (firewalld is
# experimental at the moment and not recommend outside of testing). In the future we are
# planning to add support for a "nftables" driver.
#firewall_driver = ""


# The network name of the default network to attach pods to.
#
#default_network = "podman"
Expand Down
1 change: 1 addition & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func defaultConfig() (*Config, error) {
Volumes: attributedstring.Slice{},
},
Network: NetworkConfig{
FirewallDriver: "",
DefaultNetwork: "podman",
DefaultSubnet: DefaultSubnet,
DefaultSubnetPools: DefaultSubnetPools,
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ default_subnet_pools = [{"base" = "10.89.0.0/16", "size" = 24}, {"base" = "10.90

default_rootless_network_cmd = "pasta"

# firewall driver to be used by default
firewall_driver = "none"

# dns port for netavark/aardvark
dns_bind_port = 1153

Expand Down