Skip to content

fix: support encrypted local secrets for keyring auth - #17931

Closed
mikhail-oai wants to merge 20 commits into
mainfrom
codex/keyring-mode-encrypted-auth
Closed

fix: support encrypted local secrets for keyring auth#17931
mikhail-oai wants to merge 20 commits into
mainfrom
codex/keyring-mode-encrypted-auth

Conversation

@mikhail-oai

@mikhail-oai mikhail-oai commented Apr 15, 2026

Copy link
Copy Markdown

Why

Windows Credential Manager limits a generic credential blob to 2,560 bytes. Large ChatGPT auth payloads, and MCP OAuth token payloads in the same keyring-backed storage path, can exceed that limit and make keyring persistence fail on Windows.

This PR keeps keyring-backed auth secure without requiring those large serialized payloads to fit directly in the OS credential entry. Instead, Windows can store the payload in Codex's encrypted local secrets backend while keeping the local secrets key in the OS keyring. Non-Windows platforms continue to use direct keyring storage by default. Goal is to move everything to the secrets keyring path and deprecate the old path after it's fully validated.

What Changed

  • Added AuthKeyringBackendKind and a secret_auth_storage feature that selects between direct keyring storage and encrypted local-secrets-backed keyring storage. The feature is enabled by default on Windows.
  • Updated CLI login, logout, auth loading, auth refresh, device-code login, login status, and codex doctor paths to use the configured keyring backend.
  • Reworked keyring-mode CLI auth storage so the secrets backend stores serialized AuthDotJson, removes stale fallback auth.json data after successful saves, and deletes both encrypted and fallback auth on logout.
  • Extended MCP OAuth persistence to use the same keyring backend selection for token load/save/delete, including encrypted local secrets storage and the existing file fallback behavior when keyring access fails.
  • Threaded the backend selection through MCP auth status checks, MCP client startup, app-server processors, cloud task/config adapters, and related test fixtures.

Validation

Manual macOS/Windows validation with cli_auth_credentials_store = "auto", mcp_oauth_credentials_store = "auto", and features.secret_auth_storage = true:

  • Ran CLI login and confirmed Keychain Access created the shared secrets key entry with service codex and account secrets|....
  • Ran MCP OAuth login for configured MCP servers and confirmed the same Keychain entry is used for the local secrets encryption key rather than a per-MCP plaintext token entry.
  • Listed decrypted secret names from $CODEX_HOME/secrets/local.age without printing secret values, confirming one CLI auth entry and MCP OAuth entries are present:
    • global/CLI_AUTH
    • global/MCP_OAUTH_...

Also validated that the feature flag is default on for windows and default off for macOS.

#closes #10353

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this May 7, 2026
@celia-oai celia-oai reopened this May 18, 2026
@celia-oai
celia-oai force-pushed the codex/keyring-mode-encrypted-auth branch 2 times, most recently from ee4e093 to 63482e2 Compare May 18, 2026 05:32
@celia-oai
celia-oai force-pushed the codex/keyring-mode-encrypted-auth branch 25 times, most recently from 2c08a84 to 7b0d612 Compare May 26, 2026 23:02
@celia-oai
celia-oai force-pushed the codex/keyring-mode-encrypted-auth branch from 295d319 to 95b6f6f Compare June 11, 2026 00:47
@celia-oai
celia-oai changed the base branch from main to codex/secret-auth-storage-config June 11, 2026 01:00
@celia-oai
celia-oai force-pushed the codex/secret-auth-storage-config branch from 683a9f4 to 3e3379b Compare June 12, 2026 18:53
celia-oai added a commit that referenced this pull request Jun 12, 2026
## Why

Windows Credential Manager limits generic credential blobs to 2,560
bytes. The encrypted local secrets backend avoids storing large
serialized auth payloads directly in the OS keyring, but selecting that
backend needs an independently reviewable feature/config layer before
the auth and secrets implementation is wired in.

## What Changed

- Added the stable `secret_auth_storage` feature, enabled by default on
Windows and disabled by default elsewhere.
- Added `AuthKeyringBackendKind` and config resolution for full and
bootstrap config loading.
- Applied managed feature requirements when resolving the bootstrap auth
backend.
- Updated the generated config schema and added focused tests.

This is the base PR for #17931. The auth, secrets, MCP, CLI, TUI, and
app-server implementation remains in that follow-up PR.

## Validation

