使用nginx limit_except 保护暴露外网的minio 服务

minio 做为比较热门的开源s3 服务,受到好多团队的青睐,使用率还是比较高的,如果我们的服务是部署在内网的还好
一般不用太担忧安全问题(但是也得做好内网的安全防护),但是如果直接将s3 服务暴露到公网问题就比较多了,解决
方法很多,比如使用waf,自己配置一些安全策略,以下是基于nginx limit_except 搞一个minio 快速的安全防护

参考玩法

核心是利用了limit_except 只允许,get,head, 以及options 请求,对于delete 以及put,post 等操作都禁用,好处比较明显
我们只会暴露我们需要提供给用户资源(主要是get),一般就不能利用我们的put 以及delete 操作了

 

 

参考玩法

  • docker-compose 文件
 
version: '3'
services:
  minio:
    image: minio/minio
    ports:
      - "9000:9000"
      - "19001:19001"
    environment:
      MINIO_ROOT_USER: minio
      MINIO_ROOT_PASSWORD: minio123
    command: server --console-address :19001 --quiet /data
  nginx:
    image: openresty/openresty:alpine-fat
    volumes:
      - ./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
    ports:
      - 80:80
  • nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    real_ip_header     X-Forwarded-For;
    resolver 127.0.0.11;
    real_ip_recursive on;
    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        # 基于nginx 暴露最小的请求路径,同时限制只能使用get head 以及options 请求
        location /apps/ {
            limit_except GET HEAD OPTIONS{
                 deny all;
            }
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_connect_timeout 300;
            # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            chunked_transfer_encoding off;
            proxy_pass http://minio:9000;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

说明

以上是一个简单的玩法,实际上我们基于nginx (openresty) 可以做不少关于minio 的安全防护,减少minio 因为安全问题,造成的数据泄漏以及被人利用

参考资料

https://nginx.org/en/docs/http/ngx_http_core_module.html#satisfy
https://github.com/rongfengliang/using_limit_except_protect_minio

posted on   荣锋亮  阅读(1300)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-10-26 sqlserver linux 容器运行
2018-10-26 OASGraph 转换rest api graphql 试用
2018-10-26 使用OASGraph 暴露rest 接口为graphql api
2018-10-26 hasura-graphql 集成 pipelinedb 1.0.0
2015-10-26 messagepcak 资料

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示