downgrade-identity
This module implements a single, flexible method for downgrading process identity,
e.g. after listening to a privileged port. Out of the box it supports user/group
identity specified via npm command line arguments or via the standard SUDO_
environment
variables, or it can be provide a custom options object.
Install
npm install downgrade-identity
Usage
Following examples all assume a server.js
like this:
var http = argv = argv downgradeIdentity = ; downgradeIdentityverbose = true; var server = http;server;
no args
Won't work because I'm not a privileged user.
% node test.jsinitial process identity is 113/113 events.js:72 throw er; // Unhandled 'error' event ^Error: listen EACCES
sudo
Will downgrade to identity pulled from SUDO_
environment variables.
% sudo env | grep SUDOSUDO_COMMAND=/usr/bin/envSUDO_USER=femto113SUDO_UID=113SUDO_GID=113% sudo node test.jsinitial process identity is 0/0process identity downgraded to 113/113
npm command line
Will downgrade to specified identity pulled from npm_config_
environment variables.
% sudo npm start --setuid=113 --setgid=113 > node-downgrade-identity@0.1.0 start /home/femto113/node-downgrade-identity> node server.js initial process identity is 0/0process identity downgraded to 113/113
optimist command line
Downgrade to specified identity provided via opts
export.
% sudo node server.js --setuid 113 --setgid 113 % sudo node server.js --setuid 113 --setgid 113initial process identity is 0/0process identity downgraded to 113/113