当前位置: 首页 > article >正文

SELinux refpolicy详解(4)

接前一篇文章:SELinux refpolicy详解(3)

三、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 in
			the Makefile.  If not defined, the TYPE, as defined in
			the 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.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 ran on policy sources that
			are checked out from the CVS repository before they can
			be 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 configuration
			files, web page documentation, and policy.xml.

html			Regenerate policy.xml and create web page documentation
			in the doc/html directory.

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 configuration should be set before
			using this target.

build-interface-db	Build the policy interface database with
			'sepolgen-ifgen'.  This database is required for
			reference 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, then
			load the policy.

enableaudit		Remove all dontaudit rules from policy.conf.

relabel			Relabel the filesystem.

checklabels		Check the labels on the filesystem, and report when
			a file would be relabeled, but do not change its label.

restorelabels		Relabel the filesystem and report each file that is
			relabeled.


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) 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 will be assumed to be the init
			process provider.

MLS_SENS		Integer.  Set the number of sensitivities in the MLS
			policy.  Ignored on standard and MCS policies.

MLS_CATS		Integer.  Set the number of categories in the MLS
			policy.  Ignored on standard and MCS policies.

MCS_CATS		Integer.  Set the number of categories in the MCS
			policy.  Ignored on standard and MLS policies.

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.


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 module
			policies.

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 configurations
			of the Reference Policy (targeted/strict with or without
			MLS or MCS).  These are used by SELinux-aware programs.

config/local.users	The file read by load policy for adding SELinux users
			to the policy on the fly.

doc/html/*		This contains the contents of the in-policy XML
			documentation, 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 make
			targets.  It contains the complete XML documentation
			included 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 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.

policy/constraints	This file defines additional 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.

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.  Common
			prefixes for access vectors may be defined at the
			beginning of the file.  After the common prefixes are
			defined, an access vector may be defined for each
			security 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 Policy
			all of the modules are contained in one of these layers.

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.

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 current
			directory.

load			Compile and package the modules in the current
			directory, then insert them into the module store.

refresh			Attempts to reinsert all modules that are currently
			in the module store from the local and system module
			packages.

xml			Build a policy.xml from the XML included with the
			base policy headers and any XML in the modules in
			the current directory.

针对于各步骤一一进行说明和讲解。

(1)Reference Policy make targets(参考策略make targets)

1)通用的Make targets

  • install-src

将策略源安装到/etc/selinux/NAME/src/policy中,其中NAME在Makefile中定义。如果未定义,则使用Makefile中定义的TYPE。默认名称为refpolicy。预先(之前)存在的源策略将移动到/etc/selinux/NAME/src/policy.bak。

  • conf

重新生成policy.xml,并更新/创建modules.conf和booleans.conf。这应该在添加或删除模块之后,或者在运行bare target之后完成。如果配置文件存在,则其设置将被保留。这必须在从CVS存储库签出的策略源上运行,然后才能使用它们。

  • clean

删除所有临时文件、已编译的策略和file_context。配置文件完好无损(保留配置文件)。

  • bare

执行clean make target并删除配置文件、网页文档和policy.xml。

  • html

重新生成policy.xml并在doc/html目录中创建网页文档。

2)Make特定于模块化(可加载模块)策略的targets

  • base

编译并打包基本模块。这是模块化策略的默认目标。

  • modules

编译并打包所有参考策略模块,这些模块被配置为构建为可加载的模块。

  • MODULENAME.pp

编译并打包MODULENAME参考策略模块。

  • all

编译并打包基本模块和所有的参考策略模块,其(指参考策略模块)被配置成构建为可加载的模块。

  • install

编译、打包和安装基本模块和被配置成构建为可加载模块的参考策略模块。

  • load

编译、打包和安装基本模块和被配置成构建为可加载模块的参考策略模块,然后将它们插入到模块存储(module store)中。

  • validate

验证配置的模块是否可以成功链接和扩展。

  • install-headers

将策略头安装到/usr/share/selinux/NAME(如/usr/share/selinux/default)中。

头(headers)足以在本地构建策略模块,而不需要完整的参考策略源。在使用此目标之前,用于此策略配置的build.conf的设置应被设置。

  • build-interface-db

使用“sepolgen-ifgen”构建策略接口数据库。此数据库是被“audit2allow --reference”生成的参考样式策略所需要的。

3)Make特定于单一整体策略的targets

  • policy

在本地编译一个用于开发和测试的策略。这是单一策略的默认目标。

  • install

编译并安装策略和文件上下文。

  • load

编译并安装策略和文件上下文,然后加载策略。

  • enableaudit

从policy.conf中删除所有dontaudit规则。

  • relabel

重新标记文件系统。

  • checklabels

检查文件系统上的标签,并报告何时重新标记文件,但不要更改其标签。

  • restorelabels

重新标记文件系统并报告每个重新标记的文件。

下一回中继续解析README中的其它选项。


http://www.kler.cn/a/154436.html

相关文章:

  • windows工具 -- 使用rustdesk和云服务器自建远程桌面服务, 手机, PC, Mac, Linux远程桌面 (简洁明了)
  • 【H3C华三 】VRRP与BFD、Track联动配置案例
  • Spark 之 Cache
  • Bugku CTF_Web——No one knows regex better than me
  • SpringBoot 2.2.10 无法执行Test单元测试
  • C#界面设计
  • Layer Normalization是什么
  • Oauth2.0 学习
  • 180天Java从小白到就业-Day03-03Java位运算符、赋值运算符、数据交换的三种方式
  • P1 什么是链表 C语言简单易懂
  • Sql Server数据库跨机器完整恢复(源文件恢复)
  • QPrinter 是 Qt 框架中的一个类,用于与打印机进行交互,并提供打印功能
  • Linux 进程(三)
  • 每日一练:冒泡排序
  • 7、Jenkins+Nexus3+Docker+K8s实现CICD
  • 最小生成树算法
  • C++的一些基础
  • 光伏测算工具能测量哪些数据?
  • 自己开发组件更新到npm网站上 通过npm install 安装 保姆级别教程
  • Swin Transformer实战图像分类(Windows下,无需用到Conda,亲测有效)
  • 时序预测 | Python实现TCN时间卷积神经网络时间序列预测(多图,多指标)
  • C语言-指针_02
  • 【FMC139】青翼科技基于VITA57.1标准的4路500MSPS/1GSPS/1.25GSPS采样率14位AD采集FMC子卡模块
  • [ 蓝桥杯Web真题 ]-年度明星项目
  • Linux下的文件IO之系统IO
  • 2023.11.28-电商平台建设03 - 大数据调优手段