Difference between revisions of "Access Control Lists"

From ArchWiki
Jump to: navigation, search
m (Additional Resources: > See also)
(Show ACL section)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
[[Category:Security]]
 
[[Category:Security]]
 +
[[ja:アクセス制御リスト]]
 
[[ru:Access Control Lists]]
 
[[ru:Access Control Lists]]
 
'''A'''ccess '''C'''ontrol '''L'''ist (ACL) provides an additional, more flexible permission mechanism for file systems. It is designed to assist with <code>UNIX</code> file permissions. ACL allows you to give permissions for any user or group to any disc resource.
 
'''A'''ccess '''C'''ontrol '''L'''ist (ACL) provides an additional, more flexible permission mechanism for file systems. It is designed to assist with <code>UNIX</code> file permissions. ACL allows you to give permissions for any user or group to any disc resource.
Line 13: Line 14:
 
To enable ACL, the filesystem must be mounted with the {{ic|acl}} option. You can use [[fstab]] to make it permanent on your system.
 
To enable ACL, the filesystem must be mounted with the {{ic|acl}} option. You can use [[fstab]] to make it permanent on your system.
  
There is a big chance that the {{ic|acl}} option is already active as default mount option of your filesystem. Use the following command to check it:
+
There is a possibility that the {{ic|acl}} option is already active as default mount option on the filesystem. [[Btrfs]] does and possibly ext filesystems do too.  Use the following command to check ext* formatted partitions for the option:
  
 
{{hc|# tune2fs -l /dev/sd''XY'' <nowiki>|</nowiki> grep "Default mount options:"|
 
{{hc|# tune2fs -l /dev/sd''XY'' <nowiki>|</nowiki> grep "Default mount options:"|
Line 51: Line 52:
 
  # setfacl -x "entry"
 
  # setfacl -x "entry"
  
To check permissions use:
+
=== Show ACL ===
 +
To show permissions, use:
 
  # getfacl filename
 
  # getfacl filename
  
Line 114: Line 116:
 
}}
 
}}
  
== Increase security of your web server ==
+
== Granting execution permissions for private files to a Web Server ==
You can now add permissions to our home directory and/or site directory only to nobody user any anyone else - without "whole world" to increase your security.
+
The following technique describes how a process like a web server can be granted access to files that reside in a user's home directory, without compromising security by giving the whole world access.
  
Add permissions '''+x''' for nobody user on your home directory via ACL:
+
In the following we assume that the web server runs as the user {{ic|webserver}} and grant it access to {{ic|geoffrey}}'s home directory {{ic|/home/geoffrey}}.
  # setfacl -m "u:nobody:--x" /home/homeusername/
+
 
Now you can remove whole world rx permissions:
+
The first step is granting execution permission to {{ic|webserver}} so it can access {{ic|geoffrey}}'s home:  
  # chmod o-rx /home/homeusername/
+
  # setfacl -m "u:webserver:--x" /home/geoffrey
Check our changes:
+
''Remember'': Execution permissions to a directory are necessary for a process to list the directory's content.
   
+
 
  # file: username/
+
 
  # owner: username
+
Since {{ic|webserver}} is now able to access files in {{ic|/home/geoffrey}}, {{ic|other}}s do no longer need access:
  # group: users
+
  # chmod o-rx /home/geoffrey
 +
 
 +
{{ic|getfacl}} can be used to verify the changes:
 +
  $ getfacl /home/geoffrey
 +
getfacl: Removing leading '/' from absolute path names
 +
  # file: home/geoffrey
 +
  # owner: geoffrey
 +
  # group: geoffrey
 
  user::rwx
 
  user::rwx
  user:nobody:--x
+
  user:webserver:--x
 
  group::r-x
 
  group::r-x
 
  mask::r-x
 
  mask::r-x
 
  other::---
 
  other::---
  
As we can see others do not have any permissions but user nobody have "x" permission so they can "look" into users directory and give access to users pages from their home directories to www server. Of course if www server work as nobody user. But - whole world except nobody - do not have any permissions.
+
As the above output shows, {{ic|other}}s no longer have any permissions, but {{ic|webserver}} still is able to access the files, thus security might be considered increased.
  
 
== See also ==
 
== See also ==
Line 138: Line 147:
 
* Man Page - {{ic|man getfacl}}
 
