Opened 12 years ago

Closed 8 years ago

#107 closed defect (fixed)

disable_symlinks

Reported by: Виктор Тюрин Owned by: somebody
Priority: critical Milestone:
Component: nginx-core Version: 1.1.x
Keywords: disable_symlinks Cc: admin@…, Viktor, Tyurin
uname -a: Linux mgnhost.com 2.6.32-220.4.2.el6.x86_64 #1 SMP Tue Feb 14 04:00:16 GMT 2012 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.1.15
built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-file-aio --with-mail_ssl_module --with-ipv6 --with-cc-opt='-O2 -g' --with-cc-opt='-O2 -g'

Description

При использовании disable_symlinks on; либо disable_symlinks if_not_owner; вся статика перестаёт отдаваться nginx'om, при этом в логах появляется:

*24 openat() "/var/www/user/data/www/domain.ru/images/images.gif" failed (13: Permission denied)

Удалось выяснить, что при включении опции disable_symlinks on будет работать только если все вышележащие директории имеют право на чтение списка файлов для юзера под которым работает nginx.
Пользователь под которым работает nginx может только заходить в каталоги, список файлов получать не может.
Nginx же работая под этим пользователем хочет получить листинг файлов оттуда (а вдруг там симлинк затесался) и не может - отсюда ошибка.
Повышать права на вышележащие директории, не вариант, т.к. это понижает безопасность.

С уважением, Виктор.
Администрация MGNHost.ru

Change History (7)

comment:1 by Maxim Dounin, 12 years ago

Resolution: fixed
Status: newclosed

Should be resolved by various additions in 1.1.16.

comment:2 by Виктор Тюрин, 12 years ago

При включенном disable_symlinks if_not_owner; и правах на каталог 751, под FreeBSD статика отдаётся нормально, а под линукс с теми же самыми правами, выдаётся 403 ошибка (доступ запрещён).

comment:3 by Maxim Dounin, 12 years ago

Это потому что на Linux'е нет поддержки O_SEARCH. Используйте "disable_symlinks ... from=...".

comment:4 by unreturned@…, 8 years ago

Resolution: fixed
Status: closedreopened

Проблема актуальна и не очень понятна, объясните, пожалуйста, подробнее:

В логе:

2016/02/09 12:53:12 [error] 26004#0: *499 openat() "/var/www/bsimple/data/www/bsimple.ru/games/2048/icon-128.png" failed (13: Permission denied), client: 88.201.183.42, server: bsimple.ru, request: "GET /games/2048/icon-128.png HTTP/1.1", host: "bsimple.ru"

Конфиг:

		disable_symlinks if_not_owner from=$root_path;
		index index.html, index.php;
		set $root_path /var/www/bsimple/data/www/bsimple.ru;
		location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
			root $root_path;
			expires 7d;
			access_log /var/www/nginx-logs/bsimple isp;
			access_log /var/www/httpd-logs/bsimple.ru.access.log ;
			error_page 404 = @fallback;
		}

Путь до данного файла:

namei -l /var/www/bsimple/data/www/bsimple.ru/games/2048/icon-128.png
f: /var/www/bsimple/data/www/bsimple.ru/games/2048/icon-128.png
drwxr-xr-x root    root      /
drwxr-xr-x root    root      var
drwxr-x--x root    root      www
dr-x-----x bsimple mgrsecure bsimple
drwxr-x--x bsimple bsimple   data
drwxr-x--x bsimple bsimple   www
drwxr-xr-x bsimple bsimple   bsimple.ru
drwxr-x--x bsimple bsimple   games
drwxr-xr-x bsimple bsimple   2048
-rw-r--r-- bsimple bsimple   icon-128.png

Лог strace на данный путь:

recvfrom(103, "GET /games/2048/icon-128.png HTT"..., 1024, 0, NULL, NULL) = 396
open("/var/www/bsimple/data/www/bsimple.ru", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = 104
openat(104, "games", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = -1 EACCES (Permission denied)
close(104)                              = 0
write(4, "2016/02/09 12:53:12 [error] 2600"..., 258) = 258
writev(103, [{"HTTP/1.1 403 Forbidden\r\nServer: "..., 200}, {"bb\r\n", 4}, {"\37\213\10\0\0\0\0\0\0\3", 10}, {"\355\220\261\16\2!\f\206w\23\337\241\336\216x\321\301\1Y\214&\16N>\1\\+\220p`\220D"..., 177}, {"\r\n0\r\n\r\n", 7}], 5) = 398
write(20, "398 396\n", 8)               = 8
write(21, "88.201.183.42 - - [09/Feb/2016:1"..., 207) = 207

Версия nginx

nginx -V
nginx version: nginx/1.8.1
built by gcc 4.7.2 (Debian 4.7.2-5) 
built with OpenSSL 1.0.1e 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' --with-ipv6

in reply to:  4 comment:5 by Valentin V. Bartenev, 8 years ago

sensitive: 0

Replying to unreturned@…:

Проблема актуальна и не очень понятна, объясните, пожалуйста, подробнее:

[...]

Цитата из документации:

На системах, не поддерживающих операцию открытия каталогов только для поиска, для использования этих параметров требуется, чтобы рабочие процессы имели право читать все проверяемые каталоги.

При этом у вас на каталоге games нет прав на чтение для всех пользователей и, по-видимому, рабочие процессы nginx работают не от имени bsimple и не входят в группу bsimple.

Просьба вопросы по конфигурации и документации задавать в списках рассылки.

comment:6 by unreturned@…, 8 years ago

Благодарю!

comment:7 by Maxim Dounin, 8 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.