Skip to content

feat(kimi-code): add experimental OS keychain credential storage - #3254

Open
7Sageer wants to merge 2 commits into
mainfrom
feat/keyring-credential-storage
Open

feat(kimi-code): add experimental OS keychain credential storage#3254
7Sageer wants to merge 2 commits into
mainfrom
feat/keyring-credential-storage

Conversation

@7Sageer

@7Sageer 7Sageer commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — no tracking issue; the motivation is described below.

Problem

OAuth credentials (managed provider logins and MCP server grants) are stored as plaintext JSON files under ~/.kimi-code/credentials. File permissions (0600) are their only protection — anything running as the user can read long-lived refresh tokens, and secrets like these belong in the OS credential vault.

What changed

Adds experimental OS keychain credential storage, opt-in via KIMI_CODE_EXPERIMENTAL_KEYRING=1 (with KIMI_DISABLE_KEYRING=1 as a kill switch):

  • packages/oauth stays pure TypeScript and gains a KeyringTokenStorage that stores each token in the OS keychain (macOS Keychain, Windows Credential Manager, Linux Secret Service) using the exact same wire payload as the file store. Backend selection is gated by the opt-in flag, the kill switch, backend registration, and a runtime capability probe; any keyring call that throws degrades the backend stickily to the file store, so a locked or disappearing keychain never breaks login state.
  • Plaintext tokens written by older builds migrate into the keychain on first read via lock-free compare-and-delete, and reads reconcile against the file store so a backend flip-flop can never shadow a newer token or resurrect a revoked one. Keychain services are namespaced per credentials directory, keeping the same profile isolation as the file backend.
  • apps/kimi-code loads the @napi-rs/keyring native binding at bootstrap and registers it as the backend, wired into the SEA native-asset pipeline and bundle checks; a load failure only warns and keeps the file store.
  • packages/agent-core-v2 gives the MCP OAuth grant store the same keychain-backed treatment, selected when a backend is registered and the gate opts in.
  • Docs: env-vars and data-locations pages (en + zh).

The opt-in gate is temporary; flipping the default once the rollout is proven is a one-line follow-up.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (none exists — the problem is described above).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c566aa9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c566aa9
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c566aa9

commit: c566aa9

@github-actions

Copy link
Copy Markdown
Contributor

❌ Nix build failed

Hash mismatch in pnpmDeps:

Hash
specified sha256-NDcCQ5vxsGaSdJ3U0bvq2RkXKwrYTI7/8zZn/x1fvJ8=
got sha256-YYfWyLv+CkUuPp05iUIJ+zOAU8TSQHvJFnvxyj9HeMI=

Please update flake.nix with the got hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant