Fuchsia build 集成了多个验证流程。所有这些过程都会对 build 输出工件执行某种形式的检查。这种集成的目的是在开发过程中尽早发现潜在问题。
仔细验证系统级资源
许多验证流程是通过通过 ffx 调用审查实现的。 这些流程已编码到 build/security/verifier 目录下的 gn 模板中。例如,验证组件拓扑上的格式正确的功能路由,以及验证系统中预安装的一组静态软件包。
一般来说,这些验证流程会分析整个文件集合,以测试特定属性和/或确保这些集合与人工审查的工件的许可名单相匹配。
验证配置文件
*注意:本部分仅适用于 Google 员工。目前,只有 Google 产品的非 eng build 启用了对结构化配置文件的验证功能。
在某些情况下,系统组件旨在支持 eng 和非 eng build 类型的不同配置。使用此策略设计组件时,务必通过验证非 eng build 的正确配置来保护此类 build 的完整性。
验证结构化配置文件
如需验证结构化配置的非 eng Google 产品 build,您必须执行以下步骤:
- 确定非 eng build 中预期的安全配置值;
- 提交 bug,以安全地跟踪组件或功能的实现情况;
- 将配置值添加到政策文件,将其标记为 transitional 事件;
- 签入新组件或功能;
- 清理政策文件和 bug。
下文详细介绍了此流程的每个步骤。
1. 确定非 eng build 中预期的安全配置值
系统会通过将 build 生成的值与表示要向用户提供的安全配置值的黄金文件进行比较来验证结构化配置文件。首先,写下组件的这些值。
2. 提交 bug,以安全地跟踪组件或功能的实现情况
如果您未在跟踪正在处理的组件或功能时遇到 bug,请务必提交 bug,并提及针对非 eng build 的已验证结构化配置。您将在此过程的后续步骤中引用此 bug。
3. 将配置值添加到政策文件,并将其标记为 transitional
您需要修改 //vendor/google/security/policy/**/*structured_config_policy*.json5
中的所有文件。这些文件包含一组结构化配置值,这些值按由 Fuchsia 网址标识的组成部分进行分组(请参阅下面的示例)。对于任何标记为 transitional 的组件或配置值,仅当在 build 中发现这些组件或配置值时,系统才会检查它们,否则会忽略它们。需要未标记为过渡的组件或值:非过渡组件必须包含在 build 输出中,并且每个非过渡配置值都必须与政策文件中列出的预期值一致。
例如,当您添加新组件时,政策文件可能如下所示:
{
components: {
// ...existing components...
// new component:
// <High-level description of how to configure new component>
"fuchsia-pkg://fuchsia.com/new-frobinator#meta/new-frobinator.cm": {
// TODO(https://fxbug.dev/####): Remove transitional once `new-frobinator` is integrated into
// the build.
transitional: true,
fields: {
// <Precise description of why `frobinator_debugging_enabled=false` is a safe
// configuration to ship to users>
frobinator_debugging_enabled: false,
},
},
},
}
如果向现有组件添加一个新字段,政策文件可能如下所示:
{
components: {
// ...existing components...
// component with new fields:
"fuchsia-pkg://fuchsia.com/existing-frobinator#meta/existing-frobinator.cm": {
fields: {
// ...existing fields appear as `<field_name>: <expected_value>`; e.g.,
frobinator_internal_policy: "production",
// <Precise description of why `frobinator_debugging_enabled=false` is a safe
// configuration to ship to users>
frobinator_debugging_enabled: {
expected_value: false,
// TODO(https://fxbug.dev/####): Remove transitional once `frobinator_debugging_enabled`
// is integrated into the build.
transitional: true,
},
},
},
},
}
此政策必须包含所有可能因 eng build 和非 eng build 而异的结构化配置字段。切勿跳过上述任何 <Description>
或 TODO(https://fxbug.dev/####)
注释。
具有此政策中指定的值的字段不得包含 mutability
说明符,因为这些值可能会偏离政策所要求的值。
4. 签入新组件或功能
现在,您可以放心地签入新的组件或功能,并将其连接到 build 和紫红色系统的组件树。如果您在非 eng Google 产品 build 中配置组件时出错,那么在结构化配置政策检查期间,这种错误将显示为 build 错误。
5. 清理政策文件和 bug
再次修改第 3 步中所述的政策文件,移除第 3 步中添加的 transitional
标记。
回到第 3 步中的示例,对于新组件示例,最终政策文件如下所示:
{
components: {
// ...existing components...
// new component:
// <High-level description of how to configure new component>
"fuchsia-pkg://fuchsia.com/new-frobinator#meta/new-frobinator.cm": {
fields: {
// <Precise description of why `frobinator_debugging_enabled=false` is a safe
// configuration to ship to users>
frobinator_debugging_enabled: false,
},
},
},
}
现有组件的新字段的最终政策文件如下所示:
{
components: {
// ...existing components...
// component with new fields:
"fuchsia-pkg://fuchsia.com/existing-frobinator#meta/existing-frobinator.cm": {
fields: {
// ...existing fields appear as `<field_name>: <expected_value>`; e.g.,
frobinator_internal_policy: "production",
// <Precise description of why `frobinator_debugging_enabled=false` is a safe
// configuration to ship to users>
frobinator_debugging_enabled: false,
},
},
},
}
这些更改推出后(假设新组件或功能的开发工作已完成),可以放心关闭第 2 步中所述的 bug。