雲端 setup:git 認證改用讀環境變數的 credential helper,並讓驗證有能力變紅
雲端實測(真的雲端 session,不是本機模擬): - session 是 root/HOME=/root,setup 階段寫進 $HOME 的三個機制一個都沒到 (沒有 insteadOf、沒有 ~/.git-credentials、沒有 /etc/gitconfig) - 薄殼 settings.json 的 extraKnownMarketplaces + enabledPlugins 宣告了也沒用: Claude Code 是裸 URL clone marketplace,沒有 credential helper 就靜默失敗 → 'No marketplaces configured' 改法: - credential helper 當場讀 GITEA_TOKEN_CLAUDE_CODE,磁碟不落明文(token 輪替不用重拍快照) - 寫進所有 session 可能讀到的 gitconfig,並印出實際寫進哪幾份 - 驗證先跑裸探針(GIT_CONFIG_GLOBAL/SYSTEM=/dev/null),它必須紅;紅不了就說明綠燈不算數 - 加驗 plugin 本身(只驗 marketplace 會漏掉「marketplace 有、plugin 沒有」) 在雲端容器內實跑過:裸環境正確失敗 → 補 helper 後 marketplace 就位、 isep@inkstone 0.3.1 installed/enabled,腳本 exit 0。
This commit is contained in:
@@ -52,6 +52,51 @@ git config --global url."https://x-access-token:${GITEA_TOKEN_CLAUDE_CODE}@git.u
|
||||
|
||||
完整腳本:`docs/cloud-setup-script.sh`(貼進 code-on-web 的 Setup script 欄位用)。
|
||||
|
||||
### 🔴 2026-08-20 雲端實測訂正:上面那條 `url.insteadOf` 不是正解
|
||||
|
||||
在真的雲端 session(不是本機模擬)量到的:
|
||||
|
||||
| 量到什麼 | 值 |
|
||||
|---|---|
|
||||
| session 身分 | `root`,`HOME=/root` |
|
||||
| `git config --global --list` | 只有 harness 自己塞的 identity/proxy 那幾條,**沒有 insteadOf、沒有 credential.helper** |
|
||||
| `~/.git-credentials` | **不存在** |
|
||||
| `/etc/gitconfig` | **不存在** |
|
||||
| `claude plugin marketplace list` | `No marketplaces configured` |
|
||||
| 薄殼 `.claude/settings.json` | `extraKnownMarketplaces` + `enabledPlugins` **都宣告了** |
|
||||
|
||||
⇒ 兩個結論:
|
||||
|
||||
1. **setup 階段寫進 `$HOME` 的東西沒有到 session 手上。**
|
||||
舊版三個機制(insteadOf/`~/.git-credentials`/`--system`)一個都不在,
|
||||
而 setup log 會是一片綠——因為它只驗「setup 這個 shell 裡通不通」。
|
||||
2. **光在薄殼 settings.json 宣告 `extraKnownMarketplaces` 沒有用。**
|
||||
Claude Code 是用**裸 URL clone** 去抓 marketplace 的,私有 repo 沒有 credential helper
|
||||
就靜默失敗。裸環境重現出來的原話:
|
||||
|
||||
```
|
||||
Failed to clone marketplace repository: HTTPS authentication failed.
|
||||
Please ensure your git credential helper has valid credentials for git.uncle6.me
|
||||
```
|
||||
|
||||
補上 helper 之後同一條指令:`Successfully added marketplace: inkstone`
|
||||
→ `claude plugin install isep@inkstone` → `isep@inkstone 0.3.1 · enabled`。
|
||||
**紅過也綠過,不是只看到綠。**
|
||||
|
||||
⇒ 改法(已落在 `docs/cloud-setup-script.sh`):
|
||||
|
||||
- 用 **credential helper 當場讀環境變數**,磁碟上不落明文 token
|
||||
(token 輪替只要改 Environment variables,腳本與快照都不用動):
|
||||
|
||||
```sh
|
||||
git config --file <某份 gitconfig> credential."https://git.uncle6.me".helper \
|
||||
'!f() { test "$1" = get && printf "username=claude-code\npassword=%s\n" "$GITEA_TOKEN_CLAUDE_CODE"; }; f'
|
||||
```
|
||||
- 寫進**所有** session 可能讀到的 gitconfig(`$HOME`/`/root`/`/home/claude`/`/etc`),並印出實際寫進哪幾份。
|
||||
- 驗證要**先讓它失敗一次**:用 `GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null` 跑裸探針,
|
||||
它必須紅;紅不了代表環境裡另有憑證捷徑,後面的綠燈就不能當證據。
|
||||
|
||||
|
||||
## 已驗(本機,隔離環境,不影響本機正在跑的任何 session)
|
||||
|
||||
🔴 **怎麼保證沒有干擾**:全程把 `$HOME` 指到 scratchpad 底下的隔離目錄
|
||||
|
||||
Reference in New Issue
Block a user