mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Add secret auth storage config
This commit is contained in:
@@ -588,6 +588,9 @@
|
||||
"search_tool": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"secret_auth_storage": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"shell_snapshot": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -4720,6 +4723,9 @@
|
||||
"search_tool": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"secret_auth_storage": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"shell_snapshot": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -6,8 +6,13 @@ use crate::config::edit::apply_blocking;
|
||||
use assert_matches::assert_matches;
|
||||
use codex_config::CONFIG_TOML_FILE;
|
||||
use codex_config::ConfigLayerEntry;
|
||||
use codex_config::ConfigLayerStack;
|
||||
use codex_config::ConfigRequirements;
|
||||
use codex_config::ConfigRequirementsToml;
|
||||
use codex_config::FeatureRequirementsToml;
|
||||
use codex_config::ProfileV2Name;
|
||||
use codex_config::RequirementSource;
|
||||
use codex_config::Sourced;
|
||||
use codex_config::config_toml::AgentRoleToml;
|
||||
use codex_config::config_toml::AgentsToml;
|
||||
use codex_config::config_toml::AutoReviewToml;
|
||||
@@ -34,6 +39,7 @@ use codex_config::permissions_toml::PermissionsToml;
|
||||
use codex_config::permissions_toml::WorkspaceRootsToml;
|
||||
use codex_config::types::AppToolApproval;
|
||||
use codex_config::types::ApprovalsReviewer;
|
||||
use codex_config::types::AuthKeyringBackendKind;
|
||||
use codex_config::types::BundledSkillsConfig;
|
||||
use codex_config::types::FeedbackConfigToml;
|
||||
use codex_config::types::HistoryPersistence;
|
||||
@@ -5106,6 +5112,74 @@ async fn feature_table_overrides_legacy_flags() -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_bootstrap_auth_keyring_backend_kind_uses_secret_auth_storage_feature()
|
||||
-> std::io::Result<()> {
|
||||
let config_toml = ConfigToml {
|
||||
features: Some(FeaturesToml::from(BTreeMap::from([(
|
||||
"secret_auth_storage".to_string(),
|
||||
true,
|
||||
)]))),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
resolve_bootstrap_auth_keyring_backend_kind(&config_toml_load_result(
|
||||
config_toml,
|
||||
/*feature_requirements*/ None,
|
||||
)?)?,
|
||||
AuthKeyringBackendKind::Secrets
|
||||
);
|
||||
|
||||
let config_toml = ConfigToml {
|
||||
features: Some(FeaturesToml::from(BTreeMap::from([(
|
||||
"secret_auth_storage".to_string(),
|
||||
false,
|
||||
)]))),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
resolve_bootstrap_auth_keyring_backend_kind(&config_toml_load_result(
|
||||
config_toml.clone(),
|
||||
/*feature_requirements*/ None,
|
||||
)?)?,
|
||||
AuthKeyringBackendKind::Direct
|
||||
);
|
||||
|
||||
let requirements = Sourced::new(
|
||||
FeatureRequirementsToml {
|
||||
entries: BTreeMap::from([("secret_auth_storage".to_string(), true)]),
|
||||
},
|
||||
RequirementSource::Unknown,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_bootstrap_auth_keyring_backend_kind(&config_toml_load_result(
|
||||
config_toml,
|
||||
Some(requirements),
|
||||
)?)?,
|
||||
AuthKeyringBackendKind::Secrets
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn config_toml_load_result(
|
||||
config_toml: ConfigToml,
|
||||
feature_requirements: Option<Sourced<FeatureRequirementsToml>>,
|
||||
) -> std::io::Result<ConfigTomlLoadResult> {
|
||||
let requirements = ConfigRequirements {
|
||||
feature_requirements,
|
||||
..Default::default()
|
||||
};
|
||||
Ok(ConfigTomlLoadResult {
|
||||
config_toml,
|
||||
config_layer_stack: ConfigLayerStack::new(
|
||||
Vec::new(),
|
||||
requirements,
|
||||
ConfigRequirementsToml::default(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_toggles_map_to_features() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
|
||||
@@ -38,6 +38,7 @@ use codex_config::permissions_toml::PermissionsToml;
|
||||
use codex_config::sandbox_mode_requirement_for_permission_profile;
|
||||
use codex_config::types::ApprovalsReviewer;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_config::types::AuthKeyringBackendKind;
|
||||
use codex_config::types::History;
|
||||
use codex_config::types::McpServerConfig;
|
||||
use codex_config::types::McpServerDisabledReason;
|
||||
@@ -1351,6 +1352,12 @@ impl Config {
|
||||
workspace_roots
|
||||
}
|
||||
|
||||
pub fn auth_keyring_backend_kind(&self) -> AuthKeyringBackendKind {
|
||||
auth_keyring_backend_kind_from_secret_auth_storage(
|
||||
self.features.enabled(Feature::SecretAuthStorage),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn to_models_manager_config(&self) -> ModelsManagerConfig {
|
||||
ModelsManagerConfig {
|
||||
model_context_window: self.model_context_window,
|
||||
@@ -1626,6 +1633,29 @@ pub async fn load_config_as_toml_with_cli_and_load_options(
|
||||
cli_overrides: Vec<(String, TomlValue)>,
|
||||
options: impl Into<ConfigLoadOptions>,
|
||||
) -> std::io::Result<ConfigToml> {
|
||||
load_config_toml_with_layer_stack(codex_home, cwd, cli_overrides, options)
|
||||
.await
|
||||
.map(|result| result.config_toml)
|
||||
}
|
||||
|
||||
/// Partially loaded config plus the layer stack used to derive it.
|
||||
///
|
||||
/// This is intended for startup paths that must inspect raw config before a
|
||||
/// full [`Config`] can be constructed, but still need access to managed
|
||||
/// requirements loaded with the config layers.
|
||||
pub struct ConfigTomlLoadResult {
|
||||
pub config_toml: ConfigToml,
|
||||
pub config_layer_stack: ConfigLayerStack,
|
||||
}
|
||||
|
||||
/// Loads the partially merged config together with the layer stack used to
|
||||
/// derive it, before constructing a full [`Config`].
|
||||
pub async fn load_config_toml_with_layer_stack(
|
||||
codex_home: &Path,
|
||||
cwd: Option<&AbsolutePathBuf>,
|
||||
cli_overrides: Vec<(String, TomlValue)>,
|
||||
options: impl Into<ConfigLoadOptions>,
|
||||
) -> std::io::Result<ConfigTomlLoadResult> {
|
||||
let config_layer_stack = load_config_layers_state(
|
||||
LOCAL_FS.as_ref(),
|
||||
codex_home,
|
||||
@@ -1642,7 +1672,49 @@ pub async fn load_config_as_toml_with_cli_and_load_options(
|
||||
e
|
||||
})?;
|
||||
|
||||
Ok(cfg)
|
||||
Ok(ConfigTomlLoadResult {
|
||||
config_toml: cfg,
|
||||
config_layer_stack,
|
||||
})
|
||||
}
|
||||
|
||||
/// Resolve the auth keyring backend from a partially loaded bootstrap config.
|
||||
///
|
||||
/// This is intended for startup paths that must read auth before managed cloud
|
||||
/// requirements can be loaded and before a full [`Config`] exists.
|
||||
pub fn resolve_bootstrap_auth_keyring_backend_kind(
|
||||
bootstrap_config: &ConfigTomlLoadResult,
|
||||
) -> std::io::Result<AuthKeyringBackendKind> {
|
||||
let config_toml = &bootstrap_config.config_toml;
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: config_toml.features.as_ref(),
|
||||
experimental_use_unified_exec_tool: config_toml.experimental_use_unified_exec_tool,
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
let managed_features = ManagedFeatures::from_configured(
|
||||
features,
|
||||
bootstrap_config
|
||||
.config_layer_stack
|
||||
.requirements()
|
||||
.feature_requirements
|
||||
.clone(),
|
||||
)?;
|
||||
Ok(auth_keyring_backend_kind_from_secret_auth_storage(
|
||||
managed_features.enabled(Feature::SecretAuthStorage),
|
||||
))
|
||||
}
|
||||
|
||||
fn auth_keyring_backend_kind_from_secret_auth_storage(
|
||||
secret_auth_storage_enabled: bool,
|
||||
) -> AuthKeyringBackendKind {
|
||||
if secret_auth_storage_enabled {
|
||||
AuthKeyringBackendKind::Secrets
|
||||
} else {
|
||||
AuthKeyringBackendKind::Direct
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_config_toml_with_base(
|
||||
|
||||
Reference in New Issue
Block a user