(Written: Oct 23, 2004)
This page documents how I installed SE Linux on my Debian/Testing with a custom 2.6.6 kernel. It shall help other people trying the same.
SE Linux is a set of tools and kernel patches (Kernels since 2.6.0-test3 (?) already include SE Linux support by NSA, it only needs to be enabled) that implement a mandatory access control. In short, it gives you much more flexible access control than the default unix access control system, you can specifiy much more exactly what a process or user can or cannot do. The default policy is quite restrictive. According to some people it's well suitable for internet servers running few specialized services that need enhanced security while it's perhaps to restrictive for a normal desktop user and the policy is to complicated to manage for large application servers. But some people might have a different opinion and you'd best ask a specialist. See SELinux FAQ for more.
What a user can or cannot do is determined by his unix security id (uid, gid) and SE Linux security context and the policy. Security context has the form identity:role:domain - domain is a subset of so called types. Identity is username or a default id (user_u, system_u etc.) if no usernames are specified in the file $POLICY/users and compiled into the policy. Both security models - unix and SE Linux - work at parallel (if set so) thus the user must satisfy both of them. To be able to do root stuff you must both become root with su - root that will preserve your security context (most probably aUserName:user_r:user_t) and gain the sysadm_r with newrole -r sysadm_r. Of course you must be allowed to gain that role in $POLICY/users. Note: domain is a type of the process being run (bash, su...) thus it changes quite often as opposed to role.
The 'access rights' are determined by the policy, which can only be changed by an administrator (the role sysadm_r), and si applied to the filesystem (FS) by make relabel or to a part of the FS by setfiles. If you want to change it you need to edit some files in $POLICY (?), e.g. 'users' to change roles available to particular users and then you've to recompile and reload the policy. Thus, as opposed to some other security models, ordinary users cannot change 'access rights' of their own files.
$POLICY/users
determines what roles are available to what user. The user 'kuba' cannot gain
any other role than those allowed for him, even if he su - root he
won't be able to gain sysadm_r unless $POLICY/users contains the line
'user kuba roles { user_r sysadm_r };'. That's because his uid
changed to 0, but SE Linux still remebers that he is kuba and not root. There
shall be a sample file in $POLICY.
/etc/selinux/contexts/default_contexts determines the
default context set after such operations such as a user login and ssh user
login. The default contexts says which of his available roles shall a user
gain after the action. If there is 'user kuba roles { user_r staff_r
sysadm_r };' in $POLICY/users (which is normal for those who shall
have access to root rights) we can set whether he shall become
kuba:user_r:user_t or kuba:staff_r:staff_t or kuba:sysadm_r:sysadm_r when he
logs in. The default_contexts can be changed without the need to recompile
the policy. You can set your prefered roles (only those available to you) in
$HOME/.default_contexts.
/etc/selinux/contexts/default_type determines default types for the given roles, it's used by newrole when you specify a role but not a type (e.g. newrole -r sysadm_r instead of newrole -r sysadm_r -t sysadm_t).
Not all information in the guide applied to my system - libselinux have already been installed and I had a lot of troubles with selinux-policy-default.
I assume you know how to compile a kernel for Debian. See the guide, Debian Kernel HOWTO etc.
aUser:/usr/src/linux$ make menuconfig
General setup-> [*] Auditing support # Needed for SE Linux logging [*] Enable system-call auditing support Security->Security options->
[*] Enable different security models
<M> Default Linux Capabilities
[*] NSA SELinux Support
[*] NSA SELinux Development Support # kernel will start in permissive mode by default
File systems->
[*] Ext3 Security Labels # Enable additional security info for files
<*> ROM file system support # fomfs
Pseudo filesystem->
[*] /dev file system support (OBSOLETE)
/etc/apt/preferences:
# Set Never-replace-existing package priority for unstable packages => prevent upgrading to testing
Package: *
Pin: release a=unstable
Pin-Priority: 50
# Set Always-install priority to SELinux packages
# l = label, see http://selinux.lemuria.org/newselinux/Release
Package: *
Pin: release l=etbe
Pin-Priority: 1100
/etc/apt/sources.list:
# SE Linux patches etc.
# For sid and sarge, use Russel Cokers new packages:
deb http://selinux.lemuria.org/newselinux ./ # make sure $http_proxy is set, if needed
# Unstable: selinux-default-policy is not in testing
deb ftp://ftp.cz.debian.org/debian unstable main contrib non-free
Check that packages at deb http://selinux.lemuria.org/newselinux
have replaced (possibly downgraded) the original ones.
You may get some errors while installing selinux-policy-default and
its installation may fail, ignore it for now.
You may also install the package setools
with various utilities.
image=/boot/vmlinuz-2.6.6-selin # SE Linux
label=Deb3-SElin # Any label you want to see in the lilo's menu
root=/dev/hda1 # The partition where the root / is (here: the 1st primary partition)
read-only
initrd=/boot/initrd.img-2.6.6-selin
#addappend="enforcing=1" # uncomment when everything is ok otherwise the 'permissive' mode is used
none /selinux selinuxfs defaults 0 0
to your /etc/fstab to mount it on boot.
You may get some errors while installing selinux-policy-default and
its installation may fail. Anyway the files shall be installed - see
/etc/selinux/ (Note: RedHat uses /etc/security/selinux/).
The errors you can see:
If you've troubles with the package you can compile the policy by
yourself as long as you've got a Makefile and others in $POLICY
(see above if it points to a
nonexistent directory)
root:$POLICY#
make clean; make; # this will install the unusable policy.18
root:$POLICY#
checkpolicy -c 17 -o policy.17; mv policy.17
/etc/selinux/policy/
Now you shall have policy.17 that can be loaded at boot. Note: May be checkpolicy may report some errors when not run under the SE Linux kernel, I haven't tried.
$(CHECKPOLICY) -o $@ policy.conf
becomes $(CHECKPOLICY) $(CHECKPOLICY_OPTS) -o $@
policy.conf. There shall be 2 such targets:
$(POLICYVER) and $(LOADPATH).| selinuxdisable | |
| selinuxenabled | tool to determine whether SE Linux is enabled (returns 0) or not (-256) |
| selinuxconfig | prints SE Linux configuration info |
| id | print's current user's context |
| ls --context | show context for files in `pwd` |
| checkpolicy | compile and install a policy |
| setenforce [0|1] | toggle the enforcing/the permissive mode |
| newrole [-r|-t] | run a shell with a new role |
| sestatus [-v] | display info about SE Linux, root only |
| setfiles | relabel a given part of the filesystem |
| ... |