前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cerebro+openresty拦截

cerebro+openresty拦截

作者头像
保持热爱奔赴山海
发布2023-08-19 10:01:18
1740
发布2023-08-19 10:01:18
举报
文章被收录于专栏:DevOps数据库相关

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

配置文件如下:

代码语言:javascript
复制
$ 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个配置文件如下:

代码语言:javascript
复制
$ 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;
}
代码语言:javascript
复制
$ 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;
  }

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-08-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档