[连载型] Neutron 系列 (15): OpenStack 是如何实现 Neutron 网络 和 Nova虚机 防火墙的...

问题导读:




1.Nova安全组是什么?
2.Nova的是如何配置的?
3.FWaas是什么?









1. Nova 安全组

1.1 配置

节点配置文件配置项说明
controller/etc/nova/nova.confsecurity_group_api = nova是的 nova secgroup* 命令使用的是 nova 安全组的 API
/etc/neutron/plugins/ml2/ml2_conf.inienable_security_group = False禁止 Neutron 安全组
nova-compute
/etc/nova/nova.conf
/etc/nova/nova-compute.conf
firewall_driver = nova.virt.firewall.IptablesFirewallDriver指定 Nova 安全组的驱动,可以是IptablesFirewallDriver 或者 NWFilterFirewall。默认是 IptablesFirewallDriver。见下面的说明。
 /etc/neutron/plugins/ml2/ml2_conf.inienable_security_group = False禁止 Neutron 安全组
network/etc/neutron/plugins/ml2/ml2_conf.inienable_security_group = False禁止 Neutron 安全组

 

nova 提供两种实现方式:使用 libvirt's nwfilter 的实现以及使用 linux iptables 的实现,默认的方式是使用 linux iptables。可以通过设置配置项  firewall_driver 的值指定。需要注意的是,即使使用 iptables,依然使用了部分 nwfilter 功能。参见

 

https://ask.openstack.org/en/question/19456/how-security-group-is-implemented/

 

  • firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver
  • firewall_driver=nova.virt.libvirt.firewall.NWFilterFirewall


1.2 CLI

[AppleScript] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
列表安全组:
s1@controller:~$ nova secgroup-list-rules novasg1
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range  | Source Group |
+-------------+-----------+---------+-----------+--------------+
| tcp         | 22        | 22      | 0.0.0.0/0 |              |
+-------------+-----------+---------+-----------+--------------+
创建一个安全组规则:
s1@controller:~$ nova secgroup-add-rule novasg1 udp 53 53 100.1.100.0/24
+-------------+-----------+---------+----------------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+----------------+--------------+
| udp | 53 | 53 | 100.1.100.0/24 | |
+-------------+-----------+---------+----------------+--------------+
删除虚机的安全组:
s1@controller:~$ nova remove-secgroup 2c59a875-bc23-4605-ad70-5315d7a3f8e2 novasg1
添加安全组到虚机:
s1@controller:~$ nova add-secgroup 2c59a875-bc23-4605-ad70-5315d7a3f8e2 novasg1
创建第二个安全组:
s1@controller:~$ nova secgroup-add-rule novasg2
添加规则:
s1@controller:~$ nova secgroup-add-rule novasg2 icmp -1 -1 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-----------+--------------+
| icmp | -1 | -1 | 0.0.0.0/0 | |
+-------------+-----------+---------+-----------+--------------+
再添加安全组到虚机:
s1@controller:~$ nova add-secgroup 2c59a875-bc23-4605-ad70-5315d7a3f8e2 novasg2



1.3 iptables 链

Nova-compute 增加了 filter 表的 INPUT,OUTPUT 和 FORWARD 链:

 

<ignore_js_op>

 

