NFSv4 ACL特性

更新时间:

本文介绍NFSv4 ACL权限顺序、权限继承、排序、合并、迁移等特性。

权限顺序

权限生效的顺序,按照显示的ACE顺序evaluate。

ACE类型支持Allow和Deny,Deny可以被设置在任何位置。假设ACL有两个ACE(group:adminis:rwxc和group:adminis:r---),两个ACE的先后顺序会直接决定adminis2是否具有读权限。您在设置ACL时,需要非常注意ACE的位置。

假设在目录dir4中,用户adminis2的权限如下所示,则表示用户adminis2对目录dir4具有所有权限。

#NFSv4 ACL
#owner:root
#group:root
group:adminis2:rwxc:allow
 (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (X)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED

group:adminis2:r---:deny
 (X)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED

special:owner@:---c:allow
 (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (X)CHOWN        (-)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED

special:group@:----:allow
 (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED

special:everyone@:----:allow
 (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED

假设在目录dir4中,用户adminis2的权限如下所示,则表示用户adminis2无读权限。

#NFSv4 ACL
#owner:root
#group:root
group:adminis2:r---:deny
 (X)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED

group:adminis2:rwxc:allow
 (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (X)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED

special:owner@:---c:allow
 (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (X)CHOWN        (-)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED

special:group@:----:allow
 (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED

special:everyone@:----:allow
 (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
 (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
                

ACL排序和合并

当为用户新增ACE后,新的ACE并不会与旧的ACE合并。

例如,用户1001(属于群组players)在文件file中具备如下ACL,为用户player增加W权限的ACE后,新的ACE不会与旧的ACE合并。

  • 旧ACE权限

    #NFSv4 ACL
    #owner:root
    #group:root
    special:everyone@:----:allow:FileInherit:DirInherit
     (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    special:group@:----:allow:FileInherit:DirInherit
     (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    special:owner@:----:allow:FileInherit:DirInherit
     (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    group:adminis:rwxc:allow:FileInherit:DirInherit
     (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (X)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED
    
    group:players:r-x-:allow:FileInherit:DirInherit
     (X)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
  • 新ACE权限

    #NFSv4 ACL
    #owner:root
    #group:root
    group:players:rwx-:allow:Inherited
     (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED
    
    special:everyone@:----:allow:FileInherit:DirInherit
     (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    special:group@:----:allow:FileInherit:DirInherit
     (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    special:owner@:----:allow:FileInherit:DirInherit
     (-)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    group:adminis:rwxc:allow:FileInherit:DirInherit
     (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (X)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED
    
    group:players:r-x-:allow:FileInherit:DirInherit
     (X)READ/LIST (-)WRITE/CREATE (-)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED

验证新增的权限生效。

  • 执行命令

    sudo su player -c 'echo 456 >> file'
    sudo su player -c 'cat file'
  • 返回示例

    123
    456

权限继承

假设当前目录dir5的权限是owner可写,group可读,everyone不能访问。

  • 给用户player增加读写权限并且可继承。

    1. 为用户player配置读写权限,并将规则保存至文本(例如,acl2.txt)中。

      #NFSv4 ACL
      #owner:root
      #group:root
      user:player:rwx-:allow:DirInherit
       (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
       (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
      
      user:player:rwx-:allow:FileInherit
       (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
       (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    2. 将acl2的规则应用到目录dir5上。

      mmputacl -i ~/acl2.txt dir5
  • 在目录dir5下创建的文件或目录就自动带有继承的ACE。

    1. 进入目录dir5。

      cd  dir5
    2. 创建文件file。

      touch file
    3. 确认文件file自动继承目录dir5的ACE权限。

      • 执行命令

        mmgetacl file
      • 返回示例

        #NFSv4 ACL
        #owner:root
        #group:root
        user:player:rwx-:allow:Inherited
         (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    4. 创建目录subdir。

      mkdir subdir
    5. 确认子目录subdir自动继承目录dir5的ACE权限。

      • 执行命令

        mmgetacl subdir
      • 返回示例

        #NFSv4 ACL
        #owner:root
        #group:root
        user:player:rwx-:allow:DirInherit:Inherited
         (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
        
        user:player:rwx-:allow:FileInherit:InheritOnly:Inherited
         (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
  • 继续在子目录subdir下创建的文件或目录就自动带有继承的ACE。

    1. 创建目录subdir/subdir2。

      mkdir subdir/subdir2
    2. 确认目录subdir/subdir2自动继承子目录subdir的ACE。

      • 执行命令

        mmgetacl subdir/subdir2
      • 返回示例

        #NFSv4 ACL
        #owner:root
        #group:root
        user:player:rwx-:allow:DirInherit:Inherited
         (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
        
        user:player:rwx-:allow:FileInherit:InheritOnly:Inherited
         (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    3. 创建文件subdir/file2。

      touch subdir/file2
    4. 确认文件subdir/file2自动继承子目录subdir的ACE。

      • 执行命令

        mmgetacl subdir/file2
      • 返回示例

        #NFSv4 ACL
        #owner:root
        #group:root
        user:player:rwx-:allow:Inherited
         (X)READ/LIST (X)WRITE/CREATE (-)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED      

InheritOnly在当前目录不参加权限校验,但ACE会继承。

说明
  • DirInheritFileInherit要分成两个ACE配置,否则会报错Combining FileInherit and DirInherit makes the mask ambiguous

  • inherit only时,由于ACE本身不做权限检查,父目录上要配置rx权限,否则player无法进入子目录。

输出

不支持通过extended attributes输出NFSv4 ACL。

迁移

支持cp等工具迁移NFSv4 ACL。

阿里云CPFS支持使用Redhat NFSv4 ACL迁移工具说明中提到的cp、tar、rsync工具迁移NFSv4 ACL。

下面例子中cp --preserve=xattr file2 file5拷贝file2到file5时拷贝了ACL。

说明

rsync工具可能由于版本低于3.1.2而不能迁移NFSv4 ACL。

  1. 将file2的ACL迁移至file5。

    cp --preserve=xattr newsub/file2 newsub/file5
  2. 查看file2的ACL。

    • 执行命令

      mmgetacl newsub/file2
    • 返回示例

      #NFSv4 ACL
      #owner:player
      #group:players
      user:player:rwx-:allow:Inherited
       (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
       (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (X)WRITE_ATTR (-)WRITE_NAMED
  3. 查看file5的ACL。

    • 执行命令

      mmgetacl newsub/file5
    • 返回示例

      #NFSv4 ACL
      #owner:root
      #group:root
      user:player:rwx-:allow:Inherited
       (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (-)SYNCHRONIZE (-)READ_ACL  (-)READ_ATTR  (-)READ_NAMED
       (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (X)WRITE_ATTR (-)WRITE_NAMED

NFSv4 ACL与mode的互操作

支持NFSv4 ACL和mode之间的互操作,修改ACL可能引起mode的改变,反之亦然。

例如,文件file当前mode为0666。

  • 文件file的mode权限

    -rw-rw-rw- 1 root root 0 Jun  1 14:45 file
  • 文件file的ACE权限

    #NFSv4 ACL
    #owner:root
    #group:root
    special:owner@:rw-c:allow
     (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (X)CHOWN        (-)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED
    
    special:group@:rw--:allow
     (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    
    special:everyone@:rw--:allow
     (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
     (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
  • 通过设置mode给owner增加执行权限,相应ACE也会增加执行权限。

    1. 通过设置mode给owner增加执行权限。

      chmod u+x file
    2. 查看文件file的mode权限。

      • 执行命令

        ls -l file
      • 返回示例

        -rwxrw-rw- 1 root root 0 Jun  1 14:45 file
    3. 确认ACE中owner已增加执行权限。

      • 执行命令

        mmgetacl file
      • 返回示例

        #NFSv4 ACL
        #owner:root
        #group:root
        special:owner@:rwxc:allow
         (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (X)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED
        
        special:group@:rw--:allow
         (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
        
        special:everyone@:rw--:allow
         (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
  • 通过设置ACE给group增加执行权限,相应mode也会增加执行权限。

    1. 编辑file的ACL属性给group增加执行权限。

      mmeditacl file
    2. 在返回的信息后,输入yes,确认应用修改的权限。

    3. 查看在文件file中group拥有的ACE权限。

      • 执行命令

        mmgetacl file
      • 返回示例

        #NFSv4 ACL
        #owner:root
        #group:root
        special:owner@:rwxc:allow
         (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (X)CHOWN        (X)EXEC/SEARCH (X)WRITE_ACL (X)WRITE_ATTR (X)WRITE_NAMED
        
        special:group@:rwx-:allow
         (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (X)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
        
        special:everyone@:rw--:allow
         (X)READ/LIST (X)WRITE/CREATE (X)APPEND/MKDIR (X)SYNCHRONIZE (X)READ_ACL  (X)READ_ATTR  (X)READ_NAMED
         (-)DELETE    (-)DELETE_CHILD (-)CHOWN        (-)EXEC/SEARCH (-)WRITE_ACL (-)WRITE_ATTR (-)WRITE_NAMED
    4. 确认在mode中group已增加执行权限。

      • 执行命令

        ls -l file
      • 返回示例

        -rwxrwxrw- 1 root root 0 Jun  1 14:45 file

NFSv4 ACL与POSIX ACL互操作

不支持与POSIX ACL互操作。