mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
## Why `item/permissions/requestApproval` sends a requested permission profile to app-server clients. The core profile already stores filesystem permissions as `entries`, but the v2 compatibility conversion used the legacy `read`/`write` projection whenever possible and left `entries` unset. That made the request ambiguous for clients that consume the canonical v2 shape: `permissions.fileSystem.entries` was missing even though filesystem access was being requested. A client that rendered or echoed grants from `entries` could treat the request as having no filesystem permission entries, then return an empty or incomplete grant. The app-server intersects responses with the original request, so omitted filesystem permissions are denied. ## What Changed - Populate `AdditionalFileSystemPermissions.entries` when converting legacy read/write roots for request permission payloads, while preserving `read` and `write` for compatibility. - Mark `read` and `write` as transitional schema fields in the generated app-server schema. - Add regression coverage for the v2 conversion, the app-server `item/permissions/requestApproval` round trip, and TUI app-server approval conversion expectations. - Refresh generated JSON and TypeScript schema fixtures. ## Verification - `just fmt` - `cargo test -p codex-app-server-protocol` - `cargo test -p codex-app-server request_permissions_round_trip` - `cargo test -p codex-tui converts_request_permissions_into_granted_permissions` - `cargo test -p codex-tui resolves_permissions_and_user_input_through_app_server_request_id`
147 lines
6.2 KiB
Rust
147 lines
6.2 KiB
Rust
use codex_app_server_protocol::AdditionalNetworkPermissions;
|
|
use codex_app_server_protocol::GrantedPermissionProfile;
|
|
use codex_app_server_protocol::NetworkApprovalContext as AppServerNetworkApprovalContext;
|
|
use codex_protocol::protocol::NetworkApprovalContext;
|
|
use codex_protocol::protocol::NetworkApprovalProtocol;
|
|
use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestPermissionProfile;
|
|
|
|
pub(crate) fn network_approval_context_to_core(
|
|
value: AppServerNetworkApprovalContext,
|
|
) -> NetworkApprovalContext {
|
|
NetworkApprovalContext {
|
|
host: value.host,
|
|
protocol: match value.protocol {
|
|
codex_app_server_protocol::NetworkApprovalProtocol::Http => {
|
|
NetworkApprovalProtocol::Http
|
|
}
|
|
codex_app_server_protocol::NetworkApprovalProtocol::Https => {
|
|
NetworkApprovalProtocol::Https
|
|
}
|
|
codex_app_server_protocol::NetworkApprovalProtocol::Socks5Tcp => {
|
|
NetworkApprovalProtocol::Socks5Tcp
|
|
}
|
|
codex_app_server_protocol::NetworkApprovalProtocol::Socks5Udp => {
|
|
NetworkApprovalProtocol::Socks5Udp
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
pub(crate) fn granted_permission_profile_from_request(
|
|
value: CoreRequestPermissionProfile,
|
|
) -> GrantedPermissionProfile {
|
|
GrantedPermissionProfile {
|
|
network: value.network.map(|network| AdditionalNetworkPermissions {
|
|
enabled: network.enabled,
|
|
}),
|
|
file_system: value.file_system.map(Into::into),
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::granted_permission_profile_from_request;
|
|
use super::network_approval_context_to_core;
|
|
use codex_protocol::models::FileSystemPermissions;
|
|
use codex_protocol::models::NetworkPermissions;
|
|
use codex_protocol::permissions::FileSystemAccessMode;
|
|
use codex_protocol::permissions::FileSystemPath;
|
|
use codex_protocol::permissions::FileSystemSandboxEntry;
|
|
use codex_protocol::permissions::FileSystemSpecialPath;
|
|
use codex_protocol::protocol::NetworkApprovalContext;
|
|
use codex_protocol::protocol::NetworkApprovalProtocol;
|
|
use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestPermissionProfile;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use pretty_assertions::assert_eq;
|
|
use std::path::PathBuf;
|
|
|
|
fn absolute_path(path: &str) -> AbsolutePathBuf {
|
|
AbsolutePathBuf::try_from(PathBuf::from(path)).expect("path must be absolute")
|
|
}
|
|
|
|
#[test]
|
|
fn converts_app_server_network_approval_context_to_core() {
|
|
assert_eq!(
|
|
network_approval_context_to_core(codex_app_server_protocol::NetworkApprovalContext {
|
|
host: "example.com".to_string(),
|
|
protocol: codex_app_server_protocol::NetworkApprovalProtocol::Socks5Tcp,
|
|
}),
|
|
NetworkApprovalContext {
|
|
host: "example.com".to_string(),
|
|
protocol: NetworkApprovalProtocol::Socks5Tcp,
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn converts_request_permissions_into_granted_permissions() {
|
|
assert_eq!(
|
|
granted_permission_profile_from_request(CoreRequestPermissionProfile {
|
|
network: Some(NetworkPermissions {
|
|
enabled: Some(true),
|
|
}),
|
|
file_system: Some(FileSystemPermissions::from_read_write_roots(
|
|
Some(vec![absolute_path("/tmp/read-only")]),
|
|
Some(vec![absolute_path("/tmp/write")]),
|
|
)),
|
|
}),
|
|
codex_app_server_protocol::GrantedPermissionProfile {
|
|
network: Some(codex_app_server_protocol::AdditionalNetworkPermissions {
|
|
enabled: Some(true),
|
|
}),
|
|
file_system: Some(codex_app_server_protocol::AdditionalFileSystemPermissions {
|
|
read: Some(vec![absolute_path("/tmp/read-only")]),
|
|
write: Some(vec![absolute_path("/tmp/write")]),
|
|
glob_scan_max_depth: None,
|
|
entries: Some(vec![
|
|
codex_app_server_protocol::FileSystemSandboxEntry {
|
|
path: codex_app_server_protocol::FileSystemPath::Path {
|
|
path: absolute_path("/tmp/read-only"),
|
|
},
|
|
access: codex_app_server_protocol::FileSystemAccessMode::Read,
|
|
},
|
|
codex_app_server_protocol::FileSystemSandboxEntry {
|
|
path: codex_app_server_protocol::FileSystemPath::Path {
|
|
path: absolute_path("/tmp/write"),
|
|
},
|
|
access: codex_app_server_protocol::FileSystemAccessMode::Write,
|
|
},
|
|
]),
|
|
}),
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn converts_request_permissions_into_canonical_granted_permissions() {
|
|
assert_eq!(
|
|
granted_permission_profile_from_request(CoreRequestPermissionProfile {
|
|
file_system: Some(FileSystemPermissions {
|
|
entries: vec![FileSystemSandboxEntry {
|
|
path: FileSystemPath::Special {
|
|
value: FileSystemSpecialPath::Root,
|
|
},
|
|
access: FileSystemAccessMode::Write,
|
|
}],
|
|
glob_scan_max_depth: None,
|
|
}),
|
|
..Default::default()
|
|
}),
|
|
codex_app_server_protocol::GrantedPermissionProfile {
|
|
network: None,
|
|
file_system: Some(codex_app_server_protocol::AdditionalFileSystemPermissions {
|
|
read: None,
|
|
write: None,
|
|
glob_scan_max_depth: None,
|
|
entries: Some(vec![codex_app_server_protocol::FileSystemSandboxEntry {
|
|
path: codex_app_server_protocol::FileSystemPath::Special {
|
|
value: codex_app_server_protocol::FileSystemSpecialPath::Root,
|
|
},
|
|
access: codex_app_server_protocol::FileSystemAccessMode::Write,
|
|
},]),
|
|
}),
|
|
}
|
|
);
|
|
}
|
|
}
|