- `just test -p codex-features`
- `just test -p codex-config`
- `just test -p codex-core
resolve_bootstrap_auth_keyring_backend_kind_uses_secret_auth_storage_feature`
- `just write-config-schema`
- `just fix -p codex-core`

The full `just test -p codex-core` run compiled successfully and ran
2,690 tests; 2,589 passed, one was flaky, and 101 environment-sensitive
tests failed because this shell injects a `pyenv` rehash warning into
command output or because sandboxed subprocesses timed out.
Base automatically changed from codex/secret-auth-storage-config to main June 12, 2026 19:15
@celia-oai

Copy link
Copy Markdown
Contributor

this has been merged with the PR stack ending in #27541.

@celia-oai celia-oai closed this Jun 12, 2026
celia-oai added a commit that referenced this pull request Jun 12, 2026
## Summary

- store MCP OAuth credentials in the configured auth credential backend
- support encrypted-local OAuth storage, including legacy keyring
migration
- propagate the credential backend through MCP refresh, session, CLI,
and app-server paths

## Stack

1. #27504 — config and feature flag
2. #27535 — auth-specific secret namespaces
3. #27539 — encrypted CLI auth storage
4. this PR — encrypted MCP OAuth storage

This is a parallel review stack; the original #17931 remains unchanged.

## Tests

- `just test -p codex-rmcp-client` (the transport round-trip test passed
after building the required `codex` binary and retrying)
- `just test -p codex-mcp`
- `just test -p codex-app-server
refresh_config_uses_latest_auth_keyring_backend`
- `just test -p codex-core
refresh_mcp_servers_is_deferred_until_next_turn`
- `just test -p codex-cli mcp`
- `just fix -p codex-rmcp-client -p codex-mcp -p codex-core -p codex-cli
-p codex-app-server -p codex-protocol`
- `just bazel-lock-check`
wangjiecloud pushed a commit to wangjiecloud/codex that referenced this pull request Jun 27, 2026
## Why

Windows Credential Manager limits generic credential blobs to 2,560
bytes. The encrypted local secrets backend avoids storing large
serialized auth payloads directly in the OS keyring, but selecting that
backend needs an independently reviewable feature/config layer before
the auth and secrets implementation is wired in.

## What Changed

- Added the stable `secret_auth_storage` feature, enabled by default on
Windows and disabled by default elsewhere.
- Added `AuthKeyringBackendKind` and config resolution for full and
bootstrap config loading.
- Applied managed feature requirements when resolving the bootstrap auth
backend.
- Updated the generated config schema and added focused tests.

This is the base PR for openai#17931. The auth, secrets, MCP, CLI, TUI, and
app-server implementation remains in that follow-up PR.

## Validation

- `just test -p codex-features`
- `just test -p codex-config`
- `just test -p codex-core
resolve_bootstrap_auth_keyring_backend_kind_uses_secret_auth_storage_feature`
- `just write-config-schema`
- `just fix -p codex-core`

The full `just test -p codex-core` run compiled successfully and ran
2,690 tests; 2,589 passed, one was flaky, and 101 environment-sensitive
tests failed because this shell injects a `pyenv` rehash warning into
command output or because sandboxed subprocesses timed out.
wangjiecloud pushed a commit to wangjiecloud/codex that referenced this pull request Jun 27, 2026
## Summary

- store MCP OAuth credentials in the configured auth credential backend
- support encrypted-local OAuth storage, including legacy keyring
migration
- propagate the credential backend through MCP refresh, session, CLI,
and app-server paths

## Stack

1. openai#27504 — config and feature flag
2. openai#27535 — auth-specific secret namespaces
3. openai#27539 — encrypted CLI auth storage
4. this PR — encrypted MCP OAuth storage

This is a parallel review stack; the original openai#17931 remains unchanged.

## Tests

- `just test -p codex-rmcp-client` (the transport round-trip test passed
after building the required `codex` binary and retrying)
- `just test -p codex-mcp`
- `just test -p codex-app-server
refresh_config_uses_latest_auth_keyring_backend`
- `just test -p codex-core
refresh_mcp_servers_is_deferred_until_next_turn`
- `just test -p codex-cli mcp`
- `just fix -p codex-rmcp-client -p codex-mcp -p codex-core -p codex-cli
-p codex-app-server -p codex-protocol`
- `just bazel-lock-check`
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.

OAuth tokens too long for Windows keyring

4 participants