mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
codex: use config for plugin service preview (#28582)
This commit is contained in:
@@ -1,23 +1,9 @@
|
||||
use std::ffi::OsStr;
|
||||
|
||||
/// Process signal set by an eligible host to opt plugin-service requests into preview routing.
|
||||
pub const CODEX_PLUGIN_SERVICE_PREVIEW_ENV_VAR: &str = "CODEX_PLUGIN_SERVICE_PREVIEW";
|
||||
|
||||
const PLUGIN_SERVICE_PREVIEW_ENABLED_VALUE: &str = "1";
|
||||
const PLUGIN_SERVICE_PREVIEW_COOKIE_NAME: &[u8] = b"oai-chat-plugin-service-preview";
|
||||
/// Routing cookie added to eligible plugin-service requests.
|
||||
pub const PLUGIN_SERVICE_PREVIEW_COOKIE: &str = "oai-chat-plugin-service-preview=true";
|
||||
|
||||
/// Returns whether the host opted this process into plugin-service preview routing.
|
||||
///
|
||||
/// The host owns employee eligibility. This signal is defense-in-depth routing, not an
|
||||
/// authorization boundary; authentication and authorization remain the responsibility of the
|
||||
/// existing request path and plugin-service.
|
||||
pub fn plugin_service_preview_enabled() -> bool {
|
||||
plugin_service_preview_enabled_from_value(
|
||||
std::env::var_os(CODEX_PLUGIN_SERVICE_PREVIEW_ENV_VAR).as_deref(),
|
||||
)
|
||||
}
|
||||
/// This cookie is intentionally public and untrusted. It selects a deployment after normal
|
||||
/// authentication; the gateway must independently restrict preview routing to internal traffic.
|
||||
pub const PLUGIN_SERVICE_PREVIEW_COOKIE: &str = "oai-chat-plugin-service-preview=true";
|
||||
|
||||
/// Rewrites plugin-service cookies so callers cannot override the process routing signal.
|
||||
///
|
||||
@@ -49,10 +35,6 @@ pub fn plugin_service_routing_cookie(
|
||||
(!cookies.is_empty()).then(|| cookies.join(&b"; "[..]))
|
||||
}
|
||||
|
||||
fn plugin_service_preview_enabled_from_value(value: Option<&OsStr>) -> bool {
|
||||
value == Some(OsStr::new(PLUGIN_SERVICE_PREVIEW_ENABLED_VALUE))
|
||||
}
|
||||
|
||||
fn trim_cookie_whitespace(mut value: &[u8]) -> &[u8] {
|
||||
while value
|
||||
.first()
|
||||
|
||||
@@ -1,25 +1,6 @@
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn preview_signal_requires_exact_enabled_value() {
|
||||
for value in [
|
||||
None,
|
||||
Some(""),
|
||||
Some("0"),
|
||||
Some("true"),
|
||||
Some(" 1"),
|
||||
Some("1 "),
|
||||
] {
|
||||
assert!(!plugin_service_preview_enabled_from_value(
|
||||
value.map(OsStr::new)
|
||||
));
|
||||
}
|
||||
assert!(plugin_service_preview_enabled_from_value(Some(OsStr::new(
|
||||
"1"
|
||||
))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn routing_cookie_is_disabled_by_default_and_cannot_be_enabled_by_caller() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user