cerebro+openresty拦截
  jKnO7FXA2HI8 2023年11月02日 36 0

通过openresty拦截掉危险的操作。


配置文件如下:

$ cat docker-compose.yaml 
version: '3'
networks:
    monitor:
        driver: bridge
services:
    cerebro:
        image: lmenezes/cerebro
        container_name: cerebro
        hostname: cerebro
        restart: always
        ports:
            - "1234:9000"
        networks:
            - monitor
    openresty:
        image: openresty/openresty
        container_name: openresty
        hostname: openresty
        restart: always
        ports:
            - "1235:80"
        volumes:
            - ./ngx_conf/nginx.conf:/etc/nginx/nginx.conf
            - ./ngx_conf/cerebro.conf:/etc/nginx/conf.d/cerebro.conf
        networks:
            - monitor


mkdir ngx_conf

cd ngx_conf

2个配置文件如下:

$ cat nginx.conf 
user nginx;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    
    access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  120;


    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 32k;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    gzip_vary on;
    gzip_proxied any;
    gzip_disable "MSIE [1-6]\.";

    proxy_buffer_size 8k;
    proxy_buffering on;
    client_header_buffer_size 8k;
    client_body_buffer_size 8k;
    proxy_request_buffering on;
    proxy_cache_lock on;
    proxy_cache_use_stale updating;

    include /etc/nginx/conf.d/*.conf;
}



$ cat cerebro.conf 
server {
  listen 80;
  #error_log /var/log/nginx/cerebro_proxy_err.log;

  root /usr/share/nginx/html;

  location / {
  default_type application/json;
        proxy_pass http://cerebro:9000;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  }

  # overview界面的危险操作全部拦截掉
  location /cluster_settings {
    return 403;
  }
  location ~ (/templates|/commons/indices|/disable_shard_allocation|/analysis) {
    return 403;
  }
  location /overview/relocate_shard {
    return 403;
  }
  location /overview/delete_indices {
    return 403;
  }
  location /overview/close_indices {
    return 403;
  }
  location /overview/force_merge {
    return 403;
  }
  location /overview/flush_indices {
    return 403;
  }
  location /overview/refresh_indices {
    return 403;
  }
  location /overview/clear_indices_cache {
    return 403;
  }
  
  # 对于rest界面的请求进行的拦截
  location /rest/request {
  default_type application/json;

  lua_need_request_body on;
  access_by_lua_block {
    local data1 = ngx.req.get_body_data()

    -- 拦截纯DELETE操作
    result1 = string.match(data1, "DELETE")
    if result1 == "DELETE" then
      ngx.exit(403)
    end

    -- 拦截_delete_by_query并且是match_all的操作
    result2 = string.match(data1, "_delete_by_query")
    result3 = string.match(data1, "match_all")
    result4 = string.match(data1, "POST")
    if result2 == "_delete_by_query" and result3 == "match_all" and result4 == "POST" then
      ngx.exit(403)
    end
  }

  proxy_pass http://cerebro:9000;
  proxy_set_header   Host             $host;
  proxy_set_header   X-Real-IP        $remote_addr;
  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  }

}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  P3nxyT0LRuwj   2023年11月28日   22   0   0 nginxhtmlWeb
  jnZtF7Co41Wg   2023年12月11日   27   0   0 nginx客户端服务端
  jnZtF7Co41Wg   2023年11月28日   19   0   0 nginx文件名linux命令
  stLBpDewCLT1   2023年12月08日   27   0   0 nginx
  jnZtF7Co41Wg   2023年12月10日   20   0   0 nginx客户端服务端NFS
  eHipUjOuzYYH   2023年12月06日   26   0   0 nginxHTTP
  eHipUjOuzYYH   2023年12月06日   22   0   0 nginx加载IPV6