使用 TLS 加密 syslog
最后更新于:本页内容
目标
通过使用 TLS 加密,确保 syslog 服务器上的远程日志记录安全。
Syslog 流量可以使用 TLS/SSL 加密,提供远程服务器与客户端之间的双向认证,从而防止中间人攻击。以下步骤展示了如何实现此功能。
请确保:
- 防火墙和网络上已开放端口 6514 出站,因为 TLS 使用该端口进行通信。
- 由于我们使用 GTLS 驱动程序,客户端和远程服务器上都必须安装 gnuTLS。
- 证书密钥在任何情况下都不得被第三方访问。
使用 TLS 加密 syslog 的步骤
创建自签名证书
以下是在远程 syslog 服务器上使用 gnuTLS 创建自签名证书的步骤。
-
Generate a private key using this command:
certtool --generate-privkey --outfile ca-key.pem -
Set the file inaccessible to anyone other than the root user.
chmod 400 ca-key.pem -
Use the following command to create the self-signed CA certificate:
certtool --generate-self-signed --load-privkey ca-key.pem --outfile ca.pem
提示时请适当填写详细信息。证书颁发机构(CA)现已设置完成。
为每台机器生成机器证书
-
Generate a private key and store it in the key.pem file.
certtool --generate-privkey --outfile key.pem --bits 2048 -
Create the machine certificate using the following command. The name of the file request.pem, is specific to the machine. For example, if your machine is server1, the file may be named as server1-request.pem.
certtool --generate-request --load-privkey key.pem --outfile request.pem -
Sign the machine certificate using the private key of the CA with the following command
certtool --generate-certificate --load-request request.pem --outfile cert.pem --load-ca-certificate ca.pem --load-ca-privkey ca-key.pem
提示时请根据需要填写详细信息。
分发证书
-
The following files need to be copied into all the server and client machines:
- ca.pem 的一份副本
- cert.pem
- Key.pem
在根服务器上创建一个目录以存储这些密钥。
除 root 用户外,任何用户都不应访问这些文件。
配置远程服务器通过 TCP 使用 TLS 通信
-
Create a new configuration file /etc/rsyslog.d/logserver.conf, with the code given below:
module(load="imuxsock") # local messages module(load="imtcp" # TCP listener StreamDriver.Name="gtls" StreamDriver.Mode="1" # run driver in TLS-only mode StreamDriver.Authmode="anon" ) # make gtls driver the default and set certificate files global( DefaultNetstreamDriver="gtls" DefaultNetstreamDriverCAFile="/path/to/contrib/gnutls/ca.pem" DefaultNetstreamDriverCertFile="/path/to/contrib/gnutls/cert.pem" DefaultNetstreamDriverKeyFile="/path/to/contrib/gnutls/key.pem" ) # start up listener at port 6514 input( type="imtcp" port="6514" )
配置客户端机器
-
Create a new file /etc/rsyslog.d/logclient.conf with the following code:
global( DefaultNetstreamDriver="gtls" DefaultNetstreamDriverCAFile="/path/to/contrib/gnutls/ca.pem" DefaultNetstreamDriverCertFile="/path/to/contrib/gnutls/cert.pem" DefaultNetstreamDriverKeyFile="/path/to/contrib/gnutls/key.pem" ) # set up the action for all messages action( type="omfwd" target="central.example.net" protocol="tcp" port="6514" StreamDriver="gtls" StreamDriverMode="1" # run driver in TLS-only mode StreamDriverAuthMode="x509/name" StreamDriverPermittedPeers="central.example.net" )
这将为您的系统设置加密传输的 syslog。
使用日志管理解决方案
EventLog Analyzer 是一款全面的日志管理解决方案,可收集、分析、关联、搜索并归档来自网络设备的日志数据。该解决方案通过采用多种安全协议,确保日志数据在收集和传输过程中的安全。更多关于 EventLog Analyzer 的信息请点击 这里。










