为什么为目录所有者设置了 acl 的目录的权限被拒绝(删除所有标准 posix 权限后)?

为什么为目录所有者设置了 acl 的目录的权限被拒绝(删除所有标准 posix 权限后)?

我试图ls在一个目录上执行该命令,该目录具有目录所有者和组的 acl 权限(没有设置标准 posix 权限)。这会导致权限被拒绝,即使getfacl用户应该能够这样做。

这就是我正在做的:

  1. 创建一个目录并在其中创建一个文件。

mkdir /tmp/mydir && touch /tmp/mydir/myfile

  1. 检查我是否可以ls在此目录上执行。
jgazula@gazula:/tmp$ ls -al /tmp/mydir/
total 896
drwxrwxr-x  2 jgazula jgazula   4096 Nov  1 11:57 .
drwxrwxrwt 25 root    root    909312 Nov  1 11:57 ..
-rw-rw-r--  1 jgazula jgazula      0 Nov  1 11:57 myfile
  1. 现在,让我们删除该目录的所有标准 posix 权限。

chmod 000 /tmp/mydir

  1. 验证权限。
jgazula@gazula:/tmp$ ls -al /tmp | grep mydir
d---------  2 jgazula jgazula   4096 Nov  1 11:57 mydir
  1. 我们现在应该做不到ls
jgazula@gazula:/tmp$ ls -al /tmp/mydir/
ls: cannot open directory '/tmp/mydir/': Permission denied
  1. jgazula为用户和组设置acl权限。

sudo setfacl --mask -Rm u:jgazula:rwx,g:jgazula:rwx /tmp/mydir/

  1. 验证 acl 权限。
jgazula@gazula:/tmp$ getfacl -ep /tmp/mydir/
# file: /tmp/mydir/
# owner: jgazula
# group: jgazula
user::---
user:jgazula:rwx        #effective:rwx
group::---          #effective:---
group:jgazula:rwx       #effective:rwx
mask::rwx
other::---
  1. 既然acl权限(包括有效权限)看起来不错,我应该能够ls在目录上执行?
jgazula@gazula:/tmp$ ls -al /tmp/mydir/
ls: cannot open directory '/tmp/mydir/': Permission denied

但我不能,也不明白为什么。

  1. 有趣的是,当我检查标准 posix 权限时,组权限位是否已设置?不确定我明白为什么只更新了组权限。
jgazula@gazula:/tmp$ ls -al /tmp | grep mydir
d---rwx---+  2 jgazula jgazula   4096 Nov  1 12:13 mydir
  1. 让我们为所有者和组设置 acl 权限(即,从命令中省略所有者/组)。

sudo setfacl --mask -Rm u::rwx,g::rwx /tmp/mydir/

  1. 再次验证acl权限。
jgazula@gazula:/tmp$ getfacl -ep /tmp/mydir/
# file: /tmp/mydir/
# owner: jgazula
# group: jgazula
user::rwx
user:jgazula:rwx        #effective:rwx
group::rwx          #effective:rwx
group:jgazula:rwx       #effective:rwx
mask::rwx
other::---
  1. 检查我现在是否可以执行ls
jgazula@gazula:/tmp$ ls -al /tmp/mydir/
total 896
drwxrwx---+  2 jgazula jgazula   4096 Nov  1 11:57 .
drwxrwxrwt  25 root    root    909312 Nov  1 11:57 ..
-rwxrwxr--+  1 jgazula jgazula      0 Nov  1 11:57 myfile

为什么步骤#6 本身不起作用?我正在为用户和组明确设置 acl 权限。为什么我需要执行步骤#11?

答案1

当您运行时sudo setfacl --mask -Rm u:jgazula:rwx,g:jgazula:rwx /tmp/mydir/,您正在ACL_USER为 user 创建一个条目jgazula。但ACL_USER_OBJ文件所有者的 仍然是---. (您可以getfacl在步骤 7 的输出中看到这一点。)

根据man ACL,访问检查算法如下:

1.   If the effective user ID of the process matches the user ID of the file object owner, then
           if the ACL_USER_OBJ entry contains the requested permissions, access is granted,
           else access is denied.

2.   else if the effective user ID of the process matches the qualifier of any entry of type ACL_USER, then
           if the matching ACL_USER entry and the ACL_MASK entry contain the requested permissions, access is granted,
           else access is denied.

因此,该ACL_USER条目甚至从未被检查过。

关于 serverfault 基本上有同样的问题:ACL:为文件所有者授予- - - 权限。 (但看起来答案似乎ACL_USER相反ACL_USER_OBJ。)

相关内容