為什麼目錄擁有者設定了 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。)

相關內容