【实战】Splunk 配置索引器和转发器之间加密传输 01 Splunk 环境信息
Splunk Version:Splunk 9.1.1 (build 64e843ea36b1) IP地址信息 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节点上创建证书保存目录 1 $ mkdir /opt/splunk/etc/auth/tls-forward
2.1.2 创建CA证书私钥 进入到/opt/splunk/etc/auth/tls-forward
目录为根证书颁发机构证书创建私钥
-aes256:给私钥设置密码,在设置Splunk inputs时需要添加sslPassword参数指定私钥密码,建议不要给私钥设置密码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ]$ 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文件
1 2 3 4 5 6 7 8 9 10 # 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私钥对其进行签名,创建根证书颁发机构证书。
1 2 3 4 5 6 7 8 9 10 11 12 # 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
。
提示:不要使用与签署证书颁发机构证书的私钥相同的密码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # 进入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
1 2 3 4 5 6 # 服务器私钥有设置密码 ]$ /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私钥对其进行签名,创建服务器证书。
1 2 3 4 5 6 7 8 9 10 11 12 # 服务器私钥有设置密码 ]$ /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 合并证书 1 cat ServerCertificate.pem ServerPrivateKey.key CA-Certificate.pem > Server.pem
2.3 创建indexer kafka02服务器证书 进入到/opt/splunk/etc/auth/tls-forward
目录,为idx01服务器证书创建私钥
1 2 3 4 5 6 7 8 9 ]$ 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服务器证书创建私钥
1 2 3 4 5 6 7 8 9 ]$ 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服务器证书创建私钥
1 2 3 4 5 6 7 8 9 10 ]$ 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 目录架构
1 2 3 4 5 6 7 8 9 10 [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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [splunktcp://9997] connection_host = ip[splunktcp-ssl:9998] disabled = 0 [SSL] serverCert = /opt/splunk/etc/auth/tls-forward/kafka02.pemsslPassword = $7 $Oz7qhMCLXKt4PcpVVSt8JMQRrK +i8qGA/rAJoKpwbyp4A4oQKUnGrequireClientCert = true sslCommonNameToCheck = kafka*,other-server,mss-*-hf
server.conf
1 2 3 [sslConfig] sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem
3.2 服务器私钥没有设置密码
inputs.conf
1 2 3 4 5 6 7 8 9 10 [splunktcp://9997] connection_host = ip[splunktcp-ssl:9998] disabled = 0 [SSL] serverCert = /opt/splunk/etc/auth/tls-forward/kafka02.pemrequireClientCert = true sslCommonNameToCheck = kafka*,other-server,mss-*-hf
server.conf
1 2 [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目录架构
1 2 3 4 5 6 7 8 9 10 11 12 13 [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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [tcpout] defaultGroup = SSL_primary_indexers[tcpout:SSL_primary_indexers] server = 172.16 .19.52 :9998 ,172.16 .19.53 :9998 disabled = 0 clientCert = /opt/splunk/etc/auth/tls-forward/hf-other-server.pemuseClientSSLCompression = true sslPassword = $7 $VhbPGxVDML2rcaFB3WcajgM1XMBmvVAN1ySVSVzuFKCGE7nyQOw =
server.conf
1 2 3 [sslConfig] sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem
4.2 服务器私钥没有设置密码
outputs.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [tcpout] defaultGroup = SSL_primary_indexers[tcpout:SSL_primary_indexers] server = 172.16 .19.52 :9998 ,172.16 .19.53 :9998 disabled = 0 clientCert = /opt/splunk/etc/auth/tls-forward/hf-other-server.pemuseClientSSLCompression = true
server.conf
1 2 3 [sslConfig] sslRootCAPath = /opt/splunk/etc/auth/tls-forward/CA-Certificate.pem