Welcome! Log In Create A New Profile

Advanced

File Upload Permissions Issues

Posted by VP Lists 
VP Lists
File Upload Permissions Issues
June 26, 2018 11:00PM
Hi folks.

I’m having a problem uploading any files of any significant size to a test site on my workstation.

2018/06/26 16:50:20 [crit] 36196#0: *1099 open() "/usr/local/var/run/nginx/client_body_temp/0000000018" failed (13: Permission denied), client: 127.0.0.1, server: pass1.local, request: "POST /upload HTTP/1.1", host: "pass1.local:8080", referrer: "http://pass1.local:8080/upload";
2018/06/26 16:50:20 [debug] 36196#0: *1099 http finalize request: 500, "/upload?" a:1, c:1
2018/06/26 16:50:20 [debug] 36196#0: *1099 event timer del: 16: 1530046280299
2018/06/26 16:50:20 [debug] 36196#0: *1099 http special response: 500, "/upload?"
2018/06/26 16:50:20 [debug] 36196#0: *1099 HTTP/1.1 500 Internal Server Error
Server: nginx/1.15.0
Date: Tue, 26 Jun 2018 20:50:20 GMT
Content-Type: text/html
Content-Length: 595
Connection: close

2018/06/26 16:50:20 [debug] 36196#0: *1099 write new buf t:1 f:0 00007FACB10021A0, pos 00007FACB10021A0, size: 162 file: 0, size: 0
2018/06/26 16:50:20 [debug] 36196#0: *1099 http write filter: l:0 f:0 s:162
2018/06/26 16:50:20 [debug] 36196#0: *1099 http output filter "/upload?"
2018/06/26 16:50:20 [debug] 36196#0: *1099 http copy filter: "/upload?"
2018/06/26 16:50:20 [debug] 36196#0: *1099 http postpone filter "/upload?" 00007FACB10023C0
2018/06/26 16:50:20 [debug] 36196#0: *1099 write old buf t:1 f:0 00007FACB10021A0, pos 00007FACB10021A0, size: 162 file: 0, size: 0
2018/06/26 16:50:20 [debug] 36196#0: *1099 write new buf t:0 f:0 0000000000000000, pos 000000010A332120, size: 140 file: 0, size: 0
2018/06/26 16:50:20 [debug] 36196#0: *1099 write new buf t:0 f:0 0000000000000000, pos 000000010A330F20, size: 53 file: 0, size: 0
2018/06/26 16:50:20 [debug] 36196#0: *1099 write new buf t:0 f:0 0000000000000000, pos 000000010A330FD0, size: 402 file: 0, size: 0
2018/06/26 16:50:20 [debug] 36196#0: *1099 http write filter: l:1 f:0 s:757
2018/06/26 16:50:20 [debug] 36196#0: *1099 http write filter limit 0
2018/06/26 16:50:20 [debug] 36196#0: *1099 writev: 757 of 757
2018/06/26 16:50:20 [debug] 36196#0: *1099 http write filter 0000000000000000
2018/06/26 16:50:20 [debug] 36196#0: *1099 http copy filter: 0 "/upload?"
2018/06/26 16:50:20 [debug] 36196#0: *1099 http finalize request: 0, "/upload?" a:1, c:1
2018/06/26 16:50:20 [debug] 36196#0: *1099 event timer add: 16: 5000:1530046225299
2018/06/26 16:50:20 [debug] 36196#0: *1099 http lingering close handler
2018/06/26 16:50:20 [debug] 36196#0: *1099 recv: eof:0, avail:73728, err:0

My nginx.conf has no set ‘user’ and here are the permissions set on the temp file upload folder for nginx:

$ ll /usr/local/var/run/nginx/
drwxr-xr-x 7 rich admin 238B Dec 8 2016 .
drwxr-xr-x 4 rich admin 136B Jun 19 15:19 ..
drwx------ 2 nobody admin 68B Dec 8 2016 client_body_temp

I have 4 workers owned by nobody:admin, and nginx is run as default, as root:admin.

Now this topic of permissions and “what user should run nginx” has come up before. Some say run as root, others say not. It’s my workstation, so it doesn’t really matter. It’s my dev box. The issue comes down to production.

Is there one way all of this should be run without the worried security devs out there from losing it? Since I’m here at another security issue with who runs what, maybe it’s a good time to get a consensus on how all this should be set up.

Cheers

_____________
Rich in Toronto @ VP






_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: File Upload Permissions Issues
June 27, 2018 05:00AM
Hello!

On Tue, Jun 26, 2018 at 04:56:55PM -0400, VP Lists wrote:

> I’m having a problem uploading any files of any significant size to a test site on my workstation.
>
> 2018/06/26 16:50:20 [crit] 36196#0: *1099 open() "/usr/local/var/run/nginx/client_body_temp/0000000018" failed (13: Permission denied), client: 127.0.0.1, server: pass1.local, request: "POST /upload HTTP/1.1", host: "pass1.local:8080", referrer: "http://pass1.local:8080/upload";

The error message speaks for itself: nginx has no permissions to
write temporary files to the directory it was configured to write
temporary files to. You have to fix this.

[...]

