機密管理
代理可以在執行時期透過 tai tool CLI 讀取使用者設定的機密。
機密在靜態儲存時會以 AES-256-GCM 加密,僅在讀取時解密。
可用工具
| 工具 | 說明 |
|---|---|
secret_list | 列出機密名稱與說明(不含值) |
secret_read | 依名稱讀取單一機密的值 |
使用方式
Bash
# 列出可用機密
tai tool secret_list
# 讀取機密
TOKEN=$(tai tool secret_read '{"name": "GITHUB_TOKEN"}' | jq -r '.value')
git clone "https://${TOKEN}@github.com/org/repo.git"
Node.js
const { execSync } = require("child_process");
function readSecret(name) {
const raw = execSync(
`tai tool secret_read '${JSON.stringify({ name })}'`,
{ encoding: "utf-8" }
);
return JSON.parse(raw).value;
}
const token = readSecret("GITHUB_TOKEN");
Python
import json
import subprocess
def read_secret(name: str) -> str:
result = subprocess.run(
["tai", "tool", "secret_read", json.dumps({"name": name})],
capture_output=True, text=True, check=True,
)
return json.loads(result.stdout)["value"]
token = read_secret("GITHUB_TOKEN")
PowerShell
function Read-Secret {
param([string]$Name)
$json = @{ name = $Name } | ConvertTo-Json -Compress
$result = tai tool secret_read $json | ConvertFrom-Json
return $result.value
}
$token = Read-Secret -Name "GITHUB_TOKEN"
安全規則
- 絕不列印或記錄機密值 — 請勿將機密寫入 stdout、stderr 或任何日誌檔案。
- 絕不將機密寫入檔案 — 例外:SSH 金鑰可寫入
~/.ssh/目錄,並設定權限為chmod 600。 - 絕不將機密傳送給 LLM — 機密值不得出現在提示內容、系統訊息或轉發給模型的工具呼叫結果中。
- 範圍隔離 — 機密依使用者與代理進行範圍限制。代理僅能存取為其設定的機密。
- 稽核軌跡 — 每次
secret_read呼叫都會連同呼叫者身分記錄在稽核軌跡中。