neutron安全组功能点梳理总结
来源:互联网 发布:js调用高德地图api 编辑:程序博客网 时间:2024/05/22 00:35
1.虚拟机安全组规则一致性检查
1.根据虚拟机id找到使用的port id。
2.根据port id找到port所在计算节点名字。
3.根据port id找到port所属安全组id。
4.根据安全组id查询对应的安全组规则。
5.Ssh到计算节点,根据port id查询对应的iptables规则。
6.自动分析安全组规则与iptables规则是否一致。
2.client中安全组相关接口
安全组作用范围是在虚拟机上,更具体来说是作用在虚拟机的端口而不是网络上。
neutron-diagnose vm_sg_rule [-h] [-f {json,shell,table,value,yaml}]
[-c COLUMN] [--max-width <integer>]
[--print-empty] [--noindent]
[--prefix PREFIX]
[--port]
<instance>
Instance:默认参数,需输入使用该安全组的虚拟机id,
--port:可选参数,list类型,虚拟机网卡id;如设置为空,则默认检测所有网卡安全组规则。
3.数据提取
0.通过nova interface-list vm-id 查询到该虚拟机所管理的所有port-id,依次判断
1.通过neutron port-show port-id 查询该port的binding:host_id属性,获得该port所在计算节;
2.通过neutron port-show port-id 查询该port的securitsy_groups id.
3.通过neutron security-group-show group-id 查询该安全组的security_group_rules,将该数据存入列表里面,列表里面都是字典类型
4.通过sshclient到步骤1中port所属计算节点,分别查询4个iptable表所属的iptable规则(包括raw mangle filter nat),将规则依次存入列表;最终构建一个字典类型
5.对port关联的数据库中安全组规则和port所在节点安全组规则进行分析。
4.数据比对分析
4.1 分析port所关联的安全组规则设置的合理性,以default安全组为基本依据;
在没有任何安全组规则前提下,虚拟机进出流量默认是禁止的。安全组中添加的规则都是放行的,通过选择性的放行来控制进出虚拟机的。以默认安全组(default)为例,其实现默认放行出虚拟机所有流量,放行入虚拟机的来自于规则中远端安全组的所有流量,保证最基础的虚拟机入出链路连通。
合理性检查如下:
1. 检查虚拟机默认出规则是否存在(目前只考虑iPv4),若默认出规则缺失,则抛出规则检查异常,打印目前出规则信息;若默认出规则存在,则出方向规则正常,跳入检查入规则;
2. 检查虚拟机默认入规则是否存在,若默认入规则缺失,则抛出入规则检查异常,打印目前入规则信息;若默认如规则存在,则入方向规则正常;进一步判断所有入规则中,是否存在放行所有入规则,若有,则提示放行所有入规则;
4.2 分析port所关联的安全组规则设置的一致性
底层规则正确性检查如下:
1.涉及port相关的默认入规则是否添加
具体参考5中的iptables规则分析:进入虚拟机的流量,需要检查的默认规则如下:
-A neutron-openvswi-FORWARD -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-i18fcd66b-8
-----经过qbr bridge转发并通过tap进入虚拟机的包
-A neutron-openvswi-i18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(跟踪tcp 连接状态,接受已经建立的tcp连接)
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.2/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.3/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
(默认允许所有dhcp server流量进入)
-A neutron-openvswi-i18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop,放在最后)
-A neutron-openvswi-i18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
需要考虑存在性和顺序性
2.涉及port相关的默认出规则是否添加
具体参考5中的iptables规则分析:从虚拟机发出的流量,需要检查的默认规则如下:
-A neutron-openvswi-INPUT -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct incoming traffic from VM to the security group chain." -j neutron-openvswi-o18fcd66b-8 (-N neutron-openvswi-o18fcd66b-8)
-A neutron-openvswi-o18fcd66b-8 -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
(该规则必须在下面规则之前,不然没法和dhcp server通信,发送dhcp报文)
-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8 (-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8)
-A neutron-openvswi-s18fcd66b-8 -s 192.168.22.4/32 -m mac --mac-source FA:16:3E:0C:3E:DD -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN (考虑地址队?)
-A neutron-openvswi-s18fcd66b-8 -m comment --comment "Drop traffic without an IP/MAC allow rule." -j DROP
(以上两条规则需在这里,校验从虚拟机发出包信息)
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 67 -m udp --dport 68 -m comment --comment "Prevent DHCP Spoofing by VM." -j DROP
(以上保证默认vm与dhcp通信,并防止vm伪装为dhcpserver)
-A neutron-openvswi-o18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(建立tcp连接,并追踪tcp连接状态)
-A neutron-openvswi-o18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop)
-A neutron-openvswi-o18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
需要考虑存在性和顺序性
3.涉及port相关的默认转发规则是否添加
具体参考5中的iptables规则分析:从qbr网桥的tap口转发的流量,需要检查的默认规则如下:
-A neutron-openvswi-FORWARD -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-o18fcd66b-8
4.检查安全组规则与底层iptable 规则的一致性,安全组规则设置是否成功
比对控制进入虚拟机流量的规则,举例如下:
-A neutron-openvswi-o18fcd66b-8 -p icmp -j RETURN (添加有icmp出放行)
-A neutron-openvswi-o18fcd66b-8 -p tcp -m tcp --dport 22 -j RETURN (添加tcp 22 出口放行)
-A neutron-openvswi-o18fcd66b-8 -j RETURN (添加所有规则放行)
(以上三条规则为用户自定义的规则,默认安全组只有最后一条规则,即出放行)
比对控制从虚拟机发出流量的规则,举例如下:
-A neutron-openvswi-i18fcd66b-8 -p icmp -j RETURN
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- src -j RETURN
(远端安全组相关)
-A neutron-openvswi-i18fcd66b-8 -p udp -m udp -m multiport --dports 1:65535 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -p tcp -m tcp -m multiport --dports 1:65535 -j RETURN
(以上4条为用户指定的规则)
4.3 信息比对中关键点考虑
1.port_security_enabled 在port创建过程中默认为True, 若虚拟机关联的port指定“port_security_enabled”为false,则安全组为空,虚拟机进出流量口控制都放行。
类似如下规则:
-A neutron-openvswi-FORWARD -m physdev --physdev-out tapd260fae5-2d --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT
-A neutron-openvswi-FORWARD -m physdev --physdev-in tapd260fae5-2d --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT
-A neutron-openvswi-INPUT -m physdev --physdev-in tapd260fae5-2d --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT
2.port_security_enabled 在port创建过程中默认为True,若虚拟机关联port中安全组规则为空,则虚拟机进出流量都禁止。
3.如果port中的“allowed_address_pairs”不为空,则需要考虑地址对。检查地址对与底层iptables规则设置是否正确。注意:OpenStack Networking 不允许设置和一个端口的 mac_address 和 ip_address 匹配的 allowed-address-pair。这是因为,匹配 mac_address 和 ip_address 的网络流量已被允许通过这个端口,所以这样的配置不会起任何作用。
举例如下:
-A neutron-openvswi-s18fcd66b-8 -s 192.168.22.4/32 -m mac --mac-source FA:16:3E:0C:3E:DD -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN (考虑地址队)
如果没有设置mac地址,则用Port自身的mac地址
4.远端安全组与ipset处理
举例如下:包括入出的远端安全组
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- src -j RETURN
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- dst -j RETURN
规则中设置了关联远端安全组,且有虚拟机使用该远端安全组,则需要用Ipset集合来包含这些虚拟机网卡ip,设置ipset集合流量入出放行。
5.conntrack虚拟机流量状态与raw表中port相关iptable规则检查
安全组规则存在下,检查与port相关,设置zone的规则是否存在,归属默认检查规则中
举例如下:
iptables -S -t raw
-A neutron-openvswi-PREROUTING -m physdev --physdev-in qvb754ec273-4c -j CT --zone 39
-A neutron-openvswi-PREROUTING -m physdev --physdev-in tap754ec273-4c -j CT --zone 39
5.控制进出虚拟机流量的iptable 规则分析
1.从虚拟机发出的流量
规则如下:
-P INPUT ACCEPT
-A INPUT -j neutron-openvswi-INPUT (-N neutron-openvswi-INPUT)
-A neutron-openvswi-INPUT -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct incoming traffic from VM to the security group chain." -j neutron-openvswi-o18fcd66b-8 (-N neutron-openvswi-o18fcd66b-8)
-A neutron-openvswi-o18fcd66b-8 -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
(该规则必须在下面规则之前,不然没法和dhcp server通信,发送dhcp报文)
-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8 (-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8)
-A neutron-openvswi-s18fcd66b-8 -s 192.168.22.4/32 -m mac --mac-source FA:16:3E:0C:3E:DD -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN (考虑地址队?)
-A neutron-openvswi-s18fcd66b-8 -m comment --comment "Drop traffic without an IP/MAC allow rule." -j DROP
(以上两条规则需在这里,校验从虚拟机发出包信息)
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 67 -m udp --dport 68 -m comment --comment "Prevent DHCP Spoofing by VM." -j DROP
(以上保证默认vm与dhcp通信,并防止vm伪装为dhcpserver)
-A neutron-openvswi-o18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(建立tcp连接,并追踪tcp连接状态)
-A neutron-openvswi-o18fcd66b-8 -p icmp -j RETURN (添加有icmp出放行)
-A neutron-openvswi-o18fcd66b-8 -p tcp -m tcp --dport 22 -j RETURN (添加tcp 22 出口放行)
-A neutron-openvswi-o18fcd66b-8 -j RETURN (添加所有规则放行)
(以上三条规则为用户自定义的规则,默认安全组只有最后一条规则,即出放行)
-A neutron-openvswi-o18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop,放在最后)
-A neutron-openvswi-o18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
-A neutron-openvswi-sg-fallback -m comment --comment "Default drop rule for unmatched traffic." -j DROP
(默认规则,如果没有匹配的规则,默认drop所有出方向的包)
以上有些规则必须存在,且需要按照一定顺序进行插入,否则会导致链路不通,功能异常。
2.进入虚拟机的流量
-P FORWARD ACCEPT
-A FORWARD -j neutron-filter-top
-A neutron-filter-top -j neutron-openvswi-local
-A FORWARD -j neutron-openvswi-FORWARD
-A neutron-openvswi-FORWARD -j neutron-openvswi-scope
-A neutron-openvswi-FORWARD -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-i18fcd66b-8
-----经过qbr bridge转发并通过tap进入虚拟机的包
-A neutron-openvswi-i18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(跟踪tcp 连接状态,接受已经建立的tcp连接)
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.2/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.3/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
(默认允许所有dhcp server流量进入)
-A neutron-openvswi-i18fcd66b-8 -p icmp -j RETURN
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- src -j RETURN
(远端安全组相关)
-A neutron-openvswi-i18fcd66b-8 -p udp -m udp -m multiport --dports 1:65535 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -p tcp -m tcp -m multiport --dports 1:65535 -j RETURN
(以上4条为用户指定的规则)
-A neutron-openvswi-i18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop,放在最后)
-A neutron-openvswi-i18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
-A neutron-openvswi-sg-fallback -m comment --comment "Default drop rule for unmatched traffic." -j DROP
(默认规则,如果没有匹配的规则,默认drop所有出方向的包
3进入tap口,但是只作为转发
-A neutron-openvswi-FORWARD -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-o18fcd66b-8
---匹配虚拟机出去的规则,经过qbr bridge转发经过tap离开虚拟机的包
-A neutron-openvswi-sg-chain -j ACCEPT #接受不经过 qbr bridge的网络包
6.参考
http://www.cnblogs.com/sammyliu/p/4658746.html
http://blog.csdn.net/bc_vnetwork/article/details/51350787
1.根据虚拟机id找到使用的port id。
2.根据port id找到port所在计算节点名字。
3.根据port id找到port所属安全组id。
4.根据安全组id查询对应的安全组规则。
5.Ssh到计算节点,根据port id查询对应的iptables规则。
6.自动分析安全组规则与iptables规则是否一致。
2.client中安全组相关接口
安全组作用范围是在虚拟机上,更具体来说是作用在虚拟机的端口而不是网络上。
neutron-diagnose vm_sg_rule [-h] [-f {json,shell,table,value,yaml}]
[-c COLUMN] [--max-width <integer>]
[--print-empty] [--noindent]
[--prefix PREFIX]
[--port]
<instance>
Instance:默认参数,需输入使用该安全组的虚拟机id,
--port:可选参数,list类型,虚拟机网卡id;如设置为空,则默认检测所有网卡安全组规则。
3.数据提取
0.通过nova interface-list vm-id 查询到该虚拟机所管理的所有port-id,依次判断
1.通过neutron port-show port-id 查询该port的binding:host_id属性,获得该port所在计算节;
2.通过neutron port-show port-id 查询该port的securitsy_groups id.
3.通过neutron security-group-show group-id 查询该安全组的security_group_rules,将该数据存入列表里面,列表里面都是字典类型
4.通过sshclient到步骤1中port所属计算节点,分别查询4个iptable表所属的iptable规则(包括raw mangle filter nat),将规则依次存入列表;最终构建一个字典类型
5.对port关联的数据库中安全组规则和port所在节点安全组规则进行分析。
4.数据比对分析
4.1 分析port所关联的安全组规则设置的合理性,以default安全组为基本依据;
在没有任何安全组规则前提下,虚拟机进出流量默认是禁止的。安全组中添加的规则都是放行的,通过选择性的放行来控制进出虚拟机的。以默认安全组(default)为例,其实现默认放行出虚拟机所有流量,放行入虚拟机的来自于规则中远端安全组的所有流量,保证最基础的虚拟机入出链路连通。
合理性检查如下:
1. 检查虚拟机默认出规则是否存在(目前只考虑iPv4),若默认出规则缺失,则抛出规则检查异常,打印目前出规则信息;若默认出规则存在,则出方向规则正常,跳入检查入规则;
2. 检查虚拟机默认入规则是否存在,若默认入规则缺失,则抛出入规则检查异常,打印目前入规则信息;若默认如规则存在,则入方向规则正常;进一步判断所有入规则中,是否存在放行所有入规则,若有,则提示放行所有入规则;
4.2 分析port所关联的安全组规则设置的一致性
底层规则正确性检查如下:
1.涉及port相关的默认入规则是否添加
具体参考5中的iptables规则分析:进入虚拟机的流量,需要检查的默认规则如下:
-A neutron-openvswi-FORWARD -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-i18fcd66b-8
-----经过qbr bridge转发并通过tap进入虚拟机的包
-A neutron-openvswi-i18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(跟踪tcp 连接状态,接受已经建立的tcp连接)
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.2/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.3/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
(默认允许所有dhcp server流量进入)
-A neutron-openvswi-i18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop,放在最后)
-A neutron-openvswi-i18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
需要考虑存在性和顺序性
2.涉及port相关的默认出规则是否添加
具体参考5中的iptables规则分析:从虚拟机发出的流量,需要检查的默认规则如下:
-A neutron-openvswi-INPUT -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct incoming traffic from VM to the security group chain." -j neutron-openvswi-o18fcd66b-8 (-N neutron-openvswi-o18fcd66b-8)
-A neutron-openvswi-o18fcd66b-8 -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
(该规则必须在下面规则之前,不然没法和dhcp server通信,发送dhcp报文)
-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8 (-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8)
-A neutron-openvswi-s18fcd66b-8 -s 192.168.22.4/32 -m mac --mac-source FA:16:3E:0C:3E:DD -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN (考虑地址队?)
-A neutron-openvswi-s18fcd66b-8 -m comment --comment "Drop traffic without an IP/MAC allow rule." -j DROP
(以上两条规则需在这里,校验从虚拟机发出包信息)
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 67 -m udp --dport 68 -m comment --comment "Prevent DHCP Spoofing by VM." -j DROP
(以上保证默认vm与dhcp通信,并防止vm伪装为dhcpserver)
-A neutron-openvswi-o18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(建立tcp连接,并追踪tcp连接状态)
-A neutron-openvswi-o18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop)
-A neutron-openvswi-o18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
需要考虑存在性和顺序性
3.涉及port相关的默认转发规则是否添加
具体参考5中的iptables规则分析:从qbr网桥的tap口转发的流量,需要检查的默认规则如下:
-A neutron-openvswi-FORWARD -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-o18fcd66b-8
4.检查安全组规则与底层iptable 规则的一致性,安全组规则设置是否成功
比对控制进入虚拟机流量的规则,举例如下:
-A neutron-openvswi-o18fcd66b-8 -p icmp -j RETURN (添加有icmp出放行)
-A neutron-openvswi-o18fcd66b-8 -p tcp -m tcp --dport 22 -j RETURN (添加tcp 22 出口放行)
-A neutron-openvswi-o18fcd66b-8 -j RETURN (添加所有规则放行)
(以上三条规则为用户自定义的规则,默认安全组只有最后一条规则,即出放行)
比对控制从虚拟机发出流量的规则,举例如下:
-A neutron-openvswi-i18fcd66b-8 -p icmp -j RETURN
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- src -j RETURN
(远端安全组相关)
-A neutron-openvswi-i18fcd66b-8 -p udp -m udp -m multiport --dports 1:65535 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -p tcp -m tcp -m multiport --dports 1:65535 -j RETURN
(以上4条为用户指定的规则)
4.3 信息比对中关键点考虑
1.port_security_enabled 在port创建过程中默认为True, 若虚拟机关联的port指定“port_security_enabled”为false,则安全组为空,虚拟机进出流量口控制都放行。
类似如下规则:
-A neutron-openvswi-FORWARD -m physdev --physdev-out tapd260fae5-2d --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT
-A neutron-openvswi-FORWARD -m physdev --physdev-in tapd260fae5-2d --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT
-A neutron-openvswi-INPUT -m physdev --physdev-in tapd260fae5-2d --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT
2.port_security_enabled 在port创建过程中默认为True,若虚拟机关联port中安全组规则为空,则虚拟机进出流量都禁止。
3.如果port中的“allowed_address_pairs”不为空,则需要考虑地址对。检查地址对与底层iptables规则设置是否正确。注意:OpenStack Networking 不允许设置和一个端口的 mac_address 和 ip_address 匹配的 allowed-address-pair。这是因为,匹配 mac_address 和 ip_address 的网络流量已被允许通过这个端口,所以这样的配置不会起任何作用。
举例如下:
-A neutron-openvswi-s18fcd66b-8 -s 192.168.22.4/32 -m mac --mac-source FA:16:3E:0C:3E:DD -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN (考虑地址队)
如果没有设置mac地址,则用Port自身的mac地址
4.远端安全组与ipset处理
举例如下:包括入出的远端安全组
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- src -j RETURN
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- dst -j RETURN
规则中设置了关联远端安全组,且有虚拟机使用该远端安全组,则需要用Ipset集合来包含这些虚拟机网卡ip,设置ipset集合流量入出放行。
5.conntrack虚拟机流量状态与raw表中port相关iptable规则检查
安全组规则存在下,检查与port相关,设置zone的规则是否存在,归属默认检查规则中
举例如下:
iptables -S -t raw
-A neutron-openvswi-PREROUTING -m physdev --physdev-in qvb754ec273-4c -j CT --zone 39
-A neutron-openvswi-PREROUTING -m physdev --physdev-in tap754ec273-4c -j CT --zone 39
5.控制进出虚拟机流量的iptable 规则分析
1.从虚拟机发出的流量
规则如下:
-P INPUT ACCEPT
-A INPUT -j neutron-openvswi-INPUT (-N neutron-openvswi-INPUT)
-A neutron-openvswi-INPUT -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct incoming traffic from VM to the security group chain." -j neutron-openvswi-o18fcd66b-8 (-N neutron-openvswi-o18fcd66b-8)
-A neutron-openvswi-o18fcd66b-8 -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
(该规则必须在下面规则之前,不然没法和dhcp server通信,发送dhcp报文)
-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8 (-A neutron-openvswi-o18fcd66b-8 -j neutron-openvswi-s18fcd66b-8)
-A neutron-openvswi-s18fcd66b-8 -s 192.168.22.4/32 -m mac --mac-source FA:16:3E:0C:3E:DD -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN (考虑地址队?)
-A neutron-openvswi-s18fcd66b-8 -m comment --comment "Drop traffic without an IP/MAC allow rule." -j DROP
(以上两条规则需在这里,校验从虚拟机发出包信息)
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN
-A neutron-openvswi-o18fcd66b-8 -p udp -m udp --sport 67 -m udp --dport 68 -m comment --comment "Prevent DHCP Spoofing by VM." -j DROP
(以上保证默认vm与dhcp通信,并防止vm伪装为dhcpserver)
-A neutron-openvswi-o18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(建立tcp连接,并追踪tcp连接状态)
-A neutron-openvswi-o18fcd66b-8 -p icmp -j RETURN (添加有icmp出放行)
-A neutron-openvswi-o18fcd66b-8 -p tcp -m tcp --dport 22 -j RETURN (添加tcp 22 出口放行)
-A neutron-openvswi-o18fcd66b-8 -j RETURN (添加所有规则放行)
(以上三条规则为用户自定义的规则,默认安全组只有最后一条规则,即出放行)
-A neutron-openvswi-o18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop,放在最后)
-A neutron-openvswi-o18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
-A neutron-openvswi-sg-fallback -m comment --comment "Default drop rule for unmatched traffic." -j DROP
(默认规则,如果没有匹配的规则,默认drop所有出方向的包)
以上有些规则必须存在,且需要按照一定顺序进行插入,否则会导致链路不通,功能异常。
2.进入虚拟机的流量
-P FORWARD ACCEPT
-A FORWARD -j neutron-filter-top
-A neutron-filter-top -j neutron-openvswi-local
-A FORWARD -j neutron-openvswi-FORWARD
-A neutron-openvswi-FORWARD -j neutron-openvswi-scope
-A neutron-openvswi-FORWARD -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-out tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-i18fcd66b-8
-----经过qbr bridge转发并通过tap进入虚拟机的包
-A neutron-openvswi-i18fcd66b-8 -m state --state RELATED,ESTABLISHED -m comment --comment "Direct packets associated with a known session to the RETURN chain." -j RETURN
(跟踪tcp 连接状态,接受已经建立的tcp连接)
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.2/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -s 192.168.22.3/32 -p udp -m udp --sport 67 -m udp --dport 68 -j RETURN
(默认允许所有dhcp server流量进入)
-A neutron-openvswi-i18fcd66b-8 -p icmp -j RETURN
-A neutron-openvswi-i18fcd66b-8 -m set --match-set NIPv4df7f6879-6040-4493-b59b- src -j RETURN
(远端安全组相关)
-A neutron-openvswi-i18fcd66b-8 -p udp -m udp -m multiport --dports 1:65535 -j RETURN
-A neutron-openvswi-i18fcd66b-8 -p tcp -m tcp -m multiport --dports 1:65535 -j RETURN
(以上4条为用户指定的规则)
-A neutron-openvswi-i18fcd66b-8 -m state --state INVALID -m comment --comment "Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack." -j DROP
(默认规则,tcp状态无效的要drop,放在最后)
-A neutron-openvswi-i18fcd66b-8 -m comment --comment "Send unmatched traffic to the fallback chain." -j neutron-openvswi-sg-fallback
-A neutron-openvswi-sg-fallback -m comment --comment "Default drop rule for unmatched traffic." -j DROP
(默认规则,如果没有匹配的规则,默认drop所有出方向的包
3进入tap口,但是只作为转发
-A neutron-openvswi-FORWARD -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Direct traffic from the VM interface to the security group chain." -j neutron-openvswi-sg-chain
-A neutron-openvswi-sg-chain -m physdev --physdev-in tap18fcd66b-80 --physdev-is-bridged -m comment --comment "Jump to the VM specific chain." -j neutron-openvswi-o18fcd66b-8
---匹配虚拟机出去的规则,经过qbr bridge转发经过tap离开虚拟机的包
-A neutron-openvswi-sg-chain -j ACCEPT #接受不经过 qbr bridge的网络包
6.参考
http://www.cnblogs.com/sammyliu/p/4658746.html
http://blog.csdn.net/bc_vnetwork/article/details/51350787
0 0
- neutron安全组功能点梳理总结
- neutron安全组
- Neutron 默认安全组规则
- Neutron 默认安全组规则
- 安全测试常用功能点
- coralsdk功能点总结~~
- OpenStack RDO 部署流程 - 4(Neutron安全组)
- neutron的安全组规则不生效的原因
- neutron的安全组规则不生效的原因
- opstack-neutron 安全组 博主其他文章也不错
- 带着问题了解Openstack Neutron安全组
- neutron-server分页功能
- Neutron 功能概述
- Windows 7的安全功能大盘点
- APP测试功能点总结
- APP测试功能点总结
- APP测试功能点总结
- APP测试功能点总结
- 使用java理解程序逻辑第八章
- 21
- createQuery is not valid without active transaction
- 递推递归练习 O
- ListView学习笔记
- neutron安全组功能点梳理总结
- Andrew Ng机器学习课程笔记
- php实现数据结构线性表(链式)
- 类和对象
- Blogs Links
- linux内核不发(Router Solicit)RS报文问题
- POJ
- URAL
- Opencv学习---霍夫变换检测圆的基本原理