summaryrefslogtreecommitdiff
blob: 32da030e2a4a92c804ebee90bdc3ecc099f55dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
<?xml version='1.0' encoding="utf-8"?>
<?xml-stylesheet href="/xsl/guide.xsl" type="text/xsl"?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<guide link="/proj/en/hardened/selinux/selinux-quickstart.xml">
<title>Gentoo Linux SELinux Quick Start Guide</title>
<author title="Author">
  <mail link="pebenito@gentoo.org">Chris PeBenito</mail>
</author>
<author title="Author">
  <mail link="klasikahl@gentoo.org">Zack Gilburd</mail>
</author>
<author title="Editor">
  <mail link="method@gentoo.org">Joshua Brindle</mail>
</author>
<abstract>
This will provide instructions for getting an SELinux installation running.
</abstract>
<license/>
<version>3.2</version>
<date>10 February 2004</date>

<chapter><title>Introduction</title>
<section>
<body>
<p>
  This guide contains information on converting a standard (default) profile
  Gentoo machine to SELinux.  Each chapter is a different mini-guide, for
  each respective architecture currently supported by Gentoo.
</p>
</body>
</section>
</chapter>

<chapter><title>Converting a Preexisting Standard x86 Gentoo Installation</title>
<section><title>Initial Preparations</title>
<body>

<warn>SELinux is only supported on servers.  Workstation support
will happen in the future.</warn>

<warn>SELinux is only supported on ext2/3 and XFS.  Other filesystems
lack the complete extended attribute support.  This should change
in the future.</warn>

<impo>As always, keep a LiveCD at hand in case things go wrong.</impo>

<p>First switch your profile to the SELinux profile:</p>

<pre caption="Switch profiles">
# <c>rm -f /etc/make.profile</c>
# <c>ln -sf /usr/portage/profiles/selinux-x86-1.4 /etc/make.profile</c>
</pre>

<impo>The SELinux profile has significanly fewer USE flags asserted than
the default profile.  Use "<i>emerge info</i>" to see if any use flags
need to be reenabled in make.conf.</impo>
<note>
  You may encounter this message from portage: "!!! SELinux module not found.
  Please verify that it was installed."  This is normal, and will be fixed
  later in the conversion process.
</note>

<p>
  We will start by emerging some essential packages.  Glibc must first be
  recompiled with newer linux headers.
</p>

<p>
  First check which version of linux-headers are installed.
</p>

<pre caption="Check linux-headers version">
# <c>emerge -s linux-headers</c>
<comment>or if you have gentoolkit installed:</comment>
# <c>qpkg -I -v linux-headers</c>
</pre>

<p>
  If the linux-headers version is older than 2.4.20, newer headers must be merged.
</p>

<pre caption="Merge newer headers">
# <c>emerge \>=sys-kernel/linux-headers-2.4.20</c>
</pre>

<p>
  Now, if you have merged new headers, or you are unsure if your glibc was
  compiled with newer headers, you must recompile glibc.
</p>

<pre caption="Recompile glibc">
# <c>emerge glibc</c>
</pre>

<impo>
  This is a critical operation.  Glibc must be compiled with newer linux-headers,
  otherwise some operations will malfunction.
</impo>

<p>Now merge an appropriate kernel.
</p>

<pre caption="Merge an appropriate kernel">
<comment>Use one of the following commands.</comment>
# <c>emerge selinux-sources</c>
<comment>Or</comment>
# <c>emerge hardened-sources</c>
<comment>Or</comment>
# <c>emerge gentoo-dev-sources</c>
<comment>Or</comment>
# <c>emerge development-sources</c>
<comment>Or</comment>
# <c>emerge mm-sources</c>
</pre>
<p>The kernel must  be compiled with security module support, SELinux support,
devpts, and extended attribute security labels.  Refer to the main installation
guide for futher kernel options.</p>

<pre caption="Location and required options under menuconfig">
<comment>Under "Code maturity level options"</comment>
[*] Prompt for development and/or incomplete code/drivers

