mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 09:50:21 +08:00
Enforce API key IP restrictions in proxy auth
This commit is contained in:
@@ -17,6 +17,7 @@ pub(crate) enum GatewayLocalAuthRejection {
|
||||
ProviderNotAllowed { provider: String },
|
||||
ApiFormatNotAllowed { api_format: String },
|
||||
ModelNotAllowed { model: String },
|
||||
IpNotAllowed { remote_ip: String },
|
||||
}
|
||||
|
||||
pub(crate) fn trusted_auth_local_rejection(
|
||||
@@ -566,6 +567,7 @@ mod tests {
|
||||
admin_bypass_limits: false,
|
||||
local_rejection: None,
|
||||
allowed_models: Some(allowed_models),
|
||||
allowed_ips: None,
|
||||
});
|
||||
decision
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user