From 3f04fea9b62cbee3d74677b3377960f9605bc763 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 25 Nov 2026 14:54:04 +0800 Subject: [PATCH] feat(gateway): mount native non-GET control-plane admin routes Mount the 7 non-GET native control-plane operations ahead of the ControlPlane catch-all with pre-body IAM admission, bucket-scoped ConfigUpdate enforcement, notification target parameter validation, and site-replicator public-admin rejection, while keeping the 5 GET routes on ControlPlane so presigned Object Lambda URLs (#1577) continue to succeed without touching GatewayStack. --- Cargo.lock | 22 +- Cargo.toml | 14 +- rustfs/src/admin/handlers/event.rs | 2 +- rustfs/src/admin/handlers/site_replication.rs | 2 +- rustfs/src/admin/mod.rs | 1 + rustfs/src/admin/router.rs | 8 + rustfs/src/app/context/envelope.rs | 8 +- .../src/server/gateway_stack/control_plane.rs | 42 ++- .../control_plane/native_authority.rs | 212 +++++++++++++ .../control_plane/native_routes.rs | 134 ++++++++ .../gateway_stack/tests/control_plane.rs | 298 ++++++++++++++---- 11 files changed, 653 insertions(+), 90 deletions(-) create mode 100644 rustfs/src/server/gateway_stack/control_plane/native_authority.rs create mode 100644 rustfs/src/server/gateway_stack/control_plane/native_routes.rs diff --git a/Cargo.lock b/Cargo.lock index 388f41ac13..e8924ae6e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10434,7 +10434,7 @@ dependencies = [ [[package]] name = "rustfs-gateway" version = "0.66.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "arc-swap", "bytes", @@ -10481,7 +10481,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-core" version = "0.63.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "bytes", "futures-core", @@ -10502,7 +10502,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-corpus" version = "0.1.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "serde", "serde_json", @@ -10512,7 +10512,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-corpus-recorder" version = "0.1.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "bytes", "http 1.5.0", @@ -10527,7 +10527,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-dialect-rustfs-admin" version = "0.13.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "bytes", "form_urlencoded", @@ -10541,7 +10541,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-http" version = "0.1.4" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "hmac 0.13.0", "http 1.5.0", @@ -10559,7 +10559,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-macros" version = "0.1.4" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "proc-macro2", "quote", @@ -10569,7 +10569,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-sig" version = "0.15.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "hmac 0.13.0", "http 1.5.0", @@ -10584,7 +10584,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-stream" version = "0.2.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "bitflags 2.13.2", "bytes", @@ -10595,7 +10595,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-types" version = "0.42.0+aws.2026-10-02" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "bytes", "crc-fast", @@ -10617,7 +10617,7 @@ dependencies = [ [[package]] name = "rustfs-gateway-xml" version = "0.4.0" -source = "git+https://github.com/rustfs/gateway.git?rev=9d98970d8c54da31a509f77516ca4a690ac1f794#9d98970d8c54da31a509f77516ca4a690ac1f794" +source = "git+https://github.com/rustfs/gateway.git?rev=6cb25e95ee33aefeacac057bebdc31344765238e#6cb25e95ee33aefeacac057bebdc31344765238e" dependencies = [ "quick-xml 0.41.0", ] diff --git a/Cargo.toml b/Cargo.toml index 0617e65e54..d0ab0acee7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -153,17 +153,17 @@ rustfs-utils = { path = "crates/utils", version = "1.0.5" } rustfs-zip = { path = "./crates/zip", version = "1.0.5" } # Pin the gateway and its protocol crates to the same revision. -rustfs-gateway-types = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", version = "0.42.0", default-features = false } -rustfs-gateway-stream = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", version = "0.2.0", default-features = false } +rustfs-gateway-types = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", version = "0.42.0", default-features = false } +rustfs-gateway-stream = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", version = "0.2.0", default-features = false } # The gateway framework itself, consumed for its extension traits by the ring-2 # adapter. `default-features = false` keeps the `server` feature, and with it the # server crate, out of the build. -rustfs-gateway = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", version = "0.66.0", default-features = false } +rustfs-gateway = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", version = "0.66.0", default-features = false } # Test-only: builds the `EffectiveHost` a host-resolution test queries with. -rustfs-gateway-http = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", default-features = false } -rustfs-gateway-core = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", version = "0.63.0", default-features = false } -rustfs-gateway-corpus-recorder = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", version = "0.1.0", default-features = false } -rustfs-gateway-dialect-rustfs-admin = { git = "https://github.com/rustfs/gateway.git", rev = "9d98970d8c54da31a509f77516ca4a690ac1f794", version = "0.13.0", default-features = false } +rustfs-gateway-http = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", default-features = false } +rustfs-gateway-core = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", version = "0.63.0", default-features = false } +rustfs-gateway-corpus-recorder = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", version = "0.1.0", default-features = false } +rustfs-gateway-dialect-rustfs-admin = { git = "https://github.com/rustfs/gateway.git", rev = "6cb25e95ee33aefeacac057bebdc31344765238e", version = "0.13.0", default-features = false } # Async Runtime and Networking async-channel = "2.5.0" diff --git a/rustfs/src/admin/handlers/event.rs b/rustfs/src/admin/handlers/event.rs index b1d8236e70..4fb824a29e 100644 --- a/rustfs/src/admin/handlers/event.rs +++ b/rustfs/src/admin/handlers/event.rs @@ -655,7 +655,7 @@ impl Operation for RemoveNotificationTarget { } } -fn extract_target_params<'a>(params: &'a Params<'_, '_>) -> S3Result<(&'a str, &'a str)> { +pub(crate) fn extract_target_params<'a>(params: &'a Params<'_, '_>) -> S3Result<(&'a str, &'a str)> { extract_supported_target_params(notification_target_specs(), params, "notification") } diff --git a/rustfs/src/admin/handlers/site_replication.rs b/rustfs/src/admin/handlers/site_replication.rs index a4f04ed93b..885e7a2d5b 100644 --- a/rustfs/src/admin/handlers/site_replication.rs +++ b/rustfs/src/admin/handlers/site_replication.rs @@ -596,7 +596,7 @@ async fn validate_site_replication_admin_request( authorize_admin_envelope(req.envelope(), vec![Action::AdminAction(action)]).await } -fn reject_site_replicator_on_public_admin(cred: &rustfs_credentials::Credentials) -> S3Result<()> { +pub(crate) fn reject_site_replicator_on_public_admin(cred: &rustfs_credentials::Credentials) -> S3Result<()> { if cred.access_key == SITE_REPLICATOR_SERVICE_ACCOUNT { return Err(s3_error!( AccessDenied, diff --git a/rustfs/src/admin/mod.rs b/rustfs/src/admin/mod.rs index 38b255ffb0..e0c7819e76 100644 --- a/rustfs/src/admin/mod.rs +++ b/rustfs/src/admin/mod.rs @@ -14,6 +14,7 @@ pub(crate) mod access_key_identity; mod auth; +pub(crate) use auth::{authenticate_envelope_credentials, validate_admin_request, validate_admin_request_with_bucket}; pub mod console; pub mod handlers; pub(crate) mod operation; diff --git a/rustfs/src/admin/router.rs b/rustfs/src/admin/router.rs index db92b4a94e..45841a8f14 100644 --- a/rustfs/src/admin/router.rs +++ b/rustfs/src/admin/router.rs @@ -1106,6 +1106,14 @@ where } impl S3Router { + /// Validates notification target path parameters before the native route asks IAM. + pub(crate) fn validate_notification_target_params(&self, method: &Method, uri: &Uri) -> S3Result<()> { + let key = route_key_canonical(method, uri.path()); + let matched = self.table.at(&key).map_err(|_| S3Error::new(S3ErrorCode::NotImplemented))?; + super::handlers::event::extract_target_params(&matched.params)?; + Ok(()) + } + /// The access rule of every route this router claims, whichever edge verified the request: /// `signed` is whether a signature was verified for it. The legacy `check_access` and the /// gateway stack's control-plane host both decide by this one function. diff --git a/rustfs/src/app/context/envelope.rs b/rustfs/src/app/context/envelope.rs index 80e161c66e..82080120e6 100644 --- a/rustfs/src/app/context/envelope.rs +++ b/rustfs/src/app/context/envelope.rs @@ -441,9 +441,11 @@ impl RequestEnvelope { /// The client address for policy evaluation: the verified proxy client /// when one is recorded, otherwise the connection peer (keeping its port). pub fn policy_source_addr(&self) -> Option { - let peer = self.remote_addr; - self.client_info - .as_ref() + Self::policy_source_addr_from(self.remote_addr, self.client_info.as_ref()) + } + + pub(crate) fn policy_source_addr_from(peer: Option, client_info: Option<&ClientInfo>) -> Option { + client_info .map(|client| SocketAddr::new(client.real_ip, peer.map_or(0, |addr| addr.port()))) .or(peer) } diff --git a/rustfs/src/server/gateway_stack/control_plane.rs b/rustfs/src/server/gateway_stack/control_plane.rs index 16dc58f1c9..1dfa2f1f28 100644 --- a/rustfs/src/server/gateway_stack/control_plane.rs +++ b/rustfs/src/server/gateway_stack/control_plane.rs @@ -24,6 +24,9 @@ //! (the admin router), or the ten system reads `admin.rs` serves natively. //! Upstream: `server/stack.rs`. Downstream: the gateway signature verifier and the admin router. +mod native_authority; +mod native_routes; + use super::{GatewayAssembly, GatewayAssemblyError, GatewayStack}; use crate::admin::operation::AdminResponse; use crate::admin::router::{AdminOperation, S3Router, dispatch, object_lambda_target, serve_object_lambda}; @@ -262,6 +265,7 @@ fn dialect() -> Result { .ok_or(GatewayAssemblyError::AdminOverlayMissing)?, ); rows.extend_from_slice(control_plane::ROWS); + native_routes::append_rows(&mut rows); let record = RECORD.get_or_init(|| DialectOverlay { name: "rustfs-control-plane", vendor: OVERLAY.vendor, @@ -277,7 +281,8 @@ fn dialect() -> Result { bucket_param: PostV3SpeedtestClientDevnull::BUCKET, }) .declare_form::(STS_ROUTE); - control_plane::declare(builder) + let builder = control_plane::declare(builder); + native_routes::declare(builder) .build() .map_err(GatewayAssemblyError::AdminDialect) } @@ -305,6 +310,7 @@ pub(super) fn assemble( }); let (builder, _settings) = GatewayStack::configured_builder(&assembly, iam, root, gate, authenticator)? .config(super::service_config(assembly.body_read_timeout, CLAIMED_ROUTE_BODY_BYTES)); + let builder = native_routes::register(builder, &host); let service = builder .hand_caller_secret_to_every_operation_after_listing_in_the_posture_report() .dialect(&dialect()?) @@ -371,7 +377,7 @@ struct Admission { /// Whether this host has a handler for `operation`. fn served(operation: &str) -> bool { - [NAME, STS_NAME].contains(&operation) || BORROWED.contains(&operation) + [NAME, STS_NAME].contains(&operation) || BORROWED.contains(&operation) || native_routes::contains(operation) } /// The decision once the rule has admitted a request: a served operation, or any signed request, @@ -385,7 +391,7 @@ fn routed(request: &AuthzRequest<'_>) -> Decision { } impl Admission { - fn route(&self, context: &AuthzContext<'_>, request: &AuthzRequest<'_>) -> Result { + async fn route(&self, context: &AuthzContext<'_>, request: &AuthzRequest<'_>) -> Result { if !served(request.operation) { return Ok(routed(request)); } @@ -397,18 +403,31 @@ impl Admission { self.router .admit(&head.method, &head.uri, &head.headers, signed) .map_err(handler_error)?; - Ok(if head.repeated_authorization { - Decision::Deny - } else { - Decision::Allow - }) + if head.repeated_authorization { + return Ok(Decision::Deny); + } + if native_routes::contains(request.operation) { + if request.operation + == rustfs_gateway_dialect_rustfs_admin::native::ops::delete_v3_target_by_target_type_by_target_name::NAME + { + self.router + .validate_notification_target_params(&head.method, &head.uri) + .map_err(handler_error)?; + } + if let Err(error) = native_authority::authorize(context, request, head).await { + if error.code() == &rustfs_s3_types::S3ErrorCode::AccessDenied { + return Ok(Decision::Deny); + } + return Err(handler_error(error)); + } + } + Ok(Decision::Allow) } } impl Authorizer for Admission { fn authorize_route<'a>(&'a self, context: &'a AuthzContext<'a>, request: &'a AuthzRequest<'a>) -> BoxFuture<'a, Decision> { - let decision = self.route(context, request).unwrap_or(Decision::Deny); - Box::pin(async move { decision }) + Box::pin(async move { self.route(context, request).await.unwrap_or(Decision::Deny) }) } fn authorize_route_result<'a>( @@ -416,8 +435,7 @@ impl Authorizer for Admission { context: &'a AuthzContext<'a>, request: &'a AuthzRequest<'a>, ) -> BoxFuture<'a, Result> { - let decision = self.route(context, request); - Box::pin(async move { decision }) + Box::pin(self.route(context, request)) } fn authorize_input<'a>( diff --git a/rustfs/src/server/gateway_stack/control_plane/native_authority.rs b/rustfs/src/server/gateway_stack/control_plane/native_authority.rs new file mode 100644 index 0000000000..4614194538 --- /dev/null +++ b/rustfs/src/server/gateway_stack/control_plane/native_authority.rs @@ -0,0 +1,212 @@ +// Copyright 2024 RustFS Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Pre-body IAM admission for the mounted non-GET native admin operations. + +use super::ClaimedHead; +use crate::admin::handlers::site_replication::reject_site_replicator_on_public_admin; +use crate::admin::{authenticate_envelope_credentials, validate_admin_request, validate_admin_request_with_bucket}; +use crate::app::{RequestCredentials, RequestEnvelope}; +use crate::auth::get_session_token; +use crate::shared_types::RemoteAddr; +use http::{HeaderMap, HeaderValue, header}; +use rustfs_gateway::{AuthSchemeRef, AuthzRequest, IdentityOrigin, RequestContext, ResourceShape, Subject}; +use rustfs_gateway_dialect_rustfs_admin::native::ops; +use rustfs_policy::policy::action::{Action, AdminAction}; +use rustfs_s3_types::{S3Result, s3_error}; +use rustfs_trusted_proxies::ClientInfo; + +/// Called after the host route admission and path preconditions, before the codec receives the body. +pub(super) async fn authorize(context: &RequestContext<'_>, request: &AuthzRequest<'_>, head: &ClaimedHead) -> S3Result<()> { + let identity = request + .identity + .filter(|identity| context.auth_scheme() == AuthSchemeRef::SigV4Header && identity.origin() == IdentityOrigin::AccessKey) + .ok_or_else(|| s3_error!(AccessDenied, "header-signed admin identity required"))?; + let accepted = context + .headers() + .ok_or_else(|| s3_error!(InternalError, "accepted admin headers are unavailable"))?; + let mut headers = HeaderMap::new(); + for (name, value) in accepted.iter_raw() { + headers.append(name.clone(), value.clone()); + } + if !headers.contains_key(header::HOST) + && let Some(authority) = head.uri.authority() + { + headers.insert( + header::HOST, + HeaderValue::from_str(authority.as_str()) + .map_err(|_| s3_error!(InternalError, "invalid accepted admin authority"))?, + ); + } + let session = get_session_token(&head.uri, &headers).map(str::to_owned); + let credentials = RequestCredentials::without_secret_key(identity.access_key_id().to_owned(), session); + let (credentials, owner) = authenticate_envelope_credentials(&credentials).await?; + let Permission::Admin { action, bucket } = permission(request)? else { + return Ok(()); + }; + + let extensions = context.server_extensions(); + let peer = extensions.get::>().copied().flatten().map(|peer| peer.0); + let source = RequestEnvelope::policy_source_addr_from(peer, extensions.get::()); + match bucket { + Some(bucket) => { + validate_admin_request_with_bucket(&headers, &credentials, owner, false, vec![action], source, bucket).await? + } + None => validate_admin_request(&headers, &credentials, owner, false, vec![action], source).await?, + } + if request.operation == ops::put_v3_site_replication_remove_v2::NAME { + reject_site_replicator_on_public_admin(&credentials)?; + } + Ok(()) +} + +#[derive(Debug, PartialEq, Eq)] +enum Permission<'a> { + Caller, + Admin { action: Action, bucket: Option<&'a str> }, +} + +fn permission<'a>(request: &AuthzRequest<'a>) -> S3Result> { + if request.operation == ops::post_v4_account_permissions::NAME { + if request.action == ops::post_v4_account_permissions::AUTH.action + && request.resource == ResourceShape::Service + && matches!(request.subject, Some(Subject::Caller)) + { + return Ok(Permission::Caller); + } + return Err(s3_error!(AccessDenied, "permission queries require the caller subject")); + } + let (action, shape) = match request.operation { + ops::delete_v3_bucket_etag_by_bucket::NAME | ops::put_v3_bucket_etag_by_bucket::NAME => { + (AdminAction::ConfigUpdateAdminAction, ResourceShape::Bucket) + } + ops::put_v3_site_replication_peer_remove_v2::NAME | ops::put_v3_site_replication_remove_v2::NAME => { + (AdminAction::SiteReplicationRemoveAction, ResourceShape::Service) + } + ops::delete_v3_target_by_target_type_by_target_name::NAME => (AdminAction::SetBucketTargetAction, ResourceShape::Service), + ops::post_v4_heal_mrf_cluster_responsibilities_actions::NAME => (AdminAction::HealAdminAction, ResourceShape::Service), + _ => return Err(s3_error!(InternalError, "unregistered native admin operation")), + }; + let action = Action::AdminAction(action); + if request.action != <&str>::from(&action) || request.resource != shape || request.subject.is_some() { + return Err(s3_error!(AccessDenied, "unexpected admin authorization requirement")); + } + let bucket = if shape == ResourceShape::Bucket { + Some( + request + .bucket + .ok_or_else(|| s3_error!(AccessDenied, "admin bucket is unavailable"))? + .as_str(), + ) + } else { + None + }; + Ok(Permission::Admin { action, bucket }) +} + +#[cfg(test)] +mod tests { + use super::*; + use rustfs_gateway::{BucketName, TargetOrigin}; + use rustfs_gateway_core::op::AuthRequirement; + use rustfs_s3_types::S3ErrorCode; + + fn route<'a>(operation: &'static str, auth: AuthRequirement, bucket: Option<&'a BucketName>) -> AuthzRequest<'a> { + AuthzRequest { + operation, + action: auth.action, + resource: auth.resource, + bucket, + key: None, + copy_source_identity: None, + version_id: None, + route_action: auth.action, + route_bucket: bucket, + route_key: None, + identity: None, + target_origin: TargetOrigin::Path, + subject: None, + } + } + + #[test] + fn etag_write_permissions_use_the_bucket_bound_by_each_operation() { + for (operation, auth) in [ + (ops::put_v3_bucket_etag_by_bucket::NAME, ops::put_v3_bucket_etag_by_bucket::AUTH), + (ops::delete_v3_bucket_etag_by_bucket::NAME, ops::delete_v3_bucket_etag_by_bucket::AUTH), + ] { + for name in ["first-bucket", "second-bucket"] { + let bucket = BucketName::new(name).expect("valid bucket name"); + let request = route(operation, auth, Some(&bucket)); + assert_eq!( + permission(&request).unwrap(), + Permission::Admin { + action: Action::AdminAction(AdminAction::ConfigUpdateAdminAction), + bucket: Some(name), + } + ); + } + assert_eq!(permission(&route(operation, auth, None)).unwrap_err().code(), &S3ErrorCode::AccessDenied); + } + } + + #[test] + fn service_caller_and_deferred_get_permissions_stay_fail_closed() { + for (operation, auth, expected) in [ + ( + ops::post_v4_heal_mrf_cluster_responsibilities_actions::NAME, + ops::post_v4_heal_mrf_cluster_responsibilities_actions::AUTH, + AdminAction::HealAdminAction, + ), + ( + ops::delete_v3_target_by_target_type_by_target_name::NAME, + ops::delete_v3_target_by_target_type_by_target_name::AUTH, + AdminAction::SetBucketTargetAction, + ), + ( + ops::put_v3_site_replication_peer_remove_v2::NAME, + ops::put_v3_site_replication_peer_remove_v2::AUTH, + AdminAction::SiteReplicationRemoveAction, + ), + ( + ops::put_v3_site_replication_remove_v2::NAME, + ops::put_v3_site_replication_remove_v2::AUTH, + AdminAction::SiteReplicationRemoveAction, + ), + ] { + let mut req = route(operation, auth, None); + assert_eq!( + permission(&req).unwrap(), + Permission::Admin { + action: Action::AdminAction(expected), + bucket: None, + } + ); + req.subject = Some(&Subject::Caller); + assert_eq!(permission(&req).unwrap_err().code(), &S3ErrorCode::AccessDenied); + } + + let mut permissions = route(ops::post_v4_account_permissions::NAME, ops::post_v4_account_permissions::AUTH, None); + assert_eq!(permission(&permissions).unwrap_err().code(), &S3ErrorCode::AccessDenied); + permissions.subject = Some(&Subject::Caller); + assert_eq!(permission(&permissions).unwrap(), Permission::Caller); + + for (unmounted, auth) in [ + (ops::get_v3_bucket_etag_by_bucket::NAME, ops::get_v3_bucket_etag_by_bucket::AUTH), + (ops::get_v4_heal_mrf_cluster::NAME, ops::get_v4_heal_mrf_cluster::AUTH), + ] { + assert_eq!(permission(&route(unmounted, auth, None)).unwrap_err().code(), &S3ErrorCode::InternalError); + } + } +} diff --git a/rustfs/src/server/gateway_stack/control_plane/native_routes.rs b/rustfs/src/server/gateway_stack/control_plane/native_routes.rs new file mode 100644 index 0000000000..ff7cec1ac1 --- /dev/null +++ b/rustfs/src/server/gateway_stack/control_plane/native_routes.rs @@ -0,0 +1,134 @@ +// Copyright 2024 RustFS Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Non-GET native admin routes served ahead of the host's control-plane catch-all. +//! +//! GET admin routes stay on [`super::ControlPlane`] until `GatewayStack` carries a dedicated +//! Object Lambda fallback, preserving presigned `?lambdaArn=...` requests (#1577). + +use super::{Host, NAME, ROUTER}; +use rustfs_gateway::ServiceBuilder; +use rustfs_gateway_core::dialect::{ClaimedRoute, DialectBuilder, OverlayRow}; +use rustfs_gateway_core::route::ShadowingDecl; +use rustfs_gateway_dialect_rustfs_admin::{AdminOperation, native::ops}; +use std::sync::Arc; + +const fn shadows_control_plane(winner: &'static str) -> ShadowingDecl { + ShadowingDecl { + winner, + shadowed: NAME, + reason: "The registered admin handler precedes the control-plane catch-all.", + evidence: &[ROUTER], + } +} + +macro_rules! native_routes { + ($($module:ident::$operation:ident),+ $(,)?) => { + const ROWS: &[OverlayRow] = &[$(ops::$module::OVERLAY_ROW),+]; + + pub(super) fn declare(builder: DialectBuilder) -> DialectBuilder { + $( + let builder = builder.declare_claimed::(ClaimedRoute { + precedence: ops::$module::$operation::PRECEDENCE, + rows: ops::$module::$operation::rows(), + shadows: const { &[shadows_control_plane(ops::$module::NAME)] }, + bucket_param: ops::$module::$operation::BUCKET, + }); + )+ + builder + } + + pub(super) fn register(builder: ServiceBuilder, host: &Arc) -> ServiceBuilder { + builder$(.register::(Arc::clone(host)))+ + } + }; +} + +native_routes!( + delete_v3_bucket_etag_by_bucket::DeleteV3BucketEtagByBucket, + delete_v3_target_by_target_type_by_target_name::DeleteV3TargetByTargetTypeByTargetName, + post_v4_account_permissions::PostV4AccountPermissions, + post_v4_heal_mrf_cluster_responsibilities_actions::PostV4HealMrfClusterResponsibilitiesActions, + put_v3_bucket_etag_by_bucket::PutV3BucketEtagByBucket, + put_v3_site_replication_peer_remove_v2::PutV3SiteReplicationPeerRemoveV2, + put_v3_site_replication_remove_v2::PutV3SiteReplicationRemoveV2, +); + +pub(super) fn append_rows(rows: &mut Vec) { + rows.extend_from_slice(ROWS); +} + +pub(super) fn contains(name: &str) -> bool { + ROWS.iter().any(|row| row.name == name) +} + +#[cfg(test)] +mod tests { + use super::*; + use rustfs_gateway_dialect_rustfs_admin::{ROUTES, native}; + + #[test] + fn non_get_native_admin_routes_precede_the_control_plane_and_get_routes_stay_deferred() { + let dialect = super::super::dialect().expect("control-plane dialect"); + let fallback = dialect + .claimed_operations() + .iter() + .find(|op| op.name() == NAME) + .expect("control-plane catch-all"); + let added: Vec<_> = native::ROUTES + .iter() + .filter(|record| !ROUTES.iter().any(|old| old.operation == record.operation)) + .collect(); + let deferred_reads: Vec<_> = added.iter().copied().filter(|record| record.method == "GET").collect(); + let mounted_writes: Vec<_> = added.iter().copied().filter(|record| record.method != "GET").collect(); + + assert_eq!(deferred_reads.len(), 5); + for record in deferred_reads { + assert!(!contains(record.operation), "{}", record.operation); + assert!( + !dialect.claimed_operations().iter().any(|op| op.name() == record.operation), + "{}", + record.operation + ); + } + + assert_eq!(mounted_writes.len(), 7); + assert_eq!(ROWS.len(), mounted_writes.len()); + for record in mounted_writes { + assert!(contains(record.operation), "{}", record.operation); + let op = dialect + .claimed_operations() + .iter() + .find(|op| op.name() == record.operation) + .expect("mounted native operation"); + assert!(op.precedence() < fallback.precedence()); + assert!( + op.shadows() + .iter() + .any(|shadow| shadow.winner == record.operation && shadow.shadowed == NAME) + ); + assert_eq!(op.entries().len(), 2); + for (entry, path) in op.entries().iter().zip([record.path, record.alias.expect("MinIO alias")]) { + let path = path + .split('/') + .map(|segment| if segment.starts_with('{') { "example" } else { segment }) + .collect::>() + .join("/"); + assert!(entry.template().matches(&path), "{path}"); + assert_eq!(entry.bucket_param(), record.bucket); + assert!(fallback.entries().iter().any(|other| other.template().matches(&path))); + } + } + } +} diff --git a/rustfs/src/server/gateway_stack/tests/control_plane.rs b/rustfs/src/server/gateway_stack/tests/control_plane.rs index be58193c60..97551f142c 100644 --- a/rustfs/src/server/gateway_stack/tests/control_plane.rs +++ b/rustfs/src/server/gateway_stack/tests/control_plane.rs @@ -514,28 +514,35 @@ async fn an_unsigned_amz_header_is_refused_before_any_control_plane_handler() { #[tokio::test] #[serial_test::serial] -async fn typed_admin_routes_serve_canonical_alias_verified_body_and_presigned_object_lambda() { +async fn typed_admin_routes_enforce_pre_body_iam_target_validation_and_presigned_object_lambda() { use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions}; use crate::runtime_sources::{AppContext, publish_test_app_context}; + use rustfs_gateway_dialect_rustfs_admin::native::{extensions, ops as native_ops}; use rustfs_iam::store::object::{IAM_CONFIG_PREFIX, ObjectStore}; use rustfs_iam::store::{Store as _, UserType}; + use rustfs_iam::sys::{NewServiceAccountOpts, SITE_REPLICATOR_SERVICE_ACCOUNT}; use rustfs_madmin::{AccountStatus, AddOrUpdateUserReq}; use rustfs_policy::policy::Policy; use serde_json::{Value, json}; const USER: &str = "typed-admin-caller"; const SECRET: &str = "typed-admin-caller-test-secret"; - const BUCKET: &str = "typed-etag-bucket"; + const REPLICATOR_SECRET: &str = "siteReplicatorSecretKeyForTest1234567890"; + const ALLOWED_BUCKET: &str = "typed-etag-allowed"; + const DENIED_BUCKET: &str = "typed-etag-denied"; + let env = rustfs_test_utils::TestECStoreEnv::builder() .prefix("typed_admin_routes") .disk_count(1) .init_bucket_metadata(true) .build() .await; - env.ecstore - .make_bucket(BUCKET, &MakeBucketOptions::default()) - .await - .expect("create bucket"); + for bucket in [ALLOWED_BUCKET, DENIED_BUCKET] { + env.ecstore + .make_bucket(bucket, &MakeBucketOptions::default()) + .await + .expect("create test bucket"); + } ObjectStore::new(env.ecstore.clone()) .save_iam_config(json!({"version":1}), format!("{}/format.json", *IAM_CONFIG_PREFIX)) .await @@ -552,10 +559,14 @@ async fn typed_admin_routes_serve_canonical_alias_verified_body_and_presigned_ob .await .expect("create caller"); let policy = Policy::parse_config( - br#"{"Version":"2012-10-17","Statement":[ - {"Effect":"Allow","Action":"admin:SiteReplicationRemove"}, - {"Effect":"Allow","Action":"s3:GetObject","Resource":["arn:aws:s3:::rustfs/*","arn:aws:s3:::minio/*"]} - ]}"#, + format!( + r#"{{"Version":"2012-10-17","Statement":[ + {{"Effect":"Allow","Action":["admin:SiteReplicationRemove","admin:ConfigUpdate"]}}, + {{"Effect":"Deny","Action":"*","Resource":["arn:aws:s3:::{DENIED_BUCKET}","arn:aws:s3:::{DENIED_BUCKET}/*"]}}, + {{"Effect":"Allow","Action":"s3:GetObject","Resource":["arn:aws:s3:::rustfs/*","arn:aws:s3:::minio/*"]}} + ]}}"# + ) + .as_bytes(), ) .expect("caller policy"); iam.set_policy(USER, policy).await.expect("save caller policy"); @@ -565,7 +576,7 @@ async fn typed_admin_routes_serve_canonical_alias_verified_body_and_presigned_ob let context = Arc::new(AppContext::with_default_interfaces( env.ecstore.clone(), - iam, + iam.clone(), Arc::new(rustfs_kms::KmsServiceManager::new()), )); assert!(context.iam().is_ready()); @@ -576,14 +587,60 @@ async fn typed_admin_routes_serve_canonical_alias_verified_body_and_presigned_ob ..Default::default() })); publish_test_app_context(context.clone()); + + let replicator_policy = Policy::parse_config( + br#"{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"admin:SiteReplicationRemove"}]}"#, + ) + .expect("replicator policy"); + iam.new_service_account( + ROOT_ACCESS_KEY, + None, + NewServiceAccountOpts { + access_key: SITE_REPLICATOR_SERVICE_ACCOUNT.to_owned(), + secret_key: REPLICATOR_SECRET.to_owned(), + session_policy: Some(replicator_policy), + allow_site_replicator_account: true, + ..Default::default() + }, + ) + .await + .expect("create site replicator service account"); + let assembly = assembly(); assert!(assembly.server_ctx.install(context)); let router = crate::admin::make_admin_router(false, assembly.server_ctx.clone()).expect("production router"); let stack = GatewayStack::assemble_control_plane(assembly, Arc::new(router)).expect("control-plane stack"); - for row in rustfs_gateway_dialect_rustfs_admin::native::extensions::control_plane::ROWS { + + // All 8 extension rows and all 7 non-GET native claimed routes are registered on the service, + // while the 5 GET native routes stay on ControlPlane so Object Lambda presigned URLs work. + for row in extensions::control_plane::ROWS { assert!(stack.service.operations().any(|registered| registered == row.name), "{}", row.name); } + for mounted in [ + native_ops::delete_v3_bucket_etag_by_bucket::NAME, + native_ops::delete_v3_target_by_target_type_by_target_name::NAME, + native_ops::post_v4_account_permissions::NAME, + native_ops::post_v4_heal_mrf_cluster_responsibilities_actions::NAME, + native_ops::put_v3_bucket_etag_by_bucket::NAME, + native_ops::put_v3_site_replication_peer_remove_v2::NAME, + native_ops::put_v3_site_replication_remove_v2::NAME, + ] { + assert!(stack.service.operations().any(|registered| registered == mounted), "{mounted}"); + } + for deferred_get in [ + native_ops::get_v3_bucket_etag_by_bucket::NAME, + native_ops::get_v3_site_replication_remove_v2_capabilities::NAME, + native_ops::get_v4_heal_mrf_cluster::NAME, + native_ops::get_v4_heal_mrf_cluster_responsibilities::NAME, + native_ops::get_v4_heal_mrf_cluster_responsibilities_by_node_id_by_id::NAME, + ] { + assert!( + !stack.service.operations().any(|registered| registered == deferred_get), + "{deferred_get} must stay deferred" + ); + } + // 1. Subject::Caller self-query on PostV4AccountPermissions (canonical and MinIO alias). for prefix in ["/rustfs/admin", "/minio/admin"] { let request = signed_body_request( Method::POST, @@ -591,63 +648,188 @@ async fn typed_admin_routes_serve_canonical_alias_verified_body_and_presigned_ob "", USER, SECRET, - Bytes::from_static(br#"{"checks":[{"id":"capabilities","action":"admin:SiteReplicationRemove"}]}"#), + Bytes::from_static( + br#"{"checks":[{"id":"capabilities","action":"admin:SiteReplicationRemove"},{"id":"heal","action":"admin:Heal"}]}"#, + ), ); let (status, _, body) = answer_request_full(&stack, request).await; assert_eq!(status, StatusCode::OK, "{prefix}: {body}"); assert_eq!( serde_json::from_str::(&body).expect("permission results"), - json!({"results":[{"id":"capabilities","decision":"allowed"}]}) + json!({"results":[ + {"id":"capabilities","decision":"allowed"}, + {"id":"heal","decision":"denied"} + ]}) ); } - let root_put = signed_body_request( - Method::PUT, - &format!("/rustfs/admin/v3/bucket-etag/{BUCKET}"), - "", - ROOT_ACCESS_KEY, - ROOT_SECRET_KEY, - Bytes::from_static(br#"{"algorithm":"xxh3"}"#), - ); - let (status, _, body) = answer_request_full(&stack, root_put).await; - assert_eq!(status, StatusCode::OK, "{body}"); - assert_eq!( - serde_json::from_str::(&body).expect("set bucket etag"), - json!({"bucket": BUCKET, "algorithm": "xxh3"}) - ); + // 2. Bucket-scoped ConfigUpdateAdminAction + pre-body IAM denial on Put/DeleteV3BucketEtagByBucket. + let etag_body = Bytes::from_static(br#"{"algorithm":"xxh3"}"#); + let unused_delete_body = Bytes::from_static(b"aaaa"); + for prefix in ["/rustfs/admin", "/minio/admin"] { + let denied_put = signed_body_request( + Method::PUT, + &format!("{prefix}/v3/bucket-etag/{DENIED_BUCKET}"), + "", + USER, + SECRET, + etag_body.clone(), + ); + let (counted_put, put_bytes_read) = CountedBody::new(etag_body.len()); + let response = stack.call(denied_put.map(|_| counted_put)).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN, "{prefix} denied PUT"); + assert_eq!(put_bytes_read.load(Ordering::SeqCst), 0, "{prefix} denied PUT read body"); - let payload = Bytes::from_static(b"aaaa"); - let unauth_delete = signed_body_request( - Method::DELETE, - &format!("/rustfs/admin/v3/bucket-etag/{BUCKET}"), + let denied_delete = signed_body_request( + Method::DELETE, + &format!("{prefix}/v3/bucket-etag/{DENIED_BUCKET}"), + "", + USER, + SECRET, + unused_delete_body.clone(), + ); + let (counted_delete, delete_bytes_read) = CountedBody::new(unused_delete_body.len()); + let response = stack.call(denied_delete.map(|_| counted_delete)).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN, "{prefix} denied DELETE"); + assert_eq!(delete_bytes_read.load(Ordering::SeqCst), 0, "{prefix} denied DELETE read body"); + + // Presigned URL on a privileged native admin route is rejected by the floor before reading. + let presigned_delete = signed_request( + Signed::Query, + Method::DELETE, + &format!("{prefix}/v3/bucket-etag/{ALLOWED_BUCKET}"), + "", + USER, + SECRET, + ); + let (status, _, _) = answer_request(&stack, presigned_delete).await; + assert_eq!(status, StatusCode::FORBIDDEN, "{prefix} presigned native DELETE"); + + // Allowed bucket succeeds on both PUT and body-draining DELETE for both prefixes. + let allowed_put = signed_body_request( + Method::PUT, + &format!("{prefix}/v3/bucket-etag/{ALLOWED_BUCKET}"), + "", + USER, + SECRET, + etag_body.clone(), + ); + let (status, _, body) = answer_request_full(&stack, allowed_put).await; + assert_eq!(status, StatusCode::OK, "{prefix} allowed PUT: {body}"); + assert_eq!( + serde_json::from_str::(&body).expect("set bucket etag"), + json!({"bucket": ALLOWED_BUCKET, "algorithm": "xxh3"}) + ); + + let allowed_delete = signed_body_request( + Method::DELETE, + &format!("{prefix}/v3/bucket-etag/{ALLOWED_BUCKET}"), + "", + USER, + SECRET, + unused_delete_body.clone(), + ); + let (counted, bytes_read) = CountedBody::new(unused_delete_body.len()); + let response = stack.call(allowed_delete.map(|_| counted)).await; + assert_eq!(response.status(), StatusCode::OK, "{prefix} allowed DELETE"); + assert_eq!(bytes_read.load(Ordering::SeqCst), unused_delete_body.len()); + let deleted = response.into_body().collect().await.expect("delete etag body").to_bytes(); + assert_eq!( + serde_json::from_slice::(&deleted).expect("deleted bucket etag"), + json!({"bucket": ALLOWED_BUCKET, "algorithm": null}) + ); + } + + // 3. Notification target parameter validation runs BEFORE IAM on DeleteV3TargetByTargetTypeByTargetName. + for prefix in ["/rustfs/admin", "/minio/admin"] { + let invalid_target = signed_body_request( + Method::DELETE, + &format!("{prefix}/v3/target/not-a-supported-target/test-name"), + "", + USER, + SECRET, + unused_delete_body.clone(), + ); + let (counted_invalid, invalid_read) = CountedBody::new(unused_delete_body.len()); + let response = stack.call(invalid_target.map(|_| counted_invalid)).await; + let status = response.status(); + let body = String::from_utf8_lossy(&response.into_body().collect().await.expect("error body").to_bytes()).into_owned(); + assert_eq!(status, StatusCode::BAD_REQUEST, "{prefix} invalid target: {body}"); + assert!(body.contains("InvalidArgument"), "{prefix} invalid target: {body}"); + assert_eq!(invalid_read.load(Ordering::SeqCst), 0); + + let valid_target_unauth = signed_body_request( + Method::DELETE, + &format!("{prefix}/v3/target/{}/test-name", rustfs_config::notify::NOTIFY_WEBHOOK_SUB_SYS), + "", + USER, + SECRET, + unused_delete_body.clone(), + ); + let (counted_unauth, unauth_read) = CountedBody::new(unused_delete_body.len()); + let response = stack.call(valid_target_unauth.map(|_| counted_unauth)).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN, "{prefix} valid target unauthorized"); + assert_eq!(unauth_read.load(Ordering::SeqCst), 0); + } + + // 4. reject_site_replicator_on_public_admin blocks PutV3SiteReplicationRemoveV2 pre-body, + // while PutV3SiteReplicationPeerRemoveV2 admits the replicator account and reads its body. + let removal_payload = Bytes::from_static(b"{}"); + for prefix in ["/rustfs/admin", "/minio/admin"] { + let public_remove = signed_body_request( + Method::PUT, + &format!("{prefix}/v3/site-replication/remove-v2"), + "", + SITE_REPLICATOR_SERVICE_ACCOUNT, + REPLICATOR_SECRET, + removal_payload.clone(), + ); + let (counted_public, public_read) = CountedBody::new(removal_payload.len()); + let response = stack.call(public_remove.map(|_| counted_public)).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN, "{prefix} public remove-v2"); + assert_eq!(public_read.load(Ordering::SeqCst), 0, "{prefix} public remove-v2 read body"); + + let peer_remove = signed_body_request( + Method::PUT, + &format!("{prefix}/v3/site-replication/peer/remove-v2"), + "", + SITE_REPLICATOR_SERVICE_ACCOUNT, + REPLICATOR_SECRET, + removal_payload.clone(), + ); + let (counted_peer, peer_read) = CountedBody::new(removal_payload.len()); + let _response = stack.call(peer_remove.map(|_| counted_peer)).await; + assert_eq!(peer_read.load(Ordering::SeqCst), removal_payload.len(), "{prefix} peer remove-v2"); + } + + // 5. PostV4HealMrfClusterResponsibilitiesActions denies unauthorized caller pre-body and admits root. + let heal_payload = Bytes::from_static(b"{}"); + let unauth_heal = signed_body_request( + Method::POST, + "/rustfs/admin/v4/heal/mrf/cluster/responsibilities/actions", "", USER, SECRET, - payload.clone(), + heal_payload.clone(), ); - let (status, _, _) = answer_request_full(&stack, unauth_delete).await; - assert_eq!(status, StatusCode::FORBIDDEN); + let (counted_heal, heal_read) = CountedBody::new(heal_payload.len()); + let response = stack.call(unauth_heal.map(|_| counted_heal)).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN); + assert_eq!(heal_read.load(Ordering::SeqCst), 0); - // Unused payload on a control-plane DELETE is buffered and verified before the handler answers. - let root_delete = signed_body_request( - Method::DELETE, - &format!("/rustfs/admin/v3/bucket-etag/{BUCKET}"), + let root_heal = signed_body_request( + Method::POST, + "/minio/admin/v4/heal/mrf/cluster/responsibilities/actions", "", ROOT_ACCESS_KEY, ROOT_SECRET_KEY, - payload.clone(), - ); - let (counted, bytes_read) = CountedBody::new(payload.len()); - let response = stack.call(root_delete.map(|_| counted)).await; - assert_eq!(response.status(), StatusCode::OK); - assert_eq!(bytes_read.load(Ordering::SeqCst), payload.len()); - let deleted = response.into_body().collect().await.expect("delete etag body").to_bytes(); - assert_eq!( - serde_json::from_slice::(&deleted).expect("deleted bucket etag"), - json!({"bucket": BUCKET, "algorithm": null}) + heal_payload.clone(), ); + let (counted_root_heal, root_heal_read) = CountedBody::new(heal_payload.len()); + let _response = stack.call(root_heal.map(|_| counted_root_heal)).await; + assert_eq!(root_heal_read.load(Ordering::SeqCst), heal_payload.len()); - // Admin GET paths preserve header-signed and presigned Object Lambda priority (#1577). + // 6. Deferred GET paths stay on ControlPlane so admin GETs and presigned Object Lambda (#1577) both work. let expected = json!({"contractVersion":2,"durableCleanup":true}); for prefix in ["/rustfs/admin", "/minio/admin"] { let path = format!("{prefix}/v3/site-replication/remove-v2/capabilities"); @@ -657,11 +839,17 @@ async fn typed_admin_routes_serve_canonical_alias_verified_body_and_presigned_ob assert_eq!(serde_json::from_str::(&body).expect("removal capabilities"), expected); let lambda_query = "lambdaArn=arn%3Aacme%3As3-object-lambda%3A%3Atransformer%3Awebhook"; - for form in [Signed::Header, Signed::Query] { - let lambda_get = signed_request(form, Method::GET, &path, lambda_query, USER, SECRET); - let (status, _, body) = answer_request(&stack, lambda_get).await; - assert_eq!(status, StatusCode::NOT_FOUND, "{path}?{lambda_query}: {body}"); - assert!(body.contains("NoSuchBucket"), "{path}?{lambda_query}: {body}"); + for lambda_path in [ + path.clone(), + format!("{prefix}/v3/bucket-etag/{ALLOWED_BUCKET}"), + format!("{prefix}/v4/heal/mrf/cluster"), + ] { + for form in [Signed::Header, Signed::Query] { + let lambda_get = signed_request(form, Method::GET, &lambda_path, lambda_query, USER, SECRET); + let (status, _, body) = answer_request(&stack, lambda_get).await; + assert_eq!(status, StatusCode::NOT_FOUND, "{lambda_path}?{lambda_query}: {body}"); + assert!(body.contains("NoSuchBucket"), "{lambda_path}?{lambda_query}: {body}"); + } } let encoded_query = "lambda%41rn=arn%3Aacme%3As3-object-lambda%3A%3Atransformer%3Awebhook";