[AppleScript] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-N nova-compute-FORWARD
-N nova-compute-INPUT
-N nova-compute-OUTPUT
-N nova-compute-inst-122 #每个虚机一个链,命名规则是 ”inst“-<instance 在数据库中的 id>
-N nova-compute-local
-N nova-compute-provider
-N nova-compute-sg-fallback
-N nova-filter-top
-A INPUT -j nova-compute-INPUT
-A FORWARD -j nova-filter-top
-A FORWARD -j nova-compute-FORWARD
-A OUTPUT -j nova-filter-top
-A OUTPUT -j nova-compute-OUTPUT
-A nova-compute-FORWARD -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -j ACCEPT #允许本机上的虚机发出 DHCP 广播
-A nova-compute-INPUT -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -j ACCEPT  #允许本机接受 DHCP 广播包
-A nova-compute-inst-122 -m state --state INVALID -j DROP
-A nova-compute-inst-122 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A nova-compute-inst-122 -j nova-compute-provider
-A nova-compute-inst-122 -s 91.1.180.2/32 -p udp -m udp --sport 67 --dport 68 -j ACCEPT #接受该虚机所在子网的 DHCP Server 返回的包
-A nova-compute-inst-122 -s 91.1.180.0/24 -j ACCEPT                                     #在配置项 allow_same_net_traffic = true 的情况下接受同网段虚机的来访包
-A nova-compute-inst-122 -p tcp -m tcp --dport 22 -j ACCEPT                             #用户安全组规则指定的来访包
-A nova-compute-inst-122 -s 100.1.100.0/24 -p udp -m udp --dport 53 -j ACCEPT           #用户安全组规则指定的来访包
-A nova-compute-inst-122 -p icmp -j ACCEPT                                              #用户安全组规则指定的来防爆
-A nova-compute-inst-122 -j nova-compute-sg-fallback                                    #没被上面规则处理的其它来访包
-A nova-compute-local -d 91.1.180.14/32 -j nova-compute-inst-122                        # “-d“ 决定了 nova 安全组只检查进入虚机的网络包
-A nova-compute-sg-fallback -j DROP                                                     #丢弃其它包,只允许上述规则指定的网络访问
-A nova-filter-top -j nova-compute-local



2. FWaas

2.1 概念

从 Havana 版本开始,Neutron 提供一种基于 Neutron L3 Agent 的一种网络四层防火墙虚拟化参考实现 Firewall-as-a-service,简称 FWaas。本文的分析是基于 OpenStack Juno 版本进行的。Juno 版本中,FWaas 是分租户的,但是可以在多个租户之间共享。每个租户只允许一个防火墙。与物理的防火墙类似,FWaas 也有三个主要概念:

 

(1)规则(Rule):允许用户指定所要匹配的名称,描述,针对的协议(TCP, UDP, ICMP, ANY),行为(Allow,Deny),源/目的 IP 地址/子网 和 端口号/端口号区间。

 

<ignore_js_op>

 

与 neutron 安全组中的规则的区别是,这里需要指定被匹配到的数据包的处理行为是通过(ALLOW)和不通过(DENY),但是不能指定网络方向。FWaas 会将规则同时应用到进出网络的网络包上。

 

(2)策略(Policy):规则的逻辑集合。Policy 可以是共享的 和 被审计的(Audited)。目前,FWaas 只是把 “audited” 保存到 DB 中,并没有对它做任何处理。

 

<ignore_js_op>

 

(3)防火墙(Firewall):策略的逻辑集合。见上面右图。Juno 版本中,每个租户只能拥有最多一个 Firewall。防火墙可以是共享的。

 

这里需要说明的是 FWaas 和 Security Group (安全组) 的区别。安全组规则在连接到一个实例的计算节点上的Linux桥 qbr 上实施,FWaaS 创建的防火墙规则在租户网络边缘实现的虚拟路由器上实施。 FWaaS 并不旨在取代安全组的功能,并且它提供更为补充安全组,特别是在其当前实现状态下。 FWaaS 目前缺乏安全组提供的一些功能,包括无法指定通信的方向等。与此相反,安全组,也因为他们缺乏创建特定规则拒绝所有流量的能力,因此需要 FWaas 作为补充。


2.2 配置

节点配置和操作
控制节点上修改 /etc/neutron/neutron.conf:
[default]
service_plugins = router,lbaas,firewall
[service_providers]
service_provider = FIREWALL:Iptables:neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver:default

service neutron-server restart

修改 /usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py:'enable_firewall': True
网络节点上修改 /etc/neutron/fwaas_driver.ini:
[fwaas]
driver = neutron.services.firewall.drivers.linux.iptables_fwaas.IptablesFwaasDriver
enabled = True

service neutron-l3-agent restart


2.3 实现

目前的实现中,FWaas 是通过在其所在 tenant 中的所有 Virtual Router 上添加 iptbales 规则来实现对进出数据网络的网络包进行控制的。

 

代码实现:

 

控制节点上(class FirewallPlugin):

 

(1)create rule:纯数据库操作,将 rule 保存到数据中。
(2)create policy:纯数据库操作,将 policy 保存到数据中。
(3)如果将 rule 添加到一个已经添加到 firwall 的 policy,或者将一个 policy 加入一个存在的 firewall,在数据库操作后,通过 RPC fanout 到所有的 L3 Agent host:

 

