Previous Page
Next Page

Certification Objective 10.02–Use Access Control Lists to Set File Permissions

Remember that ACLs provide greater security by enabling you to define file permissions for each user class. With UNIX file permissions, you're limited to making a file either read-only or read-write; however, by using ACLs, you can make files read-only for a certain group, and also read-write for a specific user in that group. In this section, we'll determine whether a file has an ACL, how to add an ACL to a file, and finally how to tweak ACLs.

Working with ACLs

The first step is to determine whether a file or files already has an ACL. This is easy to do with the ls command. Simply issue the command ls -l filename, where filename is the name of a specific file or directory. Take a look at the following example:

ls – l memo.txt
-rwxr-----+   1 john    memos       167 Dec 01 9:30 memo.txt

You know the file has an ACL because the plus sign (+) is listed after the mode field in this output. Unless you have added ACL entries that extend UNIX file permissions, the plus sign does not display to the right of the mode field.

Adding ACLs to a File and Modifying ACLs

To set an ACL on a file, we use the setfacl command:

setfacl -s user::perms,group::perms,other:perms,mask:perms,acl-entry-list filename ...

where

  • -s sets an ACL on the file. If a file already has an ACL, it is replaced. This option requires at least the user::, group::, and other:: entries.

  • user::perms specifies the file owner permissions.

  • group::perms specifies the group ownership permissions.

  • other:perms specifies the permissions for users other than the file owner or members of the group.

  • mask:perms specifies the permissions for the ACL mask. The mask indicates the maximum permissions that are allowed for users (other than the owner) and for groups.

  • acl-entry-list specifies the list of one or more ACL entries to set for specific users and groups on the file or directory. You can also set default ACL entries on a directory.

  • filename ... specifies one or more files or directories on which to set the ACL. Multiple filenames are separated by spaces.

Let's consider the following example:

setfacl – s user::rw-,group::r--,other:---,mask:rw-,user:joe:rw- memo.txt

Here, the owner permissions are set to read and write (user::rw-); group permissions are set to read only (group::r--); other permissions are set to none (other:---); the ACL mask permissions are set to read and write (mask:rw-, which means that no user or group can have execute permissions); and user joe is granted read and write permissions (user:joe:rw-) on file memo.txt. Note that if an ACL already exists on a file, the -s option replaces the entire ACL with the new one. To verify the file has your ACL, issue the getfacl filename command.

If you should need to copy an ACL of one file to another file, you can do so by issuing this command:

getfacl filename1 | setfacl -f -filename2

where, filename1 is the file whose ACL you wish to apply to filename2.

If you should need to modify or delete ACL entries, use the command

setfacl (-d or -m) acl-entry-list filename ...

where

  • -d deletes the specified ACL entries.

  • -m modifies the existing ACL entry.

  • acl-entry-list specifies the list of one or more ACL entries to modify on the file or directory. You can also modify default ACL entries on a directory.

  • filename ... specifies one or more files or directories, separated by a space.

Two-Minute Drill

Here are some of the key points from the certification objectives in Chapter 10.

Use UNIX Permissions to Protect Files

  • Access control lists (ACLs) provide better file security by enabling you to define file permissions for each user class.

  • The ls command is used to list files and some information about the files contained within a directory.

  • The chown command is used to change file ownership.

  • The chgrp command is used to change group ownership of a file.

  • The chmod command is used to change permissions on a file. The command changes or assigns the mode of a file (permissions and other attributes), which may be absolute or symbolic.

  • When setuid permission is set on an executable file, a process that runs this file is granted access on the basis of the owner of the file. This permission presents a security risk, as attackers can find a way to maintain the permissions that are granted to them by the setuid process even after the process has finished executing.

  • You should always monitor the system for unauthorized setuid and setgid permissions to gain superuser privileges.

Use Access Control Lists to Set File Permissions

  • Unless you have added ACL entries that extend UNIX file permissions, the plus sign (+) does not display to the right of the mode field.

  • To set an ACL on a file, use the setfacl command. Note that if an ACL already exists on a file, the -s option replaces the entire ACL with the new one. To verify the file has your ACL, issue the getfacl filename command.

Self Test

The following questions will help you measure your understanding of the material presented in this chapter. Read all the choices carefully, because there might be more than one correct answer. Choose all correct answers for each question, and in some cases explain your answer. Some questions are short-answer questions to ensure you have a good understanding of the material.

