How do I run uWSGI as a limited-access user?
Asked Answered
G

2

6

I have Django setup in NGINX + uWSGI. I'm able to get it running fine under my current logged in user (with help from a question I asked few days back) but now I want to run uwsgi --ini uwsgi.ini as a limited-access user.

Here is what I've done so far:
1. Created a user djangouser without login access and without a home directory.
2. Added user nginx into group djangouser
3. Placed my django files into /mnt/django directory and changed file permissions of django to drwxrwx--- djangouser djangouser (recursive)
4. Changed the conf files to match the file locations

uwsgi.ini file

[uwsgi]
chdir=/mnt/django/project/awssite
module=awssite.wsgi
home=/mnt/django/project
master=true
processes=2
uid=djangouser
gid=djangouser
socket=/mnt/django/djangosocket/awssite.socket
chmod-socket
vacuum=true

When I try to run uwsgi --ini uwsgi.ini, this is the error I get

[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.12 (64bit) on [Thu Feb 18 00:18:25 2016] ***
compiled with version: 4.8.3 20140911 (Red Hat 4.8.3-9) on 01 February 2016 04:17:11
os: Linux-4.1.13-19.31.amzn1.x86_64 #1 SMP Wed Jan 20 00:25:47 UTC 2016
nodename: ip-10-200-1-89
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ec2-user
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /mnt/django/project/awssite
chdir(): Permission denied [core/uwsgi.c line 2586]
chdir(): Permission denied [core/uwsgi.c line 1608]

Note: When I added my logged in user to djangouser group, uwsgi --ini uwsgi.ini ran fine and I was able to load the django pages.

I'm not sure where else to add permissions to allow this to work. Adding sudo chown-socket=djangouser:djangouser in uwsgi.ini didn't work either.

I appreciate the help :)

Gd answered 18/2, 2016 at 0:31 Comment(0)
E
4

If you want to run uWSGI as particular user, there are only 2 options:

  1. run uWSGI server directly from this user
  2. run uWSGI as root and add uid and gid options.
Extraterrestrial answered 18/2, 2016 at 0:36 Comment(0)
D
3

You can create a user and set the uid/gid properties in your uwsgi ini file.

[uwsgi] ... uid=myuser gid=mygroup

I tested this with uwsgi version 2.0.12-debian and it worked for a simple cgi app using a python3 virtualenv.

http://uwsgi-docs.readthedocs.io/en/latest/Options.html#uid

Dorty answered 22/1, 2018 at 23:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.