<comment>Under "File systems"</comment>
&lt;*&gt; Second extended fs support
[*]   Ext2 extended attributes
[ ]     Ext2 POSIX Access Control Lists
[*]     Ext2 Security Labels
&lt;*&gt; Ext3 journalling file system support
[*]   Ext3 extended attributes
[ ]     Ext3 POSIX Access Control Lists
[*]     Ext3 Security labels
&lt;*&gt; XFS filesystem support
[ ]   Realtime support (EXPERIMENTAL)
[ ]   Quota support
[ ]   ACL support
[*]   Security Labels

[ ] /dev file system support (EXPERIMENTAL)
[*] /dev/pts file system for Unix98 PTYs
[*]   /dev/pts Extended Attributes
[*]     /dev/pts Security Labels    

<comment>Under "Security options"</comment>
[*] Enable different security models
[ ] Socket and Networking Security Hooks
&lt;*&gt; Capabilities Support
[*] NSA SELinux Support
[ ]   NSA SELinux boot parameter
[*]   NSA SELinux Development Support
[ ]   NSA SELinux MLS policy (EXPERIMENTAL)
</pre>
<p>
  The extended attribute security labels must be turned on for devpts and
  your filesystem(s).  Devfs is no longer usable in SELinux, and can be
  turned off.
</p>
<note>
  The available options may vary slightly depending on if a 2.4 or 2.6 kernel
  is being used.  The other extended attribute options should be turned off.
</note>

<p>Now compile and install the kernel and modules, but do not reboot.
Devpts and selinuxfs must also be enabled to mount at boot.  Add this to /etc/fstab:</p>
<pre caption="Fstab settings for devpts and selinuxfs">
none	/dev/pts	devpts		gid=5,mode=620	0	0
none	/selinux	selinuxfs	defaults	0	0
</pre>

<p>
The command line option <i>gentoo=nodevfs</i> must be added to the kernel
command line, so the init scripts do not attempt to mount devfs.
</p>
<pre caption="Example GRUB entry">
title=linux
root (hd0,0)
kernel /bzImage root=/dev/hda3 <c>gentoo=nodevfs</c>
</pre>
<pre caption="Example LILO entry">
image=/boot/bzImage
	label=linux
	read-only
	root=/dev/hda3
	<c>append="gentoo=nodevfs"</c>
</pre>
<p>
  We need to make some directories before we reboot.
</p>
<pre caption="Making Required Directories">
# <c>mkdir /selinux</c>
# <c>mkdir /sys</c>
</pre>
<p>Now reboot with the new SELinux kernel.</p>

</body>
</section>
<section><title>Merge SELinux Packages</title>
<body>
<p>Merge the libraries, utilities and base-policy.  Then load the policy.</p>

<pre caption="Merge base SELinux packages and policy">
# <c>emerge libselinux checkpolicy policycoreutils</c>
# <c>emerge selinux-base-policy</c>

# <c>cd /etc/security/selinux/src/policy</c>
# <c>make load</c>
</pre>

<p>Merge SELinux-patched packages:</p>

<pre># <c>emerge baselayout pam coreutils findutils openssh pam-login procps psmisc shadow util-linux python-selinux</c></pre>

<p>There are other packages that have SELinux patches, but are optional.  These
should be remerged if they are already installed, so the SELinux patches are
applied:</p>
<p>app-admin/logrotate<br/>
sys-apps/vixie-cron (currently the only cron patched for SELinux)<br/>
sys-libs/pwdb</p>

<p>SELinux does not use some packages that are used in standard Gentoo:</p>

<pre caption="Remove unused packages from standard Gentoo">
# <c>emerge -C textutils fileutils sh-utils</c>
</pre>

<p>Compile and install policy, and label filesystems.</p>

