0

I have a a file in remote directory which is moulted to apache DocRoot tree. When I try to download a file (not write) from that dir I get 403: AH00037: Symbolic link not allowed or link target not accessible: /var/www/b2b/web/var

What I tried:

  • Selinux is disabled
  • Options +FollowSymLinks is present
  • If I replace link to another FS with link on the same FS - it works!

The file:

namei -l /var/www/b2b/web/var/assets/75259_box1_v29.jpg
f: /var/www/b2b/web/var/assets/75259_box1_v29.jpg
dr-xr-xr-x root     root     /
drwxr-xr-x root     root     var
drwxr-xr-x root     root     www
drwxrwxrwx www-data www-data b2b
drwxrwxrwx www-data www-data web
lrwxrwxrwx root     root     var -> /var/www/b2b/nfs/b2b-web-var
dr-xr-xr-x root     root       /
drwxr-xr-x root     root       var
drwxr-xr-x root     root       www
drwxrwxrwx www-data www-data   b2b
drwxrwxrwx www-data www-data   nfs
drwxrwxrwx www-data www-data   b2b-web-var
drwxrwxrwx www-data www-data assets
-rwxrwxrwx www-data www-data 75259_box1_v29.jpg

So, in /var/www/b2b/web/ I have:

lrwxrwxrwx 1 root     root       28 Oct  3 09:10 var -> /var/www/b2b/nfs/b2b-web-var

I've created var1 which has same content as /var/www/b2b/nfs/b2b-web-var, if I do like below (link is local) then everything works:

lrwxrwxrwx 1 root     root        4 Oct  3 18:15 var -> var1
drwxr-xr-x 4 root     root     4096 Oct  3 18:13 var1

/etc/fstab:

fs-1111111111:/  /var/www/b2b/nfs efs defaults,_netdev  0 0

DocumentRoot is /var/www/b2b/web

Also I tried strace, but cannot understand what exactly is wrong:

[pid 11381] stat("/var/www/b2b/web/var/assets/75259_box1_v29.jpg",  [wait(0x857f) = 11381] WIFSTOPPED,sig=133
{st_mode=S_IFREG|0777, st_size=201249, ...}) = 0
[pid 11381] gettimeofday( [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11419] semop(2326532, {{0, -1, SEM_UNDO|IPC_NOWAIT}}, 1 <unfinished ...>
[pid 11416] semop(2326532, {{0, -1, SEM_UNDO|IPC_NOWAIT}}, 1 <unfinished ...>
[pid 11381] stat("/var/www/b2b/web/var/assets/75259_box1_v29.jpg",  [wait(0x857f) = 11419] WIFSTOPPED,sig=133
[pid 11419] <... semop resumed> )       = -1 EAGAIN (Resource temporarily unavailable)
[pid 11416] <... semop resumed> )       = -1 EAGAIN (Resource temporarily unavailable)
[pid 11381] <... stat resumed> {st_mode=S_IFREG|0777, st_size=201249, ...}) = 0
[pid 11381] lstat("/var/www/b2b/web/var",  [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11381] stat("/var/www/b2b/web/var",  [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11381] gettimeofday( [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11381] write(7, "[Thu Oct 03 18:34:35.430672 2019"..., 175 [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11381] gettimeofday( [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11381] read(12,  [wait(0x857f) = 11381] WIFSTOPPED,sig=133
0x555c658e7068, 8000) = -1 EAGAIN (Resource temporarily unavailable)
[pid 11381] gettimeofday( [wait(0x857f) = 11381] WIFSTOPPED,sig=133
[pid 11381] writev(12, [{"HTTP/1.1 403 Forbidden\r\nDate: Th"..., 172}, {"<!DOCTYPE HTML PUBLIC \"-//IETF//"..., 357}], 2 [wait(0x857f) = 11381] WIFSTOPPED,sig=133

I thought about timeouts but I can read the file content using su apache then e.g. with head /var/www/b2b/web/var/assets/75259_box1_v29.jpg | less. So, what's wrong here?

Putnik
  • 2,217
  • 4
  • 27
  • 43

1 Answers1

0

Solution: owner of symlink must be the same as the rest of the website:

# pwd
/var/www/b2b/web
# chown -h www-data.www-data var #voila!

Note: -SymLinksIfOwnerMatch is NOT enough in my case, idk why.

Note2: don't forget '-h', otherwise chownn will be on applied the target, not on the link itself. And if you want to chown link to directory then do not add trailing slash!

Putnik
  • 2,217
  • 4
  • 27
  • 43