也許這不是回答你的問題,但我想提供我的研究結果。
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);
});
這個腳本工作正常 - 簡單server.js傾聽和回答後查詢,因爲它應該如此我要問:你如何創建你的chroot環境?我創建了礦用debootstrap
工具從Debian的:
cd /mnt/chroot/
debootstrap wheezy ./wheezy-chroot http://ftp.us.debian.org/debian
cd wheezy-chroot
然後mount
PROC,sys和開發像往常一樣:
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這樣的機制。
謝謝@zarkone!任何你可以給出更多細節的機會(一行一行)你如何使用debootstrap和mount proc/sys/dev? – outside2344
'var request = require('request'), postRequest = request.post('http://www.google.com',{form:{key:'val'}});這個代碼可以工作,我從chroot得到了結果 – zarkone
chroot命令更新的答案 – zarkone