{'args': {'firewall': {'status': 'PENDING_UPDATE', 'name': u'fw-for-tcp', 'shared': None, 'firewall_policy_id': u'd14e23a3-2ee6-411d-b678-e6db3dac45f5', 'tenant_id': u'74c8ada23a3449f888d9e19b76d13aab', 'admin_state_up': True, 'id': u'aa85bd66-dc4c-4d1b-909e-6f5736c279c7', 'firewall_rule_list': [{'protocol': u'icmp', 'description': u'', 'source_port': None, 'source_ip_address': None, 'destination_ip_address': None, 'firewall_policy_id': u'd14e23a3-2ee6-411d-b678-e6db3dac45f5', 'position': 1, 'destination_port': None, 'id': u'8658229d-6e34-4069-b091-e560f9e54dc9', 'name': u'rule-allow-icmp', 'tenant_id': u'74c8ada23a3449f888d9e19b76d13aab', 'enabled': True, 'action': u'allow', 'ip_version': 4L, 'shared': False}, {'protocol': u'tcp', 'description': u'', 'source_port': None, 'source_ip_address': None, 'destination_ip_address': None, 'firewall_policy_id': u'd14e23a3-2ee6-411d-b678-e6db3dac45f5', 'position': 2, 'destination_port': '80', 'id': u'00b5bad2-dd14-48d6-9a5c-7b65e6e8c480', 'name': u'fule-allow-tcp-80', 'tenant_id': u'74c8ada23a3449f888d9e19b76d13aab', 'enabled': True, 'action': u'allow', 'ip_version': 4L, 'shared': False}], 'description': u''}, 'host': 'controller'}, 'namespace': None, 'method': 'update_firewall'}

 

  • insert_rule/remove_rule/update_firewall_rule/update_firewall_policy -> Firewall_db_mixin.insert_rule/remove_rule/update_firewall_rule/update_firewall_policy -> _rpc_update_firewall_policy -> _rpc_update_firewall -> (if policy has a firewall) FirewallAgentApi.update_firewall
  • create_firewall -> Firewall_db_mixin.create_firewall -> FirewallAgentApi.create_firewall
  • update_firewall -> Firewall_db_mixin.update_firewall -> FirewallAgentApi.update_firewall
  • delete_firewall -> Firewall_db_mixin.delete_firewall -> FirewallAgentApi.delete_firewall
  • FirewallAgentApi.create/update/delete_firewall -> fanout_cast ("create/update/delete_firewall", topics.L3_AGENT, "controller", firewall) -----> FWaaSL3AgentRpcCallback.create/update/delete_firewall -> FWaaSL3AgentRpcCallback._invoke_driver_for_plugin_api

 

网络节点上(class FWaaSL3AgentRpcCallback):

 

(1) 通过 RPC 获取所有的 router,在获取firewall 所在的 tenant 上的 routers
(2)调用 IptablesFwaasDriver.update_firewall,依次更新每个 router 的 iptables 规则
(3)首先删除已有规则,然后根据配置的 rules 重新生成规则

 

