elasticsearch添加賬號和權限

教程:安全入門

Tutorial: Getting started with security

準備工作:常用軟件-ELKF+kafka集羣

  1. 安裝和配置Elasticsearch, Kibana, Logstash.
  2. 停止logstash
  3. 通過瀏覽器訪問Kibana web界面。例如,http://127.0.0.1:5601.

啓用Elasticsearch安全功能

Enable Elasticsearch security features

  1. 停止kibana

  2. 停止 elasticsearch

  3. 添加xpack.security.enabled 配置到文件 conf/elasticsearch.yml

    Add the xpack.security.enabled setting to the ES_PATH_CONF/elasticsearch.yml file

    Yaml
     
    xpack.security.enabled: true
  4. 啓用單節點配置, 不需要配置集羣的節點間通信配置傳輸層安全(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"] 初始化主節點
  5. 啓動elasticsearch

    Code
     
    su es -c "/opt/elasticsearch/bin/elasticsearch -d"

爲內置用戶創建密碼

Create passwords for built-in users

  1. 重啓 elasticsearch

    Code
     
    su es -c "/opt/elasticsearch/bin/elasticsearch -d"
  2. 設置內置用戶的密碼。這裏需要爲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 中存儲監控信息時使用。
  3. 修改密碼命令如下

    創建一個臨時的超級用戶 RyanMiao用這個用戶去修改elastic用戶的密碼

    Code
     
    bin/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

  1. 添加 內置用戶 kibana_system 的用戶名和密碼

    Configure Kibana to use the built-in kibana_system user and the password that you created

    Code
     
    elasticsearch.username: "kibana_system"
    elasticsearch.password: "your_password"

    如果你不想將密碼放到配置文件中,也可以放到密鑰庫中

    Code
     
    ./bin/kibana-keystore create
    ./bin/kibana-keystore add elasticsearch.username
    ./bin/kibana-keystore add elasticsearch.password
  2. 重啓kibana

    Code
     
    su es -c "cd /opt/kibana && /opt/kibana/bin/kibana &"
  3. 驗證kibana 啓動正常

配置權限

Configure authentication

  1. 權限可以使用默認即可,如果沒有特殊配置可以直接去創建用戶

創建用戶

Create users

  1. 通過內置用戶登陸 kibana
  2. 打開菜單 ,Stack Management > Security > Users.
  3. 點擊 Create user; 創建用戶,分配 role權限 kibana_user
  4. 依次創建用戶

分配角色

Assign roles

  1. 通過內置用戶登陸 kibana
  2. 打開菜單 ,Stack Management > Security > Roles.
  3. 點擊 Create Role; 創建角色
  4. 添加 Role name, Indices, Privileges
  5. 點擊左下角 Create Role
  6. 依次創建角色 role-demo2 等
  7. 編輯用戶,併爲用戶分配角色

爲logstash添加用戶

Add user information in Logstash

  1. 在logstash 配置文件中,添加kibana用戶名和密碼

    Code
     
    output {
      elasticsearch {
        hosts => "localhost:9200"
        manage_template => false
        index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
        user => "logstash_internal" 
        password => "your_password" 
      }
    }
  2. 如果你不想要在配置文件中使用用戶名和密碼,也可以存儲在密鑰中

    Code
     
    set +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

    然後你就可以在配置文件中使用變量

    Code
     
    user => "${ES_USER}"
    password => "${ES_PWD}"
  3. 啓動logstash

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章