教程:安全入門
Tutorial: Getting started with security
準備工作:常用軟件-ELKF+kafka集羣
- 安裝和配置Elasticsearch, Kibana, Logstash.
- 停止logstash
- 通過瀏覽器訪問Kibana web界面。例如,http://127.0.0.1:5601.
啓用Elasticsearch安全功能
Enable Elasticsearch security features
-
停止kibana
-
停止 elasticsearch
-
添加
xpack.security.enabled
配置到文件 conf/elasticsearch.ymlAdd the
xpack.security.enabled
setting to theES_PATH_CONF/elasticsearch.yml
fileYamlxpack.security.enabled: true
-
啓用單節點配置, 不需要配置集羣的節點間通信配置傳輸層安全(TLS)
Enable single-node discovery in the
ES_PATH_CONF/elasticsearch.yml
file.Yaml複製成功discovery.type: single-node # cluster.initial_master_nodes: ["ikj-elk-115"] 初始化主節點
-
啓動elasticsearch
Codesu es -c "/opt/elasticsearch/bin/elasticsearch -d"
爲內置用戶創建密碼
Create passwords for built-in users
-
重啓 elasticsearch
Codesu es -c "/opt/elasticsearch/bin/elasticsearch -d"
-
設置內置用戶的密碼。這裏需要爲4個用戶分別設置密碼,elastic, kibana, logstash_system,beats_system ( 注意:此時要開啓ES)
Set the built-in users’ passwords.
Sh./bin/elasticsearch-setup-passwords interactive
其中,用戶權限分別如下:
- elastic 賬號:擁有 superuser 角色,是內置的超級用戶。
- kibana 賬號:擁有 kibana_system 角色,用戶 kibana 用來連接 elasticsearch 並與之通信。Kibana 服務器以該用戶身份提交請求以訪問集羣監視 API 和 .kibana 索引。不能訪問 index。
- logstash_system 賬號:擁有 logstash_system 角色。用戶 Logstash 在 Elasticsearch 中存儲監控信息時使用。
-
修改密碼命令如下
創建一個臨時的超級用戶 RyanMiao用這個用戶去修改elastic用戶的密碼
Codebin/elasticsearch-users useradd my_admin -p my_password -r superuser curl -XPUT -u my_admin:my_password https://localhost:9200/_xpack/security/user/elastic/_password -H "Content-Type: application/json" -d '{ "password": "123456" }'
爲kibana添加內置用戶
Add the built-in user to Kibana
-
添加 內置用戶 kibana_system 的用戶名和密碼
Configure Kibana to use the built-in
kibana_system
user and the password that you createdCodeelasticsearch.username: "kibana_system" elasticsearch.password: "your_password"
如果你不想將密碼放到配置文件中,也可以放到密鑰庫中
Code./bin/kibana-keystore create ./bin/kibana-keystore add elasticsearch.username ./bin/kibana-keystore add elasticsearch.password
-
重啓kibana
Codesu es -c "cd /opt/kibana && /opt/kibana/bin/kibana &"
-
驗證kibana 啓動正常
配置權限
- 權限可以使用默認即可,如果沒有特殊配置可以直接去創建用戶
創建用戶
- 通過內置用戶登陸 kibana
- 打開菜單 ,Stack Management > Security > Users.
- 點擊 Create user; 創建用戶,分配 role權限 kibana_user
- 依次創建用戶
分配角色
- 通過內置用戶登陸 kibana
- 打開菜單 ,Stack Management > Security > Roles.
- 點擊 Create Role; 創建角色
- 添加 Role name, Indices, Privileges
- 點擊左下角 Create Role
- 依次創建角色 role-demo2 等
- 編輯用戶,併爲用戶分配角色
爲logstash添加用戶
Add user information in Logstash
-
在logstash 配置文件中,添加kibana用戶名和密碼
Codeoutput { elasticsearch { hosts => "localhost:9200" manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}" user => "logstash_internal" password => "your_password" } }
-
如果你不想要在配置文件中使用用戶名和密碼,也可以存儲在密鑰中
Codeset +o history export LOGSTASH_KEYSTORE_PASS=mypassword set -o history ./bin/logstash-keystore create ./bin/logstash-keystore add ES_USER ./bin/logstash-keystore add ES_PWD
然後你就可以在配置文件中使用變量
Codeuser => "${ES_USER}" password => "${ES_PWD}"
-
啓動logstash