Use keyring as default CLI auth store on macOS

This commit is contained in:
mikhail-oai
2026-02-15 18:47:58 -05:00
parent 85034b189e
commit 0b74e4093e
3 changed files with 26 additions and 12 deletions

View File

@@ -1283,7 +1283,7 @@
}
],
"default": null,
"description": "Preferred backend for storing CLI auth credentials. file (default): Use a file in the Codex home directory. keyring: Use an OS-specific keyring service. auto: Use the keyring if available, otherwise use a file."
"description": "Preferred backend for storing CLI auth credentials. file (default on non-macOS): Use a file in the Codex home directory. keyring (default on macOS): Use an OS-specific keyring service. auto: Use the keyring if available, otherwise use a file."
},
"compact_prompt": {
"description": "Compact prompt used for history compaction.",

View File

@@ -26,10 +26,9 @@ use codex_keyring_store::KeyringStore;
use once_cell::sync::Lazy;
/// Determine where Codex should store CLI auth credentials.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum AuthCredentialsStoreMode {
#[default]
/// Persist credentials in CODEX_HOME/auth.json.
File,
/// Persist credentials in the keyring. Fail if unavailable.
@@ -40,6 +39,19 @@ pub enum AuthCredentialsStoreMode {
Ephemeral,
}
impl Default for AuthCredentialsStoreMode {
fn default() -> Self {
#[cfg(target_os = "macos")]
{
Self::Keyring
}
#[cfg(not(target_os = "macos"))]
{
Self::File
}
}
}
/// Expected structure for $CODEX_HOME/auth.json.
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
pub struct AuthDotJson {

View File

@@ -261,8 +261,8 @@ pub struct Config {
pub cwd: PathBuf,
/// Preferred store for CLI auth credentials.
/// file (default): Use a file in the Codex home directory.
/// keyring: Use an OS-specific keyring service.
/// file (default on non-macOS): Use a file in the Codex home directory.
/// keyring (default on macOS): Use an OS-specific keyring service.
/// auto: Use the OS-specific keyring service if available, otherwise use a file.
pub cli_auth_credentials_store_mode: AuthCredentialsStoreMode,
@@ -923,8 +923,8 @@ pub struct ConfigToml {
pub forced_login_method: Option<ForcedLoginMethod>,
/// Preferred backend for storing CLI auth credentials.
/// file (default): Use a file in the Codex home directory.
/// keyring: Use an OS-specific keyring service.
/// file (default on non-macOS): Use a file in the Codex home directory.
/// keyring (default on macOS): Use an OS-specific keyring service.
/// auto: Use the keyring if available, otherwise use a file.
#[serde(default)]
pub cli_auth_credentials_store: Option<AuthCredentialsStoreMode>,
@@ -2465,9 +2465,14 @@ trust_level = "trusted"
}
#[test]
fn config_defaults_to_file_cli_auth_store_mode() -> std::io::Result<()> {
fn config_defaults_to_platform_cli_auth_store_mode() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
let cfg = ConfigToml::default();
let expected_store_mode = if cfg!(target_os = "macos") {
AuthCredentialsStoreMode::Keyring
} else {
AuthCredentialsStoreMode::File
};
let config = Config::load_from_base_config_with_overrides(
cfg,
@@ -2475,10 +2480,7 @@ trust_level = "trusted"
codex_home.path().to_path_buf(),
)?;
assert_eq!(
config.cli_auth_credentials_store_mode,
AuthCredentialsStoreMode::File,
);
assert_eq!(config.cli_auth_credentials_store_mode, expected_store_mode,);
Ok(())
}