在glusterfs存储中启用TLS/SSL加密
【介绍】
为了提高访问glusterfs存储的安全性,可以利用openssl加密数据实现传输层安全(TLS Transport Layer Security)。
Glustefs有两种加密方式:
IO加密: 客户端和服务器连接的时候进行加密
Management加密:一个存储池里所有服务器及客户端之间的通信进行加密。
Glusterfs加密涉及到三个文件:
/etc/ssl/glusterfs.pem
节点所需要的证书,必须是唯一的,不能在多节点之间不能相同。
/etc/ssl/glusterfs.key
节点所需要的私钥,在每个节点上创建,必须是独立的,不能再多节点之间不能相同。
/etc/ssl/glusterfs.ca
所有节点之间通信用的证书,在所有服务器节点上必须是相同的,所有客户端节点的CA证书可以和服务器的CA不一样,但是必须要包含所有服务器CA公钥的内容。
/var/lib/glusterd/secure-access
在每个节点上创建,用来启用management加密。
【实验环境】
主机名 |
IP |
系统 |
角色 |
s1 |
192.168.26.201 |
RHEL7.2 |
服务器 |
s2 |
192.168.26.202 |
RHEL7.2 |
服务器 |
s3 |
192.168.26.203 |
RHEL7.2 |
客户端 |
s4 |
192.168.26.204 |
RHEL7.2 |
客户端 |
【实验步骤】
关闭每个机器上的防火墙,编辑好/etc/hosts
[root@sX ~]# firewall-cmd --set-default-zone=trusted
success
[root@sX ~]#
[root@sX ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.26.201 s1
192.168.26.202 s2
192.168.26.203 s3
192.168.26.204 s4
在每个节点上创建私钥:
[root@sX ~]# openssl genrsa -out /etc/ssl/glusterfs.key 2048
Generating RSA private key, 2048 bit long modulus
..........................+++
................................................................................+++
e is 65537 (0x10001)
[root@sX ~]#
在每个节点上创建自签名的证书
[root@sX ~]# cd /etc/ssl/
[root@sX ssl]# openssl req -new -x509 -key glusterfs.key -subj "/CN=sX" -out glusterfs.pem
[root@sX ssl]#
注意-subj “/CN=sX”这里的sX要保持和/etc/hosts里的值相同。
创建CA,在s1上操作
[root@s1 ssl]# pwd
/etc/ssl
[root@s1 ssl]# scp s2:/etc/ssl/glusterfs.pem ca/s2
glusterfs.pem 100% 1074 1.1KB/s 00:00
[root@s1 ssl]# scp s3:/etc/ssl/glusterfs.pem ca/s3
root@s3's password:
glusterfs.pem 100% 1074 1.1KB/s 00:00
[root@s1 ssl]# scp s4:/etc/ssl/glusterfs.pem ca/s4
root@s4's password:
glusterfs.pem 100% 1074 1.1KB/s 00:00
[root@s1 ssl]#
[root@s1 ssl]# cat glusterfs.pem ca/s2 ca/s3 ca/s4 > glusterfs.ca
[root@s1 ssl]# cat glusterfs.pem ca/s2 > client.ca
[root@s1 ssl]#
[root@s1 ssl]#
然后拷贝到各个节点
[root@s1 ssl]#
[root@s1 ssl]# scp glusterfs.ca s2:/etc/ssl/
glusterfs.ca 100% 4296 4.2KB/s 00:00
[root@s1 ssl]# scp client.ca s3:/etc/ssl/glusterfs.ca
root@s3's password:
client.ca 100% 2148 2.1KB/s 00:00
[root@s1 ssl]# scp client.ca s4:/etc/ssl/glusterfs.ca
root@s4's password:
client.ca 100% 2148 2.1KB/s 00:00
[root@s1 ssl]#
[root@s1 ssl]#
在每个服务器节点上启用管理加密(management encryption)
[root@sX ~]# touch /var/lib/glusterd/secure-access
[root@sX ~]#
在每个服务器节点上重启glusterfs服务:
[root@sX ~]# systemctl restart glusterd
[root@sX ~]#
在指定的卷上启用TLS/SSL I/O加密:
请先关闭这个卷
[root@s1 ssl]# gluster volume stop v1
[root@s1 ~]# gluster volume set v1 auth.ssl-allow 's1,s2,s3'
volume set: success
[root@s1 ~]# gluster volume set v1 server.ssl on
volume set: success
[root@s1 ~]# gluster volume set v1 client.ssl on
[root@s1 ssl]# gluster volume start v1
在客户端上测试:
[root@s3 ssl]# mount.glusterfs s1:/v1 /aa
Mount failed. Please check the log file for more details.
[root@s3 ssl]#
在每个客户端上启用管理加密(management encryption)
[root@sX ~]# touch /var/lib/glusterd/secure-access
[root@sX ~]#
连接测试
在s3上
[root@s3 ssl]# mount.glusterfs s1:/v1 /aa/
[root@s3 ssl]# umount /aa/
[root@s3 ssl]#
在s4上
[root@s4 ssl]# mount.glusterfs s1:/v1 /aa
Mount failed. Please check the log file for more details.
[root@s4 ssl]#
在s1上做相关设置
[root@s1 ssl]# gluster volume stop v1
[root@s1 ssl]# gluster volume set v1 auth.ssl-allow 's1,s2,s3,s4'
[root@s1 ssl]# gluster volume start v1
继续回到s4测试:
[root@s4 ssl]# mount.glusterfs s1:/v2 /aa
[root@s4 ssl]# umount /aa/
[root@s4 ssl]#