-
Notifications
You must be signed in to change notification settings - Fork 110
/
reference_policy.md
3065 lines (2273 loc) · 101 KB
/
reference_policy.md
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
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The Reference Policy
- [Reference Policy Overview](#reference-policy-overview)
- [Distributing Policies](#distributing-policies)
- [Policy Functionality](#policy-functionality)
- [Reference Policy Module Files](#reference-policy-module-files)
- [Reference Policy Source](#reference-policy-source)
- [Source Layout](#source-layout)
- [Reference Policy Files and Directories](#reference-policy-files-and-directories)
- [Source Configuration Files](#source-configuration-files)
- [Reference Policy Build Options - build.conf](#reference-policy-build-options---build.conf)
- [Reference Policy Build Options - policy/modules.conf](#reference-policy-build-options---policymodules.conf)
- [Building the modules.conf File](#building-the-modules.conf-file)
- [Source Installation and Build Make Options](#source-installation-and-build-make-options)
- [Booleans, Global Booleans and Tunable Booleans](#booleans-global-booleans-and-tunable-booleans)
- [Modular Policy Build Structure](#modular-policy-build-structure)
- [Base Module Build](#base-module-build)
- [Module Build](#module-build)
- [Creating Additional Layers](#creating-additional-layers)
- [Installing and Building the Reference Policy Source](#installing-and-building-the-reference-policy-source)
- [Building Standard Reference Policy](#building-standard-reference-policy)
- [Building the Fedora Policy](#building-the-fedora-policy)
- [Reference Policy Headers](#reference-policy-headers)
- [Building and Installing the Header Files](#building-and-installing-the-header-files)
- [Using the Reference Policy Headers](#using-the-reference-policy-headers)
- [Using Fedora Supplied Headers](#using-fedora-supplied-headers)
- [Reference Policy Support Macros](#reference-policy-support-macros)
- [Loadable Policy Macros](#loadable-policy-macros)
- [*policy_module* Macro](#policy_module-macro)
- [*gen_require* Macro](#gen_require-macro)
- [*optional_policy* Macro](#optional_policy-macro)
- [*gen_tunable* Macro](#gen_tunable-macro)
- [*tunable_policy* Macro](#tunable_policy-macro)
- [*interface* Macro](#interface-macro)
- [*template* Macro](#template-macro)
- [Miscellaneous Macros](#miscellaneous-macros)
- [*gen_context* Macro](#gen_context-macro)
- [*gen_user* Macro](#gen_user-macro)
- [*gen_bool* Macro](#gen_bool-macro)
- [MLS and MCS Macros](#mls-and-mcs-macros)
- [*gen_cats* Macro](#gen_cats-macro)
- [*gen_sens* Macro](#gen_sens-macro)
- [*gen_levels* Macro](#gen_levels-macro)
- [*ifdef* / *ifndef* Parameters](#ifdef-ifndef-parameters)
- [*hide_broken_symptoms*](#hide_broken_symptoms)
- [*enable_mls* and *enable_mcs*](#enable_mls-and-enable_mcs)
- [*enable_ubac*](#enable_ubac)
- [*direct_sysadm_daemon*](#direct_sysadm_daemon)
- [Module Expansion Process](#module-expansion-process)
The [**Reference Policy**](https://github.com/SELinuxProject/refpolicy)
is now the standard policy source used to build Linux SELinux
policies. This provides a single source tree with supporting
documentation that can be used to build policies for different
purposes such as: confining important daemons, supporting MLS / MCS
type policies and locking down systems so that all processes are under
SELinux control.
This section details how the Reference Policy is:
1. Constructed and types of policy builds supported.
2. Adding new modules to the build.
3. Installation as a full Reference Policy source or as Header files.
4. Impact of the migration process being used to convert compiled
module files (*\*.pp*) to CIL.
5. Modifying the configuration files to build new policies.
6. Explain the support macros.
Note that the Reference Policy uses **NAME** to define the policy name. This
then becomes part of the policy location (i.e. */etc/selinux/\<NAME\>*).
In most documentation the policy name is defined using the
*\<SELINUXTYPE\>* convention, as that is from the
*/etc/selinux/config* file entry **SELINUXTYPE=**. This part of the Notebook
uses both forms.
### Reference Policy Overview
Strictly speaking the 'Reference Policy' should refer to the policy
taken from the master repository or the latest released version. This is
because most Linux distributors take a released version and then tailor it to
their specific requirements.
All examples in this section are based on the master Reference Policy
repository that can be checked out using the following:
```
# Check out the core policy:
git clone https://github.com/SELinuxProject/refpolicy.git
```
A list of releases can be found at <https://github.com/SELinuxProject/refpolicy/releases>
The Fedora distribution is built from a specific standard Reference Policy
build, modified and distributed by Red Hat as a source RPM. These RPMs can be
obtained from <http://koji.fedoraproject.org>. The master Fedora policy source
can be found at: <https://github.com/fedora-selinux/selinux-policy>
**Figure 26: The Reference Policy Source Tree** shows the layout of the
reference policy source tree, that once installed would be located at
```
/etc/selinux/<SELINUXTYPE>/src/policy
```
Where the **\<SELINUXTYPE\>** entry is taken from the *build.conf* file
as discussed in the
[**Reference Policy Build Options** - *build.conf*](#reference-policy-build-options---build.conf)
section. The
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section explains a simple build from source.
![](./images/26-ref-policy.png)
**Figure 26: The Reference Policy Source Tree** - *When building a modular
policy, files are added to the policy store. For monolithic builds the policy
store is not used.*
The Reference Policy can be used to build two policy types:
1. **Loadable Module Policy** - A policy that has a
base module for core services and has the ability to load / unload
modules to support applications as required. This is now the
standard used by Linux distributions.
2. **Monolithic Policy** - A policy that has all the
required policy information in a single base policy and does not
require the services of the module infrastructure (***semanage**(8)*
or ***semodule**(8)*). These are more suitable for embedded or
minimal systems.
Each of the policy types are built using module files that define the
specific rules required by the policy as detailed in the
[**Reference Policy Module Files**](#reference-policy-module-files) section.
Note that the monolithic policy is built using the same module files by
forming a single 'base' source file.
The Reference Policy relies heavily on the ***m4**(1)* macro processor
as the majority of supporting services are m4 macros.
### Distributing Policies
It is possible to distribute the Reference Policy in two forms:
1. As source code that is then used to build policies. This is not the
general way policies are distributed as it contains the complete
source that most administrators do not need. The
[**Reference Policy Source**](#reference-policy-source) section describes
the source and the
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section describes how to install the source and build a policy.
2. As 'Policy Headers'. This is the most common way to distribute the
Reference Policy. Basically, the modules that make up 'the
distribution' are pre-built and then linked to form a base and
optional modules. The 'headers' that make-up the policy are then
distributed along with makefiles and documentation. A policy writer
can then build policy using the core modules supported by the
distribution, and using development tools they can add their own
policy modules. The
[**Reference Policy Headers**](#reference-policy-headers) section describes
how these are installed and used to build modules.
The policy header files and documentation for Fedora are distributed in:
- **selinux-policy** - Contains the SELinux */etc/selinux/config* file
and rpm macros
- **selinux-policy-devel** - Contains the 'Policy Header' development
environment that is located at */usr/share/selinux/devel*
- **selinux-policy-doc** - Contains man pages and the html policy
documentation that is located at */usr/share/doc/selinux-policy/html*
These rpms contain a specific policy type containing configuration files and
packaged policy modules (*\*.pp*). The policy will be installed in the
*/etc/selinux/\<SELINUXTYPE\>* directory, along with its configuration files.
- **selinux-policy-targeted** - This is the default Fedora policy.
- selinux-policy-minimum
- selinux-policy-mls
The selinux-policy-sandbox rpm contains the sandbox module for use by the
*policycoreutils-sandbox* package. This will be installed as a module for
one of the three main policies described above.
### Policy Functionality
As can be seen from the policies distributed with Fedora above, they can
be classified by the name of the functionality they support (taken from
the *SELINUXTYPE* entry of the *build.conf* as shown in the
[**Reference Policy Build Options - build.conf**](#reference-policy-build-options---build.conf)
section, for example the Fedora policies support:
- minimum - MCS policy that supports a minimal set of confined daemons
within their own domains. The remainder run in the *unconfined_t* space.
- targeted - MCS policy that supports a greater number of confined daemons
and can also confine other areas and users.
- mls - MLS policy for server based systems.
### Reference Policy Module Files
The reference policy modules are constructed using a mixture of
[**support macros**](#reference-policy-support-macros),
[**interface calls**](#interface-macro) and
[**Kernel Policy Language Statements**](kernel_policy_language.md#kernel-policy-language),
using three principle types of source file:
- A private policy file that contains statements required to enforce
policy on the specific GNU / Linux service being defined within the
module. These files are named *\<module_name\>.te*. For example the
*ada.te* file shown below has two statements:
- one to state that the *ada_t* process has permission to write to
the stack and memory allocated to a file.
- one that states that if the *unconfined_domain* module is loaded, then
allow the *ada_t* domain unconfined access. Note that if the
flow of this statement is followed it will be seen that many
more interfaces and macros are called to build the final raw
SELinux language statements. An expanded module source isshown in the
[**Module Expansion Process**](#module-expansion-process) section.
- An external interface file that defines the services available to
other modules. These files are named *\<module_name\>.if*.
For example the *ada.if* file shown below has two interfaces defined for
other modules to call:
- *ada_domtrans* - that allows another module (running in domain *$1*) to
run the ada application in the *ada_t* domain.
- *ada_run* - that allows another module to run the ada application in
the *ada_t* domain (via the *ada_domtrans* interface), then
associate the *ada_t* domain to the caller defined role (*$2*) and
terminal (*$3*). Provided of course that the caller domain has
permission. Note that there are two types of interface specification:
- **Access Interfaces** - These are the most
common and define interfaces that *.te* modules can call as described
in the ada examples. They are generated by the *interface* macro as
detailed in the [*interface*](#interface-macro) section.
- **Template Interfaces** - These are required whenever a module is
required in different domains and allows the type(s) to be redefined by
adding a prefix supplied by the calling module. The basic idea is to
set up an application in a domain that is suitable for the defined
SELinux user and role to access but not others. These are generated by
the *template* macro as detailed in the [*template*](#template-macro)
section.
- A file labeling file that defines the labels to be added to files
for the specified module. These files are named
*\<module_name\>.fc*. The build process will amalgamate all the
*\*.fc* files and finally form the
[***file_contexts***](policy_config_files.md#contextsfilesfile_contexts)
file that will be used to label the filesystem. For example the *ada.fc*
file shown below requires that the specified files are labeled
*system_u:object_r:ada_exec_t:s0*. The *\<module_name\>* must be unique
within the reference policy source tree and should reflect the specific
Linux service being enforced by the policy.
The following examples from the ada module files show how they are
made from the Policy Macros, Interface calls and kernel policy statements
and rules:
**ada.te file contents:**
```
policy_module(ada, 1.5.0)
########################################
#
# Declarations
#
attribute_role ada_roles; # Kernel policy statement
roleattribute system_r ada_roles;
type ada_t;
type ada_exec_t;
application_domain(ada_t, ada_exec_t) # call into 'application.if'
role ada_roles types ada_t;
########################################
#
# Local policy
#
allow ada_t self:process { execstack execmem };
userdom_use_inherited_user_terminals(ada_t) # call into 'userdomain.if'
optional_policy(` # Macro in loadable_module.spt
unconfined_domain(ada_t)
')
```
**ada.if 'interface calls' file contents:**
```
## <summary>GNAT Ada95 compiler.</summary>
########################################
## <summary>
## Execute the ada program in the ada domain.
## </summary>
## <param name="domain">
## <summary>
## Domain allowed to transition.
## </summary>
## </param>
#
interface(*ada_domtrans',* # Defining an interface
gen_require(` # Macro in loadable_module.spt
type ada_t, ada_exec_t;
')
corecmd_search_bin($1)
domtrans_pattern($1, ada_exec_t, ada_t) # Macro in misc_patterns.spt
')
########################################
## <summary>
## Execute ada in the ada domain, and
## allow the specified role the ada domain.
## </summary>
## <param name="domain">
## <summary>
## Domain allowed to transition.
## </summary>
## </param>
## <param name="role">
## <summary>
## Role allowed access.
## </summary>
## </param>
#
interface(*ada_run',*
gen_require(`
attribute_role ada_roles;
')
ada_domtrans($1)
roleattribute $2 ada_roles; # Kernel policy statement
')
```
**ada.fc file contents:**
```
# gen_context is a macro in misc_macros.spt
/usr/bin/gnatbind -- gen_context(system_u:object_r:ada_exec_t,s0)
/usr/bin/gnatls -- gen_context(system_u:object_r:ada_exec_t,s0)
/usr/bin/gnatmake -- gen_context(system_u:object_r:ada_exec_t,s0)
/usr/libexec/gcc(/.*)?/gnat1 -- gen_context(system_u:object_r:ada_exec_t,s0)
```
### Reference Policy Documentation
One of the advantages of the reference policy is that it is possible to
automatically generate documentation as a part of the build process.
This documentation is defined in XML and generated as HTML files
suitable for viewing via a browser.
The documentation for Fedora can be viewed in a browser using
[*/usr/share/doc/selinux-policy/html/index.html*](/usr/share/doc/selinux-policy/html/index.html)
once the *selinux-policy-doc* rpm has been installed.
The documentation for the Reference Policy source will be available at
*\<location\>/src/policy/doc/html* once *make html* has been executed
(the *\<location\>* is the location of the installed source after
*make install-src* has been executed as described in the
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section). The Reference Policy documentation may also be available at a
default location of */usr/share/doc/refpolicy-\<VERSION\>/html* if
*make install-doc* has been executed (where *\<VERSION/>* is the entry from the
source *VERSION* file.
**Figure 27** shows an example screen shot of the documentation produced for
the ada module interfaces.
![](./images/27-ref-doc.png)
**Figure 27: Example Documentation Screen Shot**
## Reference Policy Source
This section explains the source layout and configuration files, with
the actual installation and building covered in the
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section.
The source has a README file containing information on the configuration
and installation processes that has been used within this section (and
updated with the authors comments as necessary). There is also a VERSION
file that contains the Reference Policy release date, this can then be used to
obtain a change list <https://github.com/SELinuxProject/refpolicy/releases>.
### Source Layout
**Figure 26: The Reference Policy Source Tree** shows the layout of the
reference policy source tree, that once installed would be located at:
*/etc/selinux/\<SELINUXTYPE\>/src/policy*
The following sections detail the source contents:
- [**Reference Policy Files and Directories**](#reference-policy-files-and-directories) -
Describes the files and their location.
- [**Source Configuration Files**](#source-configuration-files) -
Details the contents of the *build.conf* and *modules.conf*
configuration files.
- [**Source Installation and Build Make Options**](#source-installation-and-build-make-options) -
Describes the *make* targets.
- [**Modular Policy Build Structure**](#modular-policy-build-structure) -
Describes how the various source files are linked together to form a
base policy module *base.conf* during the build process.
The
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section then describes how the initial source is installed and
configured to allow a policy to be built.
### Reference Policy Files and Directories
The **Reference Policy Files and Directories** list shows the major
files and their directories with a description of each taken from the
README file (with comments added). All directories are relative to the root of
the [Reference Policy](https://github.com/SELinuxProject/refpolicy) source directory
[*./policy*](https://github.com/SELinuxProject/refpolicy/tree/master/policy).
The *build.conf* and *modules.conf* configuration files are further detailed
in the [**Source Configuration Files**](#source-configuration-files)
section as they define how the policy will be built.
During the build process, a file is generated in the *./policy* directory
called either *policy.conf* or *base.conf* depending whether a monolithic or
modular policy is being built. This file is explained in the
[**Modular Policy Build Structure**](#modular-policy-build-structure) section.
**Reference Policy Files and Directories:**
[*Makefile*](https://github.com/SELinuxProject/refpolicy/tree/master/Makefile)
- General rules for building the policy.
[*Rules.modular*](https://github.com/SELinuxProject/refpolicy/tree/master/Rules.modular)
- Makefile rules specific to building loadable module policies.
[*Rules.monolithic*](https://github.com/SELinuxProject/refpolicy/tree/master/Rules.monolithic)
- Makefile rules specific to building monolithic policies.
[*build.conf*](https://github.com/SELinuxProject/refpolicy/tree/master/build.conf)
- Options which influence the building of the policy, such as the policy type
and distribution. This file is described in the
[**Reference Policy Build Options - build.conf**](#reference-policy-build-options---build.conf)
section.
[*config*](https://github.com/SELinuxProject/refpolicy/tree/master/config)*/appconfig-\<type\>*
- Application configuration files for all configurations of the Reference
Policy where *\<type\>* is taken from the *build.conf* **TYPE** entry that
are currently: standard, MLS and MCS). These files are used by SELinux-aware
programs and described in the
[**SELinux Configuration Files**](policy_config_files.md#policy-configuration-files)
section.
[*config/file_contexts.subs_dist*](https://github.com/SELinuxProject/refpolicy/tree/master/config/file_contexts.subs_dist)
- Used to configure file context aliases (see the
[**contexts/files/file_contexts.subs and file_contexts.subs_dist File**](policy_config_files.md#contextsfilesfile_contexts.subs)
section).
[*config/local.users*](https://github.com/SELinuxProject/refpolicy/tree/master/config/local.users)
- The file read by load policy for adding SELinux users to the policy on
the fly. Note that this file is not used in the modular policy build.
[*doc/html*](https://github.com/SELinuxProject/refpolicy/tree/master/doc/html)*/\**
- When *make html* has been executed, contains the in-policy XML
documentation, presented in web page form.
[*doc/policy.dtd*](https://github.com/SELinuxProject/refpolicy/tree/master/doc/policy.dtd)
- The *doc/policy.xml* file is validated against this DTD.
[*doc/policy.xml*](https://github.com/SELinuxProject/refpolicy/tree/master/doc/policy.xml)
- This file is generated/updated by the conf and html make targets.
It contains the complete XML documentation included in the policy.
[*doc/templates*](https://github.com/SELinuxProject/refpolicy/tree/master/doc/templates)*/\**
- Templates used for documentation web pages.
[*man*](https://github.com/SELinuxProject/refpolicy/tree/master/man)*/\**
- Various man pages for modules (ftp, http etc.)
[*support*](https://github.com/SELinuxProject/refpolicy/tree/master/support)*/\**
- Tools used in the build process.
[*policy/flask/initial_sids*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/flask/initial_sids)
- This file has declarations for each initial SID. The file usage in policy
generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure)
section.
[*policy/flask/security_classes*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/flask/security_classes)
- This file has declarations for each security class. The file usage in
policy generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure)
section.
[*policy/flask/access_vectors*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/flask/access_vectors)
- This file defines the common permissions and class specific permissions
and is described in the [**Modular Policy Build Structure**](#modular-policy-build-structure)
section.
[*policy/modules*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/modules)*/\**
- Each directory represents a layer in Reference Policy. All of the modules
are contained in one of these layers. The *contrib* modules are supplied
externally to the Reference Policy, then linked into the build. The files
present in each directory are: *metadata.xml* that describes the layer and
*\<module_name\>.te*, *.if* and *.fc* that contain policy source as
described in the [**Reference Policy Module Files**](#reference-policy-module-files)
section. The file usage in policy generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure)
section.
[*policy/support*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/support)*/\**
- Reference Policy support macros are described in the
[**Reference Policy support Macros**](#reference-policy-support-macros)
section.
[*policy/booleans.conf*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/booleans.conf)
- This file is generated/updated by *make conf*. It contains the booleans in
the policy and their default values. If tunables are implemented as
booleans, tunables will also be included. This file will be installed as
the */etc/selinux/\<NAME\>/booleans file* (note that this is not true for
any system that implements the modular policy - see the
[**Booleans, Global Booleans and Tunable Booleans**](#booleans-global-booleans-and-tunable-booleans)
section).
[*policy/constraints*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/constraints)
- This file defines constraints on permissions in the form of boolean
expressions that must be satisfied in order for specified permissions to
be granted. These constraints are used to further refine the type
enforcement rules and the role allow rules. Typically, these constraints
are used to restrict changes in user identity or role to certain domains.
(Note that this file does not contain the MLS / MCS constraints as they
are in the *mls* and *mcs* files described below). The file usage in policy
generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure) section.
[*policy/context_defaults*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/context_defaults)
- This would contain any specific *default_user*, *default_role*,
*default_type* and/or *default_range* rules required by the policy.
[*policy/global_booleans*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/global_booleans)
- This file defines all booleans that have a global scope, their default
value, and documentation. See the
[**Booleans, Global Booleans and Tunable Booleans**](#booleans-global-booleans-and-tunable-booleans)
section.
[*policy/global_tunables*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/global_tunables)
- This file defines all tunables that have a global scope, their default
value, and documentation.
See the [**Booleans, Global Booleans and Tunable Booleans**](#booleans-global-booleans-and-tunable-booleans)
section.
[*policy/mcs*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/mcs)
- This contains information used to generate the *sensitivity*, *category*,
*level* and *mlsconstraint* statements used to define the MCS configuration.
The file usage in policy generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure) section.
[*policy/mls*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/mls)
- This contains information used to generate the *sensitivity*, *category*,
*level* and *mlsconstraint* statements used to define the MLS configuration.
The file usage in policy generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure) section.
*policy/modules.conf*
- This file contains a listing of available modules, and how they will be
used when building Reference Policy. To prevent a module from being used,
set the module to "off". For monolithic policies, modules set to "base" and
"module" will be included in the policy. For modular policies, modules set
to "base" will be included in the base module; those set to "module" will
be compiled as individual loadable modules. This file is described in the
[**Reference Policy Build Options - policy/modules.conf**](#reference-policy-build-options---policymodules.conf)
section.
[*policy/policy_capabilities*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/policy_capabilities)
- This file defines the policy capabilities that can be enabled in the policy.
The file usage in policy generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure) section.
[*policy/users*](https://github.com/SELinuxProject/refpolicy/tree/master/policy/users)
- This file defines the users included in the policy. The file usage in policy
generation is described in the
[**Modular Policy Build Structure**](#modular-policy-build-structure) section.
*securetty_types* and *setrans.conf*
- These files are not part of the standard Reference Policy distribution but
are added by Fedora source updates.
### Source Configuration Files
There are two major configuration files ([*build.conf*](https://github.com/SELinuxProject/refpolicy/tree/master/build.conf) and *modules.conf*)
that define the policy to be built and are detailed in this section.
#### Reference Policy Build Options - [build.conf](https://github.com/SELinuxProject/refpolicy/tree/master/build.conf)
This file defines the policy type to be built that will influence its
name and where the source will be located once it is finally installed.
An example file content is shown in the
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section where it is used to install and then build the policy.
The *build.conf* **Entries** below explains the fields that can be
defined within this file. The supplied fields will then be used by the *make*
process to set *m4* macro parameters. These macro definitions are also used
within the module source files to control how the policy is built with examples
shown in the [***ifdef***](#ifdef-ifndef-parameters) section.
**[*build.conf*](https://github.com/SELinuxProject/refpolicy/tree/master/build.conf) Entries:**
*TYPE*
- String - Available options are *standard*, *mls*, and *mcs*. For a type
enforcement only system, set standard. This optionally enables multi-level
security (MLS) or multi-category security (MCS) features. This option
controls *enable_mls*, and *enable_mcs* policy blocks.
*NAME*
- String (optional) - Sets the name of the policy; the *\<NAME\>* is used when
installing files to e.g., */etc/selinux/\<NAME\>* and
*/usr/share/selinux/\<NAME\>*. If not set, the policy type (*TYPE*) is used.
*DISTRO*
- String (optional) - Enable distribution-specific policy. Available options
are redhat, gentoo, and debian. This option controls *distro_redhat*,
*distro_gentoo*, and *distro_debian* build option policy blocks.
*MONOLITHIC*
- Boolean - If set, a monolithic policy is built, otherwise a modular policy
is built.
*DIRECT_INITRC*
- Boolean - If set, sysadm will be allowed to directly run init scripts,
instead of requiring the *run_init* tool. This is a build option instead
of a tunable since role transitions do not work in conditional policy. This
option controls *direct_sysadm_daemon* policy blocks.
*OUTPUT_POLICY*
- Integer - Set the version of the policy created when building a monolithic
policy. This option has no effect on modular policy.
*UNK_PERMS*
- String - Set the kernel behavior for handling of permissions defined in the
kernel but missing from the policy. The permissions can either be allowed
(*allow*), denied (*deny*), or the policy loading can be rejected (*reject*).
*UBAC*
- Boolean - If set, the SELinux user will be used additionally for approximate
role separation.
*SYSTEMD*
- Boolean - If set, ***systemd**(1)* will be assumed to be the init process
provider.
*MLS_SENS*
- Integer - Set the number of sensitivities in the MLS policy. Ignored on
*TYPE* entries of *standard* and *mcs*.
*MLS_CATS*
- Integer - Set the number of categories in the MLS policy. Ignored on
*TYPE* entries of *standard* and *mcs*.
*MCS_CATS*
- Integer - Set the number of categories in the MCS policy. Ignored on
*TYPE* entries of *standard* and *mls*.
*QUIET*
- Boolean - If set, the build system will only display status messages and
error messages. This option has no effect on policy.
*WERROR*
- Boolean - If set, the build system will treat warnings as errors. If any
warnings are encountered, the build will fail.
#### Reference Policy Build Options - policy/modules.conf
This file will not be present until *make conf* is run and controls
what modules are built within the policy, see the
[**Building the modules.conf File**](#building-the-modules.conf-file) section.
**Example entries:**
```
# Layer: kernel
# Module: kernel
# Required in base
#
# Policy for kernel threads, proc filesystem,and unlabeled processes and
# objects.
#
kernel = base
# Layer: admin
# Module: amanda
#
# Advanced Maryland Automatic Network Disk Archiver.
#
amanda = module
# Layer: admin
# Module: ddcprobe
#
# ddcprobe retrieves monitor and graphics card information
#
ddcprobe = off
```
The only active lines (those without comments) contain:
```
<module_name> = base | module | off
```
However note that the comments are important as they form part of the
documentation when it is generated by the *make html* target.
**Where:**
*module_name*
- The name of the module to be included within the build.
*base*
- The module will be in the base module for a modular policy build
(*build.conf* entry *MONOLITHIC* = n).
*module*
- The module will be built as a loadable module for a modular policy build.
If a monolithic policy is being built (*build.conf* entry *MONOLITHIC* = y),
then this module will be built into the base module.
*off*
- The module will not be included in any build.
Generally it is up to the policy distributor to decide which modules are
in the base and those that are loadable, however there are some modules
that MUST be in the base module. To highlight this there is a special
entry at the start of the modules interface file (*.if*) that has the
entry *\<required val="true"\>* as shown below (taken from the
*kernel.if* file):
```
## <summary>
## Policy for kernel threads, proc filesystem,
## and unlabeled processes and objects.
## </summary>
## <required val="true">
## This module has initial SIDs.
## </required>
```
The *modules.conf* file will also reflect that a module is required in
the base by adding a comment 'Required in base' when the make conf
target is executed (as all the *.if* files are checked during this
process and the *modules.conf* file updated).
```
# Layer: kernel
# Module: kernel
# Required in base
#
# Policy for kernel threads, proc filesystem,
# and unlabeled processes and objects.
#
kernel = base
```
Those marked as *Required in base* are shown in the
**Mandatory modules.conf Entries** (note that Fedora and the standard
Reference Policy may be different)
**Mandatory *modules.conf* Entries: 'Layer - Module Name - Comments'**
*kernel*
- *corecommands*
- Core policy for shells and generic programs in: */bin*, */sbin*,
*/usr/bin*, and */usr/sbin*. The *.fc* file sets up the labels for these
items.
- All the interface calls start with '*corecmd_*'.
- *corenetwork*
- Policy controlling access to network objects and also contains the
initial SIDs for these. The *.if* file is large and automatically
generated.
- All the interface calls start with '*corenet_*'.
- *devices*
- This module creates the device node concept and provides the policy for
many of the device files. Notable exceptions are the mass storage and
terminal devices that are covered by other modules (that is a char or
block device file, usually in */dev*). All types that are used to label
device nodes should use the dev_node macro. Additionally this module
controls access to:
1. the device directories containing device nodes.
2. device nodes as a group
3. individual access to specific device nodes covered by this module.
- All the interface calls start with '*dev_*'.
- *domain*
- Contains the core policy for forming and managing domains.
- All the interface calls start with '*domain_*'.
- *files*
- This module contains basic filesystem types and interfaces and includes:
1. The concept of different file types including basic files,
mount points, tmp files, etc.
2. Access to groups of files and all files.
3. Types and interfaces for the basic filesystem layout
(*/*, */etc*, */tmp* ...).
4. Contains the file initial SID.
- All the interface calls start with '*files_*'.
- *filesystem*
- Contains the policy for filesystems and the initial SID.
- All the interface calls start with '*fs_*'.
- *kernel*
- Contains the policy for kernel threads, proc filesystem, and unlabeled
processes and objects. This module has initial SIDs.
- All the interface calls start with '*kernel_*'.
- *mcs*
- Policy for Multicategory security. The *.te* file only contains
attributes used in MCS policy.
- All the interface calls start with '*mcs_*'.
- *mls*
- Policy for Multilevel security. The *.te* file only contains attributes
used in MLS policy. All the interface calls start with '*mls_*'.
- *selinux*
- Contains the policy for the kernel SELinux security interface
(*selinuxfs*).
- All the interface calls start with '*selinux_*'.
- *terminal*
- Contains the policy for terminals.
- All the interface calls start with '*term_*'.
- *ubac*
- Disabled by Fedora but enabled on standard Ref Policy. Support
user-based access control.
*system*
- *application*
- Enabled by Fedora but not standard Ref Policy. Defines attributes and
interfaces for all user apps.
- *setrans*
- Enabled by Fedora but not standard Ref Policy. Support for
***mcstransd**(8)*.
##### Building the modules.conf File
The file can be created by an editor, however it is generally built
initially by *make conf* that will add any additional modules to the file.
The file can then be edited to configure the required modules as base,
module or off.
As will be seen in the
[**Installing and Building the Reference Policy Source**](#installing-and-building-the-reference-policy-source)
section, the Fedora reference policy source comes with a number of
pre-configured files that are used to produce the required policy including
multiple versions of the *modules.conf* file.
### Source Installation and Build Make Options
This section explains the various make options available that have been
taken from the *README* file (with some additional minor comments).
**General Make targets:**
*install-src*
- Install the policy sources into */etc/selinux/\<NAME\>/src/policy*, where
\<NAME\> is defined in the *build.conf* file. If it is not defined, then
*TYPE* is used instead. If a *build.conf* does not have the information,
then the Makefile will default to the current entry in the
*/etc/selinux/config* file or default to *refpolicy*. A pre-existing source
policy will be moved to */etc/selinux/\<NAME\>/src/policy.bak*.
*conf*
- Regenerate *policy.xml*, and update/create *modules.conf* and
*booleans.conf*. This should be done after adding or removing modules, or
after running the bare target. If the configuration files exist, their
settings will be preserved. This must be run on policy sources that are
checked out from the CVS repository before they can be used. Note that if
*make bare* has been executed before this make target, or it is a first
build, then the *modules/kernel/corenetwork.??.in* files will be used to
generate the *corenetwork.te* and *corenetwork.if* module files.
These *\*.in* files may be edited to configure network ports etc.
(see the *# network_node* example entries in *corenetwork.te*).
*clean*
- Delete all temporary files, compiled policy, and file_contexts.
Configuration files are left intact.
*bare*
- Do the clean make target and also delete configuration files, web page
documentation, and policy.xml.
*html*
- Regenerate *policy.xml* and create web page documentation in the
*doc/html* directory.
*install-appconfig*
- Installs the appropriate SELinux-aware configuration files.
**Make targets specific to modular (loadable modules) policies:**
*base*
- Compile and package the base module. This is the default target for modular
policies.
*modules*
- Compile and package all Reference Policy modules configured to be built as
loadable modules.
*MODULENAME.pp*
- Compile and package the *MODULENAME* Reference Policy module.
*all*
- Compile and package the base module and all Reference Policy modules
configured to be built as loadable modules.
*install*
- Compile, package, and install the base module and Reference Policy modules
configured to be built as loadable modules.
*load*
- Compile, package, and install the base module and Reference Policy modules
configured to be built as loadable modules, then insert them into the
module store.
*validate*
- Validate if the configured modules can successfully link and expand.
*install-headers*
- Install the policy headers into */usr/share/selinux/\<NAME\>*. The headers
are sufficient for building a policy module locally, without requiring the
complete Reference Policy sources. The *build.conf* settings for this policy