立即注册 登录
About云-梭伦科技 返回首页

langke93的个人空间 https://www.aboutyun.com/?1415 [收藏] [复制] [分享] [RSS]

日志

如何设置port_security_enabled为False

已有 4637 次阅读2017-5-27 15:22 | False, 如何

一.什么是Port Security


Kilo 版本之前,对整个云要么禁止安全组要么使用安全组。从 Kilo 版本开始,可以使用新的属性 port-security-enabled 来启用或者禁用某个虚拟机端口上的安全组了。这个新的属性目 前被 Open vSwitch agent 和 IptablesFirewallDriver 支持。


Port Security 提供了一个新的参数port_security_enabled给network和port,其默认值为True,可以应用安全组、自动应用anti-spoof规则,当port的port_security_enabled被设置为 False时,这个port将无法设置和应用安全组,anti-spoof会被关闭,allowed address pair也将无法设置。因为这个属性与安全相关,所以只有网络的owner可以设置这个值。


当给一个网络的port_security_enabled设置为False时,这意味着该网络下建立的port都将默认应用False 的port_security_enabled。


实现概述


其原理很简单,我们知道 Neutron 的安全组被应用在了 qbrxxx 的 Linux 网桥设备中,不同的 driver 可能有所不同,这里均已默认的 neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver为例说明。 我们一共有四条 iptables 链实现 neutron 的安全组和anti-spoof:


sg-chain:安全组的父链,内容为跳转到各个子链

e-xxx:过滤 egress 流量

i-xxx:过滤 ingress 流量

s-xxx:anti-spoof规则(该 规则 基于iptables  保证虚拟机只能发出/接受以它为原地址或目的地址(IP & MAC)的流量 )

Neutron中的port_security_enabled参数,一般我们很少去注意到它。此次花些时间去捣鼓它,源自需要在OpenStack环境上创建和使用一台虚拟机,能够去PXE同网段的物理机,但实践却很 不成功,经过讨论,技术经理发现是port_security_enabled参数的启用导致过滤掉了物理机获取DHCP响应和xftp回复。接下来,我便开始了将port_security_enabled设置为False的旅程。


二.针对单个虚拟机VM


1、查看当前有哪些虚拟机及其IP


# nova list 

+--------------------------------------+----------+--------+------------+-------------+--------------------+

| ID                                   | Name     | Status | Task State | Power State | Networks           |

+--------------------------------------+----------+--------+------------+-------------+--------------------+

| c9ac16e5-5231-48cd-bd23-e2fb01ed6ac6 | Cobbler1 | ACTIVE | -          | Running     | flat=172.16.74.154 |

| fcee7bb7-8098-4ab0-a0f9-0026f8d00596 | chz_1    | ACTIVE | -          | Running     | flat=172.16.74.159 |

| 64f936f8-4e95-44c5-9428-73462d6616af | vm6      | ACTIVE | -          | Running     | flat=172.16.74.158 |

| 204bcd16-a450-4397-9f3c-89120a01e63e | vm_scalr | ACTIVE | -          | Running     | flat=172.16.74.152 |

+--------------------------------------+----------+--------+------------+-------------+--------------------+

2、这里,我查看IP地址为172.16.74.154的虚拟机Port


# neutron port-list| grep 172.16.74.154

| d0e955b6-e526-4ea0-9b31-c69a2516345f |      | fa:16:3e:b7:1c:7c | {"subnet_id": "465486d4-91ce-4ecb-bebe-2e5c4577c968", "ip_address": "172.16.74.154"} |

3、查看该虚拟机的port_security_enabled参数值,这里显示为True,意思为已启用


# neutron port-show d0e955b6-e526-4ea0-9b31-c69a2516345f | grep 'mac\|port_security'

| mac_address           | fa:16:3e:b7:1c:7c                                                                                               |

| port_security_enabled | True

4、我们希望的结果,当然是要关闭这个参数咯。在关闭之前,首先需要删除这个虚拟机的安全组


# neutron port-update --no-security-groups d0e955b6-e526-4ea0-9b31-c69a2516345f

Updated port: d0e955b6-e526-4ea0-9b31-c69a2516345f

5、现在,开始关闭这个参数,设置为False


# neutron port-update d0e955b6-e526-4ea0-9b31-c69a2516345f --port-security-enabled=False

Updated port: d0e955b6-e526-4ea0-9b31-c69a2516345f

6、验证,该虚拟机的port_security_enabled参数是否已经设置为了False


# neutron port-show d0e955b6-e526-4ea0-9b31-c69a2516345f | grep 'port_security'

| port_security_enabled | False

7、现在,我们可以看到port security已经被禁用了。现在,就去计算节点上检查这个端口的iptables规则吧


# iptables-save | grep d0e955b6

-A neutron-openvswi-FORWARD -m physdev --physdev-out tapd0e955b6-e5 --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT

-A neutron-openvswi-FORWARD -m physdev --physdev-in tapd0e955b6-e5 --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT

-A neutron-openvswi-INPUT -m physdev --physdev-in tapd0e955b6-e5 --physdev-is-bridged -m comment --comment "Accept all packets when port security is disabled." -j ACCEPT

OK,现在所有防止诸如ARP欺骗的规则都消失了,而只有“Accept all”规则了。


三.针对一个网络


由于在创建虚拟机(nova boot xxxxx)时,Neutron会给VM强制指定Security Group,所以,当创建的虚拟机使用设置port_security_enabled为False的网络时(使用此网络创建VM,会删除安全 组),会因为冲突而导致创建VM失败。因此,目前还不支持使用设置port_security_enabled为False的网络创建虚拟机。


四.小结


从某种角度而言,嗯,看得出来,社区对运行在OpenStack上的VM安全重视和投入程度还是很高的。至此,设置port_security_enabled参数为False的旅程,圆满结束。

  

来自:

http://1.chaoxu.sinaapp.com/archives/3905


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

推荐上一条 /2 下一条