<pre caption="Install policy and label">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make install</c>
# <c>make relabel</c>
</pre>
<warn>
  There is a known issue with older versions of GRUB
  not being able to read symlinks that have been labeled.
  Please make sure you have at least GRUB 0.94 installed.
  Also rerun GRUB and reinstall it into the MBR to ensure
  the updated code is in use.
  You do have a LiveCD handy, right?
</warn>

<pre caption="Reinstall GRUB on the MBR (GRUB users only)">
# <c>grub</c>

grub> root (hd0,0) <comment>(Your boot partition)</comment>
grub> setup (hd0) <comment>(Where the boot record is installed; here, it is the MBR)</comment>
</pre>
</body>
</section>
<section><title>Final reboot</title>
<body>
<p>Reboot.  Relabel again to ensure all files
are labeled correctly (some files may have been created during shutdown and
reboot)</p>
<pre caption="Relabel">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make relabel</c>
</pre>
<note>
  It is strongly suggested to <uri link="http://www.gentoo.org/main/en/lists.xml">subscribe</uri>
  to the gentoo-hardened mail list.  It is generally a low traffic list, and 
  SELinux announcements are made there.
</note>
</body>
</section>
</chapter>


<chapter><title>Converting a Preexisting Standard PPC Gentoo Installation</title>
<section><title>Initial Preparations</title>
<body>

<warn>SELinux is only supported on servers.  Workstation support
will happen in the future.</warn>

<warn>SELinux is only supported on ext2/3 and XFS.  Other filesystems
lack the complete extended attribute support.  This should change
in the future.</warn>

<impo>As always, keep a LiveCD at hand in case things go wrong.</impo>

<p>First switch your profile to the SELinux profile:</p>

<pre caption="Switch profiles">
# <c>rm -f /etc/make.profile</c>
# <c>ln -sf /usr/portage/profiles/selinux-ppc-1.4 /etc/make.profile</c>
</pre>

<impo>The SELinux profile has significanly fewer USE flags asserted than
the default profile.  Use "<i>emerge info</i>" to see if any use flags
need to be reenabled in make.conf.</impo>
<note>
  You may encounter this message from portage: "!!! SELinux module not found.
  Please verify that it was installed."  This is normal, and will be fixed
  later in the conversion process.
</note>

<p>
  We will start by emerging some essential packages.  Glibc must first be
  recompiled with newer linux headers.
</p>

<p>
  First check which version of linux-headers are installed.
</p>

<pre caption="Check linux-headers version">
# <c>emerge -s linux-headers</c>
<comment>or if you have gentoolkit installed:</comment>
# <c>qpkg -I -v linux-headers</c>
</pre>

<p>
  If the linux-headers version is older than 2.4.20, newer headers must be merged.
</p>

<pre caption="Merge newer headers">
# <c>emerge \>=sys-kernel/linux-headers-2.4.20</c>
</pre>

<p>
  Now, if you have merged new headers, or you are unsure if your glibc was
  compiled with newer headers, you must recompile glibc.
</p>

<pre caption="Recompile glibc">
# <c>emerge glibc</c>
</pre>

<impo>
  This is a critical operation.  Glibc must be compiled with newer linux-headers,
  otherwise some operations will malfunction.
</impo>

<p>Now merge an appropriate kernel.
</p>

<pre caption="Merge an appropriate kernel">
<comment>Use one of the following commands.</comment>
# <c>emerge ppc-development-sources</c>
<comment>Or</comment>
# <c>emerge development-sources</c>
<comment>Or</comment>
# <c>emerge mm-sources</c>
</pre>
<p>The kernel must  be compiled with security module support, SELinux support,
devpts, and extended attribute security labels.  Refer to the main installation
guide for futher kernel options.</p>

<pre caption="Location and required options under menuconfig">
<comment>Under "Code maturity level options"</comment>
[*] Prompt for development and/or incomplete code/drivers

