OpenClaw SecretRef 設定指南:管理 API 金鑰與憑證
處理 API Key 或是各種 Token 總是很心累,尤其是當你的專案越來越大,憑證散落在各個設定檔的時候。為了幫你解決這個痛點,OpenClaw 透過 SecretRef 提供了一套標準化的憑證管理方式,讓你不用再把敏感資訊寫死在程式碼或設定檔裡。
這篇文章會幫你釐清哪些憑證可以透過 SecretRef 來管理,哪些則因為性質特殊而不在範圍內。
SecretRef 憑證介面
Section titled “SecretRef 憑證介面”這頁定義了標準的 SecretRef 憑證範圍。
範圍定義:
- 納入範圍:嚴格限定為使用者提供的憑證,且 OpenClaw 不會自動生成或輪換這些內容。
- 不在範圍:執行時生成的憑證、OAuth 重新整理資料(refresh material)以及類似 Session 的產物。
openclaw.json 目標 (secrets configure + secrets apply + secrets audit)
Section titled “openclaw.json 目標 (secrets configure + secrets apply + secrets audit)”models.providers.*.apiKeymodels.providers.*.headers.*skills.entries.*.apiKeyagents.defaults.memorySearch.remote.apiKeyagents.list[].memorySearch.remote.apiKeytalk.apiKeytalk.providers.*.apiKeymessages.tts.providers.*.apiKeytools.web.fetch.firecrawl.apiKeyplugins.entries.brave.config.webSearch.apiKeyplugins.entries.google.config.webSearch.apiKeyplugins.entries.xai.config.webSearch.apiKeyplugins.entries.moonshot.config.webSearch.apiKeyplugins.entries.perplexity.config.webSearch.apiKeyplugins.entries.firecrawl.config.webSearch.apiKeyplugins.entries.tavily.config.webSearch.apiKeytools.web.search.apiKeytools.web.x_search.apiKeygateway.auth.passwordgateway.auth.tokengateway.remote.tokengateway.remote.passwordcron.webhookTokenchannels.telegram.botTokenchannels.telegram.webhookSecretchannels.telegram.accounts.*.botTokenchannels.telegram.accounts.*.webhookSecretchannels.slack.botTokenchannels.slack.appTokenchannels.slack.userTokenchannels.slack.signingSecretchannels.slack.accounts.*.botTokenchannels.slack.accounts.*.appTokenchannels.slack.accounts.*.userTokenchannels.slack.accounts.*.signingSecretchannels.discord.tokenchannels.discord.pluralkit.tokenchannels.discord.voice.tts.providers.*.apiKeychannels.discord.accounts.*.tokenchannels.discord.accounts.*.pluralkit.tokenchannels.discord.accounts.*.voice.tts.providers.*.apiKeychannels.irc.passwordchannels.irc.nickserv.passwordchannels.irc.accounts.*.passwordchannels.irc.accounts.*.nickserv.passwordchannels.bluebubbles.passwordchannels.bluebubbles.accounts.*.passwordchannels.feishu.appSecretchannels.feishu.encryptKeychannels.feishu.verificationTokenchannels.feishu.accounts.*.appSecretchannels.feishu.accounts.*.encryptKeychannels.feishu.accounts.*.verificationTokenchannels.msteams.appPasswordchannels.mattermost.botTokenchannels.mattermost.accounts.*.botTokenchannels.matrix.accessTokenchannels.matrix.passwordchannels.matrix.accounts.*.accessTokenchannels.matrix.accounts.*.passwordchannels.nextcloud-talk.botSecretchannels.nextcloud-talk.apiPasswordchannels.nextcloud-talk.accounts.*.botSecretchannels.nextcloud-talk.accounts.*.apiPasswordchannels.zalo.botTokenchannels.zalo.webhookSecretchannels.zalo.accounts.*.botTokenchannels.zalo.accounts.*.webhookSecretchannels.googlechat.serviceAccountvia siblingserviceAccountRef(compatibility exception)channels.googlechat.accounts.*.serviceAccountvia siblingserviceAccountRef(compatibility exception)
auth-profiles.json 目標 (secrets configure + secrets apply + secrets audit)
Section titled “auth-profiles.json 目標 (secrets configure + secrets apply + secrets audit)”profiles.*.keyRef(type: "api_key"; unsupported whenauth.profiles.<id>.mode = "oauth")profiles.*.tokenRef(type: "token"; unsupported whenauth.profiles.<id>.mode = "oauth")
備註:
- Auth-profile 計畫目標需要
agentId。 - 計畫項目會指向
profiles.*.key/profiles.*.token並寫入同級的引用(keyRef/tokenRef)。 - Auth-profile 引用已包含在執行時解析與稽核範圍內。
- OAuth 策略防護:
auth.profiles.<id>.mode = "oauth"不能與該設定檔的 SecretRef 輸入同時使用。如果違反這項策略,啟動、重新載入或進行 Auth-profile 解析時會直接報錯。 - 對於受 SecretRef 管理的模型供應商,產生的
agents/*/agent/models.json項目會保留非秘密標記(而非解析後的秘密值)用於apiKey或 Header 介面。 - 標記持久化是以來源為準:OpenClaw 會從當前的來源設定快照寫入標記,而不是使用解析後的執行時秘密值。
- 關於網路搜尋:
- 在明確供應商模式下(已設定
tools.web.search.provider),只有被選中的供應商金鑰會生效。 - 在自動模式下(未設定
tools.web.search.provider),只有根據優先順序解析出的第一個供應商金鑰會生效。 - 在自動模式下,未被選中的供應商引用會被視為非活動狀態,直到被選中為止。
- 舊有的
tools.web.search.*供應商路徑在相容期間仍可解析,但標準的 SecretRef 介面應為plugins.entries.<plugin>.config.webSearch.*。
- 在明確供應商模式下(已設定
不支援的憑證
Section titled “不支援的憑證”不屬於此範圍的憑證包括:
commands.ownerDisplaySecrethooks.tokenhooks.gmail.pushTokenhooks.mappings[].sessionKeyauth-profiles.oauth.*channels.discord.threadBindings.webhookTokenchannels.discord.accounts.*.threadBindings.webhookTokenchannels.whatsapp.creds.jsonchannels.whatsapp.accounts.*.creds.json
原因:
- 這些憑證屬於自動生成、輪換、帶有工作階段或 OAuth 持久性的類別,不適合唯讀的外部 SecretRef 解析機制。
想要更輕鬆地完成設定嗎?試試我們的 AI Setup Assistant。
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。