Use UNIX Permissions to Protect Files

1. 

With regard to general UNIX file permissions, which permissions can be applied?

   UNIX file permissions provide read, write, and execute permissions.

2. 

Explain the difference between UNIX file permissions and ACLs.

   Using standard UNIX file permissions, you can provide read, write, and execute permissions for three user classes (file owner, group, and other users), whereas ACLs take security a step further by enabling you to define file permissions for each user class. For example, let's say you want the sales user group to read a particular file; however, you want only the sales manager- part of the sales group-also to have permission to make changes to that file. With UNIX file permissions, you're limited to making the file either read-only or read-write for the sales group. On the other hand, by using ACLs, you can make the file read-only for the sales group, with the exception of read-write for the sales manager.

3. 

You can set general UNIX file permissions to which user classes?

   UNIX file permissions provide permissions for three user classes (file owner, group, and other users).

4. 

What are the attributes of the Read permission?

   The Read permission is indicated with the symbol r . This permission allows users to open and read a file and list files in a directory.

5. 

What are the attributes of the Write permission?

   The Write permission is indicated with the symbol w . This permission allows users to open, read, delete, and modify the contents of a file, and list and add files and links in a directory or remove them.

6. 

What are the attributes of the Execute permission?

   The Execute permission is indicated with the symbol x . This permission allows users to execute a file (program or shell script) in a directory.

7. 

What are the attributes of the permission indicated with the - symbol?

   The Deny permission is the one indicated with the symbol - .This permission denies read, write, and execute access.

8. 

Which of the following commands is used to change user ownership of a file?

  1. ls

  2. chown

  3. chgrp

  4. chmod

  5. All of the above

    B. The chown command is used to change user ownership of a file.     A is wrong because ls is used to list files and some information about the files contained within a directory. C is wrong because chgrp is used to change group ownership of a file. D is wrong because chmod is used to change permissions on a file.

9. 

Which of the following commands is used to change permissions on a file?

  1. ls

  2. chown

  3. chgrp

  4. chmod

  5. All of the above

    D. The chmod command is used to change permissions on a file.     A is wrong because ls is used to list files and some information about the files contained within a directory. B is wrong because chown is used to change user ownership of a file. C is wrong because chgrp is used to change group ownership of a file.

10. 

Which of the following commands is used to list files and some information about the files contained within a directory?

  1. ls

  2. chown

  3. chgrp

  4. chmod

  5. All of the above

    A. The ls command is used to list files and some information about the files contained within a directory.     B is wrong because chown is used to change user ownership of a file. C is wrong because chgrp is used to change group ownership of a file. D is wrong because chmod is used to change permissions on a file.

11. 

Which of the following commands is used to change group ownership of a file?

  1. ls

  2. chown

  3. chgrp

  4. chmod

  5. All of the above

    C. The chgrp command is used to change group ownership of a file.     A is wrong because ls is used to list files and some information about the files contained within a directory. B is wrong because chown is used to change user ownership of a file. D is wrong because chmod is used to change permissions on a file.

12. 

Explain why the setuid permission set on an executable file poses a security risk.

   When setuid permission is set on an executable file, a process that runs this file is granted access on the basis of the owner of the file. This permission presents a security risk, as attackers can find a way to maintain the permissions that are granted to them by the setuid process, even after the process has finished executing.

13. 

Explain how to locate files with setuid permissions using the find command.

   Use the find command to locate files with setuid permissions and then view the results with the more command. First, log in with an account that has root privileges, or use the switch user ( su ) command to become superuser. As superuser, you'll have full privileges, which may be required to search all files. Next, search for files with setuid permissions with the find command:  find directory -user root -perm -4000 -exec ls -ldb {} \; -/tmp/ findresults  View the results in /tmp/findresults using the more command, like so:  more /tmp/findresults where  findresults  is the name of the file to which you wrote your find results to in the /tmp directory.

14. 

What steps should you take to disable executable stacks and enable stack message logging?

   To disable executable stacks and enable stack message logging, you need to make changes in the /etc/system file, and then reboot the operating system to initiate the changes.  a. Log in with an account that has root privileges, or use the su command to become superuser.  b. Change directory to the /etc folder and edit the system file ( /etc/system ) by adding set noexec_user_stack=1 .  c. While editing the /etc/system file, add set noexec_user_stack_log=1 .  d. Save the changes and exit the editor.  e. Issue the command init 6 to restart the server.

