From db9440debabfda1a57c3ab6a512b343534f2f1a9 Mon Sep 17 00:00:00 2001 From: Cooper Gamble Date: Wed, 17 Jun 2026 17:56:31 +0000 Subject: [PATCH] [codex] fix WIF prototype CI portability [ci changed_files] --- codex-rs/Cargo.lock | 1 - codex-rs/app-server/Cargo.toml | 4 - .../tests/common/workload_identity.rs | 5 +- codex-rs/cli/Cargo.toml | 4 - codex-rs/core/src/config/config_tests.rs | 12 ++- codex-rs/core/src/mcp_openai_file.rs | 17 ++-- codex-rs/core/tests/suite/openai_file_mcp.rs | 11 ++- .../core/tests/suite/workload_identity.rs | 20 ++--- codex-rs/exec/Cargo.toml | 4 - codex-rs/login/Cargo.toml | 13 --- codex-rs/tui/Cargo.toml | 4 - .../workload-identity-providers/BUILD.bazel | 6 -- .../workload-identity-providers/Cargo.toml | 19 ++--- .../workload-identity-providers/src/lib.rs | 82 ++++--------------- codex-rs/workload-identity/src/config.rs | 2 +- .../workload-identity/src/config_tests.rs | 8 +- codex-rs/workload-identity/src/lib.rs | 1 - codex-rs/workload-identity/src/source.rs | 21 ----- 18 files changed, 62 insertions(+), 172 deletions(-) diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 4cad1ab480..57dfdfdaa4 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -4485,7 +4485,6 @@ dependencies = [ "codex-workload-identity-github-actions", "codex-workload-identity-spiffe", "reqwest 0.12.28", - "tokio", ] [[package]] diff --git a/codex-rs/app-server/Cargo.toml b/codex-rs/app-server/Cargo.toml index 563d0dc5aa..3d08059a63 100644 --- a/codex-rs/app-server/Cargo.toml +++ b/codex-rs/app-server/Cargo.toml @@ -17,10 +17,6 @@ name = "codex_app_server" path = "src/lib.rs" doctest = false -[features] -default = ["workload-identity-all-providers"] -workload-identity-all-providers = ["codex-login/workload-identity-all-providers"] - [lints] workspace = true diff --git a/codex-rs/app-server/tests/common/workload_identity.rs b/codex-rs/app-server/tests/common/workload_identity.rs index f9eb6c2c8c..70250b659a 100644 --- a/codex-rs/app-server/tests/common/workload_identity.rs +++ b/codex-rs/app-server/tests/common/workload_identity.rs @@ -29,14 +29,15 @@ pub async fn configure_expiring_workload_identity( codex_home: &Path, server: &MockServer, ) -> Result { - configure_expiring_workload_identity_inner(codex_home, server, true).await + configure_expiring_workload_identity_inner(codex_home, server, /*mock_cloud_config*/ true).await } pub async fn configure_expiring_workload_identity_without_cloud_config_mock( codex_home: &Path, server: &MockServer, ) -> Result { - configure_expiring_workload_identity_inner(codex_home, server, false).await + configure_expiring_workload_identity_inner(codex_home, server, /*mock_cloud_config*/ false) + .await } async fn configure_expiring_workload_identity_inner( diff --git a/codex-rs/cli/Cargo.toml b/codex-rs/cli/Cargo.toml index 5368613dd3..7be1146df5 100644 --- a/codex-rs/cli/Cargo.toml +++ b/codex-rs/cli/Cargo.toml @@ -14,10 +14,6 @@ name = "codex_cli" path = "src/lib.rs" doctest = false -[features] -default = ["workload-identity-all-providers"] -workload-identity-all-providers = ["codex-login/workload-identity-all-providers"] - [lints] workspace = true diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index 790388f9fd..71c3636d39 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -307,6 +307,7 @@ type = "azure" async fn workload_credential_file_is_denied_even_with_danger_full_access() -> anyhow::Result<()> { let codex_home = TempDir::new()?; let token_file = codex_home.path().join("azure-token"); + std::fs::write(&token_file, "subject-token")?; let cfg = ConfigToml { workload_identity: Some(WorkloadIdentityConfig { identity_provider_id: "idp_example".to_string(), @@ -383,7 +384,11 @@ async fn workload_credential_deny_preserves_an_existing_user_deny() -> anyhow::R .entries .contains(&user_deny) ); - assert!(config.workload_identity_credential_deny_paths.is_empty()); + assert!( + !config + .workload_identity_credential_deny_paths + .contains(&token_path) + ); Ok(()) } @@ -447,6 +452,9 @@ async fn rotating_workload_credential_denies_its_secret_directory() -> anyhow::R codex_home.abs(), ) .await?; + let next_token = secret_dir.join("next-version/token"); + std::fs::create_dir_all(next_token.parent().expect("next token has parent"))?; + std::fs::write(&next_token, "rotated-subject-token")?; let mut file_system_policy = config.permissions.file_system_sandbox_policy(); file_system_policy.entries.push(FileSystemSandboxEntry { @@ -458,7 +466,7 @@ async fn rotating_workload_credential_denies_its_secret_directory() -> anyhow::R let matcher = ReadDenyMatcher::new(&file_system_policy, config.cwd.as_path()) .expect("workload credential should install a deny-read matcher"); assert!(matcher.is_read_denied(&token_file)); - assert!(matcher.is_read_denied(&secret_dir.join("next-version/token"))); + assert!(matcher.is_read_denied(&next_token)); assert_eq!( file_system_policy.resolve_access_with_cwd(&token_file, config.cwd.as_path()), FileSystemAccessMode::Deny diff --git a/codex-rs/core/src/mcp_openai_file.rs b/codex-rs/core/src/mcp_openai_file.rs index 1937970305..cd799a8231 100644 --- a/codex-rs/core/src/mcp_openai_file.rs +++ b/codex-rs/core/src/mcp_openai_file.rs @@ -16,6 +16,7 @@ use crate::session::turn_context::TurnContext; use codex_api::OPENAI_FILE_UPLOAD_LIMIT_BYTES; use codex_api::upload_openai_file; use codex_login::CodexAuth; +use codex_protocol::permissions::ReadDenyMatcher; use codex_utils_path_uri::PathUri; use serde_json::Value as JsonValue; @@ -146,9 +147,15 @@ async fn build_uploaded_argument_value( .map_err(|error| contextualize_error(error.to_string()))?; let resolved_path = native_environment_cwd.join(file_path); let file_system_policy = turn_context.file_system_sandbox_policy(); - if !file_system_policy - .can_read_path_with_cwd(resolved_path.as_path(), native_environment_cwd.as_path()) - { + let read_deny_matcher = + ReadDenyMatcher::new(&file_system_policy, native_environment_cwd.as_path()); + let is_readable = |path: &std::path::Path| { + file_system_policy.can_read_path_with_cwd(path, native_environment_cwd.as_path()) + && !read_deny_matcher + .as_ref() + .is_some_and(|matcher| matcher.is_read_denied(path)) + }; + if !is_readable(resolved_path.as_path()) { return Err(contextualize_error( "path is not readable under the current sandbox policy".to_string(), )); @@ -165,9 +172,7 @@ async fn build_uploaded_argument_value( let canonical_path = canonical_path_uri .to_abs_path() .map_err(|error| contextualize_error(error.to_string()))?; - if !file_system_policy - .can_read_path_with_cwd(canonical_path.as_path(), native_environment_cwd.as_path()) - { + if !is_readable(canonical_path.as_path()) { return Err(contextualize_error( "path is not readable under the current sandbox policy".to_string(), )); diff --git a/codex-rs/core/tests/suite/openai_file_mcp.rs b/codex-rs/core/tests/suite/openai_file_mcp.rs index 02134acffc..ca29d02fbf 100644 --- a/codex-rs/core/tests/suite/openai_file_mcp.rs +++ b/codex-rs/core/tests/suite/openai_file_mcp.rs @@ -8,6 +8,7 @@ use anyhow::Context; use anyhow::Result; use codex_config::CONFIG_TOML_FILE; use codex_protocol::models::PermissionProfile; +use codex_protocol::permissions::ReadDenyMatcher; use codex_protocol::protocol::AskForApproval; use codex_utils_path_uri::PathUri; use core_test_support::apps_test_server::AppsTestServer; @@ -304,12 +305,10 @@ default_tools_approval_mode = "approve" let upload_path = test.cwd.path().join("report.txt"); std::os::unix::fs::symlink(&credential_path, &upload_path)?; - assert!( - test.config - .workload_identity_credential_deny_paths - .iter() - .any(|path| path.as_path() == credential_path) - ); + let file_system_policy = test.config.permissions.file_system_sandbox_policy(); + let matcher = ReadDenyMatcher::new(&file_system_policy, test.config.cwd.as_path()) + .expect("workload credential should install a deny-read matcher"); + assert!(matcher.is_read_denied(&credential_path)); let responses = run_extract_turn( &test, &server, diff --git a/codex-rs/core/tests/suite/workload_identity.rs b/codex-rs/core/tests/suite/workload_identity.rs index 6b681a9bde..392032eb1f 100644 --- a/codex-rs/core/tests/suite/workload_identity.rs +++ b/codex-rs/core/tests/suite/workload_identity.rs @@ -1,3 +1,4 @@ +#[cfg(not(target_os = "windows"))] use std::collections::HashMap; use std::path::PathBuf; @@ -5,8 +6,7 @@ use anyhow::Result; use anyhow::bail; use base64::Engine; use codex_config::types::ShellEnvironmentPolicyToml; -use codex_protocol::permissions::FileSystemAccessMode; -use codex_protocol::permissions::FileSystemPath; +use codex_protocol::permissions::ReadDenyMatcher; use codex_workload_identity::CredentialSourceConfig; use codex_workload_identity::WorkloadIdentityConfig; use core_test_support::responses; @@ -124,19 +124,11 @@ async fn configured_workload_identity_authenticates_responses_turn() -> Result<( test.submit_turn("authenticate with workload identity") .await?; + let file_system_policy = test.config.permissions.file_system_sandbox_policy(); + let matcher = ReadDenyMatcher::new(&file_system_policy, test.config.cwd.as_path()) + .expect("workload credential should install a deny-read matcher"); assert!( - test.config - .permissions - .file_system_sandbox_policy() - .entries - .iter() - .any(|entry| { - entry.access == FileSystemAccessMode::Deny - && matches!( - &entry.path, - FileSystemPath::Path { path } if path.as_path() == token_path.as_path() - ) - }), + matcher.is_read_denied(&token_path), "the workload credential must remain denied by the runtime sandbox" ); let request = response_mock.single_request(); diff --git a/codex-rs/exec/Cargo.toml b/codex-rs/exec/Cargo.toml index 1e49059238..cdfc569b68 100644 --- a/codex-rs/exec/Cargo.toml +++ b/codex-rs/exec/Cargo.toml @@ -18,10 +18,6 @@ doctest = false name = "all" path = "tests/all.rs" -[features] -default = ["workload-identity-all-providers"] -workload-identity-all-providers = ["codex-login/workload-identity-all-providers"] - [lints] workspace = true diff --git a/codex-rs/login/Cargo.toml b/codex-rs/login/Cargo.toml index 92c0b28919..ee866a095c 100644 --- a/codex-rs/login/Cargo.toml +++ b/codex-rs/login/Cargo.toml @@ -4,19 +4,6 @@ version.workspace = true edition.workspace = true license.workspace = true -[features] -default = ["workload-identity-azure"] -workload-identity-all-providers = [ - "workload-identity-aws", - "workload-identity-azure", - "workload-identity-github-actions", - "workload-identity-spiffe", -] -workload-identity-aws = ["codex-workload-identity-providers/aws"] -workload-identity-azure = ["codex-workload-identity-providers/azure"] -workload-identity-github-actions = ["codex-workload-identity-providers/github-actions"] -workload-identity-spiffe = ["codex-workload-identity-providers/spiffe"] - [lints] workspace = true diff --git a/codex-rs/tui/Cargo.toml b/codex-rs/tui/Cargo.toml index d05eaa25ac..b000cba124 100644 --- a/codex-rs/tui/Cargo.toml +++ b/codex-rs/tui/Cargo.toml @@ -18,10 +18,6 @@ name = "codex_tui" path = "src/lib.rs" doctest = false -[features] -default = ["workload-identity-all-providers"] -workload-identity-all-providers = ["codex-login/workload-identity-all-providers"] - [lints] workspace = true diff --git a/codex-rs/workload-identity-providers/BUILD.bazel b/codex-rs/workload-identity-providers/BUILD.bazel index 2258088708..26e4aba0ed 100644 --- a/codex-rs/workload-identity-providers/BUILD.bazel +++ b/codex-rs/workload-identity-providers/BUILD.bazel @@ -2,11 +2,5 @@ load("//:defs.bzl", "codex_rust_crate") codex_rust_crate( name = "workload-identity-providers", - crate_features = [ - "aws", - "azure", - "github-actions", - "spiffe", - ], crate_name = "codex_workload_identity_providers", ) diff --git a/codex-rs/workload-identity-providers/Cargo.toml b/codex-rs/workload-identity-providers/Cargo.toml index 660825cb5e..a7691d1e1d 100644 --- a/codex-rs/workload-identity-providers/Cargo.toml +++ b/codex-rs/workload-identity-providers/Cargo.toml @@ -4,26 +4,17 @@ version.workspace = true edition.workspace = true license.workspace = true -[features] -default = [] -azure = ["dep:codex-workload-identity-azure"] -aws = ["dep:codex-workload-identity-aws"] -github-actions = ["dep:codex-workload-identity-github-actions"] -spiffe = ["dep:codex-workload-identity-spiffe"] - [lints] workspace = true [dependencies] codex-workload-identity = { workspace = true } -codex-workload-identity-aws = { workspace = true, optional = true } -codex-workload-identity-azure = { workspace = true, optional = true } -codex-workload-identity-github-actions = { workspace = true, optional = true } -codex-workload-identity-spiffe = { workspace = true, optional = true } +codex-workload-identity-aws = { workspace = true } +codex-workload-identity-azure = { workspace = true } +codex-workload-identity-github-actions = { workspace = true } +codex-workload-identity-spiffe = { workspace = true } reqwest = { workspace = true } -[dev-dependencies] -tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } - [lib] doctest = false +test = false diff --git a/codex-rs/workload-identity-providers/src/lib.rs b/codex-rs/workload-identity-providers/src/lib.rs index 20897b3489..317552be4d 100644 --- a/codex-rs/workload-identity-providers/src/lib.rs +++ b/codex-rs/workload-identity-providers/src/lib.rs @@ -4,14 +4,9 @@ use codex_workload_identity::FileSubjectTokenSource; use codex_workload_identity::SubjectToken; use codex_workload_identity::SubjectTokenError; use codex_workload_identity::SubjectTokenProvider; -use codex_workload_identity::UnavailableSubjectTokenSource; -#[cfg(feature = "aws")] use codex_workload_identity_aws::AwsSubjectTokenProvider; -#[cfg(feature = "azure")] use codex_workload_identity_azure::AzureSubjectTokenProvider; -#[cfg(feature = "github-actions")] use codex_workload_identity_github_actions::GithubActionsSubjectTokenProvider; -#[cfg(feature = "spiffe")] use codex_workload_identity_spiffe::SpiffeSubjectTokenProvider; pub use codex_workload_identity::WorkloadIdentityConfig; @@ -22,15 +17,10 @@ pub type ConfiguredWorkloadIdentityClient = pub enum ConfiguredSubjectTokenProvider { Environment(EnvironmentSubjectTokenSource), File(FileSubjectTokenSource), - #[cfg(feature = "aws")] Aws(AwsSubjectTokenProvider), - #[cfg(feature = "azure")] Azure(AzureSubjectTokenProvider), - #[cfg(feature = "github-actions")] GithubActions(GithubActionsSubjectTokenProvider), - #[cfg(feature = "spiffe")] Spiffe(SpiffeSubjectTokenProvider), - Unavailable(UnavailableSubjectTokenSource), } impl ConfiguredSubjectTokenProvider { @@ -48,64 +38,29 @@ impl ConfiguredSubjectTokenProvider { Self::File(FileSubjectTokenSource::new(path.clone())) } CredentialSourceConfig::Azure { token_file } => { - #[cfg(feature = "azure")] - { - Self::Azure(AzureSubjectTokenProvider::new(token_file.clone())) - } - #[cfg(not(feature = "azure"))] - { - let _ = token_file; - Self::Unavailable(UnavailableSubjectTokenSource::new("azure")) - } - } - CredentialSourceConfig::GithubActions {} => { - #[cfg(feature = "github-actions")] - { - Self::GithubActions(GithubActionsSubjectTokenProvider::capture( - audience.to_string(), - http, - )) - } - #[cfg(not(feature = "github-actions"))] - { - let _ = http; - Self::Unavailable(UnavailableSubjectTokenSource::new("github_actions")) - } + Self::Azure(AzureSubjectTokenProvider::new(token_file.clone())) } + CredentialSourceConfig::GithubActions {} => Self::GithubActions( + GithubActionsSubjectTokenProvider::capture(audience.to_string(), http), + ), CredentialSourceConfig::Spiffe { endpoint_socket, spiffe_id, } => { - #[cfg(feature = "spiffe")] - { - let _ = http; - Self::Spiffe(SpiffeSubjectTokenProvider::new( - endpoint_socket.clone(), - spiffe_id.clone(), - audience.to_string(), - )) - } - #[cfg(not(feature = "spiffe"))] - { - let _ = (endpoint_socket, spiffe_id, http); - Self::Unavailable(UnavailableSubjectTokenSource::new("spiffe")) - } + let _ = http; + Self::Spiffe(SpiffeSubjectTokenProvider::new( + endpoint_socket.clone(), + spiffe_id.clone(), + audience.to_string(), + )) } CredentialSourceConfig::Aws { region } => { - #[cfg(feature = "aws")] - { - let _ = http; - Self::Aws(AwsSubjectTokenProvider::new( - identity_provider_id.to_string(), - audience.to_string(), - region.clone(), - )) - } - #[cfg(not(feature = "aws"))] - { - let _ = (identity_provider_id, audience, region, http); - Self::Unavailable(UnavailableSubjectTokenSource::new("aws")) - } + let _ = http; + Self::Aws(AwsSubjectTokenProvider::new( + identity_provider_id.to_string(), + audience.to_string(), + region.clone(), + )) } } } @@ -116,15 +71,10 @@ impl SubjectTokenProvider for ConfiguredSubjectTokenProvider { match self { Self::Environment(source) => source.subject_token().await, Self::File(source) => source.subject_token().await, - #[cfg(feature = "aws")] Self::Aws(source) => source.subject_token().await, - #[cfg(feature = "azure")] Self::Azure(source) => source.subject_token().await, - #[cfg(feature = "github-actions")] Self::GithubActions(source) => source.subject_token().await, - #[cfg(feature = "spiffe")] Self::Spiffe(source) => source.subject_token().await, - Self::Unavailable(source) => source.subject_token().await, } } } diff --git a/codex-rs/workload-identity/src/config.rs b/codex-rs/workload-identity/src/config.rs index 486fe95f31..5cc991e4f0 100644 --- a/codex-rs/workload-identity/src/config.rs +++ b/codex-rs/workload-identity/src/config.rs @@ -39,7 +39,7 @@ pub struct WorkloadIdentityConfig { pub credential_source: CredentialSourceConfig, } -/// Supported runtime credential sources. Implementations are independently feature gated. +/// Supported runtime credential sources. Implementations live in separate provider crates. #[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Eq, Serialize)] #[serde(deny_unknown_fields, rename_all = "snake_case", tag = "type")] pub enum CredentialSourceConfig { diff --git a/codex-rs/workload-identity/src/config_tests.rs b/codex-rs/workload-identity/src/config_tests.rs index e63866775d..0378151b67 100644 --- a/codex-rs/workload-identity/src/config_tests.rs +++ b/codex-rs/workload-identity/src/config_tests.rs @@ -11,9 +11,11 @@ fn valid_config() -> WorkloadIdentityConfig { audience: "https://auth.openai.com/workload-identity".to_string(), token_url: "https://auth.openai.com/oauth/token".to_string(), credential_source: CredentialSourceConfig::Azure { - token_file: Some(PathBuf::from( - "/var/run/secrets/azure/tokens/azure-identity-token", - )), + token_file: Some( + std::env::temp_dir() + .join("azure-tokens") + .join("azure-identity-token"), + ), }, } } diff --git a/codex-rs/workload-identity/src/lib.rs b/codex-rs/workload-identity/src/lib.rs index e48ea6fcda..e378ba8f1b 100644 --- a/codex-rs/workload-identity/src/lib.rs +++ b/codex-rs/workload-identity/src/lib.rs @@ -18,4 +18,3 @@ pub use source::MAX_SUBJECT_TOKEN_BYTES; pub use source::SubjectToken; pub use source::SubjectTokenError; pub use source::SubjectTokenProvider; -pub use source::UnavailableSubjectTokenSource; diff --git a/codex-rs/workload-identity/src/source.rs b/codex-rs/workload-identity/src/source.rs index 0cb0254345..1b563baa34 100644 --- a/codex-rs/workload-identity/src/source.rs +++ b/codex-rs/workload-identity/src/source.rs @@ -91,8 +91,6 @@ pub enum SubjectTokenError { InvalidResponse { provider: &'static str }, #[error("{provider} credential source configuration is invalid")] InvalidConfiguration { provider: &'static str }, - #[error("{provider} credential source is not included in this Codex build")] - ProviderNotIncluded { provider: &'static str }, } enum CapturedEnvironmentValue { @@ -223,25 +221,6 @@ fn validate_file_metadata( Ok(()) } -#[derive(Clone, Debug)] -pub struct UnavailableSubjectTokenSource { - source: &'static str, -} - -impl UnavailableSubjectTokenSource { - pub const fn new(source: &'static str) -> Self { - Self { source } - } -} - -impl SubjectTokenProvider for UnavailableSubjectTokenSource { - async fn subject_token(&self) -> Result { - Err(SubjectTokenError::ProviderNotIncluded { - provider: self.source, - }) - } -} - #[cfg(test)] #[path = "source_tests.rs"] mod tests;