docs: record actual groups/policies rollout + lesson learned
Applied the segmentation plan. Added an 'execution log' section with real IDs, verification results, and a rollback snippet. Key lesson corrected in the main plan: the original design missed personal<->personal connectivity (Mac<->iPhone would have broken when Default was disabled). Added personal-internal policy and a note that every desired group pair — including a group with itself — needs an explicit policy, because NetBird defaults to deny when there is no matching policy.
This commit is contained in:
@@ -43,9 +43,9 @@ Dashboard 的 Peers 頁面顯示 `Add Groups` 按鈕代表該 peer **沒有自
|
||||
4. **分享給家人**:一個 group 只給家人裝置,policy 限制他們能看到的範圍
|
||||
5. **Exit Node 授權**:只有特定 group 能把流量導去某 peer
|
||||
|
||||
### 本部署的建議分組
|
||||
### 本部署的分組(已套用,詳見文末執行紀錄)
|
||||
|
||||
以目前 4 個 peer:
|
||||
4 個 peer 分成 2 個自訂 group:
|
||||
|
||||
| Group | 成員 | 用途 |
|
||||
|-------|------|------|
|
||||
@@ -54,11 +54,14 @@ Dashboard 的 Peers 頁面顯示 `Add Groups` 按鈕代表該 peer **沒有自
|
||||
|
||||
對應的 Policy:
|
||||
|
||||
| # | From | To | 目的 |
|
||||
|---|------|-----|------|
|
||||
| 1 | `personal` | `servers` | 個人裝置能連伺服器 |
|
||||
| 2 | `servers` | `servers` | 伺服器彼此互連(例如未來備份、日誌集中) |
|
||||
| 3 | ~~`All → All` (Default)~~ | — | **刪除或停用** |
|
||||
| # | From | To | Bidirectional | 目的 |
|
||||
|---|------|-----|--------------|------|
|
||||
| 1 | `personal` | `servers` | 否 | 個人裝置能連伺服器 |
|
||||
| 2 | `servers` | `servers` | 是 | 伺服器彼此互連(例如未來備份、日誌集中) |
|
||||
| 3 | `personal` | `personal` | 是 | Mac ↔ iPhone 互通(**不能漏**,見下方教訓) |
|
||||
| 4 | ~~`All → All` (Default)~~ | — | — | **停用**(保留可快速 rollback) |
|
||||
|
||||
⚠️ **教訓**:`personal-internal` policy 是必需的。原本只設 `personal → servers` 跟 `servers → servers` 會切斷 Mac ↔ iPhone — 每個想互通的 group 組合都要一條明確 policy,包括 group 自己到自己。
|
||||
|
||||
刻意**不**建立 `servers → personal` 的 policy:伺服器被入侵時,攻擊者無法透過 NetBird 橫向移動到個人裝置。
|
||||
|
||||
@@ -246,13 +249,14 @@ Phase 1: 建 groups
|
||||
- Create group "personal" with Mac, iPhone
|
||||
|
||||
Phase 2: 建新 policies(先不刪預設)
|
||||
- Policy "personal-to-servers": personal → servers
|
||||
- Policy "servers-to-servers": servers → servers (bidirectional)
|
||||
- Policy "personal-to-servers": personal → servers (unidirectional)
|
||||
- Policy "servers-internal": servers → servers (bidirectional)
|
||||
- Policy "personal-internal": personal → personal (bidirectional)
|
||||
- 此時 All→All 跟新 policy 並存,功能不變
|
||||
|
||||
Phase 3: 驗證新 policy 生效
|
||||
- 關掉 All→All(先 disable 不 delete)
|
||||
- 實測:Mac→CT100 通、iPhone→CT101 通、CT100→Mac **不通**
|
||||
- 實測:Mac→CT100 通、CT100→Mac **不通**、Mac↔iPhone 通
|
||||
|
||||
Phase 4: 確認無誤
|
||||
- 刪除 Default policy(如果想)
|
||||
@@ -261,6 +265,72 @@ Phase 4: 確認無誤
|
||||
出問題 rollback:把 Default policy 重新啟用即可恢復原狀。
|
||||
```
|
||||
|
||||
## 執行紀錄:2026-04-18 套用到本部署
|
||||
|
||||
實際在本部署上執行此遷移的結果,供日後回溯。
|
||||
|
||||
### Groups
|
||||
|
||||
| Name | ID | Peers |
|
||||
|------|-----|------|
|
||||
| `All` | `d7h3kf6fs58s73f6qbj0` | 4(系統預設) |
|
||||
| `servers` | `d7hjr5fvjtnc738j3reg` | CT100, CT101 |
|
||||
| `personal` | `d7hjr5fvjtnc738j3rfg` | mbp-13-pro, iphone-15-pro |
|
||||
|
||||
### Policies
|
||||
|
||||
| Name | ID | Source → Destination | Bidirectional | Enabled |
|
||||
|------|-----|--------------------|--------------|--------|
|
||||
| `personal-to-servers` | `d7hjr8fvjtnc738j3rh0` | personal → servers | false | ✓ |
|
||||
| `servers-internal` | `d7hjr8fvjtnc738j3ri0` | servers → servers | true | ✓ |
|
||||
| `personal-internal` | `d7hjrenvjtnc738j3rj0` | personal → personal | true | ✓ |
|
||||
| `Default` | `d7h3kf6fs58s73f6qbjg` | All → All | true | **false**(停用,保留) |
|
||||
|
||||
### 計畫外的發現:`personal-internal` 是必需的
|
||||
|
||||
最初設計只列了兩條新 policy(`personal → servers`、`servers → servers`),停掉 Default 之後**會切斷 Mac ↔ iPhone**。補上 `personal-internal` 才維持個人裝置互通。
|
||||
|
||||
**規則**:每個想互通的 group 組合都需要明確 policy,**沒有則拒絕**。包括 group 自己到自己。
|
||||
|
||||
### 驗證結果
|
||||
|
||||
| 連線 | Policy | 結果 |
|
||||
|------|--------|------|
|
||||
| Mac → CT100 | personal-to-servers | 通 (32ms) |
|
||||
| Mac → iPhone | personal-internal | 通 (8ms) |
|
||||
| CT100 → CT101 | servers-internal | 通 (<1ms, LAN 直連) |
|
||||
| CT100 → Mac | ✗(無 policy) | 100% loss |
|
||||
| CT101 → iPhone | ✗(無 policy) | 100% loss |
|
||||
|
||||
產生的安全邊界:伺服器被攻破時無法透過 NetBird 橫向連到個人裝置。
|
||||
|
||||
### Rollback 方式
|
||||
|
||||
如果需要暫時恢復全互通:
|
||||
|
||||
```bash
|
||||
TOKEN=<your PAT>
|
||||
DEFAULT_PID="d7h3kf6fs58s73f6qbjg"
|
||||
ALL_GID="d7h3kf6fs58s73f6qbj0"
|
||||
|
||||
curl -X PUT -H "Authorization: Token $TOKEN" -H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"name\":\"Default\",
|
||||
\"description\":\"This is a default rule that allows connections between all the resources\",
|
||||
\"enabled\":true,
|
||||
\"rules\":[{
|
||||
\"name\":\"Default\",
|
||||
\"enabled\":true,
|
||||
\"action\":\"accept\",
|
||||
\"protocol\":\"all\",
|
||||
\"bidirectional\":true,
|
||||
\"sources\":[\"$ALL_GID\"],
|
||||
\"destinations\":[\"$ALL_GID\"]
|
||||
}]
|
||||
}" \
|
||||
https://netbird.timmy.us.kg/api/policies/$DEFAULT_PID
|
||||
```
|
||||
|
||||
## 相關檔案與文件
|
||||
|
||||
- `setup-keys-and-pat.md` — PAT 與 setup key 建立(建 group 需要 PAT)
|
||||
|
||||
Reference in New Issue
Block a user