<comment>Under "File systems"</comment>
&lt;*&gt; Second extended fs support
[*]   Ext2 extended attributes
[ ]     Ext2 POSIX Access Control Lists
[*]     Ext2 Security Labels
&lt;*&gt; Ext3 journalling file system support
[*]   Ext3 extended attributes
[ ]     Ext3 POSIX Access Control Lists
[*]     Ext3 Security labels
&lt;*&gt; XFS filesystem support
[ ]   Realtime support (EXPERIMENTAL)
[ ]   Quota support
[ ]   ACL support
[*]   Security Labels

[ ] /dev file system support (EXPERIMENTAL)
[*] /dev/pts file system for Unix98 PTYs
[*]   /dev/pts Extended Attributes
[*]     /dev/pts Security Labels    

<comment>Under "Security options"</comment>
[*] Enable different security models
[ ] Socket and Networking Security Hooks
&lt;*&gt; Capabilities Support
[*] NSA SELinux Support
[ ]   NSA SELinux boot parameter
[*]   NSA SELinux Development Support
[ ]   NSA SELinux MLS policy (EXPERIMENTAL)
</pre>
<p>
  The extended attribute security labels must be turned on for devpts and
  your filesystem(s).  Devfs is no longer usable in SELinux, and can be
  turned off.
</p>

<p>Now compile and install the kernel and modules, but do not reboot.
Devpts and selinuxfs must also be enabled to mount at boot.  Add this to /etc/fstab:</p>
<pre caption="Fstab settings for devpts and selinuxfs">
none	/dev/pts	devpts		gid=5,mode=620	0	0
none	/selinux	selinuxfs	defaults	0	0
</pre>

<p>
The command line option <i>gentoo=nodevfs</i> must be added to the kernel
command line, so the init scripts do not attempt to mount devfs.
</p>
<pre caption="Example yaboot Entry">
image=/boot/bzImage
	label=linux
	read-only
	root=/dev/hda3
	<c>append="gentoo=nodevfs"</c>
</pre>
<p>
  We need to make some directories before we reboot.
</p>
<pre caption="Making Required Directories">
# <c>mkdir /selinux</c>
# <c>mkdir /sys</c>
</pre>
<p>Now reboot with the new SELinux kernel.</p>

</body>
</section>
<section><title>Merge SELinux Packages</title>
<body>
<p>Merge the libraries, utilities and base-policy.  Then load the policy.</p>

<pre caption="Merge base SELinux packages and policy">
# <c>emerge libselinux checkpolicy policycoreutils</c>
# <c>emerge selinux-base-policy</c>

# <c>cd /etc/security/selinux/src/policy</c>
# <c>make load</c>
</pre>

<p>Merge SELinux-patched packages:</p>

<pre># <c>emerge baselayout pam coreutils findutils openssh pam-login procps psmisc shadow util-linux python-selinux</c></pre>

<p>There are other packages that have SELinux patches, but are optional.  These
should be remerged if they are already installed, so the SELinux patches are
applied:</p>
<p>app-admin/logrotate<br/>
sys-apps/vixie-cron (currently the only cron patched for SELinux)<br/>
sys-libs/pwdb</p>

<p>SELinux does not use some packages that are used in standard Gentoo:</p>

<pre caption="Remove unused packages from standard Gentoo">
# <c>emerge -C textutils fileutils sh-utils</c>
</pre>

<p>Compile and install policy, and label filesystems.</p>

<pre caption="Install policy and label">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make install</c>
# <c>make relabel</c>
</pre>
</body>
</section>
<section><title>Final reboot</title>
<body>
<p>Reboot.  Relabel again to ensure all files
are labeled correctly (some files may have been created during shutdown and
reboot)</p>
<pre caption="Relabel">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make relabel</c>
</pre>
<note>
  It is strongly suggested to <uri link="http://www.gentoo.org/main/en/lists.xml">subscribe</uri>
  to the gentoo-hardened mail list.  It is generally a low traffic list, and 
  SELinux announcements are made there.
</note>
</body>
</section>
</chapter>

<chapter><title>Converting a Preexisting Standard SPARC64 Gentoo Installation</title>
<section><title>Initial Preparations</title>
<body>

