mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Enable credential masking for remote exec-server commands (#54309)
## What changed Negotiate executor support for `credential_masking` and enable built-in credential brokerage in executor-local network proxies. Supported non-login Bash commands on Linux and macOS receive credential placeholders, with real credentials injected by the proxy for matching destinations. Retain credential mappings across process launches within the same executor session, scoped by environment, conversation, and broker configuration. Keep credentials and destination context on the executor. Fall back to unmasked execution for unsupported shells or shell startup, and for configured credential providers. Emit warnings when masking is unavailable, preserving shell profiles and snapshots. ## Testing Add coverage for capability negotiation, fallback behavior, mapping reuse and isolation, proxy credential injection, and keeping executor credentials out of model-visible request history. Test warning, removal, and rejection modes for credentials left unmasked during preparation. GitOrigin-RevId: f64e916a5de8350fa0d289d3440ec29761accd75
This commit is contained in:
@@ -933,13 +933,27 @@ impl NetworkProxy {
|
||||
}
|
||||
|
||||
/// Captures the static inputs needed to launch a matching executor-local proxy.
|
||||
/// Credential masking requires an explicit caller opt-in and a capable executor.
|
||||
pub async fn remote_launch_config(
|
||||
&self,
|
||||
local_binding_policy: crate::LocalBindingPolicy,
|
||||
credential_masking: bool,
|
||||
) -> Result<crate::RemoteNetworkProxyLaunchConfig> {
|
||||
let (mut config, brokerage_created_default_allowlist, _) =
|
||||
self.state.current_cfg_with_brokerage_provenance().await?;
|
||||
// Proxy enablement and credential brokerage remain controller-owned.
|
||||
// Configured providers are not transported yet, so these commands run unmasked.
|
||||
let credential_masking = credential_masking
|
||||
&& config.enabled
|
||||
&& config.credential_broker
|
||||
&& config.credential_providers.is_empty();
|
||||
anyhow::ensure!(
|
||||
!credential_masking
|
||||
|| (!config.dangerously_allow_plaintext_credential_injection
|
||||
&& config.mitm_hooks.is_empty()
|
||||
&& config.mitm_ca.is_none()),
|
||||
"executor credential masking does not support plaintext injection, MITM hooks, or external CAs"
|
||||
);
|
||||
// Legacy controller-only brokerage must not enable a remote proxy by itself.
|
||||
let mut broker_only_config = config::NetworkProxyConfig {
|
||||
enabled: config.enabled,
|
||||
allow_local_binding: config.allow_local_binding.filter(|binding| !binding),
|
||||
@@ -973,7 +987,7 @@ impl NetworkProxy {
|
||||
.as_ref()
|
||||
.and_then(|scope| scope.environment_policy.as_ref());
|
||||
if config.credential_broker {
|
||||
config.enabled &= !broker_only;
|
||||
config.enabled &= !broker_only || credential_masking;
|
||||
config.credential_broker = false;
|
||||
config.dangerously_allow_plaintext_credential_injection = false;
|
||||
if config.mitm && config.mitm_hooks.is_empty() && config.mitm_ca.is_none() {
|
||||
@@ -994,7 +1008,8 @@ impl NetworkProxy {
|
||||
|| config.allow_local_binding(),
|
||||
"MXC cannot enforce allow_local_binding=false: native host-loopback access is bidirectional; use true or a different sandbox backend"
|
||||
);
|
||||
let proxy = crate::RemoteNetworkProxyConfig::from_effective_config(&config)?;
|
||||
let mut proxy = crate::RemoteNetworkProxyConfig::from_effective_config(&config)?;
|
||||
proxy.credential_masking = credential_masking;
|
||||
tracing::debug!(network_config = ?proxy, "resolved remote execution network configuration");
|
||||
let (environment_id, execution_id) = self
|
||||
.execution_scope
|
||||
@@ -1149,11 +1164,13 @@ impl NetworkProxy {
|
||||
runtime_settings.allow_local_binding,
|
||||
runtime_settings.mitm_ca_trust_bundle.as_ref(),
|
||||
);
|
||||
let credential_environment_id = environment_id.or_else(|| {
|
||||
self.execution_scope
|
||||
.as_ref()
|
||||
.map(|scope| scope.environment_id.as_str())
|
||||
});
|
||||
let credential_environment_id = environment_id
|
||||
.or_else(|| {
|
||||
self.execution_scope
|
||||
.as_ref()
|
||||
.map(|scope| scope.environment_id.as_str())
|
||||
})
|
||||
.or(self.state.environment_id());
|
||||
self.state
|
||||
.virtualize_child_credentials_for_environment(&mut env, credential_environment_id);
|
||||
if let Some(execution_scope) = self.execution_scope.as_ref() {
|
||||
@@ -1288,6 +1305,15 @@ impl NetworkProxy {
|
||||
self.state.virtualize_brokered_text(text, env)
|
||||
}
|
||||
|
||||
/// Applies the selected failure mode to recognized credentials left unmasked after preparation.
|
||||
pub fn handle_unmasked_credentials(
|
||||
&self,
|
||||
env: &mut HashMap<String, String>,
|
||||
mode: crate::CredentialMaskingFailureMode,
|
||||
) -> anyhow::Result<()> {
|
||||
self.state.handle_unmasked_credentials(env, mode)
|
||||
}
|
||||
|
||||
/// Returns trusted provider metadata and active bindings for a child environment.
|
||||
pub fn credential_broker_environment(
|
||||
&self,
|
||||
@@ -1918,7 +1944,9 @@ mod tests {
|
||||
);
|
||||
assert_eq!(proxy.current_cfg().await?, config);
|
||||
|
||||
let remote = proxy.remote_launch_config(DefaultFalse).await?;
|
||||
let remote = proxy
|
||||
.remote_launch_config(DefaultFalse, /*credential_masking*/ false)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
(
|
||||
remote.proxy.unix_sockets,
|
||||
@@ -2015,7 +2043,7 @@ mod tests {
|
||||
owner_config.set_denied_domains(vec!["denied.example".to_string()]);
|
||||
assert_eq!(
|
||||
scoped
|
||||
.remote_launch_config(DefaultFalse)
|
||||
.remote_launch_config(DefaultFalse, /*credential_masking*/ false)
|
||||
.await?
|
||||
.proxy
|
||||
.domains,
|
||||
@@ -2432,7 +2460,7 @@ mod tests {
|
||||
"GH_HOST".to_string(),
|
||||
"local-github.example".to_string(),
|
||||
)]));
|
||||
let state = Arc::new(network_proxy_state_for_policy(config));
|
||||
let state = Arc::new(network_proxy_state_for_policy(config.clone()));
|
||||
let proxy = match NetworkProxy::builder().state(state).build().await {
|
||||
Ok(proxy) => proxy,
|
||||
Err(err) => {
|
||||
@@ -2453,7 +2481,9 @@ mod tests {
|
||||
/*environment_policy*/ None,
|
||||
/*fallback_policy_decider*/ None,
|
||||
)?;
|
||||
let launch = scoped.remote_launch_config(RequireTrue).await?;
|
||||
let launch = scoped
|
||||
.remote_launch_config(RequireTrue, /*credential_masking*/ false)
|
||||
.await?;
|
||||
let prepared = scoped.prepare_for_optional_environment(
|
||||
HashMap::from([(
|
||||
PROXY_ATTRIBUTION_TOKEN_ENV_KEY.to_string(),
|
||||
@@ -2465,6 +2495,34 @@ mod tests {
|
||||
assert_eq!(launch.environment_id.as_deref(), Some("remote-env"));
|
||||
assert_eq!(launch.execution_id.as_deref(), Some("execution-1"));
|
||||
assert!(!launch.proxy.enabled);
|
||||
assert!(
|
||||
scoped
|
||||
.remote_launch_config(DefaultFalse, /*credential_masking*/ true)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
|
||||
config.credential_providers.insert(
|
||||
"vendor".to_string(),
|
||||
crate::CredentialProviderConfig {
|
||||
env: vec!["VENDOR_TOKEN".to_string()],
|
||||
patterns: vec!["vendor_[a-z]{8}".to_string()],
|
||||
url_prefixes: vec!["https://api.vendor.example".to_string()],
|
||||
auth: vec![crate::CredentialAuthMethod::Bearer],
|
||||
..crate::CredentialProviderConfig::default()
|
||||
},
|
||||
);
|
||||
let custom_provider_proxy = NetworkProxy::builder()
|
||||
.state(Arc::new(network_proxy_state_for_policy(config)))
|
||||
.build()
|
||||
.await?;
|
||||
assert_eq!(
|
||||
custom_provider_proxy
|
||||
.remote_launch_config(DefaultFalse, /*credential_masking*/ true)
|
||||
.await?
|
||||
.proxy,
|
||||
launch.proxy
|
||||
);
|
||||
|
||||
let mut owner_config = NetworkProxyConfig::default();
|
||||
owner_config.set_allowed_domains(vec!["owner.example".to_string()]);
|
||||
@@ -2480,7 +2538,7 @@ mod tests {
|
||||
)?;
|
||||
assert!(
|
||||
owner_scoped
|
||||
.remote_launch_config(DefaultFalse)
|
||||
.remote_launch_config(DefaultFalse, /*credential_masking*/ false)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
@@ -2512,9 +2570,14 @@ mod tests {
|
||||
.state(Arc::new(network_proxy_state_for_policy(config)))
|
||||
.build()
|
||||
.await?;
|
||||
let launch = proxy.remote_launch_config(DefaultFalse).await?;
|
||||
assert!(launch.proxy.enabled);
|
||||
assert_eq!(launch.proxy.mode, mode);
|
||||
for credential_masking in [false, true] {
|
||||
let launch = proxy
|
||||
.remote_launch_config(DefaultFalse, credential_masking)
|
||||
.await?;
|
||||
assert!(launch.proxy.enabled);
|
||||
assert_eq!(launch.proxy.mode, mode);
|
||||
assert_eq!(launch.proxy.credential_masking, credential_masking);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
prepared
|
||||
|
||||
Reference in New Issue
Block a user