Is it okay to run Django API server with root permissions?

Viewed 205

I am running django server, using gunicorn. Apart from gunicorn, I have a layer of nginx as a load balancer and using supervisord to manage gunicorn.

From the perspective of security is it fine to run my gunicorn server with sudo permission? Is there any potential security leak?

Also, does it makes any difference if I am a superuser and not running process with sudo permission as in any case I have sudo permissions as the user.

3 Answers

Does it need to run as root?

If it doesn't, don't run it as root.

Even better, add a separate user for the app and run it as that user.

I believe the answer to question "is it ok to run xxx with root permissions" should not be "If it doesn't, don't run it as root." but rather a clear "NO".

Every single server and framework is designed to be run without root rights.

What can go wrong? In case you have a vulnerability allowing to remotely execute code on the server you would be simply giving root rights to whoever can exploit it. In case one of your developers in team does something stupid like deleting the root directory, it will be deleted. You don't want that a single app running on the server disrupts your whole system, do you?

It is not a good practice to run any external network facing application with root user privilege.

Consider a scenario where your uploaded file is not validated or sanitized ( file upload vulnerability). If someone uploads some vulnerable file and executes it. Consider that file to have implemented reverse shell. Then it gets easier to take down your server.

Related