root/branches/selinux-pms-support/selinux-doc/README

Revision 10, 18.0 kB (checked in by jbrindle, 2 years ago)

import selinux 2006-09-24

Line 
1 COMPONENTS
2 ----------
3 You will need the following components:
4
5 1) Linux kernel with SELinux patch merged.
6 The mainline Linux 2.6 kernel (as of 2.6.0-test3 and later) includes
7 SELinux already, but there may be interim patches from the NSA site
8 for the LSM framework and/or SELinux module that have not yet been
9 upstreamed.
10
11 2) checkpolicy
12 The checkpolicy program compiles the policy sources into a binary
13 representation that is used by the kernel security server.  The
14 binary policy representation has changed from the old SELinux, so you
15 must use this checkpolicy program to compile your policy for the new
16 SELinux kernel.
17
18 3) libselinux
19 This library provides a set of interfaces for security-aware
20 applications to get and set process and file security contexts and to
21 invoke the policy API.  It provides a layer of abstraction over the
22 /proc/pid/attr API, the xattr API, and the selinuxfs API for SELinux
23 applications.  It also handles memory allocation for security
24 contexts.  See PORTING for a discussion how the libselinux API differs
25 from the old libsecure API.  The policy API calls assume that
26 selinuxfs has already been mounted, which is typically done by /sbin/init
27 prior to initial policy load.  If not, you can do the following:
28         mount -t selinuxfs none /selinux
29
30 The libselinux/utils subdirectory contains simple utilities that
31 permit experimentation with the SELinux API.
32
33 4) policycoreutils
34 This package contains the policy core utilities that are required for
35 basic operation of a SELinux system.  These utilities include
36 load_policy to load policies, setfiles to label filesystems, newrole
37 to switch roles, and run_init to run /etc/init.d scripts in the proper
38 context.  These utilities have been rewritten from the old SELinux to
39 use the libselinux interfaces.
40
41 5) policy
42 This package contains the SELinux example policy configuration along
43 with the Flask configuration information and the application
44 configuration files.  The policy has been adapted for changes from the
45 old SELinux.  See PORTING for a discussion of how the policy has
46 changed from the old SELinux.
47
48 6) patched daemons and utilities
49 Several packages have been patched for SELinux.  The SELinux patches
50 have been rewritten to use the libselinux interfaces (see PORTING).
51
52 There is a patch to glibc to support secure transitions for
53 role/domain changes, but this change has now been upstreamed (and is
54 generalized for arbitrary Linux security modules).  Please verify that
55 your glibc supports the AT_SECURE auxv entry.
56
57 Of the other SELinux patches, the most critical patches are the ones
58 for init (sysvinit-selinux.patch), pam (pam-selinux.patch),
59 sshd (openssh-selinux.patch) and crond (vixie-cron-selinux.patch). 
60 These patches load the policy and initialize the user security context for
61 user sessions and cron jobs.  /etc/pam.d/login should be modified to include
62 pam_selinux, e.g.;
63         session    required     pam_selinux.so multiple
64 The multiple argument is only if you want it to prompt the user for
65 a security context when multiple authorized contexts are available
66 for the user, as opposed to always just using the default for the user.
67 It is presently only supported for login and su.
68
69 The SELinux wrappers for programs that modify /etc/passwd and
70 /etc/shadow (in order to preserve their security contexts and to
71 ensure that uid 0 cannot arbitrarily change other users' information)
72 have been reimplemented as direct patches to various packages
73 (util-linux, shadow-utils, passwd, libuser, pam, pwdb, etc).
74
75 SELinux patches also exist for many common utilities to provide
76 support for manipulating process and file security contexts,
77 e.g. coreutils, findutils, logrotate, procps, psmisc.
78
79 Packages with the SELinux patches integrated exist for several Linux
80 distributions, e.g. 
81 Debian          - See http://www.coker.com.au/selinux
82 Fedora Core 3 or later - See http://fedora.redhat.com
83 Gentoo          - See http://www.gentoo.org/proj/en/hardened/
84 Red Hat Enterprise Linux 4 or later - See http://www.redhat.com/security/innovative/selinux/
85 SuSE            - See http://www.cip.ifi.lmu.de/~bleher/selinux/suse/ and
86                       http://suse-selinux.leapster.org/
87 Ubuntu          - See https://www.ubuntulinux.org/wiki/SELinux
88
89 KERNEL CONFIGURATION
90 --------------------
91 When you configure your SELinux-patched kernel, you should note the
92 following items:
93
94 Under Filesystems, be sure to enable the Ext[23] extended attributes and
95 Ext[23] Security Labels options (CONFIG_EXT[23]_FS_XATTR,
96 CONFIG_EXT[23]_FS_SECURITY). 
97
98 Under Pseudo Filesystems, be sure to enable the /dev/pts
99 Extended Attributes and /dev/pts Security Labels options
100 (CONFIG_DEVPTS_FS_XATTR, CONFIG_DEVPTS_FS_SECURITY).
101
102 Under Security, be sure to enable all of the following options:
103         Enable different security models (CONFIG_SECURITY)
104         Socket and Networking Security Hooks (CONFIG_SECURITY_NETWORK)
105         Capabilities Support (CONFIG_SECURITY_CAPABILITIES)
106         NSA SELinux Support (CONFIG_SECURITY_SELINUX)
107         NSA SELinux Development Support (CONFIG_SECURITY_SELINUX_DEVELOP)
108         NSA SELinux boot parameter (CONFIG_SECURITY_SELINUX_BOOTPARAM)
109
110 BUILDING AND INSTALLING
111 ------------------------
112 1) Configure, build and install the SELinux-patched kernel, and
113 configure your boot manager so you can boot it.  Note that certain
114 distributions, like Fedora Core 3 or Hardened Gentoo, already include
115 SELinux support in the kernel.  If you are building the 2.6 SELinux kernel
116 from sources on the NSA site, the typical sequence of commands is:
117         cd linux-2.6           
118         make menuconfig         
119         make
120         make modules_install
121         make install
122
123 If you do not enable the NSA SELinux boot parameter option
124 (CONFIG_SECURITY_SELINUX_BOOTPARAM) in your kernel configuration, then
125 it is also recommended that you configure and build a separate kernel
126 that has the Ext[23] Security Labels options enabled but SELinux
127 disabled for use as a maintenance kernel.  This maintenance kernel can
128 be used to manipulate the file security labels without interference by
129 the SELinux module to perform emergency recovery.  If you did enable
130 the NSA SELinux boot parameter option, then you can simply boot with
131 "selinux=0" to disable the SELinux module at boot time to perform
132 emergency recovery.
133
134 You may want to configure and build a 2.4+EA kernel if you still want
135 to boot 2.4 kernels on your system, as unmodified 2.4 kernels prior to
136 2.4.25 will not boot after you have assigned the SELinux EAs to the
137 root filesystem.  Note:  The EA symlink compatibility fix was back ported
138 to the Fedora Core 1 kernel as of kernel-2.4.22-1.2149.nptl.
139
140 2) Build and install the new SELinux userland packages (checkpolicy,
141 libselinux, policycoreutils, policy).  Note that these packages are already
142 included in certain distributions, like Fedora Core 3 and Hardened Gentoo.
143
144 You should customize your policy configuration.  If you have already
145 installed a policy, the policy sources should be under
146 /etc/selinux/(strict|targeted)/src.  Customization of the policy includes:
147
148 - Edit policy/users for your users.  The policy/users file defines
149 each user recognized by the system security policy.  It specifies the
150 authorized roles for each user.  Be sure to authorize at least one
151 user for the system administrator roles (staff_r, sysadm_r, and
152 system_r).  Other users can be limited to the ordinary user role
153 (user_r).  Remove the example users provided in the distributed users
154 file (jadmin and jdoe).  Leave the system_u user unmodified, and do
155 NOT add an entry for it to /etc/passwd.  Remove the user_u user if you
156 do not want to allow any login access to any user who is not
157 explicitly listed in policy/users; otherwise, all unlisted users will
158 be mapped to user_u (and limited to the user_r role).
159
160 - Move up any .te files from policy/domains/program/unused to
161 policy/domains/program for services and applications that you run on
162 your system.  Anything left in unused will not be included in the
163 built policy.  If you installed from the Fedora Core policy-sources
164 RPM, then most .te files should have been automatically moved up when
165 the package was built.
166
167 - Define any desired tunables in the policy/tunables/*.tun files.
168
169 3) Install the SELinux-patched packages.
170
171 Packages with the SELinux patches integrated exist for several Linux
172 distributions, e.g.
173 Debian          - See http://www.coker.com.au/selinux.
174 Fedora Core 3 or later - See http://fedora.redhat.com
175 Gentoo          - See http://www.gentoo.org/proj/en/hardened/
176 Red Hat Enterprise Linux 4 or later - See http://www.redhat.com/security/innovative/selinux/
177 SuSE            - See http://www.cip.ifi.lmu.de/~bleher/selinux/suse/ and
178                       http://suse-selinux.leapster.org/
179 Ubuntu          - See https://www.ubuntulinux.org/wiki/SELinux
180
181 Fedora Core 3, Red Hat Enterprise Linux 4, and Hardened Gentoo already
182 include the SELinux-patched packages; other distros may require
183 separate installation of modified packages from the sites listed
184 above.
185
186 4) Create the /selinux mountpoint directory (i.e. mkdir /selinux)
187 for the selinuxfs mount (which is performed by init).
188
189 5) Boot the SELinux kernel.  Login as root with the sysadm_r role and
190 sysadm_t domain.
191
192 6) Assign extended attributes to your filesystems.  Caveat: We have
193 encountered problems booting unmodified 2.4 kernels < 2.4.25 after
194 assigning extended attributes to the root filesystem.  We are able to
195 boot older 2.4 kernels patched with the EA patch or 2.4 kernels >=
196 2.4.25.  A compatibility fix was back ported to the Fedora Core 1
197 kernel as of kernel-2.4.22-1.2149.nptl.
198         cd /etc/selinux/(strict|targeted)/src/policy
199         make relabel
200
201 7) Reboot the SELinux kernel.  Login as root with the sysadm_r role
202 and sysadm_t domain.
203
204 8) If you have installed the SELinux-patched utilities, then you can
205 run 'id' to see your security context and you can run 'ps -eZ' to see
206 the contexts of other processes.  As mentioned above, a security
207 context has the syntax user:role:domain or user:role:type.
208
209 System processes should have the system_u user identity and the
210 system_r role.  Each system process with a different executable should
211 have its own separate domain.  If some system processes are running in
212 the initrc_t domain, then there are several possible reasons:
213 - The .te file for the program wasn't moved up from the
214 policy/domains/program/unused directory before building the policy.
215 - The pathname for the program in its .fc file (in the
216  policy/file_contexts/program directory) doesn't match your system.
217 - A domain has not yet been defined for the program in the example policy.
218
219 You should either disable any system processes left in the initrc_t
220 domain (if you do not need them) or place them into a different
221 domain, possibly defining new domains if necessary.
222
223 Your user processes should have your user identity and the sysadm_r
224 role.  Your shell and most of its children will have the sysadm_t
225 domain.  Some of the processes that you run may be in different
226 domains because they require different privileges.
227
228 9) If you have built and installed the patched utilities, then you
229 can run 'ls -Z /'.  If not, you can run the getfilecon utility
230 to see a particular file context.  Initially, the system_u user
231 identity is used for all files at installation time.  When you create
232 new files after installation, they will be assigned the user identity
233 of the creating process.  The object_r role is used for all files,
234 because roles are not relevant for files.  Files with different
235 protection requirements will have different types, e.g. /boot has the
236 boot_t type and /etc has the etc_t type.  Some files in the 'ls'
237 output may show a (null) context which indicates that either
238 permission was not granted to obtain the context of the file or the
239 filesystem type does not provide an xattr handler.
240
241 10) If the NSA SELinux Development Support option was enabled in the
242 kernel configuration, then SELinux is built with development support.
243 With this option, SELinux starts in permissive mode by default,
244 logging permission failures but not enforcing them.  You can use
245 permissive mode in order to determine what additional permissions are
246 needed for your particular system and can then revise your policy
247 configuration accordingly.  You can subseqently run 'echo 1 >
248 /selinux/enforce' program to switch into enforcing mode.  Once in
249 enforcing mode, you can only switch back to permissive mode with 'echo
250 0 > /selinux/enforce' if authorized by the policy (in the example
251 policy, only the sysadm_r role can do this). 
252
253 Once you are satisfied that your policy configuration is sufficient
254 for your system, you should either specify "enforcing=1" on the kernel
255 command line to start in enforcing mode at boot time, or you should
256 rebuild the kernel without this option so that it is always in
257 enforcing mode.  The first option leaves open the possibility of
258 switching back to permissive mode by an administrator, while the
259 latter option provides stricter security.  If you choose the latter
260 option, be sure to keep a kernel that is built with the Development
261 Support option available for emergency recovery (e.g. if you make an
262 error in your policy configuration that renders your system
263 unuseable).
264
265 You may find the audit2allow script useful in generating additional
266 'allow' rules from the log messages for your policy, but the generated
267 rules should be carefully reviewed to ensure that they are consistent
268 with your security goals.  You may find it desirable to define new
269 domains and/or types rather than simply granting the permission for an
270 existing domain and/or type in order to preserve existing security
271 guarantees.  You may also find that certain permission denials require
272 other kinds of policy changes, e.g. changes to the RBAC or constraints
273 configurations.  You may also find that certain permission denials are
274 not fatal to the application and you may not want to grant these
275 permissions due to your security goals.  In that case, you may wish to
276 simply suppress logging of the denial via an 'dontaudit' rule.
277
278 11) If you subsequently reboot with a non-SELinux kernel (or with
279 "selinux=0"), be sure to run setfiles again before booting SELinux to
280 reset your file security contexts properly.
281
282 EXPERIMENTING WITH THE NEW API
283 ------------------------------
284 1) Getting and setting process contexts
285
286 The patched coreutils package provides an enhanced form of the id
287 utility that displays the current security context.  The patched
288 procps and psmisc packages provide enhanced forms of the standard
289 process utilities that support options for displaying contexts of
290 other processes.
291
292 The patched coreutils package adds a runcon utility that is a superset
293 of execcon; runcon also allows individual specification of particular
294 fields of the context, e.g. runcon -t sysadm_t bash.
295
296 The newrole and run_init utilities use the same mechanism to support
297 secure role transitions and execution of init scripts in the proper
298 context, e.g.:
299         newrole -r sysadm_r
300         run_init /etc/init.d/sshd restart
301
302 2) Getting and setting file contexts
303
304 You can run getfattr and setfattr to directly get and set
305 individual file attributes, e.g.:
306         getfattr -n security.selinux /etc/shadow
307         setfattr -n security.selinux -v system_u:object_r:shadow_t /etc/shadow
308 These utilities are directly implemented via getxattr and setxattr.
309
310 However, it is preferable to run the getfilecon and setfilecon
311 utilities, e.g.:
312         getfilecon /etc/shadow
313         setfilecon system_u:object_r:shadow_t /etc/shadow
314 These utilities are implemented using the corresponding libselinux
315 functions, and encapsulate the use of xattr and the particular
316 attribute name.
317
318 The patched coreutils package provides enhanced forms of the standard
319 file utilities that support options for preserving the security
320 context of files or for creating new files with a specified security
321 context.  It also adds a chcon utility that is a more general form of
322 setfilecon modeled after chmod/chown.
323
324 3) Getting and setting policy information
325
326 selinuxfs exports the security policy API via a set of nodes under
327 /selinux.  libselinux provides API calls that internally read and
328 write these nodes.  The /selinux nodes are:
329
330 a) 'enforce' can be read or written to get or set the enforcing
331 status, e.g. 'echo -n 1 > /selinux/enforce' switches into enforcing
332 mode. Note that the enforcing status can only be changed if you built
333 with the Development Support option enabled; otherwise, SELinux is
334 always in enforcing mode.
335
336 b) 'load' can be written to load a new policy configuration.
337 libselinux provides a security_load_policy API call to access this
338 node.  The load_policy utility opens and mmaps a binary policy file
339 and then invokes this API call.
340
341 c) 'context' can be written to check the validity of a security
342 context.  libselinux provides a security_check_context API call to
343 access this node.  The setfiles utility invokes this API call to check
344 contexts in the file contexts specification, and the newrole utility
345 invokes this API call to check the new context.  Several other
346 libselinux functions also invoke this API call to validate contexts
347 before returning them.
348
349 d) 'access' can be written to request an access decision and can then
350 be read to obtain the decision.  On a write, the decision is computed
351 and saved in the open file private data, and will be returned on
352 subsequent reads by that process until the file is closed.  libselinux
353 provides a security_compute_av API call to access this node.  The
354 patched crond invokes this API call to check entrypoint permission.
355
356 e) 'create' can be written to request a labeling (transition) decision
357 and can then be read to obtain the decision.  As with /selinux/access,
358 the decision is saved in the open file private data for subsequent
359 reads.  libselinux provides a security_compute_create API call to
360 access this node.
361
362 f) 'relabel' can be written to request a relabeling decision and can
363 then be read to obtain the decision.  As with /selinux/access, the
364 decision is saved in the open file private data for subsequent reads.
365 libselinux provides a security_compute_relabel API call to access this
366 node.  The newrole utility and the patched login and sshd invoke this
367 API call to obtain the new tty/pty context.
368
369 g) 'user' can be written to obtain the set of reachable user contexts
370 and can then be read to obtain the set.  As with /selinux/access, the
371 information is saved in the open file private data for subsequent reads.
372 libselinux provides a security_compute_user API call to access this node.
373 The patched login, sshd, and crond invoke this API call to obtain the
374 set of authorized user contexts.
375
376 End
Note: See TracBrowser for help on using the browser.