[codex] fix WIF prototype CI portability [ci changed_files]

This commit is contained in:
Cooper Gamble
2026-06-17 17:56:31 +00:00
parent db71258c57
commit db9440deba
18 changed files with 62 additions and 172 deletions
-1
View File
@@ -4485,7 +4485,6 @@ dependencies = [
"codex-workload-identity-github-actions",
"codex-workload-identity-spiffe",
"reqwest 0.12.28",
"tokio",
]
[[package]]
-4
View File
@@ -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
@@ -29,14 +29,15 @@ pub async fn configure_expiring_workload_identity(
codex_home: &Path,
server: &MockServer,
) -> Result<ExpiringWorkloadIdentityFixture> {
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<ExpiringWorkloadIdentityFixture> {
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(
-4
View File
@@ -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
+10 -2
View File
@@ -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
+11 -6
View File
@@ -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(),
));
+5 -6
View File
@@ -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,
+6 -14
View File
@@ -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();
-4
View File
@@ -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
-13
View File
@@ -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
-4
View File
@@ -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
@@ -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",
)
@@ -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
+16 -66
View File
@@ -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,
}
}
}
+1 -1
View File
@@ -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 {
@@ -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"),
),
},
}
}
-1
View File
@@ -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;
-21
View File
@@ -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<SubjectToken, SubjectTokenError> {
Err(SubjectTokenError::ProviderNotIncluded {
provider: self.source,
})
}
}
#[cfg(test)]
#[path = "source_tests.rs"]
mod tests;