[AppleScript] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
root@network:/var/cache# ip netns exec qrouter-e438bebe-6795-4b68-a613-ec0df38d3064 iptables -t filter -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N neutron-filter-top
-N neutron-l3-agent-FORWARD
-N neutron-l3-agent-INPUT
-N neutron-l3-agent-OUTPUT
-N neutron-l3-agent-fwaas-defau #新增的 firewall chain
-N neutron-l3-agent-iv4aa85bd66 #新增的 firewall chain
-N neutron-l3-agent-local
-N neutron-l3-agent-ov4aa85bd66 #for firewall
-A INPUT -j neutron-l3-agent-INPUT
-A FORWARD -j neutron-filter-top
-A FORWARD -j neutron-l3-agent-FORWARD #将 forward 转到 neutron 的chain
-A OUTPUT -j neutron-filter-top
-A OUTPUT -j neutron-l3-agent-OUTPUT
-A neutron-filter-top -j neutron-l3-agent-local
-A neutron-l3-agent-FORWARD -o qr-+ -j neutron-l3-agent-iv4aa85bd66 #进数据网络的包
-A neutron-l3-agent-FORWARD -i qr-+ -j neutron-l3-agent-ov4aa85bd66 #出数据网络的包
-A neutron-l3-agent-FORWARD -o qr-+ -j neutron-l3-agent-fwaas-defau #进数据网络的包的默认处理 chain
-A neutron-l3-agent-FORWARD -i qr-+ -j neutron-l3-agent-fwaas-defau #出数据网络的包的默认处理 chain
-A neutron-l3-agent-INPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 9697 -j ACCEPT
-A neutron-l3-agent-fwaas-defau -j DROP                             #默认丢弃没有被以上规则处理的所有包
-A neutron-l3-agent-iv4aa85bd66 -m state --state INVALID -j DROP
-A neutron-l3-agent-iv4aa85bd66 -m state --state RELATED,ESTABLISHED -j ACCEPT #接受状态为 RELATED, ESTABLISHED (已建立的连接)的包
-A neutron-l3-agent-iv4aa85bd66 -p tcp -m tcp --dport 80 -j ACCEPT             #根据定义的 FWaas rule,接受目的端口为 80 的 tcp 包
-A neutron-l3-agent-ov4aa85bd66 -m state --state INVALID -j DROP
-A neutron-l3-agent-ov4aa85bd66 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A neutron-l3-agent-ov4aa85bd66 -p tcp -m tcp --dport 80 -j ACCEPT             #根据 FWaas rule,接收目的端口为 80 的 tcp 包

转载于:https://www.cnblogs.com/liuhongru/p/11098379.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/569268.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux命令笔记

alias 查看或设置别名。 ualias 取消别名。 mkdir -p 创建目录及子目录。 vi/vim 编辑器。 seq -s 生成数字序列。 yum 解决linux下包管理工具rpm的安装软件依赖问题&#xff0c;例如&#xff1a;yum install lrzsz -y。 cp -apr 拷贝文件或目录。 tree -Ld打印目录结构…

LeetCode题解

题目是这样的&#xff1a;一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为“Start” &#xff09;。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#xff08;在下图中标记为“Finish”&#xff09;。问总共有多少条不同的路径&a…

Mysql的执行顺序与优化分析

编写顺序与执行顺序分析 一条完整的sql语句编写流程应该如下&#xff1a; select distinct 查询字段 from 表名 JOIN 表名 ON 连接条件 where 查询条件 group by 分组字段 having 分组后条件 order by 排序条件 limit 查询起始位置, 查询条数 但是在mysql实…

java获得指定的开始时间与结束时间之间的所有日期

