'permission deny with mkdir throw a symbolic-linked directory (php apache)

I have 2 websites whose must communicate to write and read documents uploaded by apache (www-data).

The documents are registered in a other disk partition named "/nas".

Here are the permission accorded to www-data

drwxrwxr-x  2 www-data www-data 4096 Jan 31 22:08 /nas/app/members
drwxrwxr-x  2 www-data www-data 4096 Jan 24 00:45 /nas/app/kbis
drwxrwxr-x 42 www-data www-data 4096 Mar 24 10:06 /nas/app/agreements

In my websites (/var/www/html/mywebsite1/ and /var/www/html/mywebsite2), i created 3 symlinks :

sudo -u www-data ln -s /nas/app/kbis kbis
sudo -u www-data ln -s /nas/app/members members
sudo -u www-data ln -s /nas/app/agreements agreements

Here are the permission accorded to www-data for my symlinks :

lrwxrwxrwx  1 www-data www-data     21 Mar 24 09:49 kbis -> /nas/app/kbis
lrwxrwxrwx  1 www-data www-data     21 Mar 24 09:49 members -> /nas/app/members
lrwxrwxrwx  1 www-data www-data     21 Mar 24 09:49 agreements -> /nas/app/agreements

When i try to create a path with mkdir in my path created it's ok :

sudo -u www-data mkdir /nas/app/agreements/test-file

When i try to create a path with mkdir in my path created throw my symlink with root, it's ok :

sudo mkdir /var/www/mywebsite1/agreements/test-file

But when i try to create a path with mkdir in my path created throw my symlink with www-data, i have a 403 (permission denied) error :

sudo -u www-data mkdir /var/www/mywebsite1/agreements/test-file

I don't understand why www-data cannot access and write throw symlink.

Other information :

  • ubuntu server 20.04
  • apache 2.4 (Symlink permission authorized in /var/www with Options Indexes FollowSymLinks)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source