> My nginx.conf has no set ‘user’

This means that nginx will use the default user for worker
processes as long as it is started as root. Usually this is
nobody:nogroup, or whatever is set via configure arguments (see
"nginx -V").

> and here are the permissions set on the temp file upload folder for nginx:
>
> $ ll /usr/local/var/run/nginx/
> drwxr-xr-x 7 rich admin 238B Dec 8 2016 .
> drwxr-xr-x 4 rich admin 136B Jun 19 15:19 ..
> drwx------ 2 nobody admin 68B Dec 8 2016 client_body_temp

You have to check all path compontents. That is, check that nginx
has at least "x" on "/", "/usr", "/usr/local", "/usr/local/var",
"/usr/local/var/run".

Additionally, if you have SELinux or equivalent enabled, you
should check it as well.

> I have 4 workers owned by nobody:admin, and nginx is run as
> default, as root:admin.
>
> Now this topic of permissions and “what user should run nginx”
> has come up before. Some say run as root, others say not. It’s
> my workstation, so it doesn’t really matter. It’s my dev box.
> The issue comes down to production.
>
> Is there one way all of this should be run without the worried
> security devs out there from losing it? Since I’m here at
> another security issue with who runs what, maybe it’s a good
> time to get a consensus on how all this should be set up.

You should never run nginx worker processes as root unless you
understand what you are doing and possible consequences.

On the other hand, nginx master process can't do many required
things - like binding to port 80 - without being root. As such,
you have to run nginx itself (that is, nginx master process) as
root.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
VP Lists
Re: File Upload Permissions Issues
June 27, 2018 07:00AM
> On Jun 26, 2018, at 10:51 PM, Maxim Dounin <[email protected]> wrote:
>
> Hello!

Hello there. Thanks for the reply.

