fix(security): extend outbound egress guard (#3744)

This commit is contained in:
houseme
2026-06-22 19:20:31 +08:00
committed by GitHub
parent 64aef06c60
commit 2f85ef4455
5 changed files with 78 additions and 1 deletions
@@ -36,6 +36,7 @@ use crate::tier::{
tier_config::TierS3,
warm_backend::{WarmBackend, WarmBackendGetOpts, build_transition_put_options},
};
use rustfs_utils::egress::validate_outbound_url;
use rustfs_utils::path::SLASH_SEPARATOR;
pub struct WarmBackendS3 {
@@ -54,6 +55,7 @@ impl WarmBackendS3 {
return Err(std::io::Error::other(err.to_string()));
}
};
validate_outbound_url(&u).map_err(|err| std::io::Error::other(format!("tier endpoint is not allowed: {err}")))?;
if conf.aws_role_web_identity_token_file == "" && conf.aws_role_arn != ""
|| conf.aws_role_web_identity_token_file != "" && conf.aws_role_arn == ""
@@ -120,6 +122,28 @@ impl WarmBackendS3 {
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn new_rejects_loopback_endpoint_before_network_setup() {
let conf = TierS3 {
endpoint: "https://127.0.0.1:9000".to_string(),
bucket: "tier-bucket".to_string(),
access_key: "access".to_string(),
secret_key: "secret".to_string(),
region: "us-east-1".to_string(),
..Default::default()
};
match WarmBackendS3::new(&conf, "tier").await {
Ok(_) => panic!("loopback endpoint should be rejected"),
Err(err) => assert!(err.to_string().contains("not allowed")),
}
}
}
#[async_trait::async_trait]
impl WarmBackend for WarmBackendS3 {
async fn put_with_meta(