如何阻止对符号链接的读取访问?

Bra*_*ley 4 ftp permissions symlink

我有这个文件结构:

> APPLICATION 1
>> CONTROLLER (@JuniorProgrammers)
>> MODELS (symlink to SHARED/MODELS)
>> VIEWS (@Designers)
> APPLICATION 2
>> CONTROLLER (@JuniorProgrammers)
>> MODELS (symlink to SHARED/MODELS)
>> VIEWS (@Designers)
> SHARED
>> MODELS (@SeniorProgrammers)
Run Code Online (Sandbox Code Playgroud)

我需要 php 才能读取文件夹 1.1 的内容,但是通过 FTP 进入文件夹 1 的程序员将无法读取符号链接(他们可以看到符号链接,但不能跟随它,包括所有读取和写入)。

@是对每一层具有读/写访问权限的用户组。

Bra*_*ley 6

符号链接本身有 777 个,因为在 Unix 中,文件安全性是根据文件/inode 判断的。如果它们操作的是相同的数据,那么它应该具有相同的安全条件,无论您为系统提供什么名称来打开它。

[root@hypervisor test]# ls -l
total 0
lrwxrwxrwx. 1 root root 10 Jun  8 16:01 symTest -> /etc/fstab
[root@hypervisor test]# chmod o-rwx symTest
[root@hypervisor test]# ls -l
total 0
lrwxrwxrwx. 1 root root 10 Jun  8 16:01 symTest -> /etc/fstab
[root@hypervisor test]# :-(
Run Code Online (Sandbox Code Playgroud)

由于在 inode 上设置了权限,因此它甚至无法处理硬链接:

[root@hypervisor test]# echo "Don't Test Me, Bro" > testing123
[root@hypervisor test]# ls -l
total 4
lrwxrwxrwx. 1 root root 10 Jun  8 16:01 symTest -> /etc/fstab
-rw-r--r--. 1 root root 19 Jun  8 16:06 testing123
[root@hypervisor test]# ln testing123 newHardLink
[root@hypervisor test]# ls -l
total 8
-rw-r--r--. 2 root root 19 Jun  8 16:06 newHardLink
lrwxrwxrwx. 1 root root 10 Jun  8 16:01 symTest -> /etc/fstab
-rw-r--r--. 2 root root 19 Jun  8 16:06 testing123
[root@hypervisor test]# chmod 770 testing123
[root@hypervisor test]# chmod 700 newHardLink
[root@hypervisor test]# ls -lh
total 8.0K
-rwx------. 2 root root 19 Jun  8 16:06 newHardLink
lrwxrwxrwx. 1 root root 10 Jun  8 16:01 symTest -> /etc/fstab
-rwx------. 2 root root 19 Jun  8 16:06 testing123
Run Code Online (Sandbox Code Playgroud)

符号链接不是 inode(它实际上存储您想要保护的数据),因此在 Unix 模型中它通过具有两组不同的权限来保护相同的数据使事情复杂化。

这听起来像是试图为不同的人群提供对同一文件的不同级别的访问权限。如果是这种情况,您实际上应该使用 POSIX ACL(通过setfaclgetfacl)来为文件在符号链接的目标上授予适当的权限。

编辑:

要详细说明您可能想要进入的方向,它类似于:

# setfacl -m u:apache:r-- "Folder 2.1"
# setfacl -m g:groupOfProgrammers:--- "Folder 2.1"
# setfacl -m g:groupOfProgrammers:r-x "Folder 1"
Run Code Online (Sandbox Code Playgroud)

以上为apache用户(替换为您的 apache/nginx/任何正在运行的任何用户)只读访问符号链接的目标,并授予groupOfProgrammers对符号链接所在目录的读取访问权限(以便groupOfProgrammers可以获得完整目录在那里列出),但关闭符号链接的同一目标的所有权限位。