<warn>SELinux is only supported on servers.  Workstation support
will happen in the future.</warn>

<warn>SELinux is only supported on ext2/3 and XFS.  Other filesystems
lack the complete extended attribute support.  This should change
in the future.</warn>

<impo>As always, keep a LiveCD at hand in case things go wrong.</impo>

<p>First switch your profile to the SELinux profile:</p>

<pre caption="Switch profiles">
# <c>rm -f /etc/make.profile</c>
# <c>ln -sf /usr/portage/profiles/selinux-sparc-1.4 /etc/make.profile</c>
</pre>

<impo>The SELinux profile has significanly fewer USE flags asserted than
the default profile.  Use "<i>emerge info</i>" to see if any use flags
need to be reenabled in make.conf.</impo>
<note>
  You may encounter this message from portage: "!!! SELinux module not found.
  Please verify that it was installed."  This is normal, and will be fixed
  later in the conversion process.
</note>

<impo>You must add <i>ACCEPT_KEYWORDS="~sparc"</i> to make.conf, as not all 	 
 SELinux packages are marked stable yet.</impo>

<p>
  We will start by emerging some essential packages.  Glibc must first be
  recompiled with newer linux headers.
</p>

<p>
  First check which version of linux-headers are installed.
</p>

<pre caption="Check linux-headers version">
# <c>emerge -s linux-headers</c>
<comment>or if you have gentoolkit installed:</comment>
# <c>qpkg -I -v linux-headers</c>
</pre>

<p>
  If the linux-headers version is older than 2.4.20, newer headers must be merged.
</p>

<pre caption="Merge newer headers">
# <c>emerge \>=sys-kernel/linux-headers-2.4.20</c>
</pre>

<p>
  Now, if you have merged new headers, or you are unsure if your glibc was
  compiled with newer headers, you must recompile glibc.
</p>

<pre caption="Recompile glibc">
# <c>emerge glibc</c>
</pre>

<impo>
  This is a critical operation.  Glibc must be compiled with newer linux-headers,
  otherwise some operations will malfunction.
</impo>

<p>Now merge an appropriate kernel.
</p>

<pre caption="Merge an appropriate kernel">
<comment>Use one of the following commands.</comment>
# <c>emerge sparc-dev-sources</c>
<comment>Or</comment>
# <c>emerge development-sources</c>
<comment>Or</comment>
# <c>emerge mm-sources</c>
</pre>
<p>The kernel must  be compiled with security module support, SELinux support,
devpts, and extended attribute security labels.  Refer to the main installation
guide for futher kernel options.</p>

<pre caption="Location and required options under menuconfig">
<comment>Under "Code maturity level options"</comment>
[*] Prompt for development and/or incomplete code/drivers

<comment>Under "File systems"</comment>
&lt;*&gt; Second extended fs support
[*]   Ext2 extended attributes
[ ]     Ext2 POSIX Access Control Lists
[*]     Ext2 Security Labels
&lt;*&gt; Ext3 journalling file system support
[*]   Ext3 extended attributes
[ ]     Ext3 POSIX Access Control Lists
[*]     Ext3 Security labels
&lt;*&gt; XFS filesystem support
[ ]   Realtime support (EXPERIMENTAL)
[ ]   Quota support
[ ]   ACL support
[*]   Security Labels

[ ] /dev file system support (EXPERIMENTAL)
[*] /dev/pts file system for Unix98 PTYs
[*]   /dev/pts Extended Attributes
[*]     /dev/pts Security Labels    

<comment>Under "Security options"</comment>
[*] Enable different security models
[ ] Socket and Networking Security Hooks
&lt;*&gt; Capabilities Support
[*] NSA SELinux Support
[ ]   NSA SELinux boot parameter
[*]   NSA SELinux Development Support
[ ]   NSA SELinux MLS policy (EXPERIMENTAL)
</pre>
<p>
  The extended attribute security labels must be turned on for devpts and
  your filesystem(s).  Devfs is no longer usable in SELinux, and can be
  turned off.