* Man Page - {{ic|man getfacl}}
 
* Man Page - {{ic|man setfacl}}
 
* Man Page - {{ic|man setfacl}}
 +
* An old but still relevant (and thorough) [http://www.vanemery.com/Linux/ACL/linux-acl.html guide] to ACL

Latest revision as of 12:09, 17 June 2016

Access Control List (ACL) provides an additional, more flexible permission mechanism for file systems. It is designed to assist with UNIX file permissions. ACL allows you to give permissions for any user or group to any disc resource.

Installation

The required package acl is a dependency of systemd, it should already be installed.

Configuration

Enabling ACL

To enable ACL, the filesystem must be mounted with the acl option. You can use fstab to make it permanent on your system.

There is a possibility that the acl option is already active as default mount option on the filesystem. Btrfs does and possibly ext filesystems do too. Use the following command to check ext* formatted partitions for the option:

# tune2fs -l /dev/sdXY | grep "Default mount options:"
Default mount options:    user_xattr acl

Also check that the default mount option is not overridden, in such case you will see noacl in /proc/mounts in the relevant line.

You can set the default mount options of a filesystem using the tune2fs -o option partition command, for example:

# tune2fs -o acl /dev/sdXY

Using the default mount options instead of an entry in /etc/fstab is very useful for external drives, such partition will be mounted with acl option also on other Linux machines. There is no need to edit /etc/fstab on every machine.

Note:
  • acl is specified as default mount option when creating an ext2/3/4 filesystem. This is configured in /etc/mke2fs.conf.
  • The default mount options are not listed in /proc/mounts.

Set ACL

To modify ACL use setfacl command. To add permissions use setfacl -m.

Add permissions to some user:

# setfacl -m "u:username:permissions"

or

# setfacl -m "u:uid:permissions"

Add permissions to some group:

# setfacl -m "g:groupname:permissions"

or

# setfacl -m "g:gid:permissions"

Remove all permissions:

# setfacl -b

Remove each entry:

# setfacl -x "entry"

Show ACL

To show permissions, use:

# getfacl filename

Examples

Set all permissions for user johny to file named "abc":

# setfacl -m "u:johny:rwx" abc

Check permissions

# getfacl abc
# file: abc
# owner: someone
# group: someone
user::rw-
user:johny:rwx
group::r--
mask::rwx
other::r--

Change permissions for user johny:

# setfacl -m "u:johny:r-x" abc

Check permissions

# getfacl abc
# file: abc
# owner: someone
# group: someone
user::rw-
user:johny:r-x
group::r--
mask::r-x
other::r--

Remove all extended ACL entries:

# setfacl -b abc

Check permissions

# getfacl abc
# file: abc
# owner: someone
# group: someone
user::rw-
group::r--
other::r--

Output of ls command

You will notice that there is an ACL for a given file because it will exhibit a + (plus sign) after its Unix permissions in the output of ls -l.

$ ls -l /dev/audio
crw-rw----+ 1 root audio 14, 4 nov.   9 12:49 /dev/audio
$ getfacl /dev/audio
getfacl: Removing leading '/' from absolute path names
# file: dev/audio
# owner: root
# group: audio
user::rw-
user:solstice:rw-
group::rw-
mask::rw-
other::---

Granting execution permissions for private files to a Web Server

The following technique describes how a process like a web server can be granted access to files that reside in a user's home directory, without compromising security by giving the whole world access.

In the following we assume that the web server runs as the user webserver and grant it access to geoffrey's home directory /home/geoffrey.

The first step is granting execution permission to webserver so it can access geoffrey's home:

# setfacl -m "u:webserver:--x" /home/geoffrey

Remember: Execution permissions to a directory are necessary for a process to list the directory's content.


Since webserver is now able to access files in /home/geoffrey, others do no longer need access:

# chmod o-rx /home/geoffrey

getfacl can be used to verify the changes:

$ getfacl /home/geoffrey
getfacl: Removing leading '/' from absolute path names
# file: home/geoffrey
# owner: geoffrey
# group: geoffrey
user::rwx
user:webserver:--x
group::r-x
mask::r-x
other::---

As the above output shows, others no longer have any permissions, but webserver still is able to access the files, thus security might be considered increased.

See also

  • Man Page - man getfacl
  • Man Page - man setfacl
  • An old but still relevant (and thorough) guide to ACL