blueprint-shared-docs 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  "entry": "blueprint-shared",
5
5
  "layer": "org",
6
6
  "describes": {
7
- "blueprint-shared-docs": "0.3.0"
7
+ "blueprint-shared-docs": "0.3.1"
8
8
  },
9
9
  "publish": {
10
10
  "target": "npm",
@@ -6903,6 +6903,124 @@
6903
6903
  "appliesFrom": "0.1.0",
6904
6904
  "supersedes": []
6905
6905
  },
6906
+ {
6907
+ "type": "decision",
6908
+ "id": "secret-management-rules",
6909
+ "title": "密鑰與設定分開放,每個組織一個 namespace,取值經中介層,路徑不帶環境,每個部署每個環境一個密鑰服務實例",
6910
+ "topics": [],
6911
+ "sections": [
6912
+ {
6913
+ "id": "context",
6914
+ "title": "背景",
6915
+ "blocks": [
6916
+ {
6917
+ "kind": "text",
6918
+ "text": "組織要把密鑰集中到自託管的密鑰服務,取用端有 GitHub Actions、本機、Mac 常駐程式與管理介面。要先定下七件事:哪些東西算密鑰、一個組織的密鑰怎麼分開、取用端怎麼知道自己能讀什麼、取值經過誰、路徑要不要帶環境、服務要開幾個實例、取用端的角色怎麼命名。規則本身寫在 fact,這份只記為什麼這樣定。"
6919
+ },
6920
+ {
6921
+ "kind": "fact",
6922
+ "facts": [
6923
+ "blueprint-shared.secrets.classification",
6924
+ "blueprint-shared.secrets.namespace-layout",
6925
+ "blueprint-shared.secrets.kv-path",
6926
+ "blueprint-shared.secrets.template-path",
6927
+ "blueprint-shared.secrets.template-location",
6928
+ "blueprint-shared.secrets.template-file",
6929
+ "blueprint-shared.secrets.template-errors",
6930
+ "blueprint-shared.secrets.access-rules"
6931
+ ]
6932
+ }
6933
+ ]
6934
+ },
6935
+ {
6936
+ "id": "options",
6937
+ "title": "選項",
6938
+ "blocks": [
6939
+ {
6940
+ "kind": "list",
6941
+ "items": [
6942
+ "a. 依「外流會不會造成損害」把密鑰和設定分開放。密鑰進密鑰服務,設定留組態倉。",
6943
+ "b. 密鑰和設定全放密鑰服務。",
6944
+ "c. 路徑帶環境段,所有環境放同一個實例。",
6945
+ "d. 路徑不帶環境,每個部署每個環境一個實例,環境由實例決定。"
6946
+ ]
6947
+ }
6948
+ ]
6949
+ },
6950
+ {
6951
+ "id": "decision",
6952
+ "title": "決定",
6953
+ "blocks": [
6954
+ {
6955
+ "kind": "text",
6956
+ "text": "採用 a 和 d。下面七點是這個決定的內容,規則本身見 fact。"
6957
+ },
6958
+ {
6959
+ "kind": "list",
6960
+ "items": [
6961
+ "密鑰與設定分開放。分類只問一件事:外流會不會讓別人冒充身分、取得存取、解密或簽章。會的是密鑰,進密鑰服務。其餘是設定,留在組態倉。",
6962
+ "每個 GitHub 組織一個 namespace,名稱同組織,不巢狀。",
6963
+ "模板放在密鑰服務裡,路徑是 `<組織>/templates/<產品>/<單元>`,例如 `templates/shop/web`(不含組織),由組態倉的 CI 寫入。模板檔在組態倉的位置由 CI 算出模板路徑與要寫進哪個實例。",
6964
+ "取值一律經中介層。取用端只送產品、單元、環境和自己的身分憑證。",
6965
+ "路徑不帶環境。密鑰路徑例如 `kv/shop/web/db`,模板路徑例如 `templates/shop/web`,環境都不在路徑裡。",
6966
+ "每個部署(正式與測試)每個環境一個密鑰服務實例。中介層只有一份,依請求的環境欄位轉給對應的實例。",
6967
+ "取用端的角色唯讀,名稱只寫 `<倉庫>`。角色建在哪個環境的實例,就屬於哪個環境。"
6968
+ ]
6969
+ }
6970
+ ]
6971
+ },
6972
+ {
6973
+ "id": "rationale",
6974
+ "title": "理由",
6975
+ "blocks": [
6976
+ {
6977
+ "kind": "list",
6978
+ "items": [
6979
+ "密鑰和設定分開放:設定的改動頻繁,而且沒有外流風險。設定留在組態倉,改了合併後只重新套用那一個實例,不重新建置,也不發新版號。密鑰放密鑰服務,寫入新版本後取用端下次取值就拿到。兩者生效方式不同,放在一起會讓設定也要走密鑰的存取控制。邊界情況也照同一個問題判斷:獨立的識別碼是設定,跟某把密鑰一起更換的識別碼跟著那把密鑰,含密碼的連線字串拆開,主機與埠是設定、密碼是密鑰,再由模板組回一條(`blueprint-shared.secrets.classification`)。",
6980
+ "每個組織一個 namespace:namespace 有自己的掛載點、登入方式、policy、entity、group 與 token,彼此獨立,組織之間讀不到對方的路徑。跨 namespace 的身分共用預設關閉,官方文件也說不應該開。多個組織共用同一個密鑰服務時,這是最小的隔離單位(`blueprint-shared.secrets.namespace-layout`)。",
6981
+ "模板放在密鑰服務裡:取用端只送產品、單元、環境,不需要知道密鑰放哪條路徑。送來的產品與單元就是模板路徑,中介層不用查表。角色能讀的路徑由模板列出的路徑產生,不手寫,所以模板就是權限的來源,改模板就改了權限。共用的模板不會自動沿用,單元的模板要在 `extends` 寫了才沿用。因為自動沿用會讓每個單元都讀得到全部共用的密鑰(`blueprint-shared.secrets.template-path`)。",
6982
+ "取值都經中介層:密鑰服務本身沒有一次讀多個路徑、再把設定和密鑰組成一組環境變數的功能(調查時在官方文件與 issue 中沒有找到,屬篩選結果)。這件事放在中介層做,取用端不必各自實作。中介層不存憑證、不存模板、不快取值,也不把值寫進 log,用呼叫者自己的憑證換一把短期 token,讀完撤銷,所以中介層被攻破時拿不到長期憑證(`blueprint-shared.secrets.template-errors`)。",
6983
+ "路徑不帶環境:環境由實例決定時,同一個單元在各環境的路徑相同,模板、程式與文件不需要為每個環境改路徑,也不會出現把 stg 的路徑寫進 prod 的錯誤。路徑只剩產品、單元、名稱三段,好記也好驗(`blueprint-shared.secrets.kv-path`)。不分環境的密鑰要寫進每個環境的實例,代價見下面。",
6984
+ "模板檔的位置環境在前:組態倉的模板檔放在 `ops/workloads/templates/<環境>/<產品>/<單元>.yml`,環境決定 CI 寫進哪個實例,後面的位置去掉 `.yml` 就是模板路徑。CI 從檔案位置算出兩者,所以沒有人要把同一件事寫兩次(`blueprint-shared.secrets.template-location`)。",
6985
+ "每個部署每個環境一個實例:環境之間的資料用不同實例隔開,而不是靠路徑段隔開,一個環境的實例出問題或被誤寫,不會動到別的環境。規劃記載這是密鑰服務官方的做法。調查時沒有在官方文件找到「dev 與 prod 要不要共用實例」的明文,所以這一條的官方出處待確認,目前依使用者的決定採用。正式部署的實例給所有環境的取用端取值,測試部署結構相同、只放假資料,用來驗證密鑰服務本身的變更,不給取用端用。因此 stg 的取用端也向正式部署取值,不向測試部署取值(`blueprint-shared.secrets.namespace-layout`)。",
6986
+ "取用端角色只寫 `<倉庫>`:角色建在哪個環境的實例,就屬於哪個環境,名字再帶環境是重複的資訊,也會讓角色名和路徑一樣出現兩種寫法。一個倉庫在一個實例最多一個角色(`blueprint-shared.secrets.access-rules`)。"
6987
+ ]
6988
+ }
6989
+ ]
6990
+ },
6991
+ {
6992
+ "id": "consequences",
6993
+ "title": "代價",
6994
+ "blocks": [
6995
+ {
6996
+ "kind": "list",
6997
+ "items": [
6998
+ "不分環境的密鑰要寫進每個環境的實例,值由人複製,同一把密鑰換值時要寫三次。不分環境的共用模板也是每個環境的目錄各放一份。",
6999
+ "分類要靠人判斷。邊界情況寫在 fact,但新的情況要補進去。",
7000
+ "實例數量是環境數量乘部署數量,資源比單一實例多。",
7001
+ "所有取值都經中介層,中介層停機時所有取用端取不到值。",
7002
+ "旗標服務另案,這份只定界線,不定旗標怎麼放。",
7003
+ "每個實例官方做法的明文出處還沒查到,見上面的理由。"
7004
+ ]
7005
+ }
7006
+ ]
7007
+ }
7008
+ ],
7009
+ "factRefs": [
7010
+ "blueprint-shared.secrets.classification",
7011
+ "blueprint-shared.secrets.namespace-layout",
7012
+ "blueprint-shared.secrets.kv-path",
7013
+ "blueprint-shared.secrets.template-path",
7014
+ "blueprint-shared.secrets.template-location",
7015
+ "blueprint-shared.secrets.template-file",
7016
+ "blueprint-shared.secrets.template-errors",
7017
+ "blueprint-shared.secrets.access-rules"
7018
+ ],
7019
+ "docRefs": [],
7020
+ "status": "accepted",
7021
+ "appliesFrom": "0.3.1",
7022
+ "supersedes": []
7023
+ },
6906
7024
  {
6907
7025
  "type": "decision",
6908
7026
  "id": "self-hosted-job-no-wait",
@@ -7276,6 +7394,116 @@
7276
7394
  "appliesFrom": "0.2.0",
7277
7395
  "supersedes": []
7278
7396
  },