</p>

<p>Now compile and install the kernel and modules, but do not reboot.
Devpts and selinuxfs must also be enabled to mount at boot.  Add this to /etc/fstab:</p>
<pre caption="Fstab settings for devpts and selinuxfs">
none	/dev/pts	devpts		gid=5,mode=620	0	0
none	/selinux	selinuxfs	defaults	0	0
</pre>

<p>
The command line option <i>gentoo=nodevfs</i> must be added to the kernel
command line, so the init scripts do not attempt to mount devfs.
</p>
<pre caption="Example SILO Entry">
image = /vmlinux
        label = linux
        root = /dev/sda2
        <c>append="gentoo=nodevfs"</c>
</pre>
<p>
  We need to make some directories before we reboot.
</p>
<pre caption="Making Required Directories">
# <c>mkdir /selinux</c>
# <c>mkdir /sys</c>
</pre>
<p>Now reboot with the new SELinux kernel.</p>

</body>
</section>
<section><title>Merge SELinux Packages</title>
<body>
<p>Merge the libraries, utilities and base-policy.  Then load the policy.</p>

<pre caption="Merge base SELinux packages and policy">
# <c>emerge libselinux checkpolicy policycoreutils</c>
# <c>emerge selinux-base-policy</c>

# <c>cd /etc/security/selinux/src/policy</c>
# <c>make load</c>
</pre>

<p>Merge SELinux-patched packages:</p>

<pre># <c>emerge baselayout pam coreutils findutils openssh pam-login procps psmisc shadow util-linux python-selinux</c></pre>

<p>There are other packages that have SELinux patches, but are optional.  These
should be remerged if they are already installed, so the SELinux patches are
applied:</p>
<p>app-admin/logrotate<br/>
sys-apps/vixie-cron (currently the only cron patched for SELinux)<br/>
sys-libs/pwdb</p>

<p>SELinux does not use some packages that are used in standard Gentoo:</p>

<pre caption="Remove unused packages from standard Gentoo">
# <c>emerge -C textutils fileutils sh-utils</c>
</pre>

<p>Compile and install policy, and label filesystems.</p>

<pre caption="Install policy and label">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make install</c>
# <c>make relabel</c>
</pre>
</body>
</section>
<section><title>Final reboot</title>
<body>
<p>Reboot.  Relabel again to ensure all files
are labeled correctly (some files may have been created during shutdown and
reboot)</p>
<pre caption="Relabel">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make relabel</c>
</pre>
<note>
  It is strongly suggested to <uri link="http://www.gentoo.org/main/en/lists.xml">subscribe</uri>
  to the gentoo-hardened mail list.  It is generally a low traffic list, and 
  SELinux announcements are made there.
</note>
</body>
</section>
</chapter>


<!--
<chapter>
	<title>
		Conversion to the 2.6 SELinux API (x86 only)
	</title>
	<section><title>Converting an old API SELinux Installation</title>
	<body>
<warn>The new API only supports ext2/3 and XFS.  Other filesystems
lack the complete extended attribute support.  This should change
in the future.</warn>
	<p>
		SELinux is available in 2.6 kernels; however, it does not use the
		same API as the old (selinux-small/libsecure) 2.4 SELinux.  
		This new API has been backported to 2.4 in newer selinux-sources
		and hardened-sources kernels.  This chapter
		of the Quick Start Guide describes the conversion
		of a old API SELinux machine to the new API.  Please read the
		entire chapter before starting.
	</p>
	<impo>
		As always, keep a LiveCD at hand in case things go wrong.
	</impo>
	</body></section>
	<section>
		<title>
			Beginning the Conversion
		</title>
		<body>
			<p>
				We will start by emerging some essential packages.
				Glibc must first be recompiled
				with newer linux headers.
			</p>

<note>It is suggested to be in permissive mode.</note>

			<p>
				First check which version of linux-headers are
				installed.
			</p>

