Ubuntu系统配置Filebeat安全策略指南
保持Filebeat为最新版本是安全基础,新版本通常包含安全漏洞修复和功能改进。使用以下命令更新:
sudo apt-get update && sudo apt-get install --only-upgrade filebeat
使用UFW(Ubuntu默认防火墙)限制Filebeat的网络访问,仅允许与Elasticsearch、Kibana等必要服务的通信:
sudo ufw allow 5044/tcp # Filebeat默认输出端口(若修改需同步调整)
sudo ufw allow 9200/tcp # Elasticsearch默认端口
sudo ufw allow 5601/tcp # Kibana默认端口
sudo ufw enable # 启用防火墙
加密Filebeat与Elasticsearch之间的数据传输,防止日志被窃听或篡改:
mkdir -p /etc/filebeat/certs
openssl req -x509 -newkey rsa:4096 -keyout /etc/filebeat/certs/ca.key -out /etc/filebeat/certs/ca.crt -days 3650 -nodes -subj "/C=CN/ST=Beijing/L=Beijing/O=YourOrg/CN=YourCA"
openssl req -newkey rsa:4096 -keyout /etc/filebeat/certs/client.key -out /etc/filebeat/certs/client.csr -nodes -subj "/C=CN/ST=Beijing/L=Beijing/O=YourOrg/CN=filebeat_client"
openssl x509 -req -in /etc/filebeat/certs/client.csr -CA /etc/filebeat/certs/ca.crt -CAkey /etc/filebeat/certs/ca.key -CAcreateserial -out /etc/filebeat/certs/client.crt -days 3650
/etc/filebeat/filebeat.yml,添加SSL参数:output.elasticsearch:
hosts: ["https://your_elasticsearch_host:9200"]
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
ssl.certificate: "/etc/filebeat/certs/client.crt"
ssl.key: "/etc/filebeat/certs/client.key"
ssl.verify_mode: full # 严格验证证书
启用Elasticsearch的X-Pack安全功能,为Filebeat配置专用用户及角色,实现身份认证与权限控制:
/etc/elasticsearch/elasticsearch.yml,添加:xpack.security.enabled: true
重启Elasticsearch:sudo systemctl restart elasticsearch
filebeat_user),并分配仅能读取日志的角色:curl -X POST "localhost:9200/_security/user/filebeat_user?pretty" -H 'Content-Type: application/json' -d'
{
"password" : "StrongPassword123!",
"roles" : [ "read_logs" ],
"full_name" : "Filebeat Log Collector"
}'
filebeat.yml的输出部分添加认证信息:output.elasticsearch:
hosts: ["https://your_elasticsearch_host:9200"]
username: "filebeat_user"
password: "StrongPassword123!"
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
ssl.certificate: "/etc/filebeat/certs/client.crt"
ssl.key: "/etc/filebeat/certs/client.key"
filebeat)并赋予权限:sudo useradd --system --no-create-home --ingroup adm filebeat
sudo chown -R filebeat:adm /etc/filebeat /var/log/filebeat
sudo systemctl edit filebeat
在编辑器中添加(覆盖默认服务配置):[Service]
User=filebeat
Group=adm
重启服务:sudo systemctl daemon-reload
sudo systemctl restart filebeat
filebeat.yml仅能被root和filebeat用户读取:sudo chmod 640 /etc/filebeat/filebeat.yml
sudo chown root:filebeat /etc/filebeat/filebeat.yml
通过Seccomp(安全计算模式)限制Filebeat可执行的系统调用,减少潜在漏洞影响。针对Ubuntu 22.04及以上版本(glibc >= 2.35),需添加rseq系统调用:
seccomp:
default_action: allow
syscalls:
- action: allow
names:
- rseq
filebeat.yml中配置日志输出,便于排查安全问题:logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7 # 保留7天日志
permissions: 0640
tail或日志分析工具监控Filebeat日志,关注异常连接或认证失败:sudo tail -f /var/log/filebeat/filebeat.log
apt定期更新Filebeat,确保安全补丁及时应用:sudo apt-get update && sudo apt-get upgrade filebeat
filebeat.yml的修改历史(如使用git版本控制),避免未授权的配置更改。仅采集必要的日志数据,减少敏感信息泄露风险。例如,仅监控/var/log/syslog和/var/log/auth.log:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/syslog
- /var/log/auth.log
exclude_lines: ["^DBG"] # 排除调试日志
通过以上步骤,可显著提升Ubuntu系统上Filebeat的安全性,防范数据泄露、未授权访问等常见安全威胁。建议结合实际环境调整配置,并定期进行安全评估。