Filebeat 和 Logstash 访问加密 Elasticsearch 集群配置指南
一、Filebeat 配置加密 ES 集群访问
1. 安全增强的 Filebeat 配置文件示例
filebeat.inputs:
- type: tcp
host: "0.0.0.0:9000"
output.elasticsearch:
hosts:
- "https://10.0.0.91:9200" # 建议使用HTTPS
- "https://10.0.0.92:9200"
- "https://10.0.0.93:9200"
index: "oldboyedu-linux92-log-es-tls"
username: "beats_system" # 建议使用专用用户而非elastic
password: "强密码" # 替换为实际密码
ssl:
certificate_authorities: ["/path/to/ca.crt"] # CA证书路径
verification_mode: "full" # 完整验证模式
setup.ilm.enabled: false
setup.template.name: "oldboyedu-linux92-modules"
setup.template.pattern: "oldboyedu-linux92-log*"
setup.template.overwrite: false
2. 安全建议
-
不要使用elastic超级用户,创建专用用户:
POST /_security/role/beats_writer { "indices": [ { "names": ["oldboyedu-linux92-log*"], "privileges": ["create_index", "write", "auto_configure"] } ] } POST /_security/user/beats_filebeat { "password": "强密码", "roles": ["beats_writer"], "full_name": "Filebeat Writer User" } -
启用HTTPS而非常规HTTP
-
使用证书认证而非基础认证
-
密码管理:
- 使用Keystore存储密码:
filebeat keystore create filebeat keystore add ES_PWD - 然后在配置中使用:
password: "${ES_PWD}"
- 使用Keystore存储密码:
二、Logstash 配置加密 ES 集群访问
1. 安全增强的 Logstash 配置示例
input {
tcp {
port => 8888
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => ["https://10.0.0.91:9200", "https://10.0.0.92:9200", "https://10.0.0.93:9200"]
index => "oldboyedu-linux92-es-tls-logstash-%{+yyyy.MM.dd}"
user => "logstash_writer" # 专用用户
password => "强密码" # 替换为实际密码
ssl => true
cacert => "/path/to/ca.crt" # CA证书路径
# 更安全的连接选项
sniffing => false
proxy => "" # 明确禁用代理
timeout => 60
}
}
2. 安全建议
-
创建专用角色和用户:
POST /_security/role/logstash_writer_role { "indices": [ { "names": ["oldboyedu-linux92-*"], "privileges": ["create_index", "write", "manage"] } ] } POST /_security/user/logstash_writer { "password": "强密码", "roles": ["logstash_writer_role"], "full_name": "Logstash Writer User" } -
使用密钥库存储敏感信息:
# 在Logstash目录下 ./bin/logstash-keystore create ./bin/logstash-keystore add ES_USER ./bin/logstash-keystore add ES_PWD然后在配置中使用:
user => "${ES_USER}" password => "${ES_PWD}"
三、Kibana RBAC 最佳实践
-
角色划分原则:
- 最小权限原则
- 职责分离原则
- 定期审计原则
-
常见角色示例:
# 只读监控角色 POST /_security/role/monitor_viewer { "cluster": ["monitor"], "indices": [ { "names": ["*"], "privileges": ["read", "view_index_metadata"] } ] } # 开发人员角色 POST /_security/role/dev_team { "indices": [ { "names": ["app-*"], "privileges": ["create_index", "write", "read", "delete"] } ] } -
用户分配示例:
POST /_security/user/john_doe { "password": "强密码", "roles": ["dev_team", "kibana_user"], "full_name": "John Doe", "email": "john@example.com" }
四、测试与验证
-
Filebeat 测试:
echo "安全测试消息 $(date)" | nc 10.0.0.91 9000 -
Logstash 测试:
echo "安全测试日志 $(date)" | nc 10.0.0.93 8888 -
Kibana 验证:
- 检查索引模式是否正常
- 验证不同角色的访问权限
- 检查审计日志是否有异常
五、故障排查技巧
-
证书问题:
openssl s_client -connect 10.0.0.91:9200 -showcerts -
权限问题:
curl -u user:password "http://10.0.0.91:9200/_security/_authenticate" -
连接问题:
telnet 10.0.0.91 9200 nc -zv 10.0.0.91 9200 -
日志检查:
journalctl -u filebeat --no-pager -n 50 tail -n 100 /var/log/logstash/logstash-plain.log
请记住,生产环境中应避免使用简单密码如"123456",并确保定期轮换凭证。
浙公网安备 33010602011771号