> On Tue, Jun 26, 2018 at 04:56:55PM -0400, VP Lists wrote:
>
>> I’m having a problem uploading any files of any significant size to a test site on my workstation.
>>
>> 2018/06/26 16:50:20 [crit] 36196#0: *1099 open() "/usr/local/var/run/nginx/client_body_temp/0000000018" failed (13: Permission denied), client: 127.0.0.1, server: pass1.local, request: "POST /upload HTTP/1.1", host: "pass1.local:8080", referrer: "http://pass1.local:8080/upload";
>
> The error message speaks for itself: nginx has no permissions to
> write temporary files to the directory it was configured to write
> temporary files to. You have to fix this.
>
> [...]
>
>> My nginx.conf has no set ‘user’
>
> This means that nginx will use the default user for worker
> processes as long as it is started as root. Usually this is
> nobody:nogroup, or whatever is set via configure arguments (see
> "nginx -V”).

That command didn’t lend itself to anything. No user mentioned anywhere in that result. It’s running as root, with the workers being run as nobody.

>> and here are the permissions set on the temp file upload folder for nginx:
>>
>> $ ll /usr/local/var/run/nginx/
>> drwxr-xr-x 7 rich admin 238B Dec 8 2016 .
>> drwxr-xr-x 4 rich admin 136B Jun 19 15:19 ..
>> drwx------ 2 nobody admin 68B Dec 8 2016 client_body_temp
>
> You have to check all path compontents. That is, check that nginx
> has at least "x" on "/", "/usr", "/usr/local", "/usr/local/var",
> "/usr/local/var/run”.

OK, here’s where things get interesting:

On MacOS El Capitan: --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp
/usr [email protected] 13 root wheel 442B May 26 2017 usr
/usr/local drwxr-xr-x 28 rich admin 952B Mar 30 16:12 local
/usr/local/var drwx------ 36 rich admin 1.2K May 7 21:01 var
/usr/local/var/run drwxr-xr-x 4 rich admin 136B Jun 19 15:19 run
/usr/local/var/run/nginx drwxr-xr-x 7 rich admin 238B Dec 8 2016 nginx
/usr/local/var/run/nginx/client_body_temp drwx------ 2 nobody admin 68B Dec 8 2016 client_body_temp


On FreeBSD 11.1-RELEASE: --http-client-body-temp-path=/var/tmp/nginx/client_body_temp
/var drwxr-xr-x 25 root wheel 25 May 7 08:48 var
/var/tmp drwxrwxrwt 4 root wheel 4 Jul 7 2017 tmp
/var/tmp/nginx drwxr-xr-x 7 root wheel 7 Jul 13 2017 nginx
/var/tmp/nginx/client_body_temp drwx------ 2 www wheel 2 Jul 7 2017 client_body_temp

On two different boxes, two different OSes, showing variable eXecution permissions within the path. Not only that, but in both instances, the client_body_temp permissions show “drwx- - - - - -“, and for two different owner:group combinations.

Why would nginx allow this to happen? Is it not thinkable that either nginx would state that a clear path to the directory responsible for receiving file uploads be permitted? Or maybe the maintainers receiving this as a criteria for installation? I find this quite odd.

Running around patching up path permissions to installed directories, specific to nginx, is truly strange.

> Additionally, if you have SELinux or equivalent enabled, you
> should check it as well.
>
>> I have 4 workers owned by nobody:admin, and nginx is run as
>> default, as root:admin.
>>
>> Now this topic of permissions and “what user should run nginx”
>> has come up before. Some say run as root, others say not. It’s
>> my workstation, so it doesn’t really matter. It’s my dev box.
>> The issue comes down to production.
>>
>> Is there one way all of this should be run without the worried
>> security devs out there from losing it? Since I’m here at
>> another security issue with who runs what, maybe it’s a good
>> time to get a consensus on how all this should be set up.
>
> You should never run nginx worker processes as root unless you
> understand what you are doing and possible consequences.

I don’t. I don’t even set nginx master to run as root, but it does. nginx.conf:

# user root admin; # commented out

> On the other hand, nginx master process can't do many required
> things - like binding to port 80 - without being root. As such,
> you have to run nginx itself (that is, nginx master process) as
> root.

This last paragraph has people doing backflips to interject. OSX has chosen to run as root, and I’m running vhosts on port 80. FreeBSD also has master user commented out as ‘root’, but working on port 8080. I doubt I asked it to work on port 80 so far, given the setup I have.

In any case, I fixed it. /usr/local/var was a bit closed up. Not friendly.

Cheers


_____________
Rich in Toronto @ VP






_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: File Upload Permissions Issues
June 27, 2018 08:10AM
Hello!

On Wed, Jun 27, 2018 at 12:56:09AM -0400, VP Lists wrote:

[...]

> OK, here’s where things get interesting:
>
> On MacOS El Capitan: --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp
> /usr [email protected] 13 root wheel 442B May 26 2017 usr
> /usr/local drwxr-xr-x 28 rich admin 952B Mar 30 16:12 local
> /usr/local/var drwx------ 36 rich admin 1.2K May 7 21:01 var

Clearly "nobody" has no rights to work with anything in
/usr/local/var. That's what causes the error you've faced. You
have to fix it for things to work.

[...]

> On two different boxes, two different OSes, showing variable
> eXecution permissions within the path. Not only that, but in
> both instances, the client_body_temp permissions show “drwx- - -
> - - -“, and for two different owner:group combinations.
>
> Why would nginx allow this to happen? Is it not thinkable that
> either nginx would state that a clear path to the directory
> responsible for receiving file uploads be permitted? Or maybe
> the maintainers receiving this as a criteria for installation?
> I find this quite odd.
>
> Running around patching up path permissions to installed
> directories, specific to nginx, is truly strange.

Permissions on FreeBSD are perfectly fine.

Permissions on macOS are broken due to incorrect permissions on
/usr/local/var, and it's clearly not nginx business to do anything
with permissions on the system-wide directory.

If you think packaging system you've used to install things into
/usr/local/ could be better at maintaining correct permissions on
various folders under /usr/local/ - you may want to contact
authors of the packaging system.

[...]

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
VP Lists
Re: File Upload Permissions Issues
June 27, 2018 03:50PM
> On Jun 27, 2018, at 2:02 AM, Maxim Dounin <[email protected]> wrote:
>
> Hello!

Hello again!

> On Wed, Jun 27, 2018 at 12:56:09AM -0400, VP Lists wrote:
>
> [...]
>
>> OK, here’s where things get interesting:
>>
>> On MacOS El Capitan: --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp
>> /usr [email protected] 13 root wheel 442B May 26 2017 usr
>> /usr/local drwxr-xr-x 28 rich admin 952B Mar 30 16:12 local
>> /usr/local/var drwx------ 36 rich admin 1.2K May 7 21:01 var
>
> Clearly "nobody" has no rights to work with anything in
> /usr/local/var. That's what causes the error you've faced. You
> have to fix it for things to work.

I changed it to 755. Works now.

> [...]
>
>> On two different boxes, two different OSes, showing variable
>> eXecution permissions within the path. Not only that, but in
>> both instances, the client_body_temp permissions show “drwx- - -
>> - - -“, and for two different owner:group combinations.
>>
>> Why would nginx allow this to happen? Is it not thinkable that
>> either nginx would state that a clear path to the directory
>> responsible for receiving file uploads be permitted? Or maybe
>> the maintainers receiving this as a criteria for installation?
>> I find this quite odd.
>>
>> Running around patching up path permissions to installed
>> directories, specific to nginx, is truly strange.
>
> Permissions on FreeBSD are perfectly fine.
>
> Permissions on macOS are broken due to incorrect permissions on
> /usr/local/var, and it's clearly not nginx business to do anything
> with permissions on the system-wide directory.
>
> If you think packaging system you've used to install things into
> /usr/local/ could be better at maintaining correct permissions on
> various folders under /usr/local/ - you may want to contact
> authors of the packaging system.

With regards to system-wide directories and nginx choosing this as the target directory, I’m not versed in who has what right to do what during installation, with regards to chmod, chown, chgrp, etc. As well, the same goes for package managers vs nginx. I was just under the assumption it would all have a collective agreement that a sticky permission (t) would apply so that there could be some kind of installation functionality happening. But I guess not, so the /usr/local/var permissions, even though a system-wide directory, needed to be changed.

Cheers

_____________
Rich in Toronto @ VP






_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login