Ubuntu Server Guide Changes, errors and bugs
Download 1.27 Mb. Pdf ko'rish
|
ubuntu-server-guide
- Bu sahifa navigatsiya:
- Adding and Deleting Users
- Other Security Considerations
- SSH Access by Disabled Users
- External User Database Authentication
- Further pre-existing Profiles
- Checking and debugging denies
Resources • DPDK Documentation • Release Notes matching the version packages in Ubuntu 16.04 • Linux DPDK User Getting Started • EAL Command-line Options • DPDK Api Documentation 76 • OpenVswitch DPDK installation • Wikipedias definition of DPDK Security Security should always be considered when installing, deploying, and using any type of computer system. Although a fresh installation of Ubuntu is relatively safe for immediate use on the Internet, it is important to have a balanced understanding of your system’s security posture based on how it will be used after deployment. This chapter provides an overview of security-related topics as they pertain to Ubuntu DISTRO-REV Server Edition, and outlines simple measures you may use to protect your server and network from any number of potential security threats. User Management User management is a critical part of maintaining a secure system. Ineffective user and privilege management often lead many systems into being compromised. Therefore, it is important that you understand how you can protect your server through simple and effective user account management techniques. Where is root? Ubuntu developers made a conscientious decision to disable the administrative root account by default in all Ubuntu installations. This does not mean that the root account has been deleted or that it may not be accessed. It merely has been given a password hash which matches no possible value, therefore may not log in directly by itself. Instead, users are encouraged to make use of a tool by the name of ‘sudo’ to carry out system administrative duties. Sudo allows an authorized user to temporarily elevate their privileges using their own password instead of having to know the password belonging to the root account. This simple yet effective methodology provides accountability for all user actions, and gives the administrator granular control over which actions a user can perform with said privileges. • If for some reason you wish to enable the root account, simply give it a password: sudo passwd Sudo will prompt you for your password, and then ask you to supply a new password for root as shown below: [ sudo ] password f o r username : ( e n t e r your own password ) Enter new UNIX password : ( e n t e r a new password f o r r o o t ) Retype new UNIX password : ( r e p e a t new password f o r r o o t ) passwd : password updated s u c c e s s f u l l y • To disable the root account password, use the following passwd syntax: sudo passwd − l r o o t • You should read more on Sudo by reading the man page: man sudo 77 By default, the initial user created by the Ubuntu installer is a member of the group sudo which is added to the file /etc/sudoers as an authorized sudo user. If you wish to give any other account full root access through sudo, simply add them to the sudo group. Adding and Deleting Users The process for managing local users and groups is straightforward and differs very little from most other GNU/Linux operating systems. Ubuntu and other Debian based distributions encourage the use of the ‘adduser’ package for account management. • To add a user account, use the following syntax, and follow the prompts to give the account a password and identifiable characteristics, such as a full name, phone number, etc. sudo ad duse r username • To delete a user account and its primary group, use the following syntax: sudo d e l u s e r username Deleting an account does not remove their respective home folder. It is up to you whether or not you wish to delete the folder manually or keep it according to your desired retention policies. Remember, any user added later on with the same UID/GID as the previous owner will now have access to this folder if you have not taken the necessary precautions. You may want to change these UID/GID values to something more appropriate, such as the root account, and perhaps even relocate the folder to avoid future conflicts: sudo chown −R r o o t : r o o t /home/ username / sudo mkdir /home/ a r c h i v e d _ u s e r s / sudo mv /home/ username /home/ a r c h i v e d _ u s e r s / • To temporarily lock or unlock a user password, use the following syntax, respectively: sudo passwd − l username sudo passwd −u username • To add or delete a personalized group, use the following syntax, respectively: sudo addgroup groupname sudo d e l g r o u p groupname • To add a user to a group, use the following syntax: sudo a d d u s e r username groupname User Profile Security When a new user is created, the adduser utility creates a brand new home directory named /home/username. The default profile is modeled after the contents found in the directory of /etc/skel, which includes all profile basics. If your server will be home to multiple users, you should pay close attention to the user home directory permissions to ensure confidentiality. By default, user home directories in Ubuntu are created with world read/execute permissions. This means that all users can browse and access the contents of other users home directories. This may not be suitable for your environment. 78 • To verify your current user home directory permissions, use the following syntax: l s −l d /home/ username The following output shows that the directory /home/username has world-readable permissions: drwxr−xr−x 2 username username 4096 2007−10−02 2 0 : 0 3 username • You can remove the world readable-permissions using the following syntax: sudo chmod 0750 /home/ username Note Some people tend to use the recursive option (-R) indiscriminately which modifies all child folders and files, but this is not necessary, and may yield other undesirable results. The parent directory alone is sufficient for preventing unauthorized access to anything below the parent. A much more efficient approach to the matter would be to modify the adduser global default permissions when creating user home folders. Simply edit the file /etc/adduser.conf and modify the DIR_MODE variable to something appropriate, so that all new home directories will receive the correct permissions. DIR_MODE=0750 • After correcting the directory permissions using any of the previously mentioned techniques, verify the results using the following syntax: l s −l d /home/ username The results below show that world-readable permissions have been removed: drwxr−x−−− 2 username username 4096 2007−10−02 2 0 : 0 3 username Password Policy A strong password policy is one of the most important aspects of your security posture. Many successful security breaches involve simple brute force and dictionary attacks against weak passwords. If you intend to offer any form of remote access involving your local password system, make sure you adequately address minimum password complexity requirements, maximum password lifetimes, and frequent audits of your authentication systems. Minimum Password Length By default, Ubuntu requires a minimum password length of 6 characters, as well as some basic entropy checks. These values are controlled in the file /etc/pam.d/common−password, which is outlined below. password [ s u c c e s s =1 d e f a u l t=i g n o r e ] pam_unix . s o o b s c u r e sha512 If you would like to adjust the minimum length to 8 characters, change the appropriate variable to min=8. The modification is outlined below. password [ s u c c e s s =1 d e f a u l t=i g n o r e ] pam_unix . s o o b s c u r e sha512 minlen=8 Note Basic password entropy checks and minimum length rules do not apply to the administrator using sudo level commands to setup a new user. 79 Password Expiration When creating user accounts, you should make it a policy to have a minimum and maximum password age forcing users to change their passwords when they expire. • To easily view the current status of a user account, use the following syntax: sudo chage − l username The output below shows interesting facts about the user account, namely that there are no policies applied: Last password change : Jan 2 0 , 2015 Password e x p i r e s : n e v e r Password i n a c t i v e : n e v e r Account e x p i r e s : n e v e r Minimum number o f days between password change : 0 Maximum number o f days between password change : 99999 Number o f days o f warning b e f o r e password e x p i r e s : 7 • To set any of these values, simply use the following syntax, and follow the interactive prompts: sudo chage username The following is also an example of how you can manually change the explicit expiration date (-E) to 01/31/2015, minimum password age (-m) of 5 days, maximum password age (-M) of 90 days, inactivity period (-I) of 30 days after password expiration, and a warning time period (-W) of 14 days before password expiration: sudo chage −E 01/31/2015 −m 5 −M 90 −I 30 −W 14 username • To verify changes, use the same syntax as mentioned previously: sudo chage − l username The output below shows the new policies that have been established for the account: Last password change : Jan 2 0 , 2015 Password e x p i r e s : Apr 1 9 , 2015 Password i n a c t i v e : May 1 9 , 2015 Account e x p i r e s : Jan 3 1 , 2015 Minimum number o f days between password change : 5 Maximum number o f days between password change : 90 Number o f days o f warning b e f o r e password e x p i r e s : 14 Other Security Considerations Many applications use alternate authentication mechanisms that can be easily overlooked by even experienced system administrators. Therefore, it is important to understand and control how users authenticate and gain access to services and applications on your server. SSH Access by Disabled Users Simply disabling/locking a user password will not prevent a user from logging into your server remotely if they have previously set up SSH public key authentication. They will still be able to gain shell access to the 80 server, without the need for any password. Remember to check the users home directory for files that will allow for this type of authenticated SSH access, e.g. /home/username/.ssh/authorized_keys. Remove or rename the directory .ssh/ in the user’s home folder to prevent further SSH authentication capabilities. Be sure to check for any established SSH connections by the disabled user, as it is possible they may have existing inbound or outbound connections. Kill any that are found. who | g r e p username ( t o g e t t h e p t s/# t e r m i n a l ) sudo p k i l l −f p t s/# Restrict SSH access to only user accounts that should have it. For example, you may create a group called “sshlogin” and add the group name as the value associated with the AllowGroups variable located in the file /etc/ssh/sshd_config. AllowGroups s s h l o g i n Then add your permitted SSH users to the group “sshlogin”, and restart the SSH service. sudo a ddu ser username s s h l o g i n sudo s y s t e m c t l r e s t a r t ss hd . s e r v i c e External User Database Authentication Most enterprise networks require centralized authentication and access controls for all system resources. If you have configured your server to authenticate users against external databases, be sure to disable the user accounts both externally and locally. This way you ensure that local fallback authentication is not possible. AppArmor AppArmor is a Linux Security Module implementation of name-based mandatory access controls. AppArmor confines individual programs to a set of listed files and posix 1003.1e draft capabilities. AppArmor is installed and loaded by default. It uses profiles of an application to determine what files and permissions the application requires. Some packages will install their own profiles, and additional profiles can be found in the apparmor-profiles package. To install the apparmor-profiles package from a terminal prompt: sudo apt i n s t a l l apparmor−p r o f i l e s AppArmor profiles have two modes of execution: • Complaining/Learning: profile violations are permitted and logged. Useful for testing and developing new profiles. • Enforced/Confined: enforces profile policy as well as logging the violation. Using AppArmor The optional apparmor-utils package contains command line utilities that you can use to change the AppAr- mor execution mode, find the status of a profile, create new profiles, etc. • apparmor_status is used to view the current status of AppArmor profiles. sudo apparmor_status 81 • aa-complain places a profile into complain mode. sudo aa−complain / path / t o / b i n • aa-enforce places a profile into enforce mode. sudo aa−e n f o r c e / path / t o / b i n • The /etc/apparmor.d directory is where the AppArmor profiles are located. It can be used to manip- ulate the mode of all profiles. Enter the following to place all profiles into complain mode: sudo aa−complain / e t c / apparmor . d/* To place all profiles in enforce mode: sudo aa−e n f o r c e / e t c / apparmor . d/* • apparmor_parser is used to load a profile into the kernel. It can also be used to reload a currently loaded profile using the -r option after modifying it to have the changes take effect. To reload a profile: sudo apparmor_parser −r / e t c / apparmor . d/ p r o f i l e . name • systemctl can be used to reload all profiles: sudo s y s t e m c t l r e l o a d apparmor . s e r v i c e • The /etc/apparmor.d/disable directory can be used along with the apparmor_parser -R option to disable a profile. sudo l n −s / e t c / apparmor . d/ p r o f i l e . name / e t c / apparmor . d/ d i s a b l e / sudo apparmor_parser −R / e t c / apparmor . d/ p r o f i l e . name To re-enable a disabled profile remove the symbolic link to the profile in /etc/apparmor.d/disable/. Then load the profile using the -a option. sudo rm / e t c / apparmor . d/ d i s a b l e / p r o f i l e . name c a t / e t c / apparmor . d/ p r o f i l e . name | sudo apparmor_parser −a • AppArmor can be disabled, and the kernel module unloaded by entering the following: sudo s y s t e m c t l s t o p apparmor . s e r v i c e sudo s y s t e m c t l d i s a b l e apparmor . s e r v i c e • To re-enable AppArmor enter: sudo s y s t e m c t l e n a b l e apparmor . s e r v i c e sudo s y s t e m c t l s t a r t apparmor . s e r v i c e Note Replace profile.name with the name of the profile you want to manipulate. Also, replace /path/ to/bin/ with the actual executable file path. For example for the ping command use /bin/ping 82 Profiles AppArmor profiles are simple text files located in /etc/apparmor.d/. The files are named after the full path to the executable they profile replacing the “/” with “.”. For example /etc/apparmor.d/bin.ping is the AppArmor profile for the /bin/ping command. There are two main type of rules used in profiles: • Path entries: detail which files an application can access in the file system. • Capability entries: determine what privileges a confined process is allowed to use. As an example, take a look at /etc/apparmor.d/bin.ping: #i n c l u d e / b i n / p i n g f l a g s =( complain ) { #i n c l u d e #i n c l u d e #i n c l u d e c a p a b i l i t y net_raw , c a p a b i l i t y s e t u i d , network i n e t raw , / b i n / p i n g mixr , / e t c / modules . c o n f r , } • #include multiple applications to be placed in a common file. • /bin/ping flags=(complain): path to the profiled program, also setting the mode to complain. • capability net_raw,: allows the application access to the CAP_NET_RAW Posix.1e capability. • /bin/ping mixr,: allows the application read and execute access to the file. Note After editing a profile file the profile must be reloaded. See above at Using AppArmor for details. Creating a Profile • Design a test plan: Try to think about how the application should be exercised. The test plan should be divided into small test cases. Each test case should have a small description and list the steps to follow. Some standard test cases are: – Starting the program. – Stopping the program. – Reloading the program. – Testing all the commands supported by the init script. • Generate the new profile: Use aa-genprof to generate a new profile. From a terminal: sudo aa−g e n p r o f e x e c u t a b l e For example: 83 sudo aa−g e n p r o f s l a p d • To get your new profile included in the apparmor-profiles package, file a bug in Launchpad against the AppArmor package: – Include your test plan and test cases. – Attach your new profile to the bug. Updating Profiles When the program is misbehaving, audit messages are sent to the log files. The program aa-logprof can be used to scan log files for AppArmor audit messages, review them and update the profiles. From a terminal: sudo aa−l o g p r o f Further pre-existing Profiles The packages apport−profiles and apparmor−profiles−extra ship some experimental profiles for AppArmor security policies. Do not expect these profiles to work out-of-the-box, but they can give you a head start when trynig to create a new profile by starting off a base that exists. These profiles are not considered mature enough to be shipped in enforce mode by default. Therefore they are shipped in complain mode so that users can test them, choose which are desired, and help improve them upstream if needed. Some even more experimental profiles carried by the package are placed in/usr/share/doc/apparmor−profiles /extras/ Checking and debugging denies You will see in ‘dmesg’ and any log that collects kernel messages if you have hit a deny. Right away it is worth to know that this will cover any access that was denied because it was not allowed, but explicit denies will put no message in your logs at all. Examples might look like: [ 1 5 2 1 0 5 6 . 5 5 2 0 3 7 ] a u d i t : type =1400 a u d i t ( 1 5 7 1 8 6 8 4 0 2 . 3 7 8 : 2 4 4 2 5 ) : apparmor=” DENIED” o p e r a t i o n =”open ” p r o f i l e =”/ u s r / s b i n / cups−browsed ” name=”/ var / l i b / l i b v i r t / dnsmasq /” p i d =1128 comm=”cups−browsed ” requested_mask=”r ” denied_mask=”r ” f s u i d =0 o u i d=0 [ 1 4 8 2 1 0 6 . 6 5 1 5 2 7 ] a u d i t : type =1400 a u d i t ( 1 5 7 1 8 2 9 4 5 2 . 3 3 0 : 2 4 3 2 3 ) : apparmor=” DENIED” o p e r a t i o n =”sendmsg ” p r o f i l e =”snap . l x d . l x c ” p i d =24115 comm=” l x c ” l a d d r = 1 0 . 7 . 0 . 6 9 l p o r t =48796 f a d d r = 1 0 . 7 . 0 . 2 3 1 f p o r t =445 f a m i l y =” i n e t ” sock_type=”stream ” p r o t o c o l =6 requested_mask=”send ” denied_mask=”send ” That follows a generic structure starting with a timestamp, an audit tag and the category apparmor=” DENIED”. From the following fields you can derive what was going on and why it was failing. In the examples above that would be First example: * operation: open (program tried to open a file) * profile: /usr/sbin/cups−browsed (you’ll find /etc/apparmor.d/usr.bin.cups−browsed) * name: /var/lib/ libvirt /dnsmasq (what it wanted to access) * pid/comm: the program that did trigger the access * requested_mask/denied_mask/fsuid/ouid: parameters of that open call 84 Second example: * operation: sendmsg (program tried send via network) * profile: snap.lxd. lxc (snaps are special, you’ll find /var/lib/snapd/apparmor/profiles/snap.lxd.lxc) * pid/comm: the program that did trigger the access * laddr/lport/faddr/fport/family/sock_type/protocol: parameters of that sendmsg call That way you know in which profile and at what action you have to start if you consider either debugging or adapting the profiles. Profile customization Profiles are meant to provide security and thereby can’t be all too open. But quite often a very special setup would work with a profile if it wold just allow this one extra access. To handle that there are three ways. • modify the profile itself – always works, but has the drawback that profiles are in /etc and considered conffiles. So after modification on a related package update you might get a conffile prompt. Worst case depending on configuration automatic updates might even override it and your custom rule is gone. • use tunables – those provide variables that can be used in templates, for example if you want a custom dir considered as it would be a home directory you could modify /etc/apparmor.d/tunables/home which defines the base path rules use for home directories – by design those variables will only influence profiles that use them • modify a local override – to mitigate the drawbacks of above approaches local includes got introduced adding the ability to write arbitrary rules that will be used, and not get issues on upgrades that modify the packaged rule. – The files can be found in /etc/apparmor.d/local/ and exist for the packages that are known to sometimes need slight tweaks for special setups References • See the AppArmor Administration Guide for advanced configuration options. • For details using AppArmor with other Ubuntu releases see the AppArmor Community Wiki page. • The OpenSUSE AppArmor page is another introduction to AppArmor. • (https://wiki.debian.org/AppArmor) is another introduction and basic howto for AppArmor. • A great place to ask for AppArmor assistance, and get involved with the Ubuntu Server community, is the #ubuntu-hardened IRC channel on freenode. Firewall Download 1.27 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling