今天有个storm的topology被人kill掉了,但是找不到是谁做的,storm的ui有kill topology的功能,但是没有权限验证,这样就导致知道ui地址的任何人都可以kill掉topology,,比较危险,考虑把这个action disable掉。
有两种方法:
1.前端增加nginx,做location
分析ui页面,对应kill的button,html中的action为:
<inputenabled=””onclick=”confirmAction(‘xxxxxxxxxx’,’xxxxxxxx’,’kill’,true,30)”type=”button”value=”Kill”>
调用了js的confirmAction方法,这个方法存在于storm-core/src/ui/public/js/script.js 中,
方法的定义如下:
functionconfirmAction(id,name,action,wait,defaultWait){varopts={type:’POST’,url:’/topology/’+id+’/’+action};if(wait){varwaitSecs=prompt(‘Doyoureallywantto’+action+’topology”‘+name+'”?’+’Ifyes,please,specifywaittimeinseconds:’,defaultWait);if(waitSecs!=null&&waitSecs!=””&&ensureInt(waitSecs)){opts.url+=’/’+waitSecs;}else{returnfalse;}}elseif(!confirm(‘Doyoureallywantto’+action+’topology”‘+name+'”?’)){returnfalse;}$(“input[type=button]”).attr(“disabled”,”disabled”);$.ajax(opts).always(function(){window.location.reload();}).fail(function(){alert(“ErrorwhilecommunicatingwithNimbus.”)});returnfalse;}
可以看到方法主要分为两步,生成post请求的url,格式为’/topology/’ + id + ‘/’ + action +’/’ + waitSecs,这里action为kill,waitSecs为触发kill时手动填入的时间,比如这里的30s,最终的url格式如下:
/topology/xxxxx/kill/xxxx
第二步就是根据这个设置触发一个ajax请求,这里我们只需要关心第一步即可,设置nginx如下:
upstreamstorm{server127.0.0.1:8888weight=3max_fails=3fail_timeout=5s;}server{server_namestorm.xxx.com;listen80;proxy_set_headerHost$host;proxy_read_timeout3600;proxy_set_headerX-Forwarded-For$remote_addr;access_log/var/log/nginx/storm.access.logmain;error_log/var/log/nginx/storm.error.logdebug;location~*/topology/(.*)/kill/(.*){return403;}location/{proxy_pass;}}这样,就可以屏蔽掉前端的kill功能了。
注意一个细节,storm ui的默认端口时8080,这个端口和nm冲突(见bughttps://github.com/yahoo/storm-yarn/issues/25),设置storm.yamlui.port: 8888,并重启ui即可.
2.更改代码,去掉action相关的button
游手好闲会使人心智生锈