前言¶
DeepSeek Harness(DSH)通過 ctx.credentials 爲適配器與工具提供 API Key、會話記錄等敏感數據。默認的 dsh-credentials-local 會把內容寫在 $DSH_HOME/.credentials.yaml,權限雖是 0600,但工具進程(bash、讀文件類工具)與 DSH 同屬當前用戶,模型側仍可能用 read、cat、grep 等方式讀到明文。若你把 profile 目錄納入備份、同步或 git,憑證還會跟着文件一起外流。
下面介紹社區插件 dsh-keychain-credentials(維護者 nengong-ai):在 macOS 上用系統登錄鑰匙串承載 DSH 憑證,磁盤上不再保留可被直接 cat 的憑證文件。分類爲 admin-security,當前 GitHub 星標爲 0。
這是什麼¶
dsh-keychain-credentials 是面向 DeepSeek Harness 的純 JavaScript 憑證 Provider,實現 ctx.credentials 的完整 seam:refs(如 API Key 引用)與 records(如 client-connection/browser-session 等結構化記錄)都寫入 macOS 登錄鑰匙串,而不是明文 YAML。
與只實現 refs、仍讓 session records 落回明文文件的 Provider 相比,該插件覆蓋 seam 的兩半;安裝無需 Swift、代碼簽名或 Xcode。
核心功能¶
相對默認本地文件的改進¶
- 密鑰不再以文件形式存在,不會進入備份目錄、同步盤或 git 倉庫。
- 讀取門檻從「任意讀文件原語」提高到「同用戶進程需調用
/usr/bin/security」——有實質提升,但不是絕對隔離。
誠實說明:仍做不到什麼¶
登錄鑰匙串在已解鎖狀態下(默認登錄後即解鎖),同用戶進程可通過 /usr/bin/security 讀取條目,且 CLI 受 ACL 信任、通常無二次提示;具備無限制 shell 且知道去查鑰匙串的智能體仍可能外傳。若要更硬邊界,需 OS 級隔離(例如帶私有 access group 的 broker,或獨立 OS 用戶),並可配合限制工具子進程的沙箱。
行爲與 seam 契約¶
- 進程環境變量優先於鑰匙串(單次運行意圖覆蓋存儲)。
- 空值視爲不存在;環境變量只讀 shadow 時,
set/unset會拒絕。 describe只檢查是否存在,不讀明文,避免狀態查詢把密鑰拉進 agent 進程。- 調用
security時錯誤信息做脫敏(退出碼與 stderr,不含可能帶密鑰的命令行)。 - 密鑰經 stdin 傳給
security,不進 argv,避免出現在ps。 - 超過 128 字節的值用
security -i寫入(stdin 密碼提示會靜默截斷);寫完後通過讀回確認。
其它選型理由(README 自述)¶
- 無 Touch ID / 密碼彈窗:讀寫 deliberately 不打擾用戶(與每次操作都彈窗的 keyringseam 類方案是不同取捨)。
環境要求¶
- 操作系統:macOS(依賴
/usr/bin/security);package.json中engines.node爲>=20,os爲darwin。 - DeepSeek Harness:≥
0.1.0-rc.6(peer 範圍覆蓋 0.1.x 與0.2.0-rc.1)。 - DSH 0.2 及更新版本:插件必須以包形式掛載——安裝進 profile 或鏈接到其
node_modules,並在配置裏用包名引用;指向絕對路徑index.js的行在 0.2+ 上不可用(peer 兼容性門禁與 asar 內 host 解析限制)。
安裝與啓用¶
官方安裝命令如下(<profile> 換成你的 profile 名):
dsh plugin --profile <profile> add dsh-keychain-credentials
# or from source:
dsh plugin --profile <profile> add github:<you>/dsh-keychain-credentials
安裝後,包內 cordis.patch.yml 會禁用默認 dsh-credentials-local 並掛載本 Provider。若需手寫 patch,可在 ~/.dsh/profiles/<profile>/cordis.patch.yml 或 --patch <file> 中加入:
- id: credentials
disabled: true
- insert:
- id: credentials-keychain
name: dsh-keychain-credentials # 包名,不是絕對路徑;插件須已裝/鏈接進該 profile
config:
servicePrefix: dsh-credentials # keychain service prefix
account: dsh # keychain account name
插件版本以發佈包爲準(資料中 package.json 爲 0.2.0);許可證 MIT。
典型用法¶
憑證引用名對應鑰匙串條目的 account;service 前綴默認與配置中的 servicePrefix 一致(示例爲 dsh-credentials)。用系統 CLI 寫入一條 API Key:
security add-generic-password -U -s dsh-credentials -a DEEPSEEK_API_KEY -w 'sk-…'
LLM 適配器會按引用名在請求時解析,輪換密鑰後無需重啓 DSH。
開發者在倉庫內可安裝依賴並跑測試(會操作真實登錄鑰匙串下的測試前綴 dsh-credentials-test,不寫真實密鑰):
npm install # or pnpm install — devDependencies supply the seam packages
npm test
適用場景與注意¶
適合:在 macOS 上長期跑 DSH、希望 refs 與 records 都離開明文 YAML、又不想引入 Swift 構建鏈的開發者。
不適合:非 macOS 環境;或要求「模型與工具完全無法觸達密鑰」的 threat model——本插件只抬高攻擊門檻,不能替代 OS 級隔離。
安裝前:插件與 DSH 同用戶、同進程權限運行;啓用前請自行審閱 GitHub 源碼 與許可證。社區插件目錄 skillhub.cn 爲獨立站點,與 DeepSeek / 幻方無官方從屬關係,並非官方應用商店。
小結¶
dsh-keychain-credentials 用 macOS 登錄鑰匙串替代 $DSH_HOME/.credentials.yaml,同時支持 refs 與 records,純 JavaScript 安裝即用。它不能消除同用戶下通過 security 讀取的可能,但可避免憑證以普通文件形式被模型常用讀路徑掃到。