mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:16:05 +00:00
Harden network proxy credential brokerage (#38049)
## What changed - Bind OpenAI credentials to `api.openai.com` and trusted HTTPS hosts derived from local configuration or `OPENAI_BASE_URL`. - Support GitHub credentials for `uploads.github.com` and translate Bearer, token, and Basic authorization forms while preserving their schemes. - Apply credential broker configuration changes without restarting the proxy, including clearing affected credential mappings when trusted OpenAI hosts change. - Restore brokered credentials in environments and command arguments that intentionally leave managed networking, while preserving user overrides and handling Windows environment keys case-insensitively. - Keep local credential brokerage out of remote proxy launch configuration and avoid launching a remote proxy when brokerage alone enabled the local proxy. ## Testing Added coverage for trusted host binding, authorization translation, live reconfiguration, credential restoration, managed-disabled behavior, remote launch configuration, and Windows environment key matching. GitOrigin-RevId: 8d8bd3aaf6e581849cb622b2faec62cee4e13e52
This commit is contained in:
1 parent
d6ca19d99b
commit
eea28321ad
9 files changed
+626
-115
No files matched your search
@@ -14,6 +14,7 @@ use tracing::warn;
|
||||
use url::Url;
|
||||
|
||||
use crate::mitm_hook::MitmHookConfig;
|
||||
use crate::policy::normalize_host;
|
||||
|
||||
/// Variant order encodes effective precedence for duplicate patterns:
|
||||
/// `None < Allow < Deny`, so deny wins over allow when entries conflict.
|
||||
@@ -137,6 +138,9 @@ pub struct NetworkProxyConfig {
|
||||
pub mitm: bool,
|
||||
#[serde(default)]
|
||||
pub credential_broker: bool,
|
||||
/// Trusted OpenAI endpoint derived from local configuration, never sent to remote executors.
|
||||
#[serde(skip)]
|
||||
pub credential_broker_openai_host: Option<String>,
|
||||
#[serde(default)]
|
||||
pub dangerously_allow_plaintext_credential_injection: bool,
|
||||
#[serde(default)]
|
||||
@@ -160,6 +164,7 @@ impl Default for NetworkProxyConfig {
|
||||
allow_local_binding: false,
|
||||
mitm: false,
|
||||
credential_broker: false,
|
||||
credential_broker_openai_host: None,
|
||||
dangerously_allow_plaintext_credential_injection: false,
|
||||
mitm_hooks: Vec::new(),
|
||||
}
|
||||
@@ -172,6 +177,10 @@ impl NetworkProxyConfig {
|
||||
self.mitm |= enabled;
|
||||
}
|
||||
|
||||
pub fn set_credential_broker_openai_base_url(&mut self, base_url: Option<&str>) {
|
||||
self.credential_broker_openai_host = base_url.and_then(trusted_credential_broker_host);
|
||||
}
|
||||
|
||||
pub fn allowed_domains(&self) -> Option<Vec<String>> {
|
||||
self.domain_entries(NetworkDomainPermission::Allow)
|
||||
}
|
||||
@@ -276,6 +285,15 @@ impl NetworkProxyConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn trusted_credential_broker_host(base_url: &str) -> Option<String> {
|
||||
Url::parse(base_url)
|
||||
.ok()
|
||||
.filter(|url| {
|
||||
url.scheme() == "https" && url.username().is_empty() && url.password().is_none()
|
||||
})
|
||||
.and_then(|url| url.host_str().map(normalize_host))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkMode {
|
||||
@@ -619,12 +637,40 @@ mod tests {
|
||||
allow_local_binding: false,
|
||||
mitm: false,
|
||||
credential_broker: false,
|
||||
credential_broker_openai_host: None,
|
||||
dangerously_allow_plaintext_credential_injection: false,
|
||||
mitm_hooks: Vec::new(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn credential_broker_only_accepts_trusted_https_openai_endpoints() {
|
||||
let mut config = NetworkProxyConfig::default();
|
||||
|
||||
for (base_url, expected_host) in [
|
||||
(
|
||||
Some("https://gateway.example.com/v1"),
|
||||
Some("gateway.example.com"),
|
||||
),
|
||||
(
|
||||
Some("https://gateway.example.com./v1"),
|
||||
Some("gateway.example.com"),
|
||||
),
|
||||
(Some("https://[2001:db8::1]/v1"), Some("2001:db8::1")),
|
||||
(Some("http://gateway.example.com/v1"), None),
|
||||
(Some("https://user@gateway.example.com/v1"), None),
|
||||
(Some("not-a-url"), None),
|
||||
(None, None),
|
||||
] {
|
||||
config.set_credential_broker_openai_base_url(base_url);
|
||||
assert_eq!(
|
||||
config.credential_broker_openai_host.as_deref(),
|
||||
expected_host
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn managed_proxy_ports_reject_ephemeral_ports() {
|
||||
let mut config = NetworkProxyConfig {
|
||||
|
||||
Reference in new issue
Block a user