【问题标题】:How to create a read-only client for ElasticSearch in python?如何在 python 中为 ElasticSearch 创建只读客户端?
【发布时间】:2016-12-07 22:39:17
【问题描述】:

我想从 ES 中读取数据,但不想意外向其中写入数据(无索引操作)。这只是一种安全措施,不允许其他人稍后修改查询函数插入数据。

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    当你说你想要只读客户端时。客户强调您的系统中可能有其他客户用于同一集群。然后将整个索引阻塞为只读将阻塞所有客户端。您必须有一个在集群中写入/更新数据的作业。

    如果这是您的用例,请将客户端视为 elasticsearch 用户,每个用户对您的集群具有不同的访问策略。

    Elasticsearch 提供shield plugin 用于实现客户端身份验证和授权。

    您可以在配置文件中创建多个具有不同访问策略的 ES - 用户。

    bin/shield/esusers useradd es_admin -r admin
    

    使用角色 api 创建角色并将每个用户专用于每个角色。

    POST /_shield/role/my_admin_role
    {
      "cluster": ["all"], 
      "indices": [ 
        {
          "names": [ "index1", "index2" ], 
          "privileges": ["read"]         
        }
      ],
      "run_as": [ "other_user" ] 
    }
    

    如果你想远离shield,你也可以在es集群之前配置nginx reverse proxy来管理用户授权。

    【讨论】:

      【解决方案2】:

      您可以将索引参数设置为“只读”:

      curl -XPUT localhost:9200/test/_settings -d '{
          "index" : {
              "blocks" : {
                  "read_only" : true
              }
          }
      }'
      

      所有索引设置都记录在这里:https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html

      这里是更新索引设置的方法:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html

      不过,这是一个非常严格的操作。

      【讨论】:

        猜你喜欢
        • 2022-12-25
        • 1970-01-01
        • 2022-12-03
        • 1970-01-01
        • 2015-11-10
        • 2015-04-29
        • 2021-09-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多