import java.text.SimpleDateFormat; import java.util.Calendar;public class TimerTest {public static void main(String[] args) throws Exception {String beginDate "2016-07-16";//开始时间String endDate "2016-07-25";//结束时间SimpleDateForm…

linux中umask的使用

在linux创建文件、文件夹的时候会给它们赋予默认的权限&#xff0c;这个默认权限的赋予就是和umask相关的。总结如下&#xff1a; 1&#xff1a;x 执行 2&#xff1a;w 写入 4&#xff1a;r 读取 文件创建的时候的权限为 666与umask的每一位对应相减&#xff1b;如 umask 为…

jieba中文分词源码分析(四)

一、未登录词问题在jieba中文分词的第一节曾提到未登录词问题 中文分词的难点 分词规范&#xff0c;词的定义还不明确 (《统计自然语言处理》宗成庆)歧义切分问题&#xff0c;交集型切分问题&#xff0c;多义组合型切分歧义等 结婚的和尚未结婚的 > 结婚&#xff0f;的&…

hadoop2.4.2集群搭建及hive与mysql集成文档记录

1.修改Linux主机名2.修改IP3.修改主机名和IP的映射关系######注意######如果你们公司是租用的服务器或是使用的云主机&#xff08;如华为用主机、阿里云主机等&#xff09;/etc/hosts里面要配置的是内网IP地址和主机名的映射关系4.关闭防火墙5.ssh免登陆6.安装JDK&#xff0c;配…

mybatis使用过程遇到的一些问题及解决方法

1.传入string单个参数进行判断是 要使用 <if test"_parameter ! null"></if> 2.mybatis批量插入 <insert id"insertSerily" parameterType"java.util.List"> insert into sys_role_resource (id, role_id, resource_id ) valu…

spring boot 与redis 整合

创建项目时需要导入的包 在application.yml 配置文件中配置需要的 spring:datasource:url: jdbc:mysql://localhost:3306/数据库名?useSSLfalse&serverTimezoneAsia/Shanghaiusername: 用户名password: 密码jpa:show-sql: truehibernate:ddl-auto: none #redis 可以不配,默…

Http长连接的例子_亲测可用哦

一、什么事Http长连接&#xff1a;在网上有很多很多关于Http长连接的文章&#xff0c;但是我看了很多都看不懂。自己总结的所谓的http长连接就是在一请求一个页面后&#xff0c;在服务器端不断开http连接&#xff0c;而是通过response一直在定时的往页面客户端刷新数据。 二、s…

不同操作系统上DNS客户端操作区别汇总

结论&#xff1a;windows有DNS缓存&#xff0c;Linux默认无DNS缓存&#xff0c;只能依赖于安装其他软件。 一、不同操作系统的客户端的DNS缓存差别 1、windows 系统中dns 解析器会使用系统的dns缓存来提高dns域名解析效率。 例如&#xff1a; 查看当前的dns cache内容&#xff…

SLAM学习心得——建图

1.建图 我们所谓的地图&#xff0c;即所有路标点的集合。一旦我们确定了路标点的位置&#xff0c;那就可以说我们完成了建图。 地图的作用&#xff1a;&#xff08;1&#xff09;定位 &#xff1b;&#xff08;2&#xff09;导航&#xff1b; &#xff08;3&#xff09;避障&am…

spark2

特点 通用 批处理 迭代式计算 交互查询 流处理 组件 spark core:任务调度 内存管理 容错机制 内部定义了RDDs 提供了很多API &#xff0c;为其他组件提供底层的服务 spark sql&#xff1a;报表统计 streaming :从kafka接收数据做实时统计 mlib&#xff1a;mll 支持横向扩展&am…

Oracle数据库----视图

--创建简单视图--建立用于查询员工号、姓名、工资的视图。create view emp_viewasselect empno,ename,sal from emp; --查询视图select * from emp_view; --创建视图时指定视图的列的别名create view emp_view2(员工号,姓名,工资)asselect empno,ename,sal from emp; --查询视图…

flume通过tcp/udp采集数据并存到kafka配置及操作方式

/*官方提供的kafka sink*/a1.sinks.k1.channel c1a1.sinks.k1.type org.apache.flume.sink.kafka.KafkaSinka1.sinks.k1.kafka.topic mytopica1.sinks.k1.kafka.bootstrap.servers localhost:9092a1.sinks.k1.kafka.flumeBatchSize 20a1.sinks.k1.kafka.producer.acks 1a…

一、免费API调用

一、免费API调用&#xff1a; 免费天气api接口 JS调用示例 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"utf-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"…

spark 监控--WebUi、Metrics System(转载)

转载自&#xff1a;https://www.cnblogs.com/barrenlake/p/4364644.html Spark 监控相关的部分有WebUi 及 Metrics System; WebUi用于展示Spark 资源状态、Metrics System 整合的指标信息。 Ui相关流程 Spark集群启动之后&#xff0c;我们可以通过Web观察集群状态等信息&#x…

js中使用shiro标签的一个小坑

在jsp页面中使用shiro标签很简单 <shiro:haspermission name"你的权限"> 你的标签 </shiro:haspermission> 这样就可以把标签加上权限了。 但是有时候你的标签是js动态生成的&#xff0c;就像下面的例子&#xff1a; <script type"text/java…

求1-100数字的和

function sum_all(){var result 0;for(var i0;i<100;i){resultresulti;}return result; } var s sum_all(100); console.log(s);// while循环 function sum_all(){var result 0;var i0;while(i<100){i;resultresulti;}return result; } //do while语句 function sum_al…

微信开发--自定义菜单

一、定义几个实体类 public class AccessToken {//这里定义一个AccessToken的实体类&#xff0c;用来保存获取到的accesstokenprivate String token;//获得到的tokenprivate int expireIn;//过期时间public String getToken() {return token;}public void setToken(String toke…