本文档提供了一个步骤指南,描述在Open Virtual Network (OVN)中使用IPSec加密隧道流量。OVN隧道流量由物理路由器和交换机传输。这些物理设备可能不受信任(公共网络中的设备)或可能受到危害。为隧道流量启用IPSec加密可以阻止流量数据被监控和操纵。有关OVN IPsec设计的更多详细信息,请参见ovn-architecture
(7)手册页。
本文档假设OVN安装在你的系统中并且运行正常。并且,你需要在每个机框中安装OVS IPsec软件包(请参阅:install-ovs-ipsec
)。
生成证书和密钥
在创建IPSec隧道时,OVN机框使用CA签名证书对对等机框进行身份验证。如果在OVN中启用了基于角色的访问控制(RBAC),你可以使用RBAC SSL的证书和密钥来设置OVN IPsec。或者你可以使用ovs-pki
生成单独的证书和密钥(请参阅:gen certs keys
)。
注意:
OVN IPsec需要x.509 version 3格式的证书,并且subjectAltname DNS字段设置与公用名(CN)字段要使用相同的字符串。CN应设置为机框名称。Open vSwitch 2.10.90或之后版本中的ovs-pki
可生成此类证书。如果你使用其它的PKI工具或旧版本的ovs-pki
,确保生成兼容的证书。
配置OVN IPSec
你需要在每个机框中安装CA证书、机框证书和私钥。使用以下命令:
$ ovs-vsctl set Open_vSwitch . \
other_config:certificate=/path/to/chassis-cert.pem \
other_config:private_key=/path/to/chassis-privkey.pem \
other_config:ca_cert=/path/to/cacert.pem
使能 OVN IPsec
要使能OVN IPSec,设置北向数据库中的NB_Global
表的ipsec
列为true:
$ ovn-nbctl set nb_global . ipsec=true
OVN IPSec使能以后,OVN中的所有隧道流量都将使用IPSec加密。禁用的话,设置北向数据库中的NB_Global
表的ipsec
列为false:
$ ovn-nbctl set nb_global . ipsec=false
排错
每个机框上的守护进程ovs-monitor-ipsec
管理和监控IPSec隧道的状态。使用以下的ovs-appctl
命令,查看ovs-monitor-ipsec
进程内部展示的隧道配置:
$ ovs-appctl -t ovs-monitor-ipsec tunnels/show
如果有配置不当,ovs-appctl
应显示原因,例如:
Interface name: ovn-host_2-0 v1 (CONFIGURED) <--- 应设置为 CONFIGURED. 否则, 将显示错误信息
Tunnel Type: geneve
Remote IP: 2.2.2.2
SKB mark: None
Local cert: /path/to/chassis-cert.pem
Local name: host_1
Local key: /path/to/chassis-privkey.pem
Remote cert: None
Remote name: host_2
CA cert: /path/to/cacert.pem
PSK: None
Ofport: 2 <--- ovs-vswitchd进程是否分配了Ofport数字到此Tunnel Port
CFM state: Disabled <--- CFM表明此隧道是否健康
Kernel policies installed:
... <--- Strongswan安装到Linux Kernel中的OVS隧道使用的IPsec策略
Kernel security associations installed:
... <--- Strongswan安装到Linux Kernel中的OVS隧道相关的IPsec安全关联security associations
IPsec connections that are active:
... <--- IPsec "connections" for this OVS tunnel
如果以上显示中没有任何活动的connection,尝试一下的命令刷新ovs-monitor-ipsec
进程:
$ ovs-appctl -t ovs-monitor-ipsec refresh
你也可检查ovs-monitor-ipsec
进程和IKE进程的日志信息,以发现问题。ovs-monitor-ipsec
的日志信息写入文件/var/log/openvswitch/ovs-monitor-ipsec.log
.