Skip to content

feat(providers): read provider keys from the freedesktop keyring - #102

Closed
alvorithm wants to merge 1 commit into
bernardopg:mainfrom
alvorithm:feat/keyring-credentials
Closed

alvorithm wants to merge 1 commit into
bernardopg:mainfrom
alvorithm:feat/keyring-credentials

Conversation

@alvorithm

@alvorithm alvorithm commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Dux Shell runs as a systemd user service, so it inherits the user manager's environment and never an interactive shell's exports. A key exported in ~/.bashrc therefore never reaches an adapter, and the settings page already says so: "a key exported only by an interactive shell is invisible when Dux Shell was started by the graphical session". The documented workaround is systemctl --user import-environment, which puts the key in every unit of the session rather than one process.

The adapters already read a credential from a keyring where one exists: providers/native/antigravity.bash calls secret-tool, and docs/security.md already lists the keyring as a credential source. This PR extends that route to the API-key providers.

This PR:

Verifications

scripts/check-metadata, scripts/check-changelog --base origin/main, scripts/check-dco origin/main, bash -n over every provider file, and the offline fixture suites pass, including the new tests/test-vault-keys.sh and the existing test-openrouter.sh, test-secret-argv.sh, test-native-adapters.sh, test-opencode.sh and the test-cov-c2-* adapter suites. The new test covers the keyring key reaching curl, exported-key precedence, a readable auth.json with no key falling through to the keyring, the bounded lookup, a missing secret-tool, and readiness without a lookup.

Shell lint ran with shellcheck 0.10.0. It reports no new findings on the changed files; it reports four pre-existing SC2034 findings in providers/get-provider-usage that an unmodified main produces at the same version.

Not verified: statement coverage, because kcov is not installed in this checkout. No QML changed, so qmllint was not run.

How to use

Store the key in the keyring and put the lookup spec in the environment the shell sees, for example ~/.config/environment.d/90-dms.conf, then restart the shell:

AIOC_VAULT_OPENROUTER="service openrouter username quota"
AIOC_VAULT_ZAI="service zai username quota"
AIOC_VAULT_OPENCODE="service opencode username quota"

The words are the attribute/value pairs secret-tool lookup takes, matching however the entry was stored, for example secret-tool store --label=OpenRouter service openrouter username quota. The spec is not a secret, so it can live in any environment file. A setup that exports the key is unchanged: the environment wins and no lookup runs. AIOC_VAULT_TIMEOUT (default 3 s) bounds the lookup, so a locked keyring delays one refresh instead of blocking it.

Out of scope

  • A settings field for the spec. It is not a secret, so an environment file works today; a field is a UI change and can follow.
  • Extending the route to the remaining API-key adapters (glm, deepseek, mistral and the rest). The helper is provider-agnostic, so each is a one-line fallback.
  • Moving the existing Authorization headers from curl's command line to --config, which docs/security.md already lists on the roadmap.

@github-actions github-actions Bot added documentation Improvements or additions to documentation area:providers Provider adapters (providers/) area:ci CI, workflows, tooling labels Nov 8, 2026
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]>
@alvorithm
alvorithm force-pushed the feat/keyring-credentials branch from 80ce0ff to 61ed714 Compare November 8, 2026 11:17
@bernardopg
bernardopg marked this pull request as ready for review November 8, 2026 18:17
@bernardopg
bernardopg self-requested a review as a code owner November 8, 2026 18:17
@bernardopg

Copy link
Copy Markdown
Owner

Thank you @alvorithm, the keyring route is a real fix for systemd-started shells, and the opt-in spec design (no secret in the environment, readiness without a lookup) was already right.

I carried it forward as #105 (stacked on #104). Your commit is kept with you as its author, and one follow-up commit addresses what came up in review:

  • No unlock prompts from a background refresh. secret-tool lookup unlocks a locked collection before it answers, so each refresh could raise the dialog again. The adapter now asks the Secret Service first with SearchItems (via busctl), which sorts matches into unlocked and locked items without prompting, and skips a locked or absent entry. The bounded lookup still covers a bus that cannot be asked.
  • No glob expansion. The unquoted $spec let a * match files in the working directory. The spec is now split with read -a, and a spec that is not attribute/value pairs is ignored, in readiness too. A malformed AIOC_VAULT_TIMEOUT falls back to the default.
  • GLM. The docs listed AIOC_VAULT_ZAI on the GLM row, but glm never read it. GLM now has its own AIOC_VAULT_GLM.
  • Docs. They now say the key reaches curl through the --config pipe, rather than "never a child process".

I checked it against a real Secret Service with a throwaway entry. The CHANGELOG ### Thanks section credits you for both #103 and this one. I'll close this PR when #105 lands. Thanks!

@bernardopg

Copy link
Copy Markdown
Owner

Merged as part of #105 with your commit and authorship intact, plus the follow-up described above. Thank you again @alvorithm!

@bernardopg bernardopg closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, workflows, tooling area:providers Provider adapters (providers/) documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants