- SELinux in FC3 uses a targeted policy by default. One could opt for a strict policy too, which was default with FC2. The policy files needed are in these RPMs
- selinux-policy-strict-
- selinux-policy-targeted-
.rpm and selinux-policy-targeted-sources- .rpm
.rpm and selinux-policy-strict-sources- .rpm - selinux-policy-targeted-
- Use
system-config-securitylevel
to change SELinux based settings. - The
ls
command's-Z
option will display the security context of a file - The
id
command's-Z
option will display the security context of a user - The
ps
command's-Z
option will display the security context of a process. - Don't take policy switching lightly. Unless of course, it's for learning :)
- To change the policy - easy way - run
system-config-securitylevel
, change the policy and reboot. - To change the policy manually -
- Edit /etc/selinux/config and change the type of policy to
SELINUXTYPE=policyname
. - Set the mode to permissive.
SELINUX=permissive
. - Tell the init scripts to relabel the system on reboot with the command
touch /.autorelabel
. - Reboot the system.
- Confirm your changes took effect with the command
sestatus -v
. With the new system running in permissive mode, check /var/log/messages for avc: denied messages. Fix any problems. - When you are satisfied that the system runs stable under the new policy, enable enforcing by changing
SELINUX=enforcing
. You can either reboot or runsetenforce 1
to turn enforcing on in real time.
- Edit /etc/selinux/config and change the type of policy to
- Ordinary backups will not backup the security context which are stored as extended attributes. Use
star
to backup files on an SElinux protected system. In particular, use the-xattr
and-H=exustar
options. Eg:star -xattr -H=exustar -c -f ../test.star ./*
- The variable SELINUX in /etc/selinux/config can take the values disabled, enforcing, or permissive. Booting the kernel with enforcing=0 is the same as SELINUX=permissive. Similarly, ooting the kernel with enforcing=1 is the same as SELINUX=enforcing
- As a safer alternative to booting with
selinux=0
, use SELINUX=disabled in /etc/selinux/config. - To temporarily turn off the enforcing mode, use
setenforce 0
. To return to enforcing mode,setenforce 1
. - To turn off selinux at bootup, add
selinux=0
to your kernel command line. Note that if you boot withselinux=0
, any files you create while SELinux is disabled will NOT have SELinux context information. If booting with selinux=1 fails, relabel the files with atouch /.autorelabel
and reboot into single user mode. /usr/sbin/sestatus -v
displays status info about SELinux- To relabel a directory, use
restorecon -v -R /path.
- If you have file systems shared by both SELinux enabled and non-SELinux machines - eg a dual-boot Suse and FC4 sharing the same /home, it sort of spells trouble when booting into SElinux as it may require relabelling.
- Mounting a non-SELinux file system via NFS results in SELinux treating all the files in the share as having a context of nfs_t. To override the default context to say, system_u:object_r:tmp_t to SELinux:
mount -t nfs -o context=system_u:object_r:tmp_t server:/shared/foo /mnt/foo
- To change and load the security policy:
cd /etc/selinux/targeted/src/policy
make clean
make load
Thursday, August 04, 2005
SE Linux essentials (FC3)
Bare minimal SElinux:
Upgrading CentOS 4.0 to CentOS 4.1
CentOS 4 is basically Red Hat Enterprise Linux 4. I just upgraded it to CentOS 4.1 using the rpms using these steps:
- Download the rpms from CentOS/4.1/os on any mirror.
- Download the updates from CentOS/4.1/updates on any mirror.
- Download any extra modules that depend on the kernel version. In my case, I had to download linux-ntfs rpms for the 2.6.11ELhugemem kernel.
- Disable selinux using
setenforce 0
.
(Failing to do this made the rpm postinstall fail for some rpm files. Off the cuff, I recall the rpms forbzip2-libs
, andkrb5-*
failing.) - From the directory containing the 4.1 rpms, run
rpm -Fvh *.rpm
You do need a lot of free disk space for this to work. Alternately, freshen a few rpms at a time :) - Now enable selinux with
setenforce 1
.
- Reboot in run level 1 so that no services start up
- Run
/sbin/fixfiles relabel
Alternately, to speeden things up, you can also use
/sbin/restorecon -R pathname
to recursively restore security context on the specified path - in my case /lib and /usr/lib were definitely affected. I opted for the fixfiles approach rather than weed out directories individually. - Change to the normal runlevel
Subscribe to:
Posts (Atom)