mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
feat(app-server): enforce managed remote control disable (#27961)
## Why Managed deployments need a reliable deny gate for remote control. Persisted enablement and explicit startup requests currently remain able to start the transport, while the removed `features.remote_control` key is intentionally only a compatibility no-op. This adds a dedicated requirement that administrators can use to force remote control off without deleting the user's persisted preference. Removing the requirement and restarting restores the prior choice. ## What Changed - Added top-level `allow_remote_control` requirements parsing, sourced layer precedence, debug output, and `configRequirements/read` exposure as `allowRemoteControl`. - Added a typed transport policy captured from the startup requirements snapshot. Managed disable forces the initial state to disabled and prevents enrollment, refresh, connection, and persisted-preference mutation. - Rejected every `remoteControl/*` RPC before parameter deserialization with JSON-RPC `-32600` and `remote control is disabled by managed requirements`. - Preserved the existing disabled status notification and the previous behavior when the requirement is `true` or omitted. - Regenerated app-server protocol schemas and documented the new requirement. ## Verification - Confirmed all remote-control RPCs, including a malformed request, return the managed-policy error while the initial status notification remains `disabled`. - Confirmed explicit ephemeral startup and persisted enablement make no backend connection and leave the SQLite preference unchanged. - Confirmed `allow_remote_control = true` does not enable or block remote control and `configRequirements/read` returns `allowRemoteControl: false` for the deny policy. Related issue: N/A (managed-policy hardening).
This commit is contained in:
committed by
GitHub
Unverified
parent
5d7db08b61
commit
b9dc3b7a8b
@@ -32,6 +32,7 @@ use crate::outgoing_message::QueuedOutgoingMessage;
|
||||
use crate::transport::CHANNEL_CAPACITY;
|
||||
use crate::transport::ConnectionState;
|
||||
use crate::transport::OutboundConnectionState;
|
||||
use crate::transport::RemoteControlPolicy;
|
||||
use crate::transport::RemoteControlStartConfig;
|
||||
use crate::transport::TransportEvent;
|
||||
use crate::transport::acquire_app_server_startup_lock;
|
||||
@@ -672,6 +673,28 @@ pub async fn run_main_with_transport_options(
|
||||
None => error!("{}", warning.summary),
|
||||
}
|
||||
}
|
||||
let remote_control_policy = if config
|
||||
.config_layer_stack
|
||||
.requirements()
|
||||
.allow_remote_control
|
||||
.as_ref()
|
||||
.is_some_and(|requirement| !requirement.value)
|
||||
{
|
||||
RemoteControlPolicy::DisabledByRequirements
|
||||
} else {
|
||||
RemoteControlPolicy::Allowed
|
||||
};
|
||||
let remote_control_startup_mode = runtime_options.remote_control_startup_mode;
|
||||
let remote_control_explicitly_requested =
|
||||
remote_control_startup_mode == RemoteControlStartupMode::EnabledEphemeral;
|
||||
if remote_control_explicitly_requested
|
||||
&& remote_control_policy == RemoteControlPolicy::DisabledByRequirements
|
||||
{
|
||||
return Err(std::io::Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
"remote control is disabled by managed requirements",
|
||||
));
|
||||
}
|
||||
let installation_id = resolve_installation_id(&config.codex_home).await?;
|
||||
let transport_shutdown_token = CancellationToken::new();
|
||||
let mut transport_accept_handles = Vec::<JoinHandle<()>>::new();
|
||||
@@ -719,10 +742,9 @@ pub async fn run_main_with_transport_options(
|
||||
let auth_manager =
|
||||
AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ false).await;
|
||||
|
||||
let remote_control_startup_mode = runtime_options.remote_control_startup_mode;
|
||||
let remote_control_explicitly_requested =
|
||||
remote_control_startup_mode == RemoteControlStartupMode::EnabledEphemeral;
|
||||
let remote_control_enabled = remote_control_explicitly_requested && state_db.is_some();
|
||||
let remote_control_enabled = remote_control_policy == RemoteControlPolicy::Allowed
|
||||
&& remote_control_explicitly_requested
|
||||
&& state_db.is_some();
|
||||
if remote_control_explicitly_requested && state_db.is_none() {
|
||||
error!("remote control disabled because sqlite state db is unavailable");
|
||||
}
|
||||
@@ -733,7 +755,9 @@ pub async fn run_main_with_transport_options(
|
||||
{
|
||||
return Err(std::io::Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
if remote_control_explicitly_requested && state_db.is_none() {
|
||||
if remote_control_policy == RemoteControlPolicy::DisabledByRequirements {
|
||||
"no transport configured; remote control disabled by managed requirements"
|
||||
} else if remote_control_explicitly_requested && state_db.is_none() {
|
||||
"no transport configured; remote control disabled because sqlite state db is unavailable"
|
||||
} else {
|
||||
"no transport configured; use --listen or enable remote control"
|
||||
@@ -745,6 +769,7 @@ pub async fn run_main_with_transport_options(
|
||||
RemoteControlStartConfig {
|
||||
remote_control_url: config.chatgpt_base_url.clone(),
|
||||
installation_id: installation_id.clone(),
|
||||
policy: remote_control_policy,
|
||||
},
|
||||
state_db.clone(),
|
||||
auth_manager.clone(),
|
||||
@@ -772,7 +797,11 @@ pub async fn run_main_with_transport_options(
|
||||
let _ = remote_control_accept_handle.await;
|
||||
return Err(std::io::Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
"no transport configured; use --listen or enable remote control",
|
||||
if remote_control_policy == RemoteControlPolicy::DisabledByRequirements {
|
||||
"no transport configured; remote control disabled by managed requirements"
|
||||
} else {
|
||||
"no transport configured; use --listen or enable remote control"
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,17 @@ use tracing::Instrument;
|
||||
const EXTERNAL_AUTH_REFRESH_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
const CONNECTION_RPC_DRAIN_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 30);
|
||||
|
||||
fn deserialize_client_request(
|
||||
request: &JSONRPCRequest,
|
||||
) -> Result<ClientRequest, JSONRPCErrorError> {
|
||||
serde_json::to_value(request)
|
||||
.map_err(|err| invalid_request(format!("Invalid request: {err}")))
|
||||
.and_then(|request_json| {
|
||||
serde_json::from_value(request_json)
|
||||
.map_err(|err| invalid_request(format!("Invalid request: {err}")))
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ExternalAuthRefreshBridge {
|
||||
outgoing: Arc<OutgoingMessageSender>,
|
||||
@@ -582,12 +593,7 @@ impl MessageProcessor {
|
||||
Arc::clone(&self.outgoing),
|
||||
request_context.clone(),
|
||||
async {
|
||||
let codex_request = serde_json::to_value(&request)
|
||||
.map_err(|err| invalid_request(format!("Invalid request: {err}")))
|
||||
.and_then(|request_json| {
|
||||
serde_json::from_value::<ClientRequest>(request_json)
|
||||
.map_err(|err| invalid_request(format!("Invalid request: {err}")))
|
||||
});
|
||||
let codex_request = deserialize_client_request(&request);
|
||||
let result = match codex_request {
|
||||
Ok(codex_request) => {
|
||||
// Websocket callers finalize outbound readiness in lib.rs after mirroring
|
||||
|
||||
@@ -364,6 +364,7 @@ fn map_requirements_toml_to_api(requirements: ConfigRequirementsToml) -> ConfigR
|
||||
}),
|
||||
allow_managed_hooks_only: requirements.allow_managed_hooks_only,
|
||||
allow_appshots: requirements.allow_appshots,
|
||||
allow_remote_control: requirements.allow_remote_control,
|
||||
computer_use: requirements
|
||||
.computer_use
|
||||
.map(map_computer_use_requirements_to_api),
|
||||
@@ -618,6 +619,16 @@ mod tests {
|
||||
assert_eq!(mapped.hooks, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requirements_api_includes_allow_remote_control() {
|
||||
let mapped = map_requirements_toml_to_api(ConfigRequirementsToml {
|
||||
allow_remote_control: Some(false),
|
||||
..ConfigRequirementsToml::default()
|
||||
});
|
||||
|
||||
assert_eq!(mapped.allow_remote_control, Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requirements_api_includes_computer_use_requirements() {
|
||||
let mapped = map_requirements_toml_to_api(ConfigRequirementsToml {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::error_code::internal_error;
|
||||
use crate::error_code::invalid_request;
|
||||
use crate::transport::RemoteControlEnableError;
|
||||
use crate::transport::RemoteControlHandle;
|
||||
use crate::transport::RemoteControlUnavailable;
|
||||
use codex_app_server_protocol::JSONRPCErrorError;
|
||||
@@ -35,7 +36,7 @@ impl RemoteControlRequestProcessor {
|
||||
) -> Result<RemoteControlEnableResponse, JSONRPCErrorError> {
|
||||
let handle = self.handle()?;
|
||||
let status = if ephemeral {
|
||||
handle.enable_ephemeral().map_err(map_unavailable)?
|
||||
handle.enable_ephemeral().map_err(map_enable_error)?
|
||||
} else {
|
||||
handle
|
||||
.enable(app_server_client_name)
|
||||
@@ -88,7 +89,8 @@ impl RemoteControlRequestProcessor {
|
||||
params: RemoteControlPairingStatusParams,
|
||||
) -> Result<RemoteControlPairingStatusResponse, JSONRPCErrorError> {
|
||||
validate_pairing_status_params(¶ms)?;
|
||||
self.handle()?
|
||||
let handle = self.handle()?;
|
||||
handle
|
||||
.pairing_status(params)
|
||||
.await
|
||||
.map_err(map_pairing_start_error)
|
||||
@@ -115,9 +117,21 @@ impl RemoteControlRequestProcessor {
|
||||
}
|
||||
|
||||
fn handle(&self) -> Result<&RemoteControlHandle, JSONRPCErrorError> {
|
||||
self.remote_control_handle
|
||||
let handle = self
|
||||
.remote_control_handle
|
||||
.as_ref()
|
||||
.ok_or_else(|| internal_error("remote control is unavailable for this app-server"))
|
||||
.ok_or_else(|| internal_error("remote control is unavailable for this app-server"))?;
|
||||
handle
|
||||
.ensure_remote_control_allowed()
|
||||
.map_err(|err| invalid_request(err.to_string()))?;
|
||||
Ok(handle)
|
||||
}
|
||||
}
|
||||
|
||||
fn map_enable_error(err: RemoteControlEnableError) -> JSONRPCErrorError {
|
||||
match err {
|
||||
RemoteControlEnableError::Unavailable(err) => map_unavailable(err),
|
||||
RemoteControlEnableError::DisabledByRequirements(err) => invalid_request(err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +140,10 @@ fn map_unavailable(err: RemoteControlUnavailable) -> JSONRPCErrorError {
|
||||
}
|
||||
|
||||
fn map_update_error(err: io::Error) -> JSONRPCErrorError {
|
||||
if err.kind() == io::ErrorKind::NotFound {
|
||||
if matches!(
|
||||
err.kind(),
|
||||
io::ErrorKind::NotFound | io::ErrorKind::PermissionDenied
|
||||
) {
|
||||
invalid_request(err.to_string())
|
||||
} else {
|
||||
internal_error(err.to_string())
|
||||
|
||||
@@ -18,7 +18,9 @@ pub(crate) use codex_app_server_transport::ConnectionId;
|
||||
pub(crate) use codex_app_server_transport::ConnectionOrigin;
|
||||
pub(crate) use codex_app_server_transport::OutgoingMessage;
|
||||
pub(crate) use codex_app_server_transport::QueuedOutgoingMessage;
|
||||
pub(crate) use codex_app_server_transport::RemoteControlEnableError;
|
||||
pub(crate) use codex_app_server_transport::RemoteControlHandle;
|
||||
pub(crate) use codex_app_server_transport::RemoteControlPolicy;
|
||||
pub(crate) use codex_app_server_transport::RemoteControlStartConfig;
|
||||
pub use codex_app_server_transport::RemoteControlStartupMode;
|
||||
pub(crate) use codex_app_server_transport::RemoteControlUnavailable;
|
||||
|
||||
Reference in New Issue
Block a user