整個組織的原則:團隊的規則、組織的規則與管線的規則
團隊的原則、其組織的原則與其管線的原則,會在一次建置中一起執行,各自附加在自己的設定檔中。團隊在其工作區中附加它的規則;組織在每次建置上再加一條,管線再加一條,而兩者都不必編輯團隊的檔案。建置會讀取所有適用於它的檔案,並執行它們所帶的每個附加項目。
這些規則以全部三種判定嚴重程度回報:info 與 warn 讓建置完成,而 halt 使它停止。其中一條,也就是組織的規則,被附加兩次,每次透過 translation 區塊以不同的嚴重程度回報。
它建置什麼
| 實例 | 目錄 Component | 它在這裡是什麼 |
|---|---|---|
db | core/datastore/mariadb | 商店的資料庫 |
web | core/devtool/adminer | 連接到 db 的資料庫管理 UI |
兩者都編譯成 Docker Compose,輸出到 dist/compose/docker-compose.yaml。一個 Aggregate、一個 Manifest 與一個 Release,即 release.yaml;它們都沒有指名原則。
三個檔案
| 誰 | 檔案 | 建置如何讀取它 | 附加項目寫在哪裡 |
|---|---|---|---|
| 團隊 | .aggrega-config.yaml | 它把此目錄標記為工作區,因此這裡的每次建置都會讀取它 | plugins.governance |
| 組織 | org/config.yaml | 作為全域設定檔,針對一次建置以 --config org/config.yaml 指名 | plugins.governance_append |
| 管線 | pipeline/.aggrega-config-append-ci.yaml | 複製到此目錄後,作為管線的覆蓋層 | plugins.governance_append |
三個附加項目都是 Rego 引擎,governance/rego:0.9.0,位於 ir-verdict 角色,它在任何東西被渲染之前判定建置圖。0.9.0 是它的 Plugin 實體在標準程式庫目錄中的版本。引擎本身編譯進 CLI——aggrega plugin list 會在內嵌的內建項目中列出 governance/rego——因此這裡沒有任何建置會擷取外掛程式。
組織的檔案是全域設定檔。 一台機器有一個,每次建置都會讀取:從其預設位置,或 AGGREGA_CONFIG 環境變數所指名的檔案。--config <path> 則是為單次執行改為指名一個,而工作區自己的檔案仍然疊在其上讀取。在組織中,該檔案會放在每位開發者機器與每條管線的預設位置;這裡它放在 org/ 中,而應該讀取它的建置會指名它。明確指名全域檔案說明了這三種方式被嘗試的順序。
管線的檔案是覆蓋層。 建置會在它讀取 .aggrega-config.yaml 的目錄中,在其旁邊讀取 .aggrega-config-append-ci.yaml。它放在這裡的 pipeline/ 中,在此目錄執行的建置不會讀取它,因為讀取它的每次建置都會中止;管線的步驟是把它複製進來:
cp pipeline/.aggrega-config-append-ci.yaml .每個檔案都是新增,而管線的覆蓋層只新增
組織與管線都把它們的附加項目寫在 plugins.governance_append 之下,這是 plugins.governance 清單的附加伴隨項。伴隨項之下的項目,會在每個檔案自己的清單被讀取之後,串接到已解析的清單上,因此團隊的 plugins.governance 與組織的項目都會執行,而且兩個檔案都不必指名對方。組織寫的是伴隨項,而不是 plugins.governance 本身,因為工作區檔案中的 plugins.governance 清單會取代全域檔案中的那一份:寫在那裡的組織規則會被團隊的清單丟棄,而建置不會對此印出任何東西。延伸清單而不是取代它列出了每個清單設定的伴隨項。
管線的覆蓋層只能新增。它為清單設定所寫的內容,會加到其他檔案所解析的內容上;它不移除任何東西,也不覆寫持有單一值的設定,例如 auto_pull。這一個帶有 auto_pull: true,而讀取它的建置會忽略該鍵,並在警告中說明。以 <workspace> 代表建置所執行之目錄的絕對路徑,該行內容如下:
warning: <workspace>/.aggrega-config-append-ci.yaml: ignoring non-additive key "auto_pull" (the CI-owned overlay is additive-only and cannot override the base config)規則,以及每條規則回報的嚴重程度
Rego 原則把每項決定收集在決定鍵之下,而該鍵決定這項決定回報的嚴重程度。沒有 translation 時,鍵是 deny、warn 與 audit,分別以 halt、warn 與 info 回報:
| 嚴重程度 | 建置會做什麼 |
|---|---|
halt | 停止、以 1 結束,且不寫出 dist/ |
warn | 完成、印出訊息,並寫出 dist/ |
info | 完成、印出訊息,並寫出 dist/ |
團隊的規則,policies/team.rego,收集在 warn 之下,而它的附加項目沒有宣告 translation,因此以 warn 回報:
warn contains msg if { some id, node in input.graph.spec.nodes node.labels["component.aggrega.ai/category"] == "datastore" input.graph.spec.infra_mapping[id].ha.enabled == false msg := sprintf("%v runs with high availability off", [id])}組織的規則,org/policies/estate.rego,拒絕其設定所列類別中的元件,並記錄每個元件執行什麼:
deny contains msg if { some id, node in input.graph.spec.nodes category := node.labels["component.aggrega.ai/category"] category in data.refused_categories msg := sprintf("%v runs %v, in the %v category, which the organization does not ship", [id, node.component, category])}
audit contains msg if { some id, node in input.graph.spec.nodes msg := sprintf("%v runs %v %v, upstream licensing %v", [id, node.component, node.resolved_version, node.labels["component.aggrega.ai/upstream-licensing"]])}refused_categories 是每個附加項目的設定,而原則會把它的附加項目的設定當作它的 data 文件來讀取。
Translation:一條規則,兩種嚴重程度
附加項目設定中的 translation 區塊,宣告要讀取哪些決定鍵,以及每個鍵回報的嚴重程度。它取代預設對應,而不是擴充它:它沒有指名的鍵就不會被讀取。
組織的檔案把它的規則以建議的形式推出。它的附加項目把 deny 以 warn 回報,並把 audit 以 info 回報:
settings: refused_categories: [devtool] translation: - key: deny severity: warn - key: audit severity: info管線附加同一個檔案,並讓同一條規則中止。它的 translation 只指名 deny,因此它的附加項目不會第二次回報 audit 記錄:
settings: refused_categories: [devtool] translation: - key: deny severity: halt所以同一條規則,針對同一個 web,在開發者的建置上是警告,卻是管線的建置停止的原因。
草擬範例
你可以用下列命令建置這個範例,或是讓你的 AI 助理替你建置。
把範例寫入一個以它命名的新資料夾:
aggrega draft --example policy-org-overlay它接著會印出要接著執行的命令。第一個會切換到新資料夾:
cd policy-org-overlay建置
標準程式庫目錄提供 Components、Recipes、Feature 及其 FeatureRecipe。 它們從 hub.aggrega.ai 解析,也就是 .aggrega-config.yaml 所指名的預設登錄庫。以 --catalog 指名目錄的簽出副本(取得方式)時,不會從登錄庫擷取任何東西,因此建置可離線執行。--auto-pull 會在建置期間填入鎖定檔;鎖定檔與渲染出的輸出是產生出來的,不隨附發布。
只用團隊的檔案時:
aggrega build --release release.yaml --auto-pull建置會印出團隊的警告並完成。再加上組織的檔案時:
aggrega build --release release.yaml --auto-pull --config org/config.yaml它會印出組織的記錄(以 info)與其規則(以 warn),位於團隊的警告旁,且仍然完成:
info: policy plugin "rego": db runs core/datastore/mariadb 1.0.0, upstream licensing osi-approved info: policy plugin "rego": web runs core/devtool/adminer 1.0.0, upstream licensing osi-approved policy plugin "rego" warning: db runs with high availability off policy plugin "rego" warning: web runs core/devtool/adminer, in the devtool category, which the organization does not shipPull complete: release.lock (entities=11, source_artifacts=0, external_inputs=0) notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)[… omitted: the build's time and the line naming the dist/ directory it wrote]每個判定指名回報它的外掛程式 rego,而不是附加它的檔案,因此團隊的警告與組織的警告讀起來一樣;像組織的那樣說明是誰的規則的訊息,就是區分它們的方法。
複製進管線的覆蓋層後,同一個命令會中止:
cp pipeline/.aggrega-config-append-ci.yaml .aggrega build --release release.yaml --auto-pull --config org/config.yaml[… omitted: the overlay's warning shown above][… omitted: the lines printed while the lockfile is resolved, which carry the verdicts below once more, the refusal among them] info: policy plugin "rego": db runs core/datastore/mariadb 1.0.0, upstream licensing osi-approved info: policy plugin "rego": web runs core/devtool/adminer 1.0.0, upstream licensing osi-approved policy plugin "rego" warning: db runs with high availability off policy plugin "rego" warning: web runs core/devtool/adminer, in the devtool category, which the organization does not ship notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)[POLICY_ERROR E0005] policy plugin "rego" rejected the build: web runs core/devtool/adminer, in the devtool category, which the organization does not ship caused by: policy violation建置以 1 結束,且不寫出 dist/。組織的規則被回報兩次,每個附加項目各一次:組織的以 warn,管線的以 halt。audit 記錄只出現一次,僅來自組織的附加項目。把 .aggrega-config-append-ci.yaml 從此目錄移除,即可再次在沒有它的情況下建置。
搭配 AI 助理
以 Aggrega 的工具設定好的 AI 助理可以做同樣的事:把這個提示貼給它。
只使用 Aggrega 工具,且不要自己建立任何資料夾。如果工作區資料夾中還沒有 `policy-org-overlay` 資料夾,就呼叫一次 `draft` 工具,將 `example` 設為 `policy-org-overlay` 且不給 `dir`:它會把範例寫入新的 `policy-org-overlay` 資料夾。接著呼叫 `build` 工具,將 `workspace_root` 設為 `policy-org-overlay`、`release` 設為 `release.yaml`、`auto_pull` 設為 true、`write` 設為 true,並告訴我原則回報了什麼。然後呼叫 `cli-build` 工具,它會執行 `aggrega build` 並接受其 `--config` 旗標,將 `workspace_root` 設為 `policy-org-overlay`、`release` 設為 `release.yaml`、`auto_pull` 設為 true、`config` 設為 `org/config.yaml`,並告訴我原則這次回報了什麼。告訴我每次建置寫出了哪些檔案;它們位於 `policy-org-overlay/dist/` 之下。檢查每次建置
這個自我檢查在文件存放庫的檢出中執行,其中有它所使用的共用建置輔助程式;aggrega draft --example 所寫出的副本不帶該輔助程式。
./check.shcheck.sh 透過 build-release 輔助程式建置 release.yaml 五次,每次都在此工作區的副本中:只用團隊的檔案、用 --config 指名組織的檔案、複製進管線的覆蓋層、兩者都用,以及用組織檔案的一份副本,它把附加項目寫在 plugins.governance 之下而不是伴隨項——團隊的清單會取代它,只印出團隊的判定。對每一次,它檢查結束狀態、是否寫出 dist/,以及建置所印出的每個判定——其嚴重程度與其訊息,沒有遺漏也沒有多出其他——並且在讀取覆蓋層之處,檢查指名 auto_pull 的警告。它每次建置印出一行,接著是各次所印出的判定,若有任何結果不同則以 1 結束,並印出該次建置的輸出:
LAYERS EXIT DIST VERDICT----------------------------------------------------------------------------------------------------team 0 yes OKteam + organization 0 yes OKteam + pipeline 1 no OKall three 1 no OKteam + organization, plugins.governance 0 yes OK
team: warn db runs with high availability off
team + organization: info db runs core/datastore/mariadb 1.0.0, upstream licensing osi-approved info web runs core/devtool/adminer 1.0.0, upstream licensing osi-approved warn db runs with high availability off warn web runs core/devtool/adminer, in the devtool category, which the organization does not ship
team + pipeline: ignored auto_pull warn db runs with high availability off halt web runs core/devtool/adminer, in the devtool category, which the organization does not ship
all three: ignored auto_pull info db runs core/datastore/mariadb 1.0.0, upstream licensing osi-approved info web runs core/devtool/adminer 1.0.0, upstream licensing osi-approved warn db runs with high availability off warn web runs core/devtool/adminer, in the devtool category, which the organization does not ship halt web runs core/devtool/adminer, in the devtool category, which the organization does not ship
team + organization, plugins.governance: warn db runs with high availability off
check: every build ended as expected.副本建立於暫存目錄,其 .aggrega-config.yaml 中的目錄路徑被改成絕對路徑,使它在那裡仍能解析;此目錄中沒有任何檔案被編輯或寫入。它使用 ./build-release.sh 所解析的二進位檔,因此由 AGGREGA_BIN 選定,而 -- 之後的引數會傳給每次建置。它的結束狀態就是整個判定。
編譯器不解讀的地方
編譯器讀取這三個檔案,串接它們所帶的附加項目,把建置圖與設定交給每個原則,並依每項決定回報的嚴重程度採取行動。它不知道 devtool 是什麼、組織為什麼不會隨附一個,或高可用性對團隊很重要:那些意義是原則的規則與設定。關於角色、酬載與決定鍵,請見治理插槽。
檔案
aggregate.yaml— 資料庫與連接到它的管理 UI。manifest.yaml— 將每個元件型別與機密 Feature 繫結到其 Docker Compose Recipe。release.yaml— 唯一的 Release。.aggrega-config.yaml— 團隊的檔案:預設登錄庫與團隊的附加項目。policies/team.rego— 團隊的規則。org/config.yaml— 組織的全域設定檔及其附加項目。org/policies/estate.rego— 組織的規則。pipeline/.aggrega-config-append-ci.yaml— 管線的覆蓋層,複製到此目錄後才會被讀取。build-release.sh— 建置該 Release,並回顯等價的aggrega build命令。check.sh— 進行五次建置並檢查每個結果。