From de4a3fa766305bed1f9d1be72fed06bade136c54 Mon Sep 17 00:00:00 2001 From: LeonWang0735 Date: Sun, 4 Jan 2026 10:13:27 +0800 Subject: [PATCH] fix:correct RemoteAddr extension type to enable IP-based policy evaluation (#1356) --- rustfs/src/admin/handlers.rs | 8 ++++---- rustfs/src/admin/handlers/bucket_meta.rs | 4 ++-- rustfs/src/admin/handlers/group.rs | 8 ++++---- rustfs/src/admin/handlers/kms.rs | 14 +++++++------- rustfs/src/admin/handlers/kms_dynamic.rs | 10 +++++----- rustfs/src/admin/handlers/kms_keys.rs | 10 +++++----- rustfs/src/admin/handlers/policies.rs | 10 +++++----- rustfs/src/admin/handlers/pools.rs | 8 ++++---- rustfs/src/admin/handlers/rebalance.rs | 6 +++--- rustfs/src/admin/handlers/service_account.rs | 10 +++++----- rustfs/src/admin/handlers/tier.rs | 14 +++++++------- rustfs/src/admin/handlers/user.rs | 14 +++++++------- rustfs/src/storage/access.rs | 2 +- rustfs/src/storage/ecfs.rs | 2 +- 14 files changed, 60 insertions(+), 60 deletions(-) diff --git a/rustfs/src/admin/handlers.rs b/rustfs/src/admin/handlers.rs index e0646840..d3126882 100644 --- a/rustfs/src/admin/handlers.rs +++ b/rustfs/src/admin/handlers.rs @@ -211,7 +211,7 @@ impl Operation for AccountInfoHandler { let claims = cred.claims.as_ref().unwrap_or(&default_claims); let cred_clone = cred.clone(); - let remote_addr = req.extensions.get::().map(|a| a.0); + let remote_addr = req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)); let conditions = get_condition_values(&req.headers, &cred_clone, None, None, remote_addr); let cred_clone = Arc::new(cred_clone); let conditions = Arc::new(conditions); @@ -407,7 +407,7 @@ impl Operation for ServerInfoHandler { let (cred, owner) = check_key_valid(get_session_token(&req.uri, &req.headers).unwrap_or_default(), &input_cred.access_key).await?; - let remote_addr = req.extensions.get::().map(|a| a.0); + let remote_addr = req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)); validate_admin_request( &req.headers, &cred, @@ -455,7 +455,7 @@ impl Operation for StorageInfoHandler { let (cred, owner) = check_key_valid(get_session_token(&req.uri, &req.headers).unwrap_or_default(), &input_cred.access_key).await?; - let remote_addr = req.extensions.get::().map(|a| a.0); + let remote_addr = req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)); validate_admin_request( &req.headers, &cred, @@ -498,7 +498,7 @@ impl Operation for DataUsageInfoHandler { let (cred, owner) = check_key_valid(get_session_token(&req.uri, &req.headers).unwrap_or_default(), &input_cred.access_key).await?; - let remote_addr = req.extensions.get::().map(|a| a.0); + let remote_addr = req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)); validate_admin_request( &req.headers, &cred, diff --git a/rustfs/src/admin/handlers/bucket_meta.rs b/rustfs/src/admin/handlers/bucket_meta.rs index 8d8317c2..013b79aa 100644 --- a/rustfs/src/admin/handlers/bucket_meta.rs +++ b/rustfs/src/admin/handlers/bucket_meta.rs @@ -98,7 +98,7 @@ impl Operation for ExportBucketMetadata { owner, false, vec![Action::AdminAction(AdminAction::ExportBucketMetadataAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -391,7 +391,7 @@ impl Operation for ImportBucketMetadata { owner, false, vec![Action::AdminAction(AdminAction::ImportBucketMetadataAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/group.rs b/rustfs/src/admin/handlers/group.rs index 91e0c0e2..89c140c3 100644 --- a/rustfs/src/admin/handlers/group.rs +++ b/rustfs/src/admin/handlers/group.rs @@ -58,7 +58,7 @@ impl Operation for ListGroups { owner, false, vec![Action::AdminAction(AdminAction::ListGroupsAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -97,7 +97,7 @@ impl Operation for GetGroup { owner, false, vec![Action::AdminAction(AdminAction::GetGroupAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -145,7 +145,7 @@ impl Operation for SetGroupStatus { owner, false, vec![Action::AdminAction(AdminAction::EnableGroupAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -213,7 +213,7 @@ impl Operation for UpdateGroupMembers { owner, false, vec![Action::AdminAction(AdminAction::AddUserToGroupAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/kms.rs b/rustfs/src/admin/handlers/kms.rs index 95e52c74..6c770e3c 100644 --- a/rustfs/src/admin/handlers/kms.rs +++ b/rustfs/src/admin/handlers/kms.rs @@ -128,7 +128,7 @@ impl Operation for CreateKeyHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], // TODO: Add specific KMS action - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -207,7 +207,7 @@ impl Operation for DescribeKeyHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -263,7 +263,7 @@ impl Operation for ListKeysHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -325,7 +325,7 @@ impl Operation for GenerateDataKeyHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -391,7 +391,7 @@ impl Operation for KmsStatusHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -449,7 +449,7 @@ impl Operation for KmsConfigHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -494,7 +494,7 @@ impl Operation for KmsClearCacheHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/kms_dynamic.rs b/rustfs/src/admin/handlers/kms_dynamic.rs index de798686..840679bb 100644 --- a/rustfs/src/admin/handlers/kms_dynamic.rs +++ b/rustfs/src/admin/handlers/kms_dynamic.rs @@ -99,7 +99,7 @@ impl Operation for ConfigureKmsHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -198,7 +198,7 @@ impl Operation for StartKmsHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -332,7 +332,7 @@ impl Operation for StopKmsHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -398,7 +398,7 @@ impl Operation for GetKmsStatusHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -470,7 +470,7 @@ impl Operation for ReconfigureKmsHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/kms_keys.rs b/rustfs/src/admin/handlers/kms_keys.rs index d1be6bcf..032dc0e0 100644 --- a/rustfs/src/admin/handlers/kms_keys.rs +++ b/rustfs/src/admin/handlers/kms_keys.rs @@ -80,7 +80,7 @@ impl Operation for CreateKmsKeyHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -214,7 +214,7 @@ impl Operation for DeleteKmsKeyHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -363,7 +363,7 @@ impl Operation for CancelKmsKeyDeletionHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -492,7 +492,7 @@ impl Operation for ListKmsKeysHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -604,7 +604,7 @@ impl Operation for DescribeKmsKeyHandler { owner, false, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/policies.rs b/rustfs/src/admin/handlers/policies.rs index a33fed81..be6a5dba 100644 --- a/rustfs/src/admin/handlers/policies.rs +++ b/rustfs/src/admin/handlers/policies.rs @@ -61,7 +61,7 @@ impl Operation for ListCannedPolicies { owner, false, vec![Action::AdminAction(AdminAction::ListUserPoliciesAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -120,7 +120,7 @@ impl Operation for AddCannedPolicy { owner, false, vec![Action::AdminAction(AdminAction::CreatePolicyAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -193,7 +193,7 @@ impl Operation for InfoCannedPolicy { owner, false, vec![Action::AdminAction(AdminAction::GetPolicyAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -251,7 +251,7 @@ impl Operation for RemoveCannedPolicy { owner, false, vec![Action::AdminAction(AdminAction::DeletePolicyAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -312,7 +312,7 @@ impl Operation for SetPolicyForUserOrGroup { owner, false, vec![Action::AdminAction(AdminAction::AttachPolicyAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/pools.rs b/rustfs/src/admin/handlers/pools.rs index c68033d5..17c14971 100644 --- a/rustfs/src/admin/handlers/pools.rs +++ b/rustfs/src/admin/handlers/pools.rs @@ -54,7 +54,7 @@ impl Operation for ListPools { Action::AdminAction(AdminAction::ServerInfoAdminAction), Action::AdminAction(AdminAction::DecommissionAdminAction), ], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -121,7 +121,7 @@ impl Operation for StatusPool { Action::AdminAction(AdminAction::ServerInfoAdminAction), Action::AdminAction(AdminAction::DecommissionAdminAction), ], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -197,7 +197,7 @@ impl Operation for StartDecommission { owner, false, vec![Action::AdminAction(AdminAction::DecommissionAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -296,7 +296,7 @@ impl Operation for CancelDecommission { owner, false, vec![Action::AdminAction(AdminAction::DecommissionAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/rebalance.rs b/rustfs/src/admin/handlers/rebalance.rs index d1fb0a8d..a96efe0c 100644 --- a/rustfs/src/admin/handlers/rebalance.rs +++ b/rustfs/src/admin/handlers/rebalance.rs @@ -104,7 +104,7 @@ impl Operation for RebalanceStart { owner, false, vec![Action::AdminAction(AdminAction::RebalanceAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -182,7 +182,7 @@ impl Operation for RebalanceStatus { owner, false, vec![Action::AdminAction(AdminAction::RebalanceAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -300,7 +300,7 @@ impl Operation for RebalanceStop { owner, false, vec![Action::AdminAction(AdminAction::RebalanceAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/service_account.rs b/rustfs/src/admin/handlers/service_account.rs index 34ad9538..739cdbbb 100644 --- a/rustfs/src/admin/handlers/service_account.rs +++ b/rustfs/src/admin/handlers/service_account.rs @@ -125,7 +125,7 @@ impl Operation for AddServiceAccount { &cred, None, None, - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ), is_owner: owner, object: "", @@ -282,7 +282,7 @@ impl Operation for UpdateServiceAccount { &cred, None, None, - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ), is_owner: owner, object: "", @@ -381,7 +381,7 @@ impl Operation for InfoServiceAccount { &cred, None, None, - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ), is_owner: owner, object: "", @@ -515,7 +515,7 @@ impl Operation for ListServiceAccount { &cred, None, None, - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ), is_owner: owner, object: "", @@ -619,7 +619,7 @@ impl Operation for DeleteServiceAccount { &cred, None, None, - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ), is_owner: owner, object: "", diff --git a/rustfs/src/admin/handlers/tier.rs b/rustfs/src/admin/handlers/tier.rs index cfcf5f5a..62516f91 100644 --- a/rustfs/src/admin/handlers/tier.rs +++ b/rustfs/src/admin/handlers/tier.rs @@ -97,7 +97,7 @@ impl Operation for AddTier { owner, false, vec![Action::AdminAction(AdminAction::SetTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -233,7 +233,7 @@ impl Operation for EditTier { owner, false, vec![Action::AdminAction(AdminAction::SetTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -316,7 +316,7 @@ impl Operation for ListTiers { owner, false, vec![Action::AdminAction(AdminAction::ListTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -360,7 +360,7 @@ impl Operation for RemoveTier { owner, false, vec![Action::AdminAction(AdminAction::SetTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -431,7 +431,7 @@ impl Operation for VerifyTier { owner, false, vec![Action::AdminAction(AdminAction::ListTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -462,7 +462,7 @@ impl Operation for GetTierInfo { owner, false, vec![Action::AdminAction(AdminAction::ListTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -522,7 +522,7 @@ impl Operation for ClearTier { owner, false, vec![Action::AdminAction(AdminAction::SetTierAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/admin/handlers/user.rs b/rustfs/src/admin/handlers/user.rs index 5512d399..a4981f30 100644 --- a/rustfs/src/admin/handlers/user.rs +++ b/rustfs/src/admin/handlers/user.rs @@ -125,7 +125,7 @@ impl Operation for AddUser { owner, deny_only, vec![Action::AdminAction(AdminAction::CreateUserAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -178,7 +178,7 @@ impl Operation for SetUserStatus { owner, false, vec![Action::AdminAction(AdminAction::EnableUserAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -223,7 +223,7 @@ impl Operation for ListUsers { owner, false, vec![Action::AdminAction(AdminAction::ListUsersAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -282,7 +282,7 @@ impl Operation for RemoveUser { owner, false, vec![Action::AdminAction(AdminAction::DeleteUserAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -382,7 +382,7 @@ impl Operation for GetUserInfo { owner, deny_only, vec![Action::AdminAction(AdminAction::GetUserAdminAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -438,7 +438,7 @@ impl Operation for ExportIam { owner, false, vec![Action::AdminAction(AdminAction::ExportIAMAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; @@ -652,7 +652,7 @@ impl Operation for ImportIam { owner, false, vec![Action::AdminAction(AdminAction::ExportIAMAction)], - req.extensions.get::().map(|a| a.0), + req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)), ) .await?; diff --git a/rustfs/src/storage/access.rs b/rustfs/src/storage/access.rs index 8d674d80..10b74164 100644 --- a/rustfs/src/storage/access.rs +++ b/rustfs/src/storage/access.rs @@ -37,7 +37,7 @@ pub(crate) struct ReqInfo { /// Authorizes the request based on the action and credentials. pub async fn authorize_request(req: &mut S3Request, action: Action) -> S3Result<()> { - let remote_addr = req.extensions.get::().map(|a| a.0); + let remote_addr = req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)); let req_info = req.extensions.get_mut::().expect("ReqInfo not found"); diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 80808ab3..1e712751 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -4693,7 +4693,7 @@ impl S3 for FS { .await .map_err(ApiError::from)?; - let remote_addr = req.extensions.get::().map(|a| a.0); + let remote_addr = req.extensions.get::>().and_then(|opt| opt.map(|a| a.0)); let conditions = get_condition_values(&req.headers, &rustfs_credentials::Credentials::default(), None, None, remote_addr); let read_only = PolicySys::is_allowed(&BucketPolicyArgs {