簡體   English   中英

node.js錯誤:getaddrinfo ENOTFOUND在chroot監獄中發出http請求

[英]node.js Error: getaddrinfo ENOTFOUND making http request in chroot jail

我試圖在chroot監獄中執行一個node.js子進程,以防止其訪問其目錄之外的文件系統。

但是,當我這樣做時,應用程序無法再通過“請求”模塊發出http請求。 我提出的任何請求均以“錯誤:getaddrinfo ENOTFOUND”結尾。

在node.js項目中關閉了一個問題,似乎表明您需要替換dns.lookup的實現或將/etc/resolv.conf復制到監獄中(對我而言都不起作用): https:// github .COM / Joyent公司/節點/問題/ 3399

還有一個Google網上論壇線程: https : //groups.google.com/forum/#!topic/ nodejs/ Qb_LMLulZS4

這似乎建議您“將綁定庫及其所有依賴項也放入監獄”。 我不明白那句話。

任何人都能正確分享他們所做的工作嗎?

也許這不是回答您的問題,但我想提供我的研究結果。

var ls = require('child_process').spawn('chroot', ['/mnt/chroot/wheezy-chroot', 'node', '/root/simple-server.js']);

ls.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

ls.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

ls.on('close', function (code) {
  console.log('child process exited with code ' + code);
});

該腳本可以正常工作-simple-server.js可以偵聽並回答帖子查詢,因此我想問:如何創建chroot環境? 我用Debian的debootstrap實用程序創建了我的:

cd /mnt/chroot/
debootstrap wheezy ./wheezy-chroot http://ftp.us.debian.org/debian
cd wheezy-chroot

然后像往常一樣mount proc,sys和dev:

mount -t proc none proc
mount --rbind /dev dev
mount --rbind /sys sys

而且我掛載/usr/local/以獲得對node訪問權。 我建議“將綁定庫及其所有依賴項也放入監獄”。 該語句意味着掛載您需要的所有東西,例如mount -o bind /usr/local /mnt/chroot/wheezy-chroot/usr/local

萬一我完全錯過了我的答案,我會留下這個鏈接: https : //github.com/magne4000/node-jail-也許您覺得這個軟件包有用。

最后一件事:據我所知chroot在某些情況下不是安全的解決方案( http://en.wikipedia.org/wiki/Chroot#Limitations )。 也許您應該看看FreeBSD Jail甚至LXC之類的機制。

我不知道子進程中的chroot。

但是對於使用chroot npm軟件包,我發現如果在chroot之前執行dns.lookup() ,即使在chroot之后,dns查找也可以正常工作。

dns.lookup()將在chroot之前將用於getaddrinfo()調用的必要庫加載到內存中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM