0

I have a weird issue I can't seem to figure out.

I am using OpenResty. The way it should work on that particular server is that the whole configuration and Lua scripts and everything comes from a Git repo. The ubuntu user should manage the repository and OpenResty's workers should run as www-data (I've set user www-data www-data; in the config). I'm using Ubuntu 22.04.

The repository is located at /home/ubuntu/app/my-project and acts as prefix for OpenResty.

It seems however like the worker processes can't access anything in that directory (the main process can). The Lua files are not executed (there is no error about that either, though), some config values seem to be ignored, and I get "error 13: permission denied" when trying to write into temp/client_body/... and also when reading from html/index.html and such:

open() "/home/ubuntu/app/my-project/temp/client_body/0000093402" failed (13: Permission denied) 

All the files and directories within the project are set to group www-data, and the temp directory which holds client_body and such even has an owner of www-data, and the read/write permissions are set correctly. When I do sudo -u www-data bash, I can read and write there just fine, but when the OpenResty worker process does that, it gets "permission denied" nonetheless.

The client_body directory was even auto-created by OpenResty and looks like this:

drwx------ 2 www-data root 4096 Dec 4 18:49 client_body 

My first thought was that ProtectHome could be an issue, but I would have expected that to interfere also with the master process and not just the workers, plus I did set that to false already.

I added an access_by_lua_block in which I run id and log its output, and I get, as expected, this:

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Interestingly though, if I use /usr/local/openresty/nginx as prefix path, everything works. (But I would prefer to have the Git repo in /home/ubuntu/app/my-project...) Also, if I configure OpenResty to run as user ubuntu and not www-data, it works too.

I am at the end of my knowledge here. What else could be wrong?

For the record, this is my openresty.service file:

[Unit] Description=The OpenResty Application Platform After=syslog.target network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] WorkingDirectory=/home/ubuntu/app/my-project Type=forking PIDFile=/home/ubuntu/app/my-project/logs/nginx.pid ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;' -p /home/ubuntu/app/my-project ExecStart=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;' -p /home/ubuntu/app/my-project ExecReload=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload -p /home/ubuntu/app/my-project ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /home/ubuntu/app/my-project/logs/nginx.pid TimeoutStopSec=5 KillMode=mixed ProtectHome=false [Install] WantedBy=multi-user.target 

Note: The answers to this question suggested it could be an SELinux issue, however sudo sestatus outputs SELinux status: disabled for me (and trying to run sudo semanage permissive -a httpd_t anyway results in an error that the policy isn't managed, as expected).

1 Answer 1

0

I figured it out.

The issue was that even though /, /home, /home/ubuntu/app and /home/ubuntu/app/my-project were accessible to www-data, /home/ubuntu was not (it was 750 with ubuntu:ubuntu).

I now decided to move the whole project directory to /var/www/my-project, adding ubuntu to the www-data group and keeping /home/ubuntu/app/my-project as symlink to /var/www/my-project while changing all the paths in the service unit file to /var/www/my-project as well. This solved the issue.


Now the part that threw me off and prevented me from realizing this sooner was this: It did work before when I tried sudo -u www-data bash and then used ls /home/ubuntu/app/my-project/html or echo hello > /home/ubuntu/app/my-project/temp/client_body/test. However, after playing with this more, I realized that it only worked when I had /home/ubuntu/app/my-project already as working directory beforehand!

ubuntu@my-server:~/app/my-project$ sudo -u www-data bash www-data@my-server:/home/ubuntu/app/my-project$ echo hello > /home/ubuntu/app/my-project/temp/client_body/test www-data@my-server:/home/ubuntu/app/my-project$ cat /home/ubuntu/app/my-project/temp/client_body/test hello 
ubuntu@my-server:/var/www$ sudo -u www-data bash www-data@my-server:/var/www$ echo hello > /home/ubuntu/app/my-project/temp/client_body/test bash: /home/ubuntu/app/my-project/temp/client_body/test: Permission denied 

This is doubly weird because in my service unit file the WorkingDirectory was defined to be that exact directory, but maybe OpenResty changed it before forking.

Anyway, if somebody has an explanation for this, please let me know in the comments!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.