mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
[codex] preserve optional auth refresh and WIF denies [ci changed_files]
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_config::CONFIG_TOML_FILE;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -16,6 +18,7 @@ use core_test_support::apps_test_server::SEARCH_CALENDAR_EXTRACT_TEXT_TOOL as DO
|
||||
use core_test_support::apps_test_server::SEARCH_CALENDAR_NAMESPACE as DOCUMENT_EXTRACT_NAMESPACE;
|
||||
use core_test_support::apps_test_server::apps_enabled_builder;
|
||||
use core_test_support::apps_test_server::recorded_apps_tool_call_by_name;
|
||||
use core_test_support::apps_test_server::recorded_apps_tool_calls;
|
||||
use core_test_support::hooks::trust_discovered_hooks;
|
||||
use core_test_support::responses::ResponseMock;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
@@ -29,6 +32,7 @@ use core_test_support::test_codex::TestCodex;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
@@ -136,8 +140,8 @@ async fn mount_file_upload_mocks(server: &MockServer, file_size_bytes: u64) {
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn run_extract_turn(test: &TestCodex, server: &MockServer) -> Result<ResponseMock> {
|
||||
let mock = mount_sse_sequence(
|
||||
async fn mount_extract_responses(server: &MockServer) -> ResponseMock {
|
||||
mount_sse_sequence(
|
||||
server,
|
||||
vec![
|
||||
sse(vec![
|
||||
@@ -157,12 +161,20 @@ async fn run_extract_turn(test: &TestCodex, server: &MockServer) -> Result<Respo
|
||||
]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
}
|
||||
|
||||
async fn run_extract_turn(
|
||||
test: &TestCodex,
|
||||
server: &MockServer,
|
||||
permission_profile: PermissionProfile,
|
||||
) -> Result<ResponseMock> {
|
||||
let mock = mount_extract_responses(server).await;
|
||||
|
||||
test.submit_turn_with_approval_and_permission_profile(
|
||||
"Extract the report text with the app tool.",
|
||||
AskForApproval::Never,
|
||||
PermissionProfile::Disabled,
|
||||
permission_profile,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -187,7 +199,7 @@ async fn codex_apps_file_params_upload_environment_files_before_mcp_tool_call()
|
||||
Ok(())
|
||||
});
|
||||
let test = builder.build_with_remote_env(&server).await?;
|
||||
let mock = run_extract_turn(&test, &server).await?;
|
||||
let mock = run_extract_turn(&test, &server, PermissionProfile::Disabled).await?;
|
||||
|
||||
let requests = mock.requests();
|
||||
let body = requests[0].body_json();
|
||||
@@ -243,7 +255,7 @@ async fn codex_apps_file_params_pass_uploaded_file_to_post_tool_use_hook() -> Re
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
tokio::fs::write(test.cwd.path().join("report.txt"), b"hello world").await?;
|
||||
let _responses = run_extract_turn(&test, &server).await?;
|
||||
let _responses = run_extract_turn(&test, &server, PermissionProfile::Disabled).await?;
|
||||
|
||||
let hook_inputs = read_post_tool_use_hook_inputs(test.codex_home_path())?;
|
||||
assert_eq!(hook_inputs.len(), 1);
|
||||
@@ -255,3 +267,78 @@ async fn codex_apps_file_params_pass_uploaded_file_to_post_tool_use_hook() -> Re
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn codex_apps_file_params_reject_wif_credential_symlink_before_upload() -> Result<()> {
|
||||
let server = start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount(&server).await?;
|
||||
let home = Arc::new(TempDir::new()?);
|
||||
let credential_path = home.path().join("subject-token");
|
||||
let credential_contents = "external.subject.token.must-not-leak";
|
||||
fs::write(&credential_path, credential_contents)?;
|
||||
|
||||
let credential_path_for_config = credential_path.clone();
|
||||
let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url.clone())
|
||||
.with_home(Arc::clone(&home))
|
||||
.with_pre_build_hook(move |home| {
|
||||
let config = format!(
|
||||
r#"[workload_identity]
|
||||
identity_provider_id = "idp_example"
|
||||
identity_provider_mapping_id = "idpm_example"
|
||||
audience = "openai-audience"
|
||||
token_url = "https://auth.openai.com/oauth/token"
|
||||
|
||||
[workload_identity.credential_source]
|
||||
type = "file"
|
||||
path = "{}"
|
||||
|
||||
[apps.calendar]
|
||||
default_tools_approval_mode = "approve"
|
||||
"#,
|
||||
credential_path_for_config.display()
|
||||
);
|
||||
fs::write(home.join(CONFIG_TOML_FILE), config).expect("write workload identity config");
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
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 responses = run_extract_turn(
|
||||
&test,
|
||||
&server,
|
||||
test.config.permissions.permission_profile().clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let output = responses
|
||||
.function_call_output_text("extract-call-1")
|
||||
.context("Apps file tool failure should be returned to the model")?;
|
||||
assert!(output.contains("path is not readable under the current sandbox policy"));
|
||||
assert!(!output.contains(credential_contents));
|
||||
assert!(!output.contains(credential_path.to_string_lossy().as_ref()));
|
||||
assert_eq!(recorded_apps_tool_calls(&server).await, Vec::<Value>::new());
|
||||
|
||||
let upload_requests = server
|
||||
.received_requests()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter(|request| {
|
||||
matches!(
|
||||
request.url.path(),
|
||||
"/files" | "/upload/file_123" | "/files/file_123/uploaded"
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert!(upload_requests.is_empty(), "unexpected file upload request");
|
||||
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user