Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Storm UI 的 kill 功能怎麼關?兩種禁用手法與注意事項

今天有個 topology 被人 kill 掉,卻查不出是誰做的。Storm UI 自帶 kill topology 的功能,但完全沒有權限驗證——只要知道 UI 位址,任何人都能把 topology 停掉,風險不小,因此決定把這個 action 封掉。

方法一:在 nginx 層攔截請求

先分析 UI 頁面上 kill 按鈕的行為,html 中的 action 為:

<input enabled="" onclick="confirmAction('xxxxxxxxxx', 'xxxxxxxx', 'kill', true, 30)"
       type="button" value="Kill">

它呼叫 script.js 裡的 confirmAction:

function confirmAction(id, name, action, wait, defaultWait) {
    var opts = {type:'POST', url:'/topology/' + id + '/' + action};
    if (wait) {
        var waitSecs = prompt('Do you really want to ' + action + ' topology "'
            + name + '"? If yes, please, specify wait time in seconds:', defaultWait);
        if (waitSecs != null && waitSecs != "" && ensureInt(waitSecs)) {
            opts.url += '/' + waitSecs;
        } else {
            return false;
        }
    }
    ...
    $.ajax(opts).always(function () { window.location.reload(); });
    return false;
}

可見流程只有兩步:先組出 POST 的 url,格式為 /topology/{id}/{action}/{waitSecs},這裡 action 是 kill、waitSecs 是使用者手動填入的秒數(例如 30),最終形如 /topology/xxxxx/kill/30;接著發出 ajax 請求。我們只要攔住第一步即可,nginx 設定如下:

upstream storm {
    server 127.0.0.1:8888 weight=3 max_fails=3 fail_timeout=5s;
}
server {
    server_name storm.xxx.com;
    listen 80;
    proxy_set_header Host $host;
    proxy_read_timeout 3600;
    proxy_set_header X-Forwarded-For $remote_addr;
    access_log /var/log/nginx/storm.access.log main;
    error_log  /var/log/nginx/storm.error.log debug;

    location ~* /topology/(.*)/kill/(.*) {
        return 403;
    }
    location / {
        proxy_pass https://storm;
    }
}

這樣一來,前端送出的 kill 請求會被直接回 403,功能等於被關閉,而且不必改 Storm 原始碼。

這裡有個容易忽略的細節:Storm UI 預設埠是 8080,會與 NodeManager 衝突(見 storm-yarn issue #25),因此實務上多把 ui.port 改為 8888 並重啟 UI,上面的 upstream 也才對得上。

方法二:改原始碼移除按鈕

編輯 storm-core/src/ui/public/topology.html,刪掉動作區塊:

<div id="topology-actions">
 <h2 class="js-only">Topology actions</h2>
 <p id="topology-actions" class="js-only"></p>
</div>

這種做法需要重新編譯打包,我還沒實際測試。

兩種方式取捨很清楚:nginx 攔截改動小、可立即生效,缺點是繞過 UI 直連 Nimbus 埠仍下得了手,所以真正的根本解法是限制 Nimbus 埠的存取來源;改原始碼則是讓按鈕消失,屬於介面上的收斂,防禦等級並不比較高。

Copyright © Linux教程網 All Rights Reserved