這篇文章主要講解了“如何構(gòu)建基于WAF的s3cmd安全體系”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“如何構(gòu)建基于WAF的s3cmd安全體系”吧!
創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為垣曲等服務(wù)建站,垣曲等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為垣曲企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
有線上項(xiàng)目需要對RGW的bucket的訪問進(jìn)行白名單控制,只允許白名單內(nèi)的IP去訪問指定的bucket,簡單寫了個demo,基本思路是通過openresty寫一個WAF模塊,去實(shí)現(xiàn)設(shè)置bucket、IP白名單設(shè)置。
OpenResty 處理一個請求,它的處理流程請參考下圖(從 Request start 開始):
幾個關(guān)鍵階段的簡介如下
set_by_lua*:流程分支處理判斷變量初始化
rewrite_by_lua*:轉(zhuǎn)發(fā)、重定向、緩存等功能(例如特定請求代理到外網(wǎng))
access_by_lua*:IP 準(zhǔn)入、接口權(quán)限等情況集中處理(例如配合 iptable 完成簡單防火墻)
content_by_lua*:內(nèi)容生成
header_filter_by_lua*:響應(yīng)頭部過濾處理(例如添加頭部信息)
body_filter_by_lua*:響應(yīng)體過濾處理(例如完成應(yīng)答內(nèi)容統(tǒng)一成大寫)
log_by_lua*:會話完成后本地異步完成日志記錄(日志可以記錄在本地,還可以同步到其他機(jī)器)
本文的原理非常簡單:通過設(shè)置bucket和IP的白名單,在access_by_lua階段對request里面的host和uri等字段進(jìn)行規(guī)則匹配再決定是否放行。
配置文件路徑 /etc/nginx/conf.d/default.conf
upstream zone_write { server 10.63.48.18:7480 weight=13;#對應(yīng)后端RGW civetweb節(jié)點(diǎn) keepalive 30; } server { listen 80; server_name s3.ceph.work *.s3.ceph.work; #endpoint對應(yīng)的域名 location / { proxy_ignore_client_abort on ; proxy_http_version 1.1; #指定http版本,減少低版本帶來的安全隱患 proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; access_by_lua_file /etc/nginx/conf.d/access.lua; #WAF腳本 proxy_pass http://zone_write; } }
腳本路徑 /etc/nginx/conf.d/access.lua
local uri = ngx.var.uri local client_ip = ngx.var.remote_addr local host = ngx.var.host local endpoint = 's3.ceph.work' #endpoint地址 local white_ip_list = {["127.0.0.1"]=true} #IP白名單 local bucket_list = {["bucket1"]=true,["bucket2"]=true} #bucket白名單 function get_bucketname(host,uri,endpoint) local bucket_name = string.match(host, '^[%w-]+.' .. tostring(endpoint) .. '$') if (string.match(host, '^' .. tostring(endpoint) .. '$')) then if (string.match(uri,'^/$')) then return end local bucket_name = string.match(uri, '^/[%w-]+/') return string.sub(bucket_name,2,string.len(bucket_name)-1) elseif bucket_name then return string.sub(bucket_name,1,string.len(bucket_name)-string.len(endpoint)-1) else return end end if true == bucket_list[get_bucketname(host,uri,endpoint)] then if true ~= white_ip_list[client_ip] then ngx.log(ngx.ERR,"Forbidden:",client_ip) ngx.exit(ngx.HTTP_FORBIDDEN) end end
在一個IP白名單以外的機(jī)器訪問
curl bucket1.s3.ceph.work/asdasd #virtual hosted style 方式 <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h2>403 Forbidden</h2></center> <hr><center>nginx</center> </body> </html> curl s3.ceph.work/bucket2/1233 #path-style 方式 <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h2>403 Forbidden</h2></center> <hr><center>nginx</center> </body> </html>
對應(yīng)的nginx日志
2017/09/21 14:05:42 [error] 30725#0: *28 [lua] access.lua:29: forbidden:10.xx.xx.xx, client: 10.xx.xx.xx, server: s3.ceph.work, request: "GET /asdasd HTTP/1.1", host: "bucket1.s3.ceph.work" 2017/09/21 14:02:47 [error] 30725#0: *22 [lua] access.lua:29: forbidden:10.xx.xx.xx, client: 10.xx.xx.xx, server: s3.ceph.work, request: "GET /bucket2/1233 HTTP/1.1", host: "s3.ceph.work"
感謝各位的閱讀,以上就是“如何構(gòu)建基于WAF的s3cmd安全體系”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對如何構(gòu)建基于WAF的s3cmd安全體系這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
分享標(biāo)題:如何構(gòu)建基于WAF的s3cmd安全體系
鏈接URL:http://jinyejixie.com/article30/pgisso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、定制網(wǎng)站、網(wǎng)站設(shè)計(jì)、標(biāo)簽優(yōu)化、做網(wǎng)站、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)