This topic describes how to configure NFSv4 access control lists (ACLs) and apply these ACLs to NFSv4 file systems to control access to files and directories.
Prerequisites
The NFS ACL feature is available only for NFS file systems in the following regions: China (Zhangjiakou-Beijing Winter Olympics), China (Beijing), China (Hohhot), China (Hangzhou), China (Shanghai), China (Chengdu), China (Hong Kong), Australia (Sydney), Indonesia (Jakarta), US (Silicon Valley), US (Virginia), Germany (Frankfurt), UK (London), and India (Mumbai). If the region where your file system resides does not support the NFS ACL feature, submit a ticket.
Background information
You can mount an NFSv4 file system on an Elastic Compute Service (ECS) instance that runs Linux and install the Linux-specific nfs4-acl-tools tool on the instance. You can use the standard nfs4_getfacl and nfs4_setfacl tools to configure NFSv4 ACLs after the installation is complete.
Description
Before you configure NFSv4 ACLs, we recommend that you familiarize yourself with the related commands.
Command | Description |
---|---|
nfs4_getfacl <filename> |
Views the access permissions for the specified file. |
nfs4_setfacl -a A::GROUP@:W <filename> |
Adds an access control entry (ACE) that grants the GROUP@ principal the write access to the specified file. |
nfs4_setfacl -a A::1000:W <filename> |
Adds an ACE that grants a user principal named 1000 the write access to the specified file. |
nfs4_setfacl -a A:g:10001:W <filename> |
Adds an ACE that grants a group principal named 10001 the write access to the specified file. |
nfs4_setfacl -e <filename> |
Configures an ACL in an interactive mode. |
nfs4_getfacl <filename> > saved_acl.txt |
Saves a list of permissions for the specified file as a TXT file. |
nfs4_setfacl -S saved_acl.txt <filename> |
Configures permissions for the specified file by using a TXT file that includes a list of ready-made permissions. |
nfs4_setfacl -m A::1001:rwaxTNcCy A::1001:rxtcy file1 |
Modifies the permission of an ACE that applies to the file1 file. |
nfs4_getfacl file1 | nfs4_setfacl -S - file2 |
Copies the permissions for the file1 file to the file2 file. |
nfs4_getfacl file1 | grep @ | nfs4_setfacl -S - file1 |
Deletes all ACEs that apply to the file1 file except for ACEs that include the following principals: OWNER@, GROUP@, and EVERYONE@. |
nfs4_setfacl -R -a A:g:10001:rW dir |
Adds an ACE that grants a group principal named 10001 the read and write access to files and subdirectories in the dir directory. |
find dir -type f -exec sh -c 'for ace in $(nfs4_getfacl \{} | grep "^A.*\:1005\:");
do nfs4_setfacl -x $ace \{}; done' \; |
Deletes ACEs that grant a user principal named 1005 any access to files in the dir directory. |
nfs4_setfacl -a A:fdg:10001:rW dir1 |
Adds an ACE that grants a group principal named 10001 the read and write access to all newly created files and subdirectories in the dir1 directory. |
nfs4_setfacl -a A:fg:10001:rx dir1 |
Adds an ACE that grants a group principal named 10001 the read and write access to all newly created files in the dir1 directory. |
Procedure
You can configure NFSv4 ACLs to control access to files and directories by performing the following steps.
Related operations
If you want to remove user permissions, use the following method.
We recommend that you sort each user into different groups when you use NFSv4 ACLs. Then, when you configure NFSv4 ACLs, you only need to configure permissions for a group rather than a separate user. You can disable access to an object from a user by removing the user from a group that has access to the object. For example, use the following commands to remove the admini user from the adminis group and add the user to the adminis2 group:
[root@vbox test] sudo groupadd adminis2
[root@vbox test] sudo usermod -g adminis2 admini
[root@vbox test] id admini
uid=1057(admini) gid=1057(admini) groups=1054(adminis2)
[root@vbox test] sudo su admini -c 'ls dir0'
ls: cannot open directory dir0: Permission denied
[root@vbox test] sudo su admini -c 'cat dir0/file'
cat: dir0/file: Permission denied
[root@vbox test] sudo su admini -c 'nfs4_getfacl dir0/file'
Invalid filename: dir0/file