【问题标题】:unexpected behaviour of ACL linux [closed]ACL linux的意外行为[关闭]
【发布时间】:2016-03-12 09:51:17
【问题描述】:

发现使用 d 开关使用 acl 时最奇怪的行为:

在 setfacl commando 中使用 d: 进行测试

create directory: mkdir /var/tmp/tester
create three users: useradd userA -d /tmp etc…
remove the other permission of the directory: chmod 750 /var/tmp/tester
grant acl permissions for userA: # file: setfacl -md:u:userA:rwx var/tmp/tester/
grant acl permissions for userB: setfacl -m d:u:userB:rx /var/tmp/tester
grant acl permissions for userC(not really needed): setfacl -m d:u:userC:rwx /var/tmp/tester
list the acl of the directory: getfacl /var/tmp/tester

       # owner: root
        # group: root
        user::rwx
        group::r-x
        other::---
        default:user::rwx
        default:user:userA:rwx
        default:user:userB:r-x
        default:user:userC:---
        default:group::r-x
        default:mask::rwx
        default:other::---

Become userA and navigate to the tester dir: ''su - userA cd /var/tmp''/tester

结果:-bash: cd: /var/tmp/tester: Permission denied

现在相同的测试,但不在我的 acl setfacl commando 中使用 d:

create directory: mkdir /var/tmp/tester
create three users: useradd userA -d /tmp etc…
remove the other permission of the directory: chmod 750 /var/tmp/tester
grant acl permissions for userA: # file: setfacl -m u:userA:rwx var/tmp/tester/
grant acl permissions for userB: setfacl -m u:userB:rx /var/tmp/tester
grant acl permissions for userC(not really needed): setfacl -m u:userC:rwx /var/tmp/tester
list the acl of the directory: getfacl /var/tmp/tester

       # owner: root
        # group: root
        user::rwx
        group::r-x
        other::---
        default:user::rwx
        default:user:userA:rwx
        default:user:userB:r-x
        default:user:userC:---
        default:group::r-x
        default:mask::rwx
        default:other::---

Become userA and navigate to the tester dir: ''su - userA cd /var/tmp''/tester

结果:成功!?

这是预期的行为吗? 为什么 getfacl 在测试中没有显示任何差异?

【问题讨论】:

    标签: linux bash acl


    【解决方案1】:

    d:default: 的缩写,指定目录的默认 ACL,而不是真正的ACL。来自man 5 acl

    OBJECT CREATION AND DEFAULT ACLs
         The access ACL of a file object is initialized when the object is created
         with any of the creat(), mkdir(), mknod(), mkfifo(), or open() functions.
         If a default ACL is associated with a directory, the mode parameter to
         the functions creating file objects and the default ACL of the directory
         are used to determine the ACL of the new object:
    
         1.   The new object inherits the default ACL of the containing directory
              as its access ACL.
    
         2.   The access ACL entries corresponding to the file permission bits are
              modified so that they contain no permissions that are not contained
              in the permissions specified by the mode parameter.
    

    所以,是的:当(不)使用d: 时,您观察到不同的行为是正常的。

    但是请注意,您发布的 getfacl 的输出是错误的:在第二种情况下(不使用 d: 时),您应该有一些以 user:userAuser:userBuser:userC 为前缀的行,而不是以default: 为前缀的行。这是一个更简单的例子:

    $ mkdir a b
    $ setfacl -m u:nobody:rx a
    $ setfacl -m d:u:nobody:rx b
    $ diff -u <(getfacl a) <(getfacl b)
    --- /dev/fd/63  2016-03-12 11:10:20.032239216 +0100
    +++ /dev/fd/62  2016-03-12 11:10:20.024239117 +0100
    @@ -1,9 +1,12 @@
    -# file: a
    +# file: b
     # owner: andrea
     # group: andrea
     user::rwx
    -user:nobody:r-x
     group::rwx
    -mask::rwx
     other::r-x
    +default:user::rwx
    +default:user:nobody:r-x
    +default:group::rwx
    +default:mask::rwx
    +default:other::r-x
    

    【讨论】:

    • @Sander: 使用d 您正在设置 default ACL,而不是真正的 ACL。阅读我发布的手册页摘录以了解有关默认 ACL 的更多信息
    • 你是对的,我发布的输出不正确,我在这个网站上粘贴我的文字时遇到了一些问题。所以我的第二个问题不是一个正确的问题。但是我的第一个呢。我创建了一个目录,对其进行 chmod,设置 acl 为 userA 提供完全权限,并且在使用带有 d:? 的 acl commando 时无法访问 /var/tmp/tester 目录。对我来说,使用默认的 acl 开关不会授予对目录的奇怪访问权限,这会使我设置的 acl 无用,而不使用 d 开关会使 acl 按我的预期工作。我希望你在使用我的突击队员时明白我的意思
    • @Sander:再次,请务必阅读手册页摘录。只有在创建新对象(文件、目录、fifo、设备)时才应用默认 ACL。它完全不影响目录本身的所有权限
    • 谢谢你,andrea,我看到了这个人,不知道这一点,如果我想将 acl 应用于当前文件和目录以及未来的文件,我应该执行两个 acl 命令,一个用于默认, 一个用于当前。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    相关资源
    最近更新 更多