Introduction
What are ACLs?
ACLs versus Traditional Permissions
ACLs though powerful add additional complexity to the system and do have some limitations discussed further down this article. You will notice throughout the Bonsai Framework we add ACLs only when absolutely necessary.
Limitations
Support in Utilities - For example, the version of GNU tar packaged with the OS may not back up or restore ACLs.
Standardizing Across Operating Systems - Moving files with ACLs between operating systems that both support ACLs may not work.
Move - Moving a file created outside of an ACL directory into an ACL directory will not result in inheritance of permissions.
Backup - The most used backup command in *nix, tar, does not support ACLs unless modified. Some distributions like redhat have this built into tar. Otherwise your options are to use star or manually backup and restore the ACLs. Options are covered in this article.
Copying Files - This is no-longer an issue with modern (2012 is when I checked) versions of Ubuntu and I would guess other *nix systems. With an older system, check that when setting default ACLs on a directory, the following commands will inherit permissions properly: local copy, sftp remote create and sftp remote copy.
ACLs and Groups
The most scalable way to use ACLs is to apply groups. A tutorial approach will be used to illustrate the commands.
The scenario is we want to provide website hosting for two different clients who we will start by categorizing into two different groups,
User | Group | Web Directory | File Access | Directory Access |
---|---|---|---|---|
Daily Planet Employees | wgdailyplanet | /home/www.dailyplanet.com/ | Read, Write and Execute | Read, Write and Execute |
LexCorp Employees | wglexcorp | /hom/www.lexcorp.com/ | Read, Write and Execute | Read, Write and Execute |
Apache Server | www-data | /home/www.dailyplanet.com/ /home/www.lexcorp.com/ | Read | Read and Execute (required to transverse directories) |
Staff Users | staff | /home/www.dailyplanet.com/ | Read | Read and Execute (required to transverse directories) |
We do not want employees from different companies access or even have awareness of each others web directory. At the same time, the Apache Server running as user www-data belonging to group www-data also needs access to the directories. We also want to grant users of the staff group read access for support purposes.
The utility setfacl is used to add the groups to the ACL for the respective directories,
cd /home/ # Normal permissions sudo chmod -R o-rwx ./www.dailyplanet.com/ # ACL permissions sudo setfacl -Rm g:wgdailyplanet:rwX ./www.dailyplanet.com/ sudo setfacl -Rm g:www-data:rX ./www.dailyplanet.com/ sudo setfacl -Rm g:staff:rX ./www.dailyplanet.com/
Take a look at the ACLs,
getfacl ./www.dailyplanet.com/ # file: www.dailyplanet.com # owner: ckent # group: ckent user::rwx group::rwx group:www-data:r-x group:staff:r-x group:wgdailyplanet:rwx mask::rwx other::--- default:user::rwx default:group::rwx default:group:www-data:r-x default:group:staff:r-x default:group:wgdailyplanet:rwx default:mask::rwx default:other::---
Don't be alarmed that you see x on the groups www-data, staff and wgdailyplanet. That is normal *nix convention it means that execute permission will only be applied on directories. Files will be default not have execute permission applied.
Once we are happy with the permissions, change the default ACLs so any files or folders created underneath the parent directories are maintained,
getfacl --access ./www.dailyplanet.com/ | sudo setfacl -d -RM - ./www.dailyplanet.com/
getfacl --access generates the details of the permissions applied to the directory. The details are then piped to setfacl and the parameters read,
-d = Change default permissions for newly created files and folder.
-M = Take as input files. Because the dash is used, the file is instead standard input.
R = Apply changes recursively to folders and files.
Repeat the same steps for www.lexcorp.com and change the group accordingly,
cd /home/ # Normal permissions sudo chmod -R o-rwx ./www.lexcorp.com/ # ACL permissions sudo setfacl -Rm g:wglexcorp:rwX ./www.lexcorp.com/ sudo setfacl -Rm g:www-data:rX ./www.lexcorp.com/ sudo setfacl -Rm g:staff:rX ./www.lexcorp.com/ # Apply default ACLs getfacl --access ./www.lexcorp.com/ | sudo setfacl -d -RM - ./www.lexcorp.com/
Backup and Restore
Introduction
The current (September 2012) GNU version of TAR does not support ACLs without modifications.
As with any backup and restore scenario where user based permissions matter, make sure the users actually exist and match. To ensure you have no issues, also ensure consistent use of user and group UIDs.
Backup
ACLs permissions can be backed up to a text file,
cd /home/ sudo getfacl -R ./www.dailyplanet.com/ > ./www.dailyplanet.com.acl.bck.txt
It is important to run with sudo so that getfacl can properly transverse the directories and owner comments or group comments will be retained.
Backup the files into tar and gzip or similar program,
# consider command what will also drop in the acl.bck file.
Restore
Uncompress the backup, in this case we used the tar with gunzip,
....
Restoring ACLs
Restoring is a pretty straightforward process.
cd /home/ sudo setfacl --restore ./bck.www.dailyplanet.com.acl.bck.txt
References
Good introduction from the Ubuntu docs - https://help.ubuntu.com/community/FilePermissionsACLs
Slightly Skeptical view on ACLs - http://www.softpanorama.org/Articles/slightly_skeptical_view_on_unix_acl.shtml
Got me to understand why execute permission was set on the groups - http://superuser.com/questions/180545/setting-differing-acls-on-directories-and-files
Notes on backup and restoring ACLs using dump file - http://www.projectenvision.com/blog/4/Enable-Support-for-ACL-in-Debian-Ubuntu