接前一篇文章:SELinux refpolicy详解(6)
三、refpolicy内容详解
1. README
文件路径:refpolicy源码根目录/README。
文件内容如下:
1) Reference Policy make targets:General Make targets:install-src Install the policy sources into/etc/selinux/NAME/src/policy, where NAME is defined inthe Makefile. If not defined, the TYPE, as defined inthe Makefile, is used. The default NAME is refpolicy.A pre-existing source policy will be moved to/etc/selinux/NAME/src/policy.bak.conf Regenerate policy.xml, and update/create modules.confand booleans.conf. This should be done after addingor removing modules, or after running the bare target.If the configuration files exist, their settings willbe preserved. This must be ran on policy sources thatare checked out from the CVS repository before they canbe used.clean Delete all temporary files, compiled policies,and file_contexts. Configuration files are left intact.bare Do the clean make target and also delete configurationfiles, web page documentation, and policy.xml.html Regenerate policy.xml and create web page documentationin the doc/html directory.Make targets specific to modular (loadable modules) policies:base Compile and package the base module. This is thedefault target for modular policies.modules Compile and package all Reference Policy modulesconfigured to be built as loadable modules.MODULENAME.pp Compile and package the MODULENAME Reference Policymodule.all Compile and package the base module and all ReferencePolicy modules configured to be built as loadablemodules.install Compile, package, and install the base module andReference Policy modules configured to be built asloadable modules.load Compile, package, and install the base module andReference Policy modules configured to be built asloadable modules, then insert them into the modulestore.validate Validate if the configured modules can successfullylink and expand.install-headers Install the policy headers into /usr/share/selinux/NAME.The headers are sufficient for building a policymodule locally, without requiring the completeReference Policy sources. The build.conf settingsfor this policy configuration should be set beforeusing this target.build-interface-db Build the policy interface database with'sepolgen-ifgen'. This database is required forreference style policy generation by'audit2allow --reference'.Make targets specific to monolithic policies:policy Compile a policy locally for development and testing.This is the default target for monolithic policies.install Compile and install the policy and file contexts.load Compile and install the policy and file contexts, thenload the policy.enableaudit Remove all dontaudit rules from policy.conf.relabel Relabel the filesystem.checklabels Check the labels on the filesystem, and report whena file would be relabeled, but do not change its label.restorelabels Relabel the filesystem and report each file that isrelabeled.2) Reference Policy Build Options (build.conf)TYPE String. Available options are standard, mls, and mcs.For a type enforcement only system, set standard.This optionally enables multi-level security (MLS) ormulti-category security (MCS) features. This optioncontrols enable_mls, and enable_mcs policy blocks.NAME String (optional). Sets the name of the policy; theNAME is used when installing files to e.g.,/etc/selinux/NAME and /usr/share/selinux/NAME. If notset, 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, anddistro_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 directlyrun init scripts, instead of requiring the run_inittool. This is a build option instead of a tunable sincerole transitions do not work in conditional policy.This option controls direct_sysadm_daemon policyblocks.OUTPUT_POLICY Integer. Set the version of the policy created whenbuilding a monolithic policy. This option has no effecton modular policy.UNK_PERMS String. Set the kernel behavior for handling ofpermissions defined in the kernel but missing from thepolicy. 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 usedadditionally for approximate role separation.SYSTEMD Boolean. If set, systemd will be assumed to be the initprocess provider.MLS_SENS Integer. Set the number of sensitivities in the MLSpolicy. Ignored on standard and MCS policies.MLS_CATS Integer. Set the number of categories in the MLSpolicy. Ignored on standard and MCS policies.MCS_CATS Integer. Set the number of categories in the MCSpolicy. Ignored on standard and MLS policies.QUIET Boolean. If set, the build system will only displaystatus messages and error messages. This option has noeffect on policy.WERROR Boolean. If set, the build system will treat warningsas errors. If any warnings are encountered, the buildwill fail.3) Reference Policy Files and Directories
All directories relative to the root of the Reference Policy sources directory.Makefile General rules for building the policy.Rules.modular Makefile rules specific to building loadable modulepolicies.Rules.monolithic Makefile rules specific to building monolithic policies.build.conf Options which influence the building of the policy,such as the policy type and distribution.config/appconfig-* Application configuration files for all configurationsof the Reference Policy (targeted/strict with or withoutMLS or MCS). These are used by SELinux-aware programs.config/local.users The file read by load policy for adding SELinux usersto the policy on the fly.doc/html/* This contains the contents of the in-policy XMLdocumentation, presented in web page form.doc/policy.dtd The doc/policy.xml file is validated against this DTD.doc/policy.xml This file is generated/updated by the conf and html maketargets. It contains the complete XML documentationincluded in the policy.doc/templates/* Templates used for documentation web pages.policy/booleans.conf This file is generated/updated by the conf make target.It contains the booleans in the policy, and theirdefault values. If tunables are implemented asbooleans, tunables will also be included. This filewill be installed as the /etc/selinux/NAME/booleansfile.policy/constraints This file defines additional constraints on permissionsin the form of boolean expressions that must besatisfied in order for specified permissions to begranted. These constraints are used to further refinethe type enforcement rules and the role allow rules.Typically, these constraints are used to restrictchanges in user identity or role to certain domains.policy/global_booleans This file defines all booleans that have a global scope,their default value, and documentation.policy/global_tunables This file defines all tunables that have a global scope,their default value, and documentation.policy/flask/initial_sids This file has declarations for each initial SID.policy/flask/security_classes This file has declarations for each security class.policy/flask/access_vectors This file defines the access vectors. Commonprefixes for access vectors may be defined at thebeginning of the file. After the common prefixes aredefined, an access vector may be defined for eachsecurity class.policy/mcs The multi-category security (MCS) configuration.policy/mls The multi-level security (MLS) configuration.policy/modules/* Each directory represents a layer in Reference Policyall of the modules are contained in one of these layers.policy/modules.conf This file contains a listing of available modules, andhow they will be used when building Reference Policy. Toprevent 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. Formodular policies, modules set to "base" will be includedin the base module; those set to "module" will becompiled as individual loadable modules.policy/support/* Support macros.policy/users This file defines the users included in the policy.support/* Tools used in the build process.4) Building policy modules using Reference Policy headers:The system must first have the Reference Policy headers installed, typically
by the distribution. Otherwise, the headers can be installed using the
install-headers target from the full Reference Policy sources.To set up a directory to build a local module, one must simply place a .te
file in a directory. A sample Makefile to use in the directory is the
Makefile.example in the doc directory. This may be installed in
/usr/share/doc, under the directory for the distribution's policy.
Alternatively, the primary Makefile in the headers directory (typically
/usr/share/selinux/NAME/Makefile) can be called directly, using make's -f
option.Larger projects can set up a structure of layers, just as in Reference
Policy, by creating policy/modules/LAYERNAME directories. Each layer also
must have a metadata.xml file which is an XML file with a summary tag and
optional desc (long description) tag. This should describe the purpose of
the layer.Metadata.xml example:<summary>ABC modules for the XYZ components.</summary>Make targets for modules built from headers:MODULENAME.pp Compile and package the MODULENAME local module.all Compile and package the modules in the currentdirectory.load Compile and package the modules in the currentdirectory, then insert them into the module store.refresh Attempts to reinsert all modules that are currentlyin the module store from the local and system modulepackages.xml Build a policy.xml from the XML included with thebase policy headers and any XML in the modules inthe current directory.
上一回讲解了README文件的第三部分,本回将讲解第四部分即最后一部分。
(4)Building policy modules using Reference Policy headers(使用参考策略头构建策略模块)
系统必须首先安装参考策略头,通常由发布版安装;否则,可以使用来自完整参考策略源的install-headers target(目标)来安装头。
要建立(设置)一个目录来构建本地模块,只需在目录中放置一个.te文件即可。在该目录下使用的示例Makefile是doc目录中的Makefile.example。
它可以安装在/usr/share/doc中,位于分发策略的目录下。或者,headers目录中的主Makefile(通常是/usr/share/selinux/NAME/Makefile)可以使用make -f选项直接调用。
较大的项目可以通过创建policy/modules/LAYERNAME目录来设置层结构,就像在参考策略中一样。每个层还必须有一个metadata.xml文件,该文件是一个带有摘要标记和可选的desc(长描述)标记的xml文件。其应该描述图层的用途。
Metadata.xml示例:
<summary>ABC modules for the XYZ components.</summary>
基于头构建模块的make target(目标):
- MODULENAME.pp
编译并打包MODULENAME本地模块。
- all
编译并打包当前目录下的模块。
- load
编译并打包当前目录下的模块,然后将它们插入到模块存储(module store)中。
- refresh
尝试从本地和系统模块包中重新插入模块存储区中当前的所有模块。
- xml
根据基本策略头中包含的xml和当前目录中模块中的任何xml,构建policy.xml。
至此,README文件就讲解完了。