From 2c3650746cd90fed63b140a8d393e18bd35cd8f9 Mon Sep 17 00:00:00 2001 From: Niall O'Higgins Date: Mon, 27 Feb 2012 14:34:34 -0800 Subject: [PATCH] problem: don't want to run my server as root to bind to privileged ports (e.g. 80, 443). solution: support privilege drop after socket bind via new --user parameter. --- bin/node-http-proxy | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/node-http-proxy b/bin/node-http-proxy index b15d164..a0d2b89 100755 --- a/bin/node-http-proxy +++ b/bin/node-http-proxy @@ -17,6 +17,7 @@ var help = [ " --target HOST:PORT Location of the server the proxy will target", " --config OUTFILE Location of the configuration file for the proxy server", " --silent Silence the log output from the proxy server", + " --user USER User to drop privileges to once server socket is bound", " -h, --help You're staring at it" ].join('\n'); @@ -28,6 +29,7 @@ var location, config = {}, port = argv.port || 80, host = argv.host || undefined, target = argv.target; + user = argv.user; // // If we were passed a config, parse it @@ -85,6 +87,14 @@ if (host) { server.listen(port); } + +// +// Drop privileges if requested +// +if (typeof user === 'string') { + process.setuid(user); +} + // // Notify that the server is started //