1

I am having some problems understanding all the mechanisms behind the user management with upstart, node and bash.

What I want to do:

I want to have a service, that executes a node script. This node script opens a port and the server, and when it receives a request, it executes a bash file via a child process.

I have a user named myuser with sudo rights.

So here is my service description:

description "Some Service"
author "My User"

start on filesystem runlevel [2345]
stop on shutdown
respawn
setuid myuser

exec /usr/bin/node /home/myuser/deploy/index.js

Then, here is my node file:

app.post('/deploy', function (req, res) {
    ...
    var child = execFile('/home/myuser/deploy/deploy.sh', execOptions, function(error, stdout, stderr) {
        ...
    });
    res.send('ok');
});

And next, here is a part of my bash file:

LOG_FILE="/home/myuser/bash_deployer.log"

echo "User that deploys: $USER" >> $LOG_FILE;
echo "UID that deploys: $UID" >> $LOG_FILE;

So here is the result of the bash_deployer.log file:

User that deploys:
UID that deploys: 1001

So I can't understand why my $USER variable stays empty while the $UID is good.

I want to make sure that all commands that are in my bash script are run by the user myuser. How could I do that?

Additional information:

When I run my node script from the command line logged as myuser: node index.js and make a request, the information is good:

User that deploys: myuser
UID that deploys: 1001

So the problem must be between upstart and node, or how I could make sure the upstart service runs my node script as myuser

Hammerbot
  • 175
  • 2
  • 8

1 Answers1

0

I think I found a solution, not sure if it's the right solution, but I post it anyway. And I actually don't understand very well, what I did wrong in the first place.

The problem was in the upstart service, here is my new one that works well:

description "Some Service"
author "My User"

start on filesystem runlevel [2345]
stop on shutdown
respawn

exec sudo -u myuser /usr/bin/node /home/myuser/deploy/index.js

As you see, I execute the command itself as myuser instead of using the setuid of upstart.

Hammerbot
  • 175
  • 2
  • 8