Skip to content

Commit 61ed714

Browse files
committed
feat(providers): read provider keys from the freedesktop keyring
A plugin started by the graphical session inherits the user manager's environment and never an interactive shell's exports, so a key exported in ~/.bashrc never reaches an adapter. The OpenRouter, GLM / Z.ai and OpenCode Go adapters can now read the key from the keyring at the moment of use. The environment carries only a lookup spec, AIOC_VAULT_OPENROUTER and its siblings, which names the secret-tool attributes. The spec is not a secret, so it can live in a display manager or user-service environment file, and the key never enters a process environment, a child process, a cache or a log. An exported key still wins, and AIOC_VAULT_TIMEOUT bounds the lookup so a locked keyring cannot stall a refresh. Readiness accepts a spec without performing a lookup, so the settings page cannot raise a prompt. The test covers the key reaching curl, exported-key precedence, the bound, a missing secret-tool, and readiness without a lookup. Signed-off-by: Álvaro Tejero Cantero <[email protected]>
1 parent e8632e7 commit 61ed714

13 files changed

Lines changed: 234 additions & 15 deletions

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,9 @@ jobs:
745745
- name: Credentials off the command line, owner-only caches
746746
run: tests/test-secret-argv.sh
747747

748+
- name: Provider keys from the keyring
749+
run: tests/test-vault-keys.sh
750+
748751
- name: Append-only contributor grid
749752
run: tests/test-render-contributors.sh
750753

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Providers
6+
7+
- A provider key can come from the freedesktop keyring, read at the moment of use, for a session that never exported it. `AIOC_VAULT_OPENROUTER`, `AIOC_VAULT_ZAI`, and `AIOC_VAULT_OPENCODE` name the `secret-tool lookup` words for an entry, and the OpenRouter, GLM / Z.ai, and OpenCode Go adapters use that key when the environment has none. The spec is not a secret, so it can live in a display manager or user-service environment file. An exported key still wins, and `AIOC_VAULT_TIMEOUT` (default 3 s) bounds the lookup so a locked keyring cannot stall a refresh. Readiness accepts a spec without performing a lookup, so the settings page cannot raise a prompt.
8+
59
## 2.2.4 - 2026-11-04
610

711
A bug-fix release for Dux Shell 2.0 and 2.1, the shell formerly called DankMaterialShell. The Claude card stops polling Anthropic's usage endpoint while it is rate-limited, sharing one backoff across every bar, and the bar fades numbers that are no longer fresh. The docs and settings strings use the Dux Shell names, and the documented checkout install works again. Settings, profiles, pins and history carry over unchanged; no restart is needed.

‎docs/configuration.md‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ systemctl --user restart dms.service
118118

119119
For a durable environment-variable setup, configure your display manager or user-service environment rather than relying on an interactive shell.
120120

121+
### Keys from the keyring
122+
123+
A provider key can come from the freedesktop keyring instead, read at the moment of use. Give the provider a lookup spec and the adapter runs `secret-tool lookup` with those words whenever the environment has no key:
124+
125+
```bash
126+
AIOC_VAULT_OPENROUTER="service openrouter username quota"
127+
AIOC_VAULT_ZAI="service zai username quota"
128+
AIOC_VAULT_OPENCODE="service opencode username quota"
129+
```
130+
131+
The spec names the attributes the entry is stored under, so it is not a secret and can live in the display manager's or the user service's environment file. The key itself never enters the process environment, a child process, a cache or a log. An exported key still wins, so an existing setup keeps working unchanged. `AIOC_VAULT_TIMEOUT` bounds the lookup in seconds (default 3): a locked keyring raises a prompt and waits, and the refresh continues without a key rather than blocking. Readiness accepts a spec without performing a lookup, so opening the settings never raises a prompt.
132+
121133
## Provider readiness labels
122134

