[pve-devel] [PATCH] removed firewall code for openVZ
Alen Grizonic
a.grizonic at proxmox.com
Tue Aug 11 14:50:53 CEST 2015
[PATCH 2/2] changed to [PATCH] with the following fix:
Subroutine verify_rule (re)fixed to correctly check only for eth (on vm) or veth (on ct) interface device names
---
src/PVE/Firewall.pm | 137 ++--------------------------------------------------
1 file changed, 5 insertions(+), 132 deletions(-)
diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index 1e918ab..2c3af4a 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -23,7 +23,7 @@ my $hostfw_conf_filename = "/etc/pve/local/host.fw";
my $pvefw_conf_dir = "/etc/pve/firewall";
my $clusterfw_conf_filename = "$pvefw_conf_dir/cluster.fw";
-# dynamically include PVE::QemuServer and PVE::OpenVZ
+# dynamically include PVE::QemuServer and PVE::LXC
# to avoid dependency problems
my $have_qemu_server;
eval {
@@ -31,12 +31,6 @@ eval {
$have_qemu_server = 1;
};
-my $have_pve_manager;
-eval {
- require PVE::OpenVZ;
- $have_pve_manager = 1;
-};
-
my $have_lxc;
eval {
require PVE::LXC;
@@ -1344,8 +1338,8 @@ sub verify_rule {
&$add_error('iface', "value does not match the regex pattern 'net\\d+'")
if $rule->{iface} !~ m/^net(\d+)$/;
} elsif ($rule_env eq 'ct') {
- &$add_error('iface', "value does not match the regex pattern '(venet|eth\\d+)'")
- if $rule->{iface} !~ m/^(venet|eth(\d+))$/;
+ &$add_error('iface', "value does not match the regex pattern '(veth|eth\\d+)'")
+ if $rule->{iface} !~ m/^((veth\d+i\d+)|eth(\d+))$/;
}
}
@@ -1526,8 +1520,6 @@ sub iptables_get_chains {
return 1 if $name =~ m/^veth\d+.\d+-(:?IN|OUT)$/; # fixme: dev name is configurable
- return 1 if $name =~ m/^venet0-\d+-(:?IN|OUT)$/;
-
return 1 if $name =~ m/^fwbr\d+(v\d+)?-(:?FW|IN|OUT|IPS)$/;
return 1 if $name =~ m/^GROUP-(:?[^\s\-]+)-(:?IN|OUT)$/;
@@ -2021,48 +2013,6 @@ sub ruleset_generate_vm_ipsrules {
}
}
-sub generate_venet_rules_direction {
- my ($ruleset, $cluster_conf, $vmfw_conf, $vmid, $ip, $direction, $ipversion) = @_;
-
- my $lc_direction = lc($direction);
-
- my $rules = $vmfw_conf->{rules};
-
- my $options = $vmfw_conf->{options};
- my $loglevel = get_option_log_level($options, "log_level_${lc_direction}");
-
- my $chain = "venet0-$vmid-$direction";
-
- ruleset_create_vm_chain($ruleset, $chain, $ipversion, $options, undef, undef, $direction);
-
- ruleset_generate_vm_rules($ruleset, $rules, $cluster_conf, $vmfw_conf, $chain, 'venet', $direction, undef, $ipversion);
-
- # implement policy
- my $policy;
-
- if ($direction eq 'OUT') {
- $policy = $options->{policy_out} || 'ACCEPT'; # allow everything by default
- } else {
- $policy = $options->{policy_in} || 'DROP'; # allow nothing by default
- }
-
- my $accept = generate_nfqueue($options);
- my $accept_action = $direction eq 'OUT' ? "PVEFW-SET-ACCEPT-MARK" : $accept;
- ruleset_add_chain_policy($ruleset, $chain, $ipversion, $vmid, $policy, $loglevel, $accept_action);
-
- if ($direction eq 'OUT') {
- ruleset_generate_rule_insert($ruleset, "PVEFW-VENET-OUT", $ipversion, {
- action => $chain,
- source => $ip,
- iface_in => 'venet0'});
- } else {
- ruleset_generate_rule($ruleset, "PVEFW-VENET-IN", $ipversion, {
- action => $chain,
- dest => $ip,
- iface_out => 'venet0'});
- }
-}
-
sub generate_tap_rules_direction {
my ($ruleset, $cluster_conf, $iface, $netid, $macaddr, $vmfw_conf, $vmid, $direction, $ipversion) = @_;
@@ -2693,11 +2643,10 @@ sub run_locked {
sub read_local_vm_config {
- my $openvz = {};
my $qemu = {};
my $lxc = {};
- my $vmdata = { openvz => $openvz, qemu => $qemu, lxc => $lxc };
+ my $vmdata = { qemu => $qemu, lxc => $lxc };
my $vmlist = PVE::Cluster::get_vmlist();
return $vmdata if !$vmlist || !$vmlist->{ids};
@@ -2708,14 +2657,7 @@ sub read_local_vm_config {
my $d = $ids->{$vmid};
next if !$d->{node} || $d->{node} ne $nodename;
next if !$d->{type};
- if ($d->{type} eq 'openvz') {
- if ($have_pve_manager) {
- my $cfspath = PVE::OpenVZ::cfs_config_path($vmid);
- if (my $conf = PVE::Cluster::cfs_read_file($cfspath)) {
- $openvz->{$vmid} = $conf;
- }
- }
- } elsif ($d->{type} eq 'qemu') {
+ if ($d->{type} eq 'qemu') {
if ($have_qemu_server) {
my $cfspath = PVE::QemuServer::cfs_config_path($vmid);
if (my $conf = PVE::Cluster::cfs_read_file($cfspath)) {
@@ -2890,11 +2832,6 @@ sub read_vm_firewall_configs {
next if !$vmfw_conf->{options}; # skip if file does not exists
$vmfw_configs->{$vmid} = $vmfw_conf;
}
- foreach my $vmid (keys %{$vmdata->{openvz}}) {
- my $vmfw_conf = load_vmfw_conf($cluster_conf, 'ct', $vmid, $dir, $verbose);
- next if !$vmfw_conf->{options}; # skip if file does not exists
- $vmfw_configs->{$vmid} = $vmfw_conf;
- }
foreach my $vmid (keys %{$vmdata->{lxc}}) {
my $vmfw_conf = load_vmfw_conf($cluster_conf, 'ct', $vmid, $dir, $verbose);
next if !$vmfw_conf->{options}; # skip if file does not exists
@@ -3147,9 +3084,6 @@ sub compile {
sub compile_iptables_filter {
my ($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $ipversion, $verbose) = @_;
- $cluster_conf->{ipset}->{venet0} = [];
- my $venet0_ipset_chain = compute_ipset_chain_name(0, 'venet0', $ipversion);
-
my $localnet;
if ($cluster_conf->{aliases}->{local_network}) {
$localnet = $cluster_conf->{aliases}->{local_network}->{cidr};
@@ -3179,11 +3113,6 @@ sub compile_iptables_filter {
ruleset_chain_add_conn_filters($ruleset, "PVEFW-FORWARD", "ACCEPT");
-
- ruleset_create_chain($ruleset, "PVEFW-VENET-OUT");
- ruleset_addrule($ruleset, "PVEFW-FORWARD", "-i venet0 -m set --match-set ${venet0_ipset_chain} src -j PVEFW-VENET-OUT");
- ruleset_addrule($ruleset, "PVEFW-INPUT", "-i venet0 -m set --match-set ${venet0_ipset_chain} src -j PVEFW-VENET-OUT");
-
ruleset_create_chain($ruleset, "PVEFW-FWBR-IN");
ruleset_chain_add_input_filters($ruleset, "PVEFW-FWBR-IN", $ipversion, $hostfw_options, $cluster_conf, $loglevel);
@@ -3192,11 +3121,6 @@ sub compile_iptables_filter {
ruleset_create_chain($ruleset, "PVEFW-FWBR-OUT");
ruleset_addrule($ruleset, "PVEFW-FORWARD", "-m physdev --physdev-is-bridged --physdev-out fwln+ -j PVEFW-FWBR-OUT");
- ruleset_create_chain($ruleset, "PVEFW-VENET-IN");
- ruleset_chain_add_input_filters($ruleset, "PVEFW-VENET-IN", $ipversion, $hostfw_options, $cluster_conf, $loglevel);
-
- ruleset_addrule($ruleset, "PVEFW-FORWARD", "-o venet0 -m set --match-set ${venet0_ipset_chain} dst -j PVEFW-VENET-IN");
-
generate_std_chains($ruleset, $hostfw_options, $ipversion);
my $hostfw_enable = !(defined($hostfw_options->{enable}) && ($hostfw_options->{enable} == 0));
@@ -3208,8 +3132,6 @@ sub compile_iptables_filter {
warn $@ if $@; # just to be sure - should not happen
}
- ruleset_addrule($ruleset, "PVEFW-OUTPUT", "-o venet0 -m set --match-set ${venet0_ipset_chain} dst -j PVEFW-VENET-IN");
-
# generate firewall rules for QEMU VMs
foreach my $vmid (keys %{$vmdata->{qemu}}) {
eval {
@@ -3261,55 +3183,6 @@ sub compile_iptables_filter {
warn $@ if $@; # just to be sure - should not happen
}
- # generate firewall rules for OpenVZ containers
- foreach my $vmid (keys %{$vmdata->{openvz}}) {
- eval {
- my $conf = $vmdata->{openvz}->{$vmid};
-
- my $vmfw_conf = $vmfw_configs->{$vmid};
- return if !$vmfw_conf;
-
- generate_ipset_chains($ipset_ruleset, $cluster_conf, $vmfw_conf);
-
- if ($vmfw_conf->{options}->{enable}) {
- if ($conf->{ip_address} && $conf->{ip_address}->{value}) {
- my $ip = $conf->{ip_address}->{value};
- $ip =~ s/\s+/,/g;
-
- my @ips = ();
-
- foreach my $singleip (split(',', $ip)) {
- my $singleip_ver = parse_address_list($singleip); # make sure we have a valid $ip list
- push @{$cluster_conf->{ipset}->{venet0}}, { cidr => $singleip };
- push @ips, $singleip if $singleip_ver == $ipversion;
- }
-
- if (scalar(@ips)) {
- my $ip_list = join(',', @ips);
- generate_venet_rules_direction($ruleset, $cluster_conf, $vmfw_conf, $vmid, $ip_list, 'IN', $ipversion);
- generate_venet_rules_direction($ruleset, $cluster_conf, $vmfw_conf, $vmid, $ip_list, 'OUT', $ipversion);
- }
- }
- }
-
- if ($conf->{netif} && $conf->{netif}->{value}) {
- my $netif = PVE::OpenVZ::parse_netif($conf->{netif}->{value});
- foreach my $netid (keys %$netif) {
- my $d = $netif->{$netid};
- my $bridge = $d->{bridge};
- next if !$bridge || $bridge !~ m/^vmbr\d+(v(\d+))?f$/; # firewall enabled ?
- my $macaddr = $d->{mac};
- my $iface = $d->{host_ifname};
- generate_tap_rules_direction($ruleset, $cluster_conf, $iface, $netid, $macaddr,
- $vmfw_conf, $vmid, 'IN', $ipversion);
- generate_tap_rules_direction($ruleset, $cluster_conf, $iface, $netid, $macaddr,
- $vmfw_conf, $vmid, 'OUT', $ipversion);
- }
- }
- };
- warn $@ if $@; # just to be sure - should not happen
- }
-
if(ruleset_chain_exist($ruleset, "PVEFW-IPS")){
ruleset_insertrule($ruleset, "PVEFW-FORWARD", "-m conntrack --ctstate RELATED,ESTABLISHED -j PVEFW-IPS");
}
--
2.1.4
More information about the pve-devel
mailing list