Fuchsia 版本整合了多項驗證程序。這些程序都會針對建構輸出構件執行某種形式的檢查。這項整合的目的是在開發過程中盡早找出潛在問題。
仔細確認系統通用資源
許多驗證程序都是透過叫用ffx 審查實現。這些程序會在 build/security/verifier 目錄的 gn 範本中編寫。例如,針對元件拓撲驗證格式正確的能力路徑,以及驗證系統上預先安裝的靜態套件組合。
一般而言,這些驗證程序會分析整個檔案集合,以便測試特定屬性,和/或確保這些集合符合手動審查成果的許可清單。
驗證設定檔
*注意:本節僅適用於 Google 員工。目前僅針對非工程版本的 Google 產品啟用結構化設定檔驗證。
在某些情況下,系統元件的設計可支援 eng 和非參與的建構類型不同的設定。使用這項策略設計元件時,請務必驗證這類建構作業的正確設定,以保護非工程建構作業的完整性。
驗證結構化設定檔
如要為結構化設定驗證非 Google 產品建構作業,您必須按照下列步驟操作:
- 找出非參與版本預期的安全設定值;
- 回報錯誤,安全追蹤元件或功能的位置;
- 為政策檔案新增設定值並標示為轉換版本;
- 瞭解新的元件或功能
- 清理政策檔案和錯誤。
以下將詳述這個程序的各個步驟。
1. 找出非參與建構作業中預期的安全設定值
系統會驗證結構化設定檔,方法是將版本產生的值與代表提供給使用者安全的設定值黃金檔案進行比較。首先,寫下這些值適用於元件。
2. 回報錯誤,安全追蹤元件或功能登陸位置
如果您還沒有錯誤追蹤正在處理的元件或功能,請務必提交一項錯誤,並提及非參與版本適用的已驗證結構化設定。您將在本程序的後續步驟中參考此錯誤。
3. 為政策檔案新增設定值,並標示為轉換版本
您必須修改 //vendor/google/security/policy/**/*structured_config_policy*.json5
中的所有檔案。這些檔案包含一組結構化設定值,並按 Fuchsia 網址識別的元件分組 (請參閱下方的範例)。標示為轉換機制的任何元件或設定值只會在建構中找到,否則會遭到忽略。未標示為轉換的元件或值為必要的:非轉換元件必須出現在建構輸出內容中,且每個非轉換設定值都必須與政策檔案中指出的預期值相符。
舉例來說,新增新元件時,政策檔案看起來會像這樣:
{
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 與非參與版本之間可能不同的所有結構化設定欄位。請勿略過上述任何 <Description>
或 TODO(https://fxbug.dev/####)
註解。
具有政策指定值的欄位不得含有 mutability
指定碼,因為這些值可能與政策所要求的值有所出入。
4. 查看新元件或功能
現在,您可以放心檢查新的元件或功能,並將其連接至建構及其元件樹狀結構。如果您在非工程 Google 產品上設定該元件時發生錯誤,系統會在結構化設定政策檢查期間將這項元件顯示為建構錯誤。
5. 清理政策檔案和錯誤
再次編輯步驟 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 中提及的錯誤。