123135
The settings health check describes whether the plugin can run an adapter in the current shell process; it is not a claim that the provider publishes a quota API.
@@ -132,12 +144,13 @@ The settings health check describes whether the plugin can run an adapter in the
132144
| Copilot | `COPILOT_GITHUB_TOKEN`, `GH_TOKEN`, or `GITHUB_TOKEN`; `AIOC_NO_DOH_FALLBACK=1` disables the `dns.google` DNS-over-HTTPS fallback used to resolve an alternate `api.github.com` edge after a regional route fails (TLS hostname verification stays enabled either way) |
133145
| Antigravity | No environment variable is normally required. Credentials are discovered from `~/.gemini/antigravity-cli/antigravity-oauth-token`, the desktop keyring, or the IDE state database. Optional `ANTIGRAVITY_API_BASE_URL` retargets Cloud Code Assist; `ANTIGRAVITY_QUOTA_METHOD` can pin the compatibility method for diagnostics. |
134146
| Gemini | Gemini CLI sign-in (`~/.gemini/oauth_creds.json`) for per-model quota with a Code Assist Standard or Enterprise project; optional `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) selects the project. Otherwise `GEMINI_API_KEY`, `GOOGLE_API_KEY`, or `GOOGLE_GENERATIVE_AI_API_KEY` for a key check. The CLI token is renewed in memory only; `GEMINI_CLI_OAUTH_CLIENT_ID`, `GEMINI_CLI_OAUTH_CLIENT_SECRET`, `GEMINI_CLI_TOKEN_URL` and `GEMINI_CODE_ASSIST_ENDPOINT` override the CLI's defaults for diagnostics |
135-
| OpenRouter | `OPENROUTER_API_KEY` |
147+
| OpenRouter | `OPENROUTER_API_KEY`, or `AIOC_VAULT_OPENROUTER` for a keyring entry |
148+
| OpenCode | `OPENCODE_API_KEY`, or `AIOC_VAULT_OPENCODE` for a keyring entry; otherwise the CLI's `~/.local/share/opencode/auth.json` |
136149
| DeepSeek | `DEEPSEEK_API_KEY` |
137150
| Kimi | Balance: `MOONSHOT_API_KEY` or `KIMI_API_KEY` (optional `MOONSHOT_API_BASE`). Kimi Code subscription quota: `KIMI_CODING_API_KEY` (or a `sk-kimi-` prefixed `KIMI_API_KEY`; optional `KIMI_CODE_BASE_URL`; legacy `KIMI_BASE_URL` also accepted) |
138151
| MiniMax | `MINIMAX_TOKEN_PLAN_KEY` (Token Plan Subscription Key, `sk-cp-...`) — backward-compatible: a `sk-cp-` value in `MINIMAX_API_KEY` is also recognised. PAYG `sk-api-` keys stay on `MINIMAX_API_KEY` and surface auth-only; set both to keep an auth-only card when the Token Plan endpoint is unreachable. Optional `MINIMAX_API_BASE` retargets both read-only endpoints at a gateway or mirror. |
139152
| Command Code | `COMMAND_CODE_API_KEY`, or the `apiKey` saved by `cmd login` in `~/.commandcode/auth.json` |
140-
| GLM / Z.ai | `ZAI_API_KEY`, `GLM_API_KEY`, or `ZHIPU_API_KEY`; optional `GLM_API_BASE` |
153+
| GLM / Z.ai | `ZAI_API_KEY`, `GLM_API_KEY`, or `ZHIPU_API_KEY`, or `AIOC_VAULT_ZAI` for a keyring entry; optional `GLM_API_BASE` |
141154
| Mistral | `MISTRAL_API_KEY` |
142155
| Ollama | optional `OLLAMA_HOST`; requires the `ollama` CLI in PATH |
143156
| Ollama Cloud | `OLLAMA_API_KEY` |

‎docs/providers.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The matrix below summarises the **authentication/billing surface** for every sup
151151
<td>✅ per-window % + reset timestamp</td>
152152
<td>✅ GLM Coding Plan $18–$160/mo</td>
153153
<td>✅ per token</td>
154-
<td><code>ZAI_API_KEY</code> / <code>GLM_API_KEY</code> (<code>ZHIPU_API_KEY</code> also accepted; precedence depends on the adapter — see <a href="#glm--zai-zhipu-ai">GLM / Z.ai</a>)</td>
154+
<td><code>ZAI_API_KEY</code> / <code>GLM_API_KEY</code> (<code>ZHIPU_API_KEY</code> also accepted; precedence depends on the adapter — see <a href="#glm--zai-zhipu-ai">GLM / Z.ai</a>), or a keyring entry (<code>AIOC_VAULT_ZAI</code>)</td>
155155
<td><a href="https://z.ai/manage-apikey/billing">z.ai/manage-apikey</a></td>
156156
<td><a href="https://docs.z.ai/">docs.z.ai</a> / <a href="https://open.bigmodel.cn/dev/api">open.bigmodel.cn</a></td>
157157
</tr>
@@ -239,7 +239,7 @@ The matrix below summarises the **authentication/billing surface** for every sup
239239
<td>✅ <code>/zen/go/v1/usage</code> (5h + weekly + monthly)</td>
240240
<td>✅ OpenCode Go $10/mo</td>
241241
<td>—</td>
242-
<td><code>OPENCODE_API_KEY</code> or CLI <code>~/.local/share/opencode/auth.json</code></td>
242+
<td><code>OPENCODE_API_KEY</code>, a keyring entry (<code>AIOC_VAULT_OPENCODE</code>), or CLI <code>~/.local/share/opencode/auth.json</code></td>
243243
<td><a href="https://opencode.ai/zen">opencode.ai/zen</a></td>
244244
<td><a href="https://opencode.ai/docs/go">opencode.ai/docs/go</a></td>
245245
</tr>
@@ -339,7 +339,7 @@ The matrix below summarises the **authentication/billing surface** for every sup
339339
<td>✅ limit/daily/monthly/balance + free-model requests/day</td>
340340
<td>—</td>
341341
<td>✅ per token</td>
342-
<td><code>OPENROUTER_API_KEY</code></td>
342+
<td><code>OPENROUTER_API_KEY</code> or a keyring entry (<code>AIOC_VAULT_OPENROUTER</code>)</td>
343343
<td><a href="https://openrouter.ai/credits">openrouter.ai/credits</a></td>
344344
<td><a href="https://openrouter.ai/docs/api-reference/limits">openrouter.ai/docs</a></td>
345345
</tr>

‎docs/security.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ expectations. To report a vulnerability, follow
1414
(for example `~/.codex/auth.json`, `gh auth token`, `KIMI_CODING_API_KEY`).
1515
A credential is sent only to the API of the provider it belongs to. The
1616
plugin never copies credentials into its settings, caches, logs,
17-
notifications, history exports or test fixtures.
17+
notifications, history exports or test fixtures. The keyring route is
18+
opt-in per provider through a lookup spec in the environment
19+
(`AIOC_VAULT_OPENROUTER` and its siblings), which is not a secret. The
20+
lookup is bounded by `AIOC_VAULT_TIMEOUT`, and readiness never performs
21+
one, so a locked keyring cannot stall a refresh or raise a prompt from the
22+
settings page.
1823
2. **Read-only access, with one confirmed exception.** The plugin reads quota,
1924
billing and usage data. It never changes provider settings, buys credits or
2025
writes into a tool's own configuration directory. The one write is redeeming

‎providers/get-provider-health‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ umask 077
55

66
# shellcheck source=providers/claude-profile-common
77
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/claude-profile-common"
8+
# shellcheck source=providers/vault-common
9+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/vault-common"
810

911
has_any_env() {
1012
local name
@@ -145,7 +147,7 @@ status_for() {
145147
fi
146148
;;
147149
9router) [ -f "$HOME/.9router/db/data.sqlite" ] || [ -f "$HOME/.9router/usage.json" ] || { status="missing"; detail="9Router usage database"; } ;;
148-
openrouter) has_any_env OPENROUTER_API_KEY || [ -f "$HOME/.9router/db/data.sqlite" ] || { status="missing"; detail="OPENROUTER_API_KEY or 9Router data"; } ;;
150+
openrouter) has_any_env OPENROUTER_API_KEY || has_vault_spec openrouter || [ -f "$HOME/.9router/db/data.sqlite" ] || { status="missing"; detail="OPENROUTER_API_KEY, a keyring entry, or 9Router data"; } ;;
149151
deepseek) has_any_env DEEPSEEK_API_KEY || { status="missing"; detail="DEEPSEEK_API_KEY"; } ;;
150152
kimi-code)
151153
if ! has_any_env KIMI_CODING_API_KEY && [[ "${MOONSHOT_API_KEY:-${KIMI_API_KEY:-}}" != sk-kimi-* ]]; then
@@ -159,10 +161,10 @@ status_for() {
159161
if [ -f "${OPENCODE_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/opencode}/opencode.db" ] && [ "${OPENCODE_USAGE_SOURCE:-local}" != api ]; then
160162
command -v sqlite3 >/dev/null || { status="missing"; detail="sqlite3"; }
161163
else
162-
has_opencode_credentials || { status="missing"; detail="OpenCode local database or OPENCODE_API_KEY"; }
164+
has_opencode_credentials || has_vault_spec opencode || { status="missing"; detail="OpenCode local database, OPENCODE_API_KEY, or a keyring entry"; }
163165
fi ;;
164166
glm|zhipu) has_any_env GLM_API_KEY ZHIPU_API_KEY || { status="missing"; detail="GLM_API_KEY or ZHIPU_API_KEY"; } ;;
165-
zai|z.ai) has_any_env ZAI_API_KEY GLM_API_KEY ZHIPU_API_KEY || { status="missing"; detail="ZAI_API_KEY"; } ;;
167+
zai|z.ai) has_any_env ZAI_API_KEY GLM_API_KEY ZHIPU_API_KEY || has_vault_spec zai || { status="missing"; detail="ZAI_API_KEY or a keyring entry"; } ;;
166168
mistral) has_any_env MISTRAL_API_KEY || { status="missing"; detail="MISTRAL_API_KEY"; } ;;
167169
ollama) command -v ollama >/dev/null 2>&1 || { status="missing"; detail="ollama CLI"; } ;;
168170
nvidia|nim) has_any_env NVIDIA_API_KEY || { status="missing"; detail="NVIDIA_API_KEY"; } ;;

‎providers/get-provider-usage‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ CLAUDE_SCRIPT="$SCRIPT_DIR/get-claude-usage"
1212
CODEX_SCRIPT="$SCRIPT_DIR/get-codex-usage"
1313
# shellcheck source=providers/http-common
1414
source "$SCRIPT_DIR/http-common"
15+
# shellcheck source=providers/vault-common
16+
source "$SCRIPT_DIR/vault-common"
1517
# Caches created before 2.1.0 used the default umask; tighten them once.
1618
AIOC_CACHE_ROOT="${XDG_CACHE_HOME:-$HOME/.cache}/AiOverviewControl"
1719
if [ -d "$AIOC_CACHE_ROOT" ] && [ "$(stat -c %a "$AIOC_CACHE_ROOT" 2>/dev/null)" != 700 ]; then
@@ -643,14 +645,19 @@ opencode_api_key() {
643645
# and key shape verified against opencode's docs and the opencode CLI
644646
# behavior on Linux. Honor XDG_DATA_HOME for non-default DMS sessions.
645647
local auth_file="${XDG_DATA_HOME:-$HOME/.local/share}/opencode/auth.json"
648+
local key=""
646649
if [ -n "${OPENCODE_API_KEY:-}" ]; then
647-
printf '%s' "$OPENCODE_API_KEY"
650+
key="$OPENCODE_API_KEY"
648651
elif [ -r "$auth_file" ]; then
649652
# Accept either the {"opencode":{"key":...}} shape (current CLI) or a
650653
# legacy flat {"apiKey":...} shape so the bridge still works for users
651654
# who hand-edited the file before the rename.
652-
jq -r '."opencode".key // ."opencode-go".key // ."opencode_go".key // .apiKey // empty' "$auth_file" 2>/dev/null || true
655+
key="$(jq -r '."opencode".key // ."opencode-go".key // ."opencode_go".key // .apiKey // empty' "$auth_file" 2>/dev/null || true)"
653656
fi
657+
# A readable file that holds no key falls through: logged out, or a legacy
658+
# file the CLI stopped updating.
659+
[ -n "$key" ] || key="$(vault_key opencode)"
660+
printf '%s' "$key"
654661
}
655662

656663

‎providers/native/opencode.bash‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fetch_opencode_native() {
4545
local key
4646
key="$(opencode_api_key)"
4747
if [ -z "$key" ]; then
48-
json_error opencode opencode-api 2 provider "OpenCode credentials are unavailable. Set OPENCODE_API_KEY or run 'opencode auth login' so ~/.local/share/opencode/auth.json has a key."
48+
json_error opencode opencode-api 2 provider "OpenCode credentials are unavailable. Set OPENCODE_API_KEY, set AIOC_VAULT_OPENCODE for a keyring entry, or run 'opencode auth login' so ~/.local/share/opencode/auth.json has a key."
4949
return 0
5050
fi
5151

‎providers/native/openrouter.bash‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Sourced adapter; shared transport/normalization helpers live in get-provider-usage.
22
fetch_openrouter_native() {
33
local key="${OPENROUTER_API_KEY:-}"
4+
[ -n "$key" ] || key="$(vault_key openrouter)"
45
if [ -z "$key" ]; then
5-
json_error openrouter openrouter-api 2 provider "OPENROUTER_API_KEY is not set and no local 9Router usage was found."
6+
json_error openrouter openrouter-api 2 provider "OPENROUTER_API_KEY is not set, AIOC_VAULT_OPENROUTER has no keyring entry, and no local 9Router usage was found."
67
return 0
78
fi
89

‎providers/native/zai.bash‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Sourced adapter; shared transport/normalization helpers live in get-provider-usage.
22
fetch_zai_native() {
33
local key="${ZAI_API_KEY:-${GLM_API_KEY:-${ZHIPU_API_KEY:-}}}"
4+
[ -n "$key" ] || key="$(vault_key zai)"
45
if [ -z "$key" ]; then
5-
json_error zai zai-api 2 provider "ZAI_API_KEY is not set. Get your key at z.ai/manage-apikey/apikey-list"
6+
json_error zai zai-api 2 provider "ZAI_API_KEY is not set and AIOC_VAULT_ZAI has no keyring entry. Get your key at z.ai/manage-apikey/apikey-list"
67
return 0
78
fi
89

0 commit comments

Comments
 (0)