<pre caption="Check linux-headers version">
# <c>emerge -s linux-headers</c>
<comment>or if you have gentoolkit installed:</comment>
# <c>qpkg -I -v linux-headers</c>
</pre>

			<p>
				If the linux-headers version is older than 2.4.20,
				newer headers must be merged.
			</p>

<pre caption="Merge newer headers">
# <c>emerge \>=sys-kernel/linux-headers-2.4.20</c>
</pre>

			<p>
				Now, if you have merged new headers, or you are
				unsure if your glibc was compiled with newer
				headers, you must recompile glibc.
			</p>

<pre caption="Recompile glibc">
# <c>emerge glibc</c>
</pre>

			<impo>
				This is a critical operation.
				Glibc must be compiled with newer linux-headers,
				otherwise some operations will malfunction.
			</impo>

			<p>
				These packages contain the equivalent of the old
				selinux-small.  Do not unmerge selinux-small yet.
			</p>

<pre caption="Installing the New Packages">
# <c>emerge sys-libs/libselinux</c>
# <c>emerge sys-apps/checkpolicy</c>
# <c>emerge sys-apps/policycoreutils</c>
</pre>
			<p>
				Now you should either move, or remove your old SELinux policy (/etc/security/selinux/src/policy) and then emerge the new policy.
			</p>
<pre caption="Emerging the New Policy">
# <c>emerge \>=sec-policy/selinux-base-policy-20030817</c>
</pre>
		</body>
	</section>
	<section>
		<title>
			Compiling and Installing the New Kernel
		</title>
		<body>
			<p>
				We will first emerge a kernel that contains the new API.
			</p>
<pre caption="Emerging the Kernel">
<comment>Use one of the following commands.</comment>
# <c>emerge \>=selinux-sources-2.4.21-r2</c>
<comment>Or</comment>
# <c>emerge \>=hardened-sources-2.4.22</c>
<comment>Or</comment>
# <c>emerge \>=development-sources-2.6.0_beta3</c>
<comment>Or</comment>
# <c>emerge \>=mm-sources-2.6.0_beta3</c>
</pre>
			<p>
				Now we must configure the kernel.
			</p>
<pre caption="Location and required options under menuconfig">
<comment>Under "Code maturity level options"</comment>
[*] Prompt for development and/or incomplete code/drivers

<comment>Under "File systems"</comment>
&lt;*&gt; Second extended fs support
[*]   Ext2 extended attributes
[ ]     Ext2 POSIX Access Control Lists
[*]     Ext2 Security Labels
&lt;*&gt; Ext3 journalling file system support
[*]   Ext3 extended attributes
[ ]     Ext3 POSIX Access Control Lists
[*]     Ext3 security labels
&lt;*&gt; XFS filesystem support
[ ]   Realtime support (EXPERIMENTAL)
[ ]   Quota support
[ ]   ACL support
[*]   Security Labels

[ ] /dev file system support (EXPERIMENTAL)
[*] /dev/pts file system for Unix98 PTYs
[*]   /dev/pts Extended Attributes
[*]     /dev/pts Security Labels    

<comment>Under "Security options"</comment>
[*] Enable different security models
[ ] Socket and Networking Security Hooks
&lt;*&gt; Capabilities Support
[*] NSA SELinux Support
[ ]   NSA SELinux boot parameter
[*]   NSA SELinux Development Support
[ ]   NSA SELinux MLS policy (EXPERIMENTAL)
</pre>
<p>
  The extended attribute security labels must be turned on for devpts and
  your filesystem(s).  Devfs is no longer usable in SELinux, and can be
  turned off.
</p>

			<note>
				The available options may vary slightly depending on
				if a 2.4 or 2.6 kernel is being used.  The other
				extended attribute options should be turned off.
			</note>

<pre caption="Compile and Install the Kernel">
<comment>For 2.4 kernels:</comment>
# <c>make dep &amp;&amp; make clean bzImage modules modules_install</c>

