mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
fix: preserve sandbox audit context after restack
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -45,7 +45,12 @@ impl SandboxViolationAuditContext {
|
||||
.auth_mode()
|
||||
.map(|mode| mode.to_string());
|
||||
let metadata = NetworkProxyAuditMetadata {
|
||||
conversation_id: Some(ctx.session.conversation_id.to_string()),
|
||||
conversation_id: ctx
|
||||
.session
|
||||
.services
|
||||
.network_proxy_audit_metadata
|
||||
.conversation_id
|
||||
.clone(),
|
||||
app_version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
||||
user_account_id: auth.as_ref().and_then(CodexAuth::get_account_id),
|
||||
auth_mode,
|
||||
@@ -116,6 +121,7 @@ fn security_event_create_params(
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: None,
|
||||
@@ -138,6 +144,7 @@ fn security_event_create_params(
|
||||
port: violation.port,
|
||||
protocol: Some(violation.protocol.clone()),
|
||||
method: violation.method.clone(),
|
||||
network_mode: violation.mode.map(|mode| mode.as_str().to_string()),
|
||||
decision: violation.decision.clone(),
|
||||
source: violation.source.clone(),
|
||||
review_id: None,
|
||||
@@ -184,6 +191,7 @@ fn emit_sandbox_violation_audit_event(
|
||||
server.port = fields.port,
|
||||
network.transport.protocol = fields.protocol,
|
||||
http.request.method = fields.method,
|
||||
network.mode = fields.network_mode,
|
||||
network.policy.decision = fields.decision,
|
||||
network.policy.source = fields.source,
|
||||
);
|
||||
@@ -198,6 +206,7 @@ struct SandboxViolationAuditFields<'a> {
|
||||
port: Option<i64>,
|
||||
protocol: Option<&'a str>,
|
||||
method: Option<&'a str>,
|
||||
network_mode: Option<&'a str>,
|
||||
decision: Option<&'a str>,
|
||||
source: Option<&'a str>,
|
||||
}
|
||||
@@ -214,6 +223,7 @@ impl<'a> SandboxViolationAuditFields<'a> {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
},
|
||||
@@ -226,6 +236,7 @@ impl<'a> SandboxViolationAuditFields<'a> {
|
||||
port: violation.port.map(i64::from),
|
||||
protocol: Some(violation.protocol.as_str()),
|
||||
method: violation.method.as_deref(),
|
||||
network_mode: violation.mode.map(codex_network_proxy::NetworkMode::as_str),
|
||||
decision: violation.decision.as_deref(),
|
||||
source: violation.source.as_deref(),
|
||||
},
|
||||
|
||||
@@ -375,6 +375,7 @@ async fn unsandboxed_intercepted_exec_strips_managed_network_env() -> anyhow::Re
|
||||
windows_sandbox_workspace_roots: vec![workdir.clone()],
|
||||
codex_linux_sandbox_exe: None,
|
||||
use_legacy_landlock: false,
|
||||
sandbox_violation_context: None,
|
||||
};
|
||||
let mut env = HashMap::new();
|
||||
env.insert(PROXY_ACTIVE_ENV_KEY.to_string(), "1".to_string());
|
||||
|
||||
@@ -298,6 +298,13 @@ pub enum NetworkMode {
|
||||
}
|
||||
|
||||
impl NetworkMode {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Limited => "limited",
|
||||
Self::Full => "full",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allows_method(self, method: &str) -> bool {
|
||||
match self {
|
||||
Self::Full => true,
|
||||
|
||||
@@ -14,6 +14,7 @@ CREATE TABLE security_events (
|
||||
port INTEGER,
|
||||
protocol TEXT,
|
||||
method TEXT,
|
||||
network_mode TEXT,
|
||||
decision TEXT,
|
||||
source TEXT,
|
||||
review_id TEXT,
|
||||
|
||||
@@ -69,6 +69,7 @@ pub struct SecurityEventCreateParams {
|
||||
pub port: Option<u16>,
|
||||
pub protocol: Option<String>,
|
||||
pub method: Option<String>,
|
||||
pub network_mode: Option<String>,
|
||||
pub decision: Option<String>,
|
||||
pub source: Option<String>,
|
||||
pub review_id: Option<String>,
|
||||
@@ -95,6 +96,7 @@ pub struct SecurityEvent {
|
||||
pub port: Option<u16>,
|
||||
pub protocol: Option<String>,
|
||||
pub method: Option<String>,
|
||||
pub network_mode: Option<String>,
|
||||
pub decision: Option<String>,
|
||||
pub source: Option<String>,
|
||||
pub review_id: Option<String>,
|
||||
@@ -138,6 +140,7 @@ impl SecurityEvent {
|
||||
port,
|
||||
protocol: row.try_get("protocol")?,
|
||||
method: row.try_get("method")?,
|
||||
network_mode: row.try_get("network_mode")?,
|
||||
decision: row.try_get("decision")?,
|
||||
source: row.try_get("source")?,
|
||||
review_id: row.try_get("review_id")?,
|
||||
|
||||
@@ -25,13 +25,14 @@ INSERT INTO security_events (
|
||||
port,
|
||||
protocol,
|
||||
method,
|
||||
network_mode,
|
||||
decision,
|
||||
source,
|
||||
review_id,
|
||||
reviewer,
|
||||
review_decision,
|
||||
details_json
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
"#,
|
||||
)
|
||||
.bind(event.created_at)
|
||||
@@ -48,6 +49,7 @@ INSERT INTO security_events (
|
||||
.bind(event.port.map(i64::from))
|
||||
.bind(event.protocol.as_deref())
|
||||
.bind(event.method.as_deref())
|
||||
.bind(event.network_mode.as_deref())
|
||||
.bind(event.decision.as_deref())
|
||||
.bind(event.source.as_deref())
|
||||
.bind(event.review_id.as_deref())
|
||||
@@ -154,6 +156,7 @@ SELECT
|
||||
port,
|
||||
protocol,
|
||||
method,
|
||||
network_mode,
|
||||
decision,
|
||||
source,
|
||||
review_id,
|
||||
|
||||
@@ -27,6 +27,7 @@ async fn security_events_round_trip_and_filter() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: None,
|
||||
@@ -52,6 +53,7 @@ async fn security_events_round_trip_and_filter() {
|
||||
port: Some(443),
|
||||
protocol: Some("https_connect".to_string()),
|
||||
method: Some("CONNECT".to_string()),
|
||||
network_mode: Some("limited".to_string()),
|
||||
decision: Some("deny".to_string()),
|
||||
source: Some("proxy_state".to_string()),
|
||||
review_id: None,
|
||||
@@ -77,6 +79,7 @@ async fn security_events_round_trip_and_filter() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: Some("review-1".to_string()),
|
||||
@@ -113,6 +116,7 @@ async fn security_events_round_trip_and_filter() {
|
||||
port: Some(443),
|
||||
protocol: Some("https_connect".to_string()),
|
||||
method: Some("CONNECT".to_string()),
|
||||
network_mode: Some("limited".to_string()),
|
||||
decision: Some("deny".to_string()),
|
||||
source: Some("proxy_state".to_string()),
|
||||
review_id: None,
|
||||
@@ -136,6 +140,7 @@ async fn security_events_round_trip_and_filter() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: None,
|
||||
@@ -171,6 +176,7 @@ async fn security_events_round_trip_and_filter() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: Some("review-1".to_string()),
|
||||
@@ -207,6 +213,7 @@ async fn insert_security_event_prunes_old_rows_per_thread_and_kind() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: None,
|
||||
@@ -233,6 +240,7 @@ async fn insert_security_event_prunes_old_rows_per_thread_and_kind() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: Some("review-1".to_string()),
|
||||
@@ -258,6 +266,7 @@ async fn insert_security_event_prunes_old_rows_per_thread_and_kind() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: None,
|
||||
@@ -337,6 +346,7 @@ async fn delete_security_events_before_removes_old_rows() {
|
||||
port: None,
|
||||
protocol: None,
|
||||
method: None,
|
||||
network_mode: None,
|
||||
decision: None,
|
||||
source: None,
|
||||
review_id: None,
|
||||
|
||||
Reference in New Issue
Block a user