Splunk 配置索引和转发器加密传输
01 Splunk 环境信息
Splunk version:Splunk 9.1.1 (build 64e843ea36b1)
Master:172.16.19.51
IDX01 :172.16.19.52
IDX02 :172.16.19.53
HF : 172.16.19.54
02 创建自签名证书
自行创建和签署证书有几个步骤:
- 创建根证书颁发机构证书
- 创建服务器证书并使用根证书颁发机构证书对其进行签名
2.1 创建CA根证书(颁发机构证书)
根证书颁发机构证书充当基础证书,用于签署其他证书,您将分发到部署中的 Splunk 平台实例。它被称为“根证书颁发机构证书”的原因如下:作为证书颁发机构,您确定信任基于此根证书的任何证书。
您只需创建一个根证书颁发机构证书。
2.1.1 在Master节点上创建证书保存目录
mkdir /opt/splunk/etc/auth/tls-forward
2.1.2 创建CA证书私钥
进入到/opt/splunk/etc/auth/tls-forward
目录为根证书颁发机构证书创建私钥
-aes256:给私钥设置密码,在设置Splunk inputs时需要添加sslPassword参数指定私钥密码,建议不要给私钥设置密码。
]$ cd /opt/splunk/etc/auth/tls-forward
# CA私钥有设置密码
]$ /opt/splunk/bin/splunk cmd openssl genrsa -aes256 -out CA-PrivateKey.key 2048
Generating RSA private key, 2048 bit long modulus
........+++++
....+++++
e is 65537 (0x10001)
Enter pass phrase for CA-PrivateKey.key: splunk # 设置CA私钥密码
Verifying - Enter pass phrase for CA-PrivateKey.key: splunk # 设置CA私钥密码
# CA私钥没有设置密码
]$ /opt/splunk/bin/splunk cmd openssl genrsa -out CA-PrivateKey.key 2048
Generating RSA private key, 2048 bit long modulus
..+++++
.............................................................+++++
e is 65537 (0x10001)
2.1.3 生成CSR文件
基于刚才创建的CA私钥生成CA-Certificate.csr文件
# CA私钥有设置密码
]$ /opt/splunk/bin/splunk cmd openssl req -new -key CA-PrivateKey.key -out CA-Certificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Master"
Enter pass phrase for CA-PrivateKey.key: splunk # 输入CA私钥密码
# CA私钥没有设置密码
]$ /opt/splunk/bin/splunk cmd openssl req -new -key CA-PrivateKey.key -out CA-Certificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Master"
]$ ll
total 8
-rw-------. 1 root root 997 Nov 14 21:29 CA-Certificate.csr
-rw-------. 1 root root 1675 Nov 14 21:28 CA-PrivateKey.key
subj参数说明
参数 | 示例 | 含义 |
---|---|---|
C | CN | 国家(Country Name) |
ST | guangdong | 州或省(State or Province Name) |
L | shenzhen | 地区或市(Locality Name) |
O | Eccom | 组织(Organization Name) |
OU | IT | 部门(Organization Unit Name) |
CN | Master | 证书使用者的通用名称(Common Name) |
2.1.4 生成CA证书
使用创建的CSR
文件并使用之前创建的CA私钥对其进行签名,创建根证书颁发机构证书。
# CA私钥有设置密码
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in CA-Certificate.csr -sha512 -signkey CA-PrivateKey.key -CAcreateserial -out CA-Certificate.pem -days 3650
Signature ok
subject=/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Master
Getting Private key
Enter pass phrase for CA-PrivateKey.key: splunk
# CA私钥没有设置密码
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in CA-Certificate.csr -sha512 -signkey CA-PrivateKey.key -CAcreateserial -out CA-Certificate.pem -days 3650
Signature ok
subject=/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Master
Getting Private key
2.2 创建服务器证书<例子>
创建根证书颁发机构证书后,您可以创建其他证书,然后使用CA(根)证书对其进行签名。
与根CA证书类似,您必须创建私钥和证书签名请求才能为Splunk服务器生成证书。
2.2.1 创建服务器证书私钥
进入到
/opt/splunk/etc/auth/tls-forward
目录,为服务器证书创建私钥-aes256:给私钥设置密码,在设置Splunk inputs时需要添加sslPassword参数指定私钥密码,建议不要给私钥设置密码。
当OpenSSL
程序提示您时,输入密钥的密码。然后OpenSSL
程序创建一个文件 ServerPrivateKey.key
。
提示:不要使用与签署证书颁发机构证书的私钥相同的密码。
# 进入tls-forward证书保存目录
]$ cd /opt/splunk/etc/auth/tls-forward
# 服务器私钥有设置密码
]$ /opt/splunk/bin/splunk cmd openssl genrsa -aes256 -out ServerPrivateKey.key 2048
Generating RSA private key, 2048 bit long modulus
..............+++++
......................................................................................................................................+++++
e is 65537 (0x10001)
Enter pass phrase for ServerPrivateKey.key: server # 设置服务器私钥密码
Verifying - Enter pass phrase for ServerPrivateKey.key: server # 设置服务器私钥密码
# 服务器私钥未设置密码
]$ /opt/splunk/bin/splunk cmd openssl genrsa -out ServerPrivateKey.key 2048
Generating RSA private key, 2048 bit long modulus
..............................................................+++++
.......................................+++++
e is 65537 (0x10001)
2.2.2 生成服务器CSR文件
使用私钥 ServerPrivateKey.key
证书生成 ServerCertificate.CSR
# 服务器私钥有设置密码
]$ /opt/splunk/bin/splunk cmd openssl req -new -key ServerPrivateKey.key -out ServerCertificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Server"
Enter pass phrase for ServerPrivateKey.key: server # 输入服务器私钥密码
# 服务器私钥没有设置密码
/opt/splunk/bin/splunk cmd openssl req -new -key ServerPrivateKey.key -out ServerCertificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Server"
提示:
"Common Name"
字段提供的信息是Splunk
平台用于TLS
证书主机名验证的信息可以使用
-subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Server/CN=HF/CN=HF01"
设置多个"Common Name"
值
2.2.3 生成服务器证书
基于刚才创建的
CSR
文件,使用Server私钥、CA证书及CA私钥对其进行签名,创建服务器证书。
# 服务器私钥有设置密码
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in ServerCertificate.csr -SHA256 -CA CA-Certificate.pem -CAkey CA-PrivateKey.key -CAcreateserial -out ServerCertificate.pem -days 3650
Signature ok
subject=/C=cn/ST=guangdong/L=shenzhen/O=Eccom/OU=IT/CN=kafka02
Getting CA Private Key
Enter pass phrase for CA-PrivateKey.key: server
# 服务器私钥没有设置密码
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in ServerCertificate.csr -SHA256 -CA CA-Certificate.pem -CAkey CA-PrivateKey.key -CAcreateserial -out ServerCertificate.pem -days 3650
Signature ok
subject=/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=Server
Getting CA Private Key
2.2.4 合并证书
cat ServerCertificate.pem ServerPrivateKey.key CA-Certificate.pem > Server.pem
2.3 创建indexer kafka02服务器证书
进入到/opt/splunk/etc/auth/tls-forward
目录,为idx01服务器证书创建私钥
]$ cd /opt/splunk/etc/auth/tls-forward
# 生成kafka02服务器证书私钥
]$ /opt/splunk/bin/splunk cmd openssl genrsa -out kafka02-PrivateKey.key 2048
# 生成kafka02服务器证书csr文件
]$ /opt/splunk/bin/splunk cmd openssl req -new -key kafka02-PrivateKey.key -out kafka02-Certificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=kafka02"
# 生成kafka02服务器证书
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in kafka02-Certificate.csr -SHA256 -CA CA-Certificate.pem -CAkey CA-PrivateKey.key -CAcreateserial -out kafka02-Certificate.pem -days 3650
# 证书合并
]$ cat kafka02-Certificate.pem kafka02-PrivateKey.key CA-Certificate.pem > kafka02.pem
2.4 创建indexer kafka03服务器证书
进入到/opt/splunk/etc/auth/tls-forward
目录,为idx01服务器证书创建私钥
]$ cd /opt/splunk/etc/auth/tls-forward
# 生成kafka03服务器证书私钥
]$ /opt/splunk/bin/splunk cmd openssl genrsa -out kafka03-PrivateKey.key 2048
# 生成kafka03服务器证书csr文件
]$ /opt/splunk/bin/splunk cmd openssl req -new -key kafka03-PrivateKey.key -out kafka03-Certificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=kafka03"
# 生成kafka03服务器证书
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in kafka03-Certificate.csr -SHA256 -CA CA-Certificate.pem -CAkey CA-PrivateKey.key -CAcreateserial -out kafka03-Certificate.pem -days 3650
# 证书合并
]$ cat kafka03-Certificate.pem kafka03-PrivateKey.key CA-Certificate.pem > kafka03.pem
2.5 创建HF other-server服务器证书
进入到/opt/splunk/etc/auth/tls-forward
目录,为idx01服务器证书创建私钥
]$ cd /opt/splunk/etc/auth/tls-forward
# 生成hf服务器证书私钥
# -aes256:给私钥设置密码
]$ /opt/splunk/bin/splunk cmd openssl genrsa -out hf-PrivateKey.key 2048
# 生成hf服务器证书csr文件
]$ /opt/splunk/bin/splunk cmd openssl req -new -key hf-PrivateKey.key -out hf-Certificate.csr -subj "/C=CN/ST=guangdong/L=shenzhen/O=eccom/OU=IT/CN=hf"
# 生成hf服务器证书
]$ /opt/splunk/bin/splunk cmd openssl x509 -req -in hf-Certificate.csr -SHA256 -CA CA-Certificate.pem -CAkey CA-PrivateKey.key -CAcreateserial -out hf-Certificate.pem -days 3650
# hf证书合并
]$ cat hf-Certificate.pem hf-PrivateKey.key CA-Certificate.pem > hf-other-server.pem
03 Indxer服务器配置
org_all_ssl_inputs add-on 目录架构
[root@kafka02 apps]# tree org_all_ssl_inputs
org_all_ssl_inputs
├── local
│ ├── app.conf
│ ├── inputs.conf
│ └── server.conf
└── metadata
└── local.meta
2 directories, 4 files
3.1 服务器私钥有设置密码
-
inputs.conf
# 普通splunktcp数据接收端口,splunktcp端口可以与splunktcp-ssl接收端口并存。 [splunktcp://9997] connection_host = ip # 设置9998为splunktcp-ssl模式接收数据端口 [splunktcp-ssl:9998] # 设置禁用状态为0,表示启用该TCP输采集。 disabled = 0 [SSL] # 合并后的服务器证书路径 serverCert = /opt/splunk/etc/auth/tls-forward/kafka02.pem # 指定服务器私钥证书密码,这个密码是创建创建服务器私钥时设置的密码,设置完成后,重新splunk服务会对密码进行加密。 # sslPassword = server 原密码 sslPassword = $7$Oz7qhMCLXKt4PcpVVSt8JMQRrK+i8qGA/rAJoKpwbyp4A4oQKUnG # Indexer服务器要求客户端提供证书以进行验证。只有当客户端提供有效的证书时,服务器才会接受连接。 requireClientCert = true # 重要:能提升安全性!客户端证书中的CN如果与sslCommonNameToCheck设置的主机名与通配符匹配时链接才会别接受。 sslCommonNameToCheck = kafka*,other-server,mss-*-hf
-
server.conf
[sslConfig] # 设置CA证书路径 sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem
3.2 服务器私钥没有设置密码
-
inputs.conf
[splunktcp://9997] connection_host = ip [splunktcp-ssl:9998] disabled = 0 [SSL] serverCert = /opt/splunk/etc/auth/tls-forward/kafka02.pem requireClientCert = true sslCommonNameToCheck = kafka*,other-server,mss-*-hf
-
server.conf
[sslConfig] sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem
04 转发器配置
给转发器节点生成的证书可以让多个HF节点共同使用,但是此种方法有着非常大的安全隐患。
如果需要操作步骤:
1、复制CA证书。
2、复制转发器合并处理后的证书。
3、如果转发器证书私钥有设置密码,需要知道对应的密码。
4.1 服务器私钥有设置密码
org_all_forwarder_outputs add-on目录架构
[root@other-server apps]# tree org_all_forwarder_outputs
org_all_forwarder_outputs
├── default
│ └── app.conf
├── local
│ ├── app.conf
│ ├── limits.conf
│ ├── outputs.conf
│ └── server.conf
└── metadata
└── local.meta
3 directories, 6 files
-
outputs.conf
[tcpout] # 指定默认组名为"SSL_primary_indexers" defaultGroup = SSL_primary_indexers [tcpout:SSL_primary_indexers] # 指定服务器地址和端口号,Splunk将通过TCP连接到这些服务器进行数据输出。 server = 172.16.19.52:9998,172.16.19.53:9998 # 设置禁用状态为0,表示启用该组的TCP输出。 disabled = 0 # 指定客户端证书的路径,用于与服务器建立安全连接。 clientCert = /opt/splunk/etc/auth/tls-forward/hf-other-server.pem # 启用客户端SSL压缩,以提高数据传输效率。 useClientSSLCompression = true # 指定服务器私钥证书密码,这个密码是创建创建服务器私钥时设置的密码,设置完成后,重新splunk服务会对密码进行加密。 # sslPassword = server 原密码 sslPassword = $7$VhbPGxVDML2rcaFB3WcajgM1XMBmvVAN1ySVSVzuFKCGE7nyQOw=
-
server.conf
[sslConfig] # 设置CA证书路径 sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem
4.2 服务器私钥没有设置密码
-
outputs.conf
[tcpout] # 指定默认组名为"SSL_primary_indexers" defaultGroup = SSL_primary_indexers [tcpout:SSL_primary_indexers] # 指定服务器地址和端口号,Splunk将通过TCP连接到这些服务器进行数据输出。 server = 172.16.19.52:9998,172.16.19.53:9998 # 设置禁用状态为0,表示启用该组的TCP输出。 disabled = 0 # 指定客户端证书的路径,用于与服务器建立安全连接。 clientCert = /opt/splunk/etc/auth/tls-forward/hf-other-server.pem # 启用客户端SSL压缩,以提高数据传输效率。 useClientSSLCompression = true
-
server.conf
[sslConfig] # 设置CA证书路径 sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem
评论区