<comment>For 2.6 kernels:</comment>
# <c>make clean bzImage modules modules_install</c>

<comment>For both versions:</comment>
<comment>if necessary, mount your boot partition.</comment>
# <c>mount /boot</c>
# <c>cp arch/i386/boot/bzImage /boot</c>
</pre>
		</body>
	</section>
	<section>
		<title>Reboot Preperations</title>
		<body>
			<p>
				We need to make some directories before we reboot.
			</p>
<pre caption="Making Required Directories">
# <c>mkdir /selinux</c>
# <c>mkdir /sys</c>
</pre>
			<p>
				Now, we need to add a line to our fstab:
			</p>
<pre caption="/etc/fstab">
# <c>nano -w /etc/fstab</c>
<comment>Add the following line.</comment>
none	/selinux	selinuxfs	defaults	0	0
</pre>
			<p>
				Now the bootloader will have to be configured.
				The command line option
				<i>gentoo=nodevfs</i> must be added to the kernel
				command line, so the init scripts do not attempt
				to mount devfs.
			</p>
<pre caption="Example GRUB entry">
title=linux
root (hd0,0)
kernel /bzImage root=/dev/hda3 <c>gentoo=nodevfs</c>
</pre>
<pre caption="Example LILO entry">
image=/boot/bzImage
	label=linux
	read-only
	root=/dev/hda3
	<c>append="gentoo=nodevfs"</c>
</pre>
			<p>
				You may now <c>reboot</c>.
			</p>
		</body>
	</section>
	<section>
		<title>Post-Reboot</title>
		<body>
			<p>
				Several packages need to be re-emerged.
			</p>
<pre caption="Re-emerge the Following Packages">
sys-libs/pam
sys-libs/pwdb
sys-apps/baselayout
sys-apps/coreutils
sys-apps/findutils
sys-apps/procps
sys-apps/psmisc
sys-apps/util-linux
sys-apps/pam-login
sys-apps/shadow
sys-apps/tar
net-misc/openssh
dev-python/python-selinux

<comment>The following are optional packages that must be re-emerged if you use them.</comment>
app-admin/logrotate
dev-util/strace
sys-apps/vixie-cron
sys-apps/stat
</pre>
			<p>
				Now all packages have been recompiled with the
				new API.  Now the old API can finally be unmerged.
			</p>
<pre caption="Unmerge selinux-small">
# <c>emerge unmerge selinux-small</c>
</pre>
		</body>
	</section>
	<section>
		<title>
			Relabeling and Final Reboot
		</title>
		<body>
			<p>
				As a one-time process, the filesystem must be relabled, the computer rebooted, then the filesystem relabled once again.
			</p>
			<warn>
				There is a known issue with older versions of GRUB
				not being able to read symlinks that have been labeled.
				Please make sure you have at least GRUB 0.94 installed.
				Also rerun GRUB and reinstall it into the MBR to ensure
				the updated code is in use.
				You do have a LiveCD handy, right?
			</warn>
<pre caption="Reinstall GRUB on the MBR (GRUB users only)">
# <c>grub</c>
                                                                                                        
grub> root (hd0,0) <comment>(Your boot partition)</comment>
grub> setup (hd0) <comment>(Where the boot record is installed; here, it is the MBR)</comment>
</pre>

<pre caption="Relabeling">
# <c>cd /etc/security/selinux/src/policy</c>
# <c>make relabel</c>

<comment>Reboot</comment>

# <c>cd /etc/security/selinux/src/policy</c>
# <c>make relabel</c>
</pre>
			<p>
				The conversion is complete.  When policy is
				added or changed, remember to load policy and relabel, or
				rlpkg the affected packages.
			</p>
<note>
  It is strongly suggested to <uri link="http://www.gentoo.org/main/en/lists.xml">subscribe</uri>
  to the gentoo-hardened mail list.  It is generally a low traffic list, and
  SELinux announcements are made there.
</note>
		</body>
	</section>
</chapter> -->
</guide>