Answers

1. 

þ UNIX file permissions provide read, write, and execute permissions.

2. 

þ Using standard UNIX file permissions, you can provide read, write, and execute permissions for three user classes (file owner, group, and other users), whereas ACLs take security a step further by enabling you to define file permissions for each user class. For example, let's say you want the sales user group to read a particular file; however, you want only the sales manager— part of the sales group—also to have permission to make changes to that file. With UNIX file permissions, you're limited to making the file either read-only or read-write for the sales group. On the other hand, by using ACLs, you can make the file read-only for the sales group, with the exception of read-write for the sales manager.

3. 

þ UNIX file permissions provide permissions for three user classes (file owner, group, and other users).

4. 

þ The Read permission is indicated with the symbol r. This permission allows users to open and read a file and list files in a directory.

5. 

þ The Write permission is indicated with the symbol w. This permission allows users to open, read, delete, and modify the contents of a file, and list and add files and links in a directory or remove them.

6. 

þ The Execute permission is indicated with the symbol x. This permission allows users to execute a file (program or shell script) in a directory.

7. 

þ The Deny permission is the one indicated with the symbol -.This permission denies read, write, and execute access.

8. 

þ B. The chown command is used to change user ownership of a file.

ý A is wrong because ls is used to list files and some information about the files contained within a directory. C is wrong because chgrp is used to change group ownership of a file. D is wrong because chmod is used to change permissions on a file.

9. 

þ D. The chmod command is used to change permissions on a file.

ý A is wrong because ls is used to list files and some information about the files contained within a directory. B is wrong because chown is used to change user ownership of a file. C is wrong because chgrp is used to change group ownership of a file.

10. 

þ A. The ls command is used to list files and some information about the files contained within a directory.

ý B is wrong because chown is used to change user ownership of a file. C is wrong because chgrp is used to change group ownership of a file. D is wrong because chmod is used to change permissions on a file.

11. 

þ C. The chgrp command is used to change group ownership of a file.

ý A is wrong because ls is used to list files and some information about the files contained within a directory. B is wrong because chown is used to change user ownership of a file. D is wrong because chmod is used to change permissions on a file.

12. 

þ When setuid permission is set on an executable file, a process that runs this file is granted access on the basis of the owner of the file. This permission presents a security risk, as attackers can find a way to maintain the permissions that are granted to them by the setuid process, even after the process has finished executing.

13. 

þ Use the find command to locate files with setuid permissions and then view the results with the more command. First, log in with an account that has root privileges, or use the switch user (su) command to become superuser. As superuser, you'll have full privileges, which may be required to search all files. Next, search for files with setuid permissions with the find command:

find directory -user root -perm -4000 -exec ls -ldb {} \; >/tmp/findresults

View the results in /tmp/findresults using the more command, like so:

more /tmp/findresults

where findresults is the name of the file to which you wrote your find results to in the /tmp directory.

14. 

þ To disable executable stacks and enable stack message logging, you need to make changes in the /etc/system file, and then reboot the operating system to initiate the changes.

  1. Log in with an account that has root privileges, or use the su command to become superuser.

  2. Change directory to the /etc folder and edit the system file (/etc/system) by adding set noexec_user_stack=1.

  3. While editing the /etc/system file, add set noexec_user_stack_log=1.

  4. Save the changes and exit the editor.

  5. Issue the command init 6 to restart the server.

Use Access Control Lists to Set File Permissions

15. 

What command(s) would you use to set an ACL on a file?

   To set an ACL on a file, use the setfacl command.

16. 

What command(s) would you use to verify an ACL was set?

   To verify the file has your ACL, issue the getfacl filename command. Use the setfacl command with the following syntax:  setfacl -s user::perms,group::perms,other:perms,mask:perms,acl-entry-list filename ...; where:  *  -s sets an ACL on the file. If a file already has an ACL, it is replaced. This option requires at least the user:: , group:: , and other:: entries.  *  user::   perms  specifies the file owner permissions.  *  group::   perms  specifies the group ownership permissions.  *  other:   perms  specifies the permissions for users other than the file owner or members of the group.  *  mask:   perms  specifies the permissions for the ACL mask. The mask indicates the maximum permissions that are allowed for users (other than the owner) and for groups.  *   acl-entry-list  specifies the list of one or more ACL entries to set for specific users and groups on the file or directory. You can also set default ACL entries on a directory.  *   filename ...  specifies one or more files or directories on which to set the ACL. Multiple filenames are separated by spaces.

