Enforce API key IP restrictions in proxy auth

This commit is contained in:
RWDai
2026-05-18 20:47:28 +08:00
parent 276d19b63c
commit fc12cc8a36
4 changed files with 81 additions and 3 deletions
@@ -48,6 +48,8 @@ pub(crate) struct GatewayControlAuthContext {
pub(crate) local_rejection: Option<GatewayLocalAuthRejection>,
#[serde(skip)]
pub(crate) allowed_models: Option<Vec<String>>,
#[serde(skip)]
pub(crate) allowed_ips: Option<Vec<String>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -207,6 +209,9 @@ fn log_local_auth_rejection(trace_id: &str, decision: &GatewayControlDecision) {
GatewayLocalAuthRejection::ModelNotAllowed { model } => {
("model_not_allowed", model.clone())
}
GatewayLocalAuthRejection::IpNotAllowed { remote_ip } => {
("ip_not_allowed", remote_ip.clone())
}
};
info!(
event_name = "local_auth_rejected",
@@ -581,6 +586,7 @@ pub(super) async fn resolve_data_backed_auth_context(
admin_bypass_limits: false,
local_rejection: Some(GatewayLocalAuthRejection::InvalidApiKey),
allowed_models: None,
allowed_ips: None,
}));
};
@@ -638,6 +644,7 @@ async fn resolve_trusted_auth_context(
admin_bypass_limits: false,
local_rejection: Some(GatewayLocalAuthRejection::InvalidApiKey),
allowed_models: None,
allowed_ips: None,
}));
};
@@ -728,6 +735,7 @@ async fn build_data_backed_auth_context(
&& !snapshot.api_key_is_standalone,
local_rejection,
allowed_models,
allowed_ips: snapshot.api_key_allowed_ips,
}
}