【问题标题】:Use Nginx as proxy to prevent create/update/delete operations on ElasticSearch via JavaScript client-side使用 Nginx 作为代理来防止通过 JavaScript 客户端对 ElasticSearch 进行创建/更新/删除操作
【发布时间】:2015-02-07 23:41:39
【问题描述】:

我有一个本地 ElasticSearch 服务器,由 Nginx 公开,可以防止 POST、PUT 和 DELETE 请求。这是我的 Nginx 配置足以防止超出信息获取的操作吗?您有什么改进建议吗?

  upstream elasticsearch {
      server localhost:9200;
  }

  server {
      listen 7777;

      location / {
        return 403;
        limit_except PUT POST DELETE {
          proxy_pass http://elasticsearch;
        }
        proxy_redirect off;
      }

  }

谢谢。

[更新]

我根据deagh的建议配置:

  upstream elasticsearch {
      server localhost:9200;
  }

  server {
      listen 7777;

      location / {
        return 403;
        limit_except PUT POST DELETE {
          proxy_pass http://elasticsearch;
        }
        proxy_redirect off;
      }

      location ~* ^(/_cluster|/_nodes|/_shutdown) {
        return 403;
        break;
      }

  }

【问题讨论】:

    标签: nginx proxy elasticsearch


    【解决方案1】:

    您还应该注意与不同弹性搜索位置的连接,例如

    • _cluster
    • _nodes
    • _shutdown

    您可以在文档中找到有关 nginx 和 elasticsearch 的工作(和安全)设置的更多信息 => http://www.elasticsearch.org/blog/playing-http-tricks-nginx/

    【讨论】:

    • 谢谢!如果你想检查,我已经更新了配置。
    【解决方案2】:

    谢谢,我不知道你必须保护 Elastic X_X

    我通过 Kibana 发现了一些您通常不需要的 _commands,它们可以被列入黑名单,也就是说,如果您确实需要,您可以输入密码。

    # 2020-01-07
    # Whitelist: _count, _mget, _search
    # Greylist (blacklisted anyway): _analyze, _msearch, _validate
    # Blacklist:
    location ~* /_(aliases|all|analyze|bulk|cache|cluster|data_frame|delete_by_query|field_caps|flush|forcemerge|ilm|ingest|license|mapping|mappings|migration|ml|monitoring|msearch|mtermvectors|nodes|refresh|scripts|security|shutdown|snapshot|sql|tasks|template|upgrade|update_by_query|validate|watcher)
    {
        auth_basic "Elastic1";
        auth_basic_user_file /etc/nginx/.htpasswd;  # create with Apache tool htpasswd
    
        include proxy_params;
        proxy_cookie_domain <HOSTNAME> $server_name;
        proxy_pass http://10.0.0.1:9201;
    }
    
    location /
    {
        # Blacklist: CONNECT, DELETE, PATCH, PUT, TRACE
        # Whitelist:
        limit_except GET HEAD OPTIONS POST
        {
            auth_basic "Elastic1";
            auth_basic_user_file /etc/nginx/.htpasswd;  # create with Apache tool htpasswd
        }
    
        include proxy_params;
        proxy_cookie_domain <HOSTNAME> $server_name;
        proxy_pass http://10.0.0.1:9201;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      相关资源
      最近更新 更多