All technological notes.
Access Control List (ACL)
Advantages:
categorized
access ACLs: set on individual files and directoriesdefault ACLs: only be applied at the directory level with files and subdirectories inheriting them automatically.Default ACLs:
default ACLs can be described as the maximum discretionary permissions that can be allocated on a directory.
Example:
# Set a Default ACL:
setfacl -m d:u:alice:rwx /parent_directory
# View Default ACLs:
getfacl /parent_directory
# # file: parent_directory
# # owner: root
# # group: root
# user::rwx
# group::r-x
# other::---
# default:user::rwx
# default:user:alice:rwX
# default:group::r-x
# default:mask::rwx
# default:other::---
# Inheritance
touch /parent_directory/new_file
getfacl /parent_directory/new_file
# # file: new_file
# # owner: root
# # group: root
# user::rw-
# user:alice:rw-
# group::r--
# mask::rw-
# other::r--
# Remove a Default ACL
setfacl -x d:u:alice /parent_directory
su - user1
mkdir /tmp/projectacl
getfacl -c /tmp/projectacl
# user::rwx
# group::r-x
# other::r-x
setfacl -dm u:user100:7,u:user200:rwx /tmp/projectacl
getfacl -c /tmp/projectacl
# user::rwx
# group::r-x
# other::r-x
# default:user::rwx
# default:user:user100:rwx
# default:user:user200:rwx
# default:group::r-x
# default:mask::rwx
# default:other::r-x
# create dir under project
mkdir /tmp/projectacl/projdir1
getfacl -c /tmp/projectacl/projdir1
# user::rwx
# user:user100:rwx
# user:user200:rwx
# group::r-x
# mask::rwx
# other::r-x
# default:user::rwx
# default:user:user100:rwx
# default:user:user200:rwx
# default:group::r-x
# default:mask::rwx
# default:other::r-x
# creat fiel under project
# note the effective is rw
touch /tmp/projectacl/projfile1
getfacl -c /tmp/projectacl/projfile1
# user::rw-
# user:user100:rwx #effective:rw-
# user:user200:rwx #effective:rw-
# group::r-x #effective:r--
# mask::rw-
# other::r--
setfacl -k /tmp/projectacl
getfacl -c /tmp/projectacl
# user::rwx
# group::r-x
# other::r-x
Effective ACLs:
mask), providing an additional level of control.mask limits the permissions of all ACL entries except the file owner.Mask
effective permissions for users and groups specified in ACL entries.getfacl file1
# file: file1
# owner: user
# group: group
user::rw-
group::r--
mask::r--
other::---
user:alice:rw-
- The
mask::r--restricts the maximum permissions to read-only forgroup::r--anduser:alice:rw-.Effective permissionsfor Alice are reduced to read-only (r–), even though the ACL grantsrw-.
| CMD | DESC |
|---|---|
getfacl filename |
Display the ACL of a file or directory |
setfacl -m u:lisa:r filee |
Grant a user specific permissions |
setfacl -rm u:username:permissions directory_name |
Grant a user specific permissions recursively |
setfacl -m g:groupname:permissions filename |
Grant a group specific permissions |
setfacl -x u:lisa file |
Remove specific ACLs |
setfacl -x g:staff file |
Remove specific ACLs |
setfacl -b filename |
Remove all ACLs |
| CMD | DESC |
|---|---|
setfacl -m m::rx file |
Modify the Mask |
setfacl -n filename |
Prevents an automatic recalculation of the mask |
| CMD | DESC |
|---|---|
setfacl -m d:u:username:permissions directory_name |
Set a default ACL for directories |
setfacl -d filename |
Applies to default ACLs |
setfacl -k filename |
Removes all default ACLs |
ls -l command contains a + at the end of the permissions (e.g., rw-rw----+), ACLs are in use.Setting w permission with ACL does not allow to remove the a file.
u:uid:perms:
g:gid:perms
m:perms
o:perms
d:rules
ACL mask
getfacl -c aclfile1
# user::rw-
# group::r--
# other::r--
setfacl -m u:user100:rw,m:r aclfile1
getfacl -c aclfile1
# user::rw-
# user:user100:rw- #effective:r--
# group::r--
# mask::r--
# other::r--
# update mask
setfacl -m m:rw aclfile1
getfacl -c aclfile1
# user::rw-
# user:user100:rw-
# group::r--
# mask::rw-
# other::r--
# login as user100
su - user100
touch /tmp/acluser100
ll /tmp/acluser100
# -rw-r--r--. 1 user100 user100 0 Feb 15 15:22 /tmp/acluser100
getfacl -c /tmp/acluser100
# user::rw-
# group::r--
# other::r--
# acl: grant
# note the mask always eqaul to the max
setfacl -m u:user200:6 /tmp/acluser100
ll /tmp/acluser100
# -rw-rw-r--+ 1 user100 user100 0 Feb 15 15:22 /tmp/acluser100
getfacl -c /tmp/acluser100
# getfacl: Removing leading '/' from absolute path names
# user::rw-
# user:user200:rw-
# group::r--
# mask::rw-
# other::r--
setfacl -m u:user1:rwx /tmp/acluser100
getfacl -c /tmp/acluser100
# getfacl: Removing leading '/' from absolute path names
# user::rw-
# user:user200:rw-
# user:user1:rwx
# group::r--
# mask::rwx
# other::r--
setfacl -x u:user1 /tmp/acluser100
# confirm
# note the mask shrink
getfacl -c /tmp/acluser100
# getfacl: Removing leading '/' from absolute path names
# user::rw-
# user:user200:rw-
# group::r--
# mask::rw-
# other::r--
# delete all acl
setfacl -b /tmp/acluser100
getfacl -c /tmp/acluser100
# getfacl: Removing leading '/' from absolute path names
# user::rw-
# group::r--
# other::r--
ll /tmp/acluser100
# -rw-r--r--. 1 user100 user100 0 Feb 15 15:22 /tmp/acluser100
Standard permissions
read (r), write (w), and execute (x) permissions assigned to three categories: Owner, Group, and Others.ls -l commandumask(user file-creation mask) concept
Default permissions = Base permissions - umaskACLs
umask by adding or modifying permissions for specific users or groups after creation.+ symbol appears at the end of the permission stringMask
effective permissions for users and groups specified in ACL entries.useradd serveradmin
useradd devops
su - serveradmin
# create a file
touch /tmp/acltest
# get the default permissions
ll /tmp/acltest
# -rw-rw-r--. 1 serveradmin serveradmin 0 Dec 18 20:23 /tmp/acltest
# get the acl of the file
getfacl /tmp/acltest
# getfacl: Removing leading '/' from absolute path names
# # file: tmp/acltest
# # owner: serveradmin
# # group: serveradmin
# user::rw-
# group::rw-
# other::r--
su - devops
vi /tmp/acltest
# "/tmp/acltest" [readonly]
# E45: 'readonly' option is set
# "/tmp/acltest" E212: Can't open file for writing
su - serveradmin
# Grant write permission to devops user
setfacl -m u:devops:rw /tmp/acltest
# confirm
getfacl /tmp/acltest
# getfacl: Removing leading '/' from absolute path names
# # file: tmp/acltest
# # owner: serveradmin
# # group: serveradmin
# user::rw-
# user:devops:rw-
# group::rw-
# mask::rw-
# other::r--
ll /tmp/acltest
# -rw-rw-r--+ 1 serveradmin serveradmin 12 Dec 18 20:33 /tmp/acltest
- Note:
user:devops:rw-indicates that userdevopshas been grantedwpermission.+indicates that acl is applied to the file.
devopssu - devops
vi /tmp/acltest
su - serveradmin
getfacl /tmp/acltest
# getfacl: Removing leading '/' from absolute path names
# # file: tmp/acltest
# # owner: serveradmin
# # group: serveradmin
# user::rw-
# user:devops:rw-
# group::rw-
# mask::rw-
# other::r--
# remove from devops
setfacl -x u:devops /tmp/acltest
# confirm
getfacl /tmp/acltest
# getfacl: Removing leading '/' from absolute path names
# # file: tmp/acltest
# # owner: serveradmin
# # group: serveradmin
# user::rw-
# group::rw-
# mask::rw-
# other::r--
ll /tmp/acltest
# -rw-rw-r--+ 1 serveradmin serveradmin 12 Dec 18 20:33 /tmp/acltest
Note:
+indicates that acl still applied to the file, even though the acl has been revoked from the user.
# Get file metadata
ll /tmp/acltest
# -rw-rw-r--+ 1 serveradmin serveradmin 12 Dec 18 20:33 /tmp/acltest
# Remove all ACL
setfacl -b /tmp/acltest
# confirm
getfacl /tmp/acltest
# getfacl: Removing leading '/' from absolute path names
# # file: tmp/acltest
# # owner: serveradmin
# # group: serveradmin
# user::rw-
# group::rw-
# other::r--
ll /tmp/acltest
# -rw-rw-r--. 1 serveradmin serveradmin 12 Dec 18 20:33 /tmp/acltest