17. 

What command(s) would you use to modify or delete ACL entries?

   If you should need to modify or delete ACL entries, use the setfacl (-d or -m) acl-entry-list filename... command; where:  *  -d deletes the specified ACL entries.  *  -m modifies the existing ACL entry.  *   acl-entry-list  specifies the list of one or more ACL entries to modify on the file or directory. You can also modify default ACL entries on a directory.  *   filename ...  specifies one or more files or directories, separated by a space.

Answers

15. 

þ To set an ACL on a file, use the setfacl command.

16. 

þ To verify the file has your ACL, issue the getfacl filename command. Use the setfacl command with the following syntax:

setfacl -s user::perms,group::perms,other:perms,mask:perms,acl-entry-list filename ...;

where:

  • -s sets an ACL on the file. If a file already has an ACL, it is replaced. This option requires at least the user::, group::, and other:: entries.

  • user::perms specifies the file owner permissions.

  • group::perms specifies the group ownership permissions.

  • other:perms specifies the permissions for users other than the file owner or members of the group.

  • mask:perms specifies the permissions for the ACL mask. The mask indicates the maximum permissions that are allowed for users (other than the owner) and for groups.

  • acl-entry-list specifies the list of one or more ACL entries to set for specific users and groups on the file or directory. You can also set default ACL entries on a directory.

  • filename ... specifies one or more files or directories on which to set the ACL. Multiple filenames are separated by spaces.

17. 

þ If you should need to modify or delete ACL entries, use the setfacl (-d or -m) acl-entry-list filename... command; where:

  • -d deletes the specified ACL entries.

  • -m modifies the existing ACL entry.

  • acl-entry-list specifies the list of one or more ACL entries to modify on the file or directory. You can also modify default ACL entries on a directory.

  • filename ... specifies one or more files or directories, separated by a space.

Lab Question

 

You are called to ABCD Inc.'s site to prevent executable files from compromising the system by disabling programs from using executable stacks. The customer has already confirmed that its software does not require running code from the stack. Additionally, ABCD would like to have the system log any time a program attempts to execute stack code. What steps would you perform onsite?

Most programs will run smoothly without running code from the stack; however, the customer has confirmed that its software does not require executable stacks. Therefore, if you can, you should disable executable stacks. To do so, follow these steps:  a. Assume the role of superuser.  b. Change directory to the /etc folder and edit the system file ( /etc/system ) by adding set noexec_user_stack=1 . To do so, type cd /etc , press ENTER, and then type vi system and press ENTER again.  c. In the visual editor, press the I key (to switch to edit mode and insert text), type set noexec_user_stack=1 , and then press ENTER.  d. Press the ESC key (to enter into command mode) and type :wq . Then press ENTER to save and exit.  e. At the terminal prompt, reboot the system by typing the command init 6 and then pressing ENTER.   To enable executable stack message logging, follow these steps:  a. Assume the role of superuser.  b. Edit the /etc/system file and add set noexec_user_stack_log=1 .  c. Reboot the system.

Answers

 

Most programs will run smoothly without running code from the stack; however, the customer has confirmed that its software does not require executable stacks. Therefore, if you can, you should disable executable stacks. To do so, follow these steps:

  1. Assume the role of superuser.

  2. Change directory to the /etc folder and edit the system file (/etc/system) by adding set noexec_user_stack=1. To do so, type cd /etc, press ENTER, and then type vi system and press ENTER again.

  3. In the visual editor, press the I key (to switch to edit mode and insert text), type set noexec_user_stack=1, and then press ENTER.

  4. Press the ESC key (to enter into command mode) and type :wq. Then press ENTER to save and exit.

  5. At the terminal prompt, reboot the system by typing the command init 6 and then pressing ENTER.

To enable executable stack message logging, follow these steps:

  1. Assume the role of superuser.

  2. Edit the /etc/system file and add set noexec_user_stack_log=1.

  3. Reboot the system.


Previous Page
Next Page