7397
+ {
7398
+ "type": "decision",
7399
+ "id": "template-reads-retry-transient",
7400
+ "title": "範本的唯讀 gh 與 git 呼叫先經 read_retry 重問暫時性錯誤,仍失敗才停並印出錯誤",
7401
+ "topics": [],
7402
+ "sections": [
7403
+ {
7404
+ "id": "context",
7405
+ "title": "背景",
7406
+ "blocks": [
7407
+ {
7408
+ "kind": "text",
7409
+ "text": "decision `ci-gate-fails-on-query-error` 要求 ci 閘查詢失敗時立即失敗並印出 gh 的錯誤,不當成還沒有 run,同時寫「不重試」。decision `transient-error-shared-retry` 之後讓讀取經共用重試,只對 HTTP 500、502、503、504 與連線逾時重問。"
7410
+ },
7411
+ {
7412
+ "kind": "text",
7413
+ "text": "範本的唯讀呼叫碰到暫時性錯誤時,一次失敗就讓整段推進中斷,要人重跑,雖然下一次請求就會成功。`scripts/release/ensure-stage-deploys.sh` 還有另一個問題:它讀 tag 與 run 失敗時,若當成沒有 tag 或沒有 run,會判斷錯誤並照這個判斷派送。"
7414
+ }
7415
+ ]
7416
+ },
7417
+ {
7418
+ "id": "options",
7419
+ "title": "選項",
7420
+ "blocks": [
7421
+ {
7422
+ "kind": "list",
7423
+ "items": [
7424
+ "a. 維持「查詢失敗立即停,不重試」。",
7425
+ "b. 唯讀呼叫經 `read_retry`,仍失敗才停並印出錯誤。",
7426
+ "c. 唯讀呼叫失敗時一律當成沒有結果,繼續往下。"
7427
+ ]
7428
+ }
7429
+ ]
7430
+ },
7431
+ {
7432
+ "id": "decision",
7433
+ "title": "決定",
7434
+ "blocks": [
7435
+ {
7436
+ "kind": "text",
7437
+ "text": "採用 b。`templates/base/scripts/lib/common.sh` 的 `read_retry` 對暫時性錯誤重問,仍失敗時印出 gh 或 git 的錯誤並以非 0 結束。"
7438
+ },
7439
+ {
7440
+ "kind": "list",
7441
+ "items": [
7442
+ "ci 閘的 `gh run list` 與 `gh run view`、部署閘的 tag 檢查(`git ls-remote`)、deploy-prerelease 的 `gh run list`,與 ops-deploy 的 `gh run list` 和 `gh api …/contents/ops/versions.json`(經 `dg_ops_gh`)都經 `read_retry`。",
7443
+ "`ensure-stage-deploys.sh` 讀 tag(`git ls-remote`)與讀 run(`gh run list`)經 `read_retry`。仍失敗就 die「…沒有派送」,不當成沒有 tag 或沒有 run,也不派送。",
7444
+ "派送本身(`gh workflow run`)仍不重試,理由見 decision `transient-error-shared-retry`。",
7445
+ "查詢仍失敗時立即停下並印出錯誤,不用 `2>/dev/null || true` 吞掉錯誤。這一點延續 `ci-gate-fails-on-query-error`。"
7446
+ ]
7447
+ },
7448
+ {
7449
+ "kind": "fact",
7450
+ "facts": [
7451
+ "blueprint-shared.git-flow.ci-gate-bypass",
7452
+ "blueprint-shared.git-flow.deploy-gate"
7453
+ ]
7454
+ }
7455
+ ]
7456
+ },
7457
+ {
7458
+ "id": "supersedes",
7459
+ "title": "取代的部分",
7460
+ "blocks": [
7461
+ {
7462
+ "kind": "text",
7463
+ "text": "這份只取代 `ci-gate-fails-on-query-error` 的「不重試」:暫時性錯誤現在先重問。該決定的其餘條文仍然成立,包括「查詢失敗不當成還沒有 run」與「查詢成功但沒有 run 才繼續等」,所以它不標成 superseded,內文也不動。`ci-gate-queue-not-counted` 與 `deploy-gate-before-advance` 引用它並寫「不重試」,這兩處同樣以這份為準。"
7464
+ }
7465
+ ]
7466
+ },
7467
+ {
7468
+ "id": "rationale",
7469
+ "title": "理由",
7470
+ "blocks": [
7471
+ {
7472
+ "kind": "list",
7473
+ "items": [
7474
+ "暫時性錯誤下一次就好,重問成本低。",
7475
+ "讀取重做不改任何東西,所以重問沒有重複寫入的風險。",
7476
+ "權限不足、倉不存在這類錯誤不是暫時性錯誤,`read_retry` 不重問,仍然立即停下並印出 gh 的錯誤。",
7477
+ "`ensure-stage-deploys.sh` 把讀取失敗當成沒有 run,會對已經有 run 的 tag 重複派送。把它當成沒有 tag,則會漏派該派的 tag。所以讀取失敗要停,不派送。"
7478
+ ]
7479
+ }
7480
+ ]
7481
+ },
7482
+ {
7483
+ "id": "consequences",
7484
+ "title": "代價",
7485
+ "blocks": [
7486
+ {
7487
+ "kind": "list",
7488
+ "items": [
7489
+ "暫時性錯誤持續超過 `read_retry` 的上限時,閘仍會失敗,人重跑即可。",
7490
+ "`ci-gate-fails-on-query-error`、`ci-gate-queue-not-counted` 與 `deploy-gate-before-advance` 的原文仍寫「不重試」,讀的人要看這份才知道現行行為。"
7491
+ ]
7492
+ }
7493
+ ]
7494
+ }
7495
+ ],
7496
+ "factRefs": [
7497
+ "blueprint-shared.git-flow.ci-gate-bypass",
7498
+ "blueprint-shared.git-flow.deploy-gate"
7499
+ ],
7500
+ "docRefs": [],
7501
+ "status": "accepted",
7502
+ "appliesFrom": "0.11.0",
7503
+ "supersedes": [
7504
+ "ci-gate-fails-on-query-error"
7505
+ ]
7506
+ },
7279
7507
  {
7280
7508
  "type": "decision",
7281
7509
  "id": "template-scope-mechanism",
@@ -7757,6 +7985,124 @@
7757
7985
  "appliesFrom": "0.1.0",
7758
7986
  "supersedes": []
7759
7987
  },
