> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/handbook/di-19-zhang-qiang-zhi-fang-wen-kong-zhi/19.4.-gui-hua-an-quan-pei-zhi.md).

# 19.4.规划安全配置

在实施任何 MAC 策略之前，建议先规划。在规划阶段，管理员应考虑实施要求和目标，例如：

* 如何对目标系统上的信息和资源分类。
* 哪些信息或资源需要限制访问，以及需要应用哪些类型的限制。
* 为实现该目标需要哪些 MAC 模块。

在将 MAC 实施应用于生产系统之前，应该对受信系统及其配置进行试运行。由于不同的环境有不同的需求和要求，因此建立完整的安全配置文件将减少系统上线后需要的更改。

考虑 MAC 框架如何增强整个系统的安全性。MAC 框架提供的各种安全策略模块可用于保护网络和文件系统，或阻止用户访问某些端口和套接字。可能最好的策略模块使用方式是一次加载多个安全策略模块，以提供 MLS 环境。这种方法与加固策略不同，后者通常只加固用于特定目的的系统元素。MLS 的缺点是增加了管理开销。

与框架（提供按需选择策略并保持低性能开销的能力）的长期效益相比，开销是最小的。减少对不必要策略的支持可提高系统的整体性能，同时提供选择的灵活性。好的实施方案应考虑整体安全需求，并有效地实施框架提供的各种安全策略模块。

使用 MAC 的系统保证用户不能随意更改安全属性。所有的用户工具、程序和脚本都必须在所选安全策略模块提供的访问规则约束下工作，MAC 访问规则的控制权在系统管理员手中。

系统管理员的责任是仔细选择正确的安全策略模块。对于需要限制网络访问控制的环境，[mac\_portacl(4)](https://man.freebsd.org/cgi/man.cgi?query=mac_portacl\&sektion=4\&format=html)、[mac\_ifoff(4)](https://man.freebsd.org/cgi/man.cgi?query=mac_ifoff\&sektion=4\&format=html) 和 [mac\_biba(4)](https://man.freebsd.org/cgi/man.cgi?query=mac_biba\&sektion=4\&format=html) 策略模块是不错的起点。对于需要严格保密文件系统对象的环境，可考虑使用 [mac\_bsdextended(4)](https://man.freebsd.org/cgi/man.cgi?query=mac_bsdextended\&sektion=4\&format=html) 和 [mac\_mls(4)](https://man.freebsd.org/cgi/man.cgi?query=mac_mls\&sektion=4\&format=html) 策略模块。

策略决策可基于网络配置。如果只有某些用户应该能访问 [ssh(1)](https://man.freebsd.org/cgi/man.cgi?query=ssh\&sektion=1\&format=html)，则可选择 [mac\_portacl(4)](https://man.freebsd.org/cgi/man.cgi?query=mac_portacl\&sektion=4\&format=html) 策略模块。在文件系统方面，对对象的访问可能对某些用户是机密的，而对其他用户则不是。例如，大型开发团队可能被分成多个小项目，其中项目 A 的开发人员可能不能访问项目 B 开发人员写的对象。然而，这两个项目可能需要访问项目 C 开发人员创建的对象。使用 MAC 框架提供的不同安全策略模块，用户可划分到这些组中，然后授予访问适当对象的权限。

每个安全策略模块都有其独特的方式来处理系统的整体安全性。模块选择应基于经过深思熟虑的安全策略，这可能需要修订和重新实施。了解 MAC 框架提供的不同安全策略模块将帮助管理员为其情况选择最佳策略。

本章的其余部分将介绍可用的模块，说明它们的使用和配置，并在某些情况下，提供有关适用情况的见解。

> **当心**
>
> 实施 MAC 就像实施防火墙一样，因为必须小心防止被完全锁在系统之外。应考虑恢复到先前配置的能力，并且通过远程连接实施 MAC 应格外谨慎。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/handbook/di-19-zhang-qiang-zhi-fang-wen-kong-zhi/19.4.-gui-hua-an-quan-pei-zhi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