7988
+ {
7989
+ "type": "decision",
7990
+ "id": "workload-and-instance-naming",
7991
+ "title": "後綴只表示部署環境,依服務環境分成多份的工作負載帶前綴,移除 `serves`",
7992
+ "topics": [],
7993
+ "sections": [
7994
+ {
7995
+ "id": "context",
7996
+ "title": "背景",
7997
+ "blocks": [
7998
+ {
7999
+ "kind": "text",
8000
+ "text": "組織有自己的測試與正式兩個部署,每個部署裡又為 dev、stg、prod 各開一個實例給取用端用。名稱裡的環境標記一度同時有兩個意思:位置與 VM 的 `-<環境>` 表示部署所在的環境,部署裡元件的 `-<環境>` 表示服務哪個環境的取用端。同一個後綴兩個意思,讀名稱的人和檢查的程式都無法判斷。"
8001
+ },
8002
+ {
8003
+ "kind": "text",
8004
+ "text": "`targets.json` 的 `serves` 欄位記 `shared` 實例服務哪些環境。查過之後沒有任何程式或檢查讀它,環境一律取自實例路徑。"
8005
+ },
8006
+ {
8007
+ "kind": "text",
8008
+ "text": "這份 decision 部分取代 `targets-json-merged-format` 的下列段落,原文不改,其餘條文仍然成立:"
8009
+ },
8010
+ {
8011
+ "kind": "list",
8012
+ "items": [
8013
+ "`targets-json-merged-format.doc.ts:24`:決定段的「只有環境是 `shared` 的實例必寫 `serves`」。",
8014
+ "`targets-json-merged-format.doc.ts:38`:代價段 schema 驗得了的四項裡的「只有 `shared` 實例必寫 `serves`」。驗得了的項目剩三項:鍵的格式、`host` 與 `ref` 二選一、`provider` 是 `orbstack` 時只能有一個母叢集。"
8015
+ ]
8016
+ },
8017
+ {
8018
+ "kind": "fact",
8019
+ "facts": [
8020
+ "blueprint-shared.infra-layout.cluster-naming",
8021
+ "blueprint-shared.infra-layout.targets"
8022
+ ]
8023
+ }
8024
+ ]
8025
+ },
8026
+ {
8027
+ "id": "options",
8028
+ "title": "選項",
8029
+ "blocks": [
8030
+ {
8031
+ "kind": "list",
8032
+ "items": [
8033
+ "a. 後綴只表示部署環境。依服務環境分成多份的工作負載寫成 `<服務環境>-<用途>`,每份都帶前綴,含 `prod-`。其他工作負載只寫用途。",
8034
+ "b. 同 a,但正式環境的那一份可以省略前綴。",
8035
+ "c. 維持兩種意思共用同一個 `-<環境>` 後綴。"
8036
+ ]
8037
+ }
8038
+ ]
8039
+ },
8040
+ {
8041
+ "id": "decision",
8042
+ "title": "決定",
8043
+ "blocks": [
8044
+ {
8045
+ "kind": "text",
8046
+ "text": "採用 a,並移除 `targets.json` 的 `serves`。規則本身見 fact,下面列取捨。"
8047
+ },
8048
+ {
8049
+ "kind": "list",
8050
+ "items": [
8051
+ "組織的服務有自己的測試與正式部署時,實例路徑的環境用服務自己部署的環境,例如 `secrets/stg` 與 `secrets/prod`。它和這個服務為哪些環境的取用端取值無關。",
8052
+ "VM 用用途命名,例如 `secrets`、`ci`,不用專案名或產品名。",
8053
+ "後綴只表示部署環境,用在位置、VM、叢集、租戶、實例路徑和網址。",
8054
+ "前綴只表示服務哪個環境,只用在一個部署裡依服務環境分成多份的工作負載。每份都帶前綴,`prod-` 也要寫。其他工作負載只寫用途。",
8055
+ "同一個用途在同一個部署裡只有兩種合法寫法:只有一份叫 `<用途>`,分成多份時每份都帶前綴。混用、同時帶前綴與後綴、只有一份卻帶前綴都不合法。",
8056
+ "變更流程與權限看所在部署的環境,不看工作負載的前綴。",
8057
+ "命名的對象是工作負載:容器、Kubernetes 工作負載、Worker 和主機上的常駐程式,不只是容器。",
8058
+ "移除 `serves`。環境一律取自實例路徑。"
8059
+ ]
8060
+ }
8061
+ ]
8062
+ },
8063
+ {
8064
+ "id": "rationale",
8065
+ "title": "理由",
8066
+ "blocks": [
8067
+ {
8068
+ "kind": "list",
8069
+ "items": [
8070
+ "部署環境和服務環境是兩件事。位置 `stg` 是測試部署所在的環境,它裡面可以有給 dev、stg、prod 三個環境用的實例。實例路徑用部署自己的環境,取用端的環境不應該決定實例叫什麼,所以 dev 或 stg 的取用端不會因此去找 `secrets/stg`。",
8071
+ "VM 用用途命名:VM 的壽命比專案和產品長,專案改名或產品異動時 VM 名不該跟著改。",
8072
+ "一個標記一個意思:後綴只講部署在哪,前綴只講服務誰。讀名稱的人和程式看到後綴就知道部署環境,看到前綴就知道服務環境,不需要再查表。",
8073
+ "前綴不省略:省略 `prod-` 會讓同一個用途出現 `secrets` 與 `stg-secrets` 並存的寫法,之後從一份增加到多份時,原有那份還要改名。每份都帶前綴,一個部署裡同一個用途就只有兩種合法寫法,檢查只要比對這兩種。",
8074
+ "服務多個環境是少數情況,多數工作負載只有一份,直接叫用途名,不需要帶任何標記。所以不為少數情況讓所有工作負載都背上前綴。",
8075
+ "對象寫工作負載:部署進去的程式不一定是容器,也可能是 Kubernetes 工作負載、Worker 或主機上的常駐程式。規則只寫容器會讓其他形式沒有規則可依。",
8076
+ "移除 `serves`:欄位沒有消費者,留著只會和實例路徑上的環境不一致時產生兩個答案。"
8077
+ ]
8078
+ }
8079
+ ]
8080
+ },
8081
+ {
8082
+ "id": "consequences",
8083
+ "title": "代價",
8084
+ "blocks": [
8085
+ {
8086
+ "kind": "list",
8087
+ "items": [
8088
+ "依服務環境分成多份的工作負載,每份都要寫前綴,包含正式的那一份。",
8089
+ "一份增加為多份時,原本叫 `<用途>` 的那份要改名成帶前綴的寫法。",
8090
+ "`targets-json-merged-format` 的原文仍寫 `serves`,讀的人要看這份才知道現行規則。clarify-kit 沒有標示部分取代的欄位,所以那份決策的狀態維持已採納,由這份列出被取代的段落。",
8091
+ "已有 `serves` 的 `targets.json` 要刪掉那個欄位。"
8092
+ ]
8093
+ }
8094
+ ]
8095
+ }
8096
+ ],
8097
+ "factRefs": [
8098
+ "blueprint-shared.infra-layout.cluster-naming",
8099
+ "blueprint-shared.infra-layout.targets"
8100
+ ],
8101
+ "docRefs": [],
8102
+ "status": "accepted",
8103
+ "appliesFrom": "0.3.1",
8104
+ "supersedes": []
8105
+ },
7760
8106
  {
7761
8107
  "type": "decision",
7762
8108
  "id": "workspace-dependents-by-config-packages",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blueprint-shared-docs",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Decisions and explanations shared by several products, published on its own",
5
5
  "license": "MIT",
6
6
  "author": "Carlos Space",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "devDependencies": {
20
- "blueprint-shared-facts": "0.5.0",
20
+ "blueprint-shared-facts": "0.6.0",
21
21
  "clarify-kit": "^0.3.1",
22
22
  "fact-kit": "^0.14.1",
23
23
  "oxc-parser": "^0.155.0"