mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 13:00:52 +00:00
feat(gateway): serve signed admin system reads
Serve the storage info, runtime capabilities and object cache statistics
GET aliases through the native admin service. Call the existing full IAM
gates and owned handlers, preserve raw request facts and keep the Keystone
guard first.
Add two contract matrices (42 allowed and 168 refused rows), with expanded
selector, registry, envelope and readiness coverage. On 2fea17d57d, the
restored source passed 72 scoped tests, fmt and both rustfs all-targets
Clippy modes. Script tests and test wiring also passed.
29 effective fault runs cover selection, lambda precedence, all three
dispatch/action/authorization bindings, signature verification, source IP,
raw URI/query, request context, readiness, response bytes/status/headers/
length and the registry. Nine controls ran in separate processes against
the same binary before those faults.
Not verified: live listeners and full production middleware, session
credentials, active cache statistics, CI or the full workspace tests.
This commit is contained in:
@@ -922,11 +922,21 @@ pub(crate) fn claims_route(method: &Method, uri: &Uri, headers: &HeaderMap) -> b
|
||||
|| is_control_plane_route(method, uri, headers)
|
||||
}
|
||||
|
||||
/// The signed server-info aliases, after object-lambda routing has had its existing priority.
|
||||
/// Signed system-status reads, after object-lambda routing has had its existing priority.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn claims_native_admin_route(method: &Method, uri: &Uri) -> bool {
|
||||
method == Method::GET
|
||||
&& matches!(uri.path(), "/rustfs/admin/v3/info" | "/minio/admin/v3/info")
|
||||
&& matches!(
|
||||
uri.path(),
|
||||
"/rustfs/admin/v3/info"
|
||||
| "/minio/admin/v3/info"
|
||||
| "/rustfs/admin/v3/storageinfo"
|
||||
| "/minio/admin/v3/storageinfo"
|
||||
| "/rustfs/admin/v4/runtime/capabilities"
|
||||
| "/minio/admin/v4/runtime/capabilities"
|
||||
| "/rustfs/admin/v3/object-data-cache/stats"
|
||||
| "/minio/admin/v3/object-data-cache/stats"
|
||||
)
|
||||
&& parse_object_lambda_request(method, uri).is_none()
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Bridges the two signed server-info aliases to the owned admin handler.
|
||||
//! Bridges signed system-status reads to their owned admin handlers.
|
||||
//! It owns neither IAM policy decisions nor other admin routes. Upstream: the edge selector;
|
||||
//! downstream: the gateway signature verifier and the real ServerInfoHandler.
|
||||
//! downstream: the gateway signature verifier and the real admin handlers.
|
||||
|
||||
use super::{GatewayAssembly, GatewayAssemblyError, GatewayStack};
|
||||
use crate::admin::handlers::system::ServerInfoHandler;
|
||||
use crate::admin::operation::{AdminRequest, AdminResponse, Operation as _};
|
||||
use crate::admin::handlers::object_data_cache::ObjectDataCacheStatsHandler;
|
||||
use crate::admin::handlers::system::{RuntimeCapabilitiesHandler, ServerInfoHandler, StorageInfoHandler};
|
||||
use crate::admin::operation::{AdminRequest, AdminResponse, Operation as AdminHandler};
|
||||
use crate::app::RequestEnvelope;
|
||||
use crate::runtime_sources::ServerContextSlot;
|
||||
use crate::server::gateway_handlers::{handler_error, verified_signature};
|
||||
@@ -26,30 +27,48 @@ use crate::storage_api::server::http::access::ReqInfo;
|
||||
use http_body_util::BodyExt as _;
|
||||
use rustfs_gateway::{Decision, Handler, HandlerResult, Operation, Req, RequestContextView, Resp, decide_with};
|
||||
use rustfs_gateway_adapter::{IamKeyLookup, RootSource};
|
||||
use rustfs_gateway_core::dialect::{ClaimedRoute, Dialect, DialectOverlay};
|
||||
use rustfs_gateway_dialect_rustfs_admin::ops::get_v3_info::GetV3Info;
|
||||
use rustfs_gateway_core::dialect::{ClaimedRoute, Dialect, DialectBuilder, DialectOverlay, OverlayRow};
|
||||
use rustfs_gateway_dialect_rustfs_admin::ops::{
|
||||
get_v3_info::GetV3Info, get_v3_object_data_cache_stats::GetV3ObjectDataCacheStats, get_v3_storageinfo::GetV3Storageinfo,
|
||||
get_v4_runtime_capabilities::GetV4RuntimeCapabilities,
|
||||
};
|
||||
use rustfs_gateway_dialect_rustfs_admin::{AdminOperation, AdminResponse as WireResponse, CLAIMS, OVERLAY};
|
||||
use rustfs_s3_types::{Body, S3Result, s3_error};
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
const OPERATIONS: [&str; 4] = [
|
||||
GetV3Info::NAME,
|
||||
GetV3Storageinfo::NAME,
|
||||
GetV4RuntimeCapabilities::NAME,
|
||||
GetV3ObjectDataCacheStats::NAME,
|
||||
];
|
||||
|
||||
fn declare<O: AdminOperation>(builder: DialectBuilder) -> DialectBuilder {
|
||||
builder.declare_claimed::<O>(ClaimedRoute {
|
||||
precedence: O::PRECEDENCE,
|
||||
rows: O::rows(),
|
||||
shadows: &[],
|
||||
bucket_param: O::BUCKET,
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn dialect() -> Result<Dialect, GatewayAssemblyError> {
|
||||
static OVERLAY_INFO: OnceLock<DialectOverlay> = OnceLock::new();
|
||||
let row = OVERLAY
|
||||
.row(GetV3Info::NAME)
|
||||
.ok_or(GatewayAssemblyError::AdminOverlayMissing)?;
|
||||
let overlay = OVERLAY_INFO.get_or_init(|| DialectOverlay {
|
||||
name: "rustfs-server-info",
|
||||
static ROWS: OnceLock<Vec<OverlayRow>> = OnceLock::new();
|
||||
static OVERLAY_READS: OnceLock<DialectOverlay> = OnceLock::new();
|
||||
let rows = OPERATIONS
|
||||
.iter()
|
||||
.map(|name| OVERLAY.row(name).copied().ok_or(GatewayAssemblyError::AdminOverlayMissing))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let overlay = OVERLAY_READS.get_or_init(|| DialectOverlay {
|
||||
name: "rustfs-system-reads",
|
||||
vendor: OVERLAY.vendor,
|
||||
claims: &CLAIMS[..2],
|
||||
operations: std::slice::from_ref(row),
|
||||
operations: ROWS.get_or_init(|| rows),
|
||||
});
|
||||
Dialect::assemble(overlay)
|
||||
.declare_claimed::<GetV3Info>(ClaimedRoute {
|
||||
precedence: GetV3Info::PRECEDENCE,
|
||||
rows: GetV3Info::rows(),
|
||||
shadows: &[],
|
||||
bucket_param: GetV3Info::BUCKET,
|
||||
})
|
||||
let builder = declare::<GetV3Info>(Dialect::assemble(overlay));
|
||||
let builder = declare::<GetV3Storageinfo>(builder);
|
||||
let builder = declare::<GetV4RuntimeCapabilities>(builder);
|
||||
declare::<GetV3ObjectDataCacheStats>(builder)
|
||||
.build()
|
||||
.map_err(GatewayAssemblyError::AdminDialect)
|
||||
}
|
||||
@@ -60,7 +79,7 @@ pub(super) fn assemble(
|
||||
root: Arc<dyn RootSource>,
|
||||
) -> Result<GatewayStack, GatewayAssemblyError> {
|
||||
let gate = decide_with(|request| {
|
||||
if request.operation == GetV3Info::NAME {
|
||||
if OPERATIONS.contains(&request.operation) {
|
||||
Decision::Allow
|
||||
} else {
|
||||
Decision::Deny
|
||||
@@ -69,8 +88,21 @@ pub(super) fn assemble(
|
||||
let builder = GatewayStack::configured_builder(&assembly, iam, root, gate)?;
|
||||
let service = builder
|
||||
.dialect(&dialect()?)
|
||||
.register::<GetV3Info, _>(Arc::new(ServerInfoBridge {
|
||||
.register::<GetV3Info, _>(Arc::new(AdminBridge {
|
||||
server_ctx: assembly.server_ctx.clone(),
|
||||
handler: &ServerInfoHandler {},
|
||||
}))
|
||||
.register::<GetV3Storageinfo, _>(Arc::new(AdminBridge {
|
||||
server_ctx: assembly.server_ctx.clone(),
|
||||
handler: &StorageInfoHandler {},
|
||||
}))
|
||||
.register::<GetV4RuntimeCapabilities, _>(Arc::new(AdminBridge {
|
||||
server_ctx: assembly.server_ctx.clone(),
|
||||
handler: &RuntimeCapabilitiesHandler {},
|
||||
}))
|
||||
.register::<GetV3ObjectDataCacheStats, _>(Arc::new(AdminBridge {
|
||||
server_ctx: assembly.server_ctx,
|
||||
handler: &ObjectDataCacheStatsHandler {},
|
||||
}))
|
||||
.build()
|
||||
.map_err(GatewayAssemblyError::Service)?;
|
||||
@@ -80,7 +112,8 @@ pub(super) fn assemble(
|
||||
})
|
||||
}
|
||||
|
||||
struct ServerInfoBridge {
|
||||
struct AdminBridge {
|
||||
handler: &'static dyn AdminHandler,
|
||||
server_ctx: Arc<ServerContextSlot>,
|
||||
}
|
||||
|
||||
@@ -92,13 +125,14 @@ pub(super) fn envelope(context: &RequestContextView, server_ctx: &Arc<ServerCont
|
||||
Ok(envelope)
|
||||
}
|
||||
|
||||
impl Handler<GetV3Info> for ServerInfoBridge {
|
||||
async fn call(&self, request: Req<GetV3Info>) -> HandlerResult<GetV3Info> {
|
||||
impl<O: Operation<Output = WireResponse>> Handler<O> for AdminBridge {
|
||||
async fn call(&self, request: Req<O>) -> HandlerResult<O> {
|
||||
if self.server_ctx.installed_app_context().is_none() {
|
||||
return Err(handler_error(s3_error!(ServiceUnavailable, "server context is not ready")));
|
||||
}
|
||||
let envelope = envelope(request.context(), &self.server_ctx).map_err(handler_error)?;
|
||||
let response = ServerInfoHandler {}
|
||||
let response = self
|
||||
.handler
|
||||
.call(AdminRequest::new(envelope, Body::empty()), matchit::Params::new())
|
||||
.await
|
||||
.map_err(handler_error)?;
|
||||
@@ -106,13 +140,13 @@ impl Handler<GetV3Info> for ServerInfoBridge {
|
||||
}
|
||||
}
|
||||
|
||||
// ServerInfoHandler already constructs the complete JSON in memory. This bridge does not serve streams.
|
||||
pub(super) async fn complete_response(response: AdminResponse) -> HandlerResult<GetV3Info> {
|
||||
// These handlers construct complete JSON in memory. This bridge does not serve streams.
|
||||
pub(super) async fn complete_response<O: Operation<Output = WireResponse>>(response: AdminResponse) -> HandlerResult<O> {
|
||||
let (status, mut headers, body) = response.into_parts();
|
||||
let bytes = body
|
||||
.collect()
|
||||
.await
|
||||
.map_err(|_| handler_error(s3_error!(InternalError, "failed to read server info response")))?
|
||||
.map_err(|_| handler_error(s3_error!(InternalError, "failed to read admin response")))?
|
||||
.to_bytes();
|
||||
headers.remove(http::header::CONTENT_LENGTH);
|
||||
Ok(Resp::with_status(WireResponse::bytes("", bytes.to_vec()), status.as_u16()).with_extra_headers(headers))
|
||||
|
||||
@@ -27,23 +27,42 @@ use http::{HeaderMap, Method, StatusCode};
|
||||
use rustfs_gateway::Answer;
|
||||
use rustfs_gateway::{Decision, Handler, HandlerResult, Operation, PathStyleOnly, Req, Resp, decide_with};
|
||||
use rustfs_gateway_dialect_rustfs_admin::AdminResponse as WireResponse;
|
||||
use rustfs_gateway_dialect_rustfs_admin::ops::get_v3_info::GetV3Info;
|
||||
use rustfs_gateway_dialect_rustfs_admin::ops::{
|
||||
get_v3_info::GetV3Info, get_v3_object_data_cache_stats::GetV3ObjectDataCacheStats, get_v3_storageinfo::GetV3Storageinfo,
|
||||
get_v4_runtime_capabilities::GetV4RuntimeCapabilities,
|
||||
};
|
||||
use rustfs_s3_types::Body;
|
||||
use rustfs_trusted_proxies::ClientInfo;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[test]
|
||||
fn native_admin_registers_one_operation_and_both_claims() {
|
||||
fn native_admin_registers_only_system_reads_and_both_claims() {
|
||||
let dialect = dialect().unwrap();
|
||||
assert_eq!(dialect.operation_names().collect::<Vec<_>>(), [GetV3Info::NAME]);
|
||||
let mut expected = [
|
||||
GetV3Info::NAME,
|
||||
GetV3Storageinfo::NAME,
|
||||
GetV4RuntimeCapabilities::NAME,
|
||||
GetV3ObjectDataCacheStats::NAME,
|
||||
];
|
||||
expected.sort();
|
||||
let mut names = dialect.operation_names().collect::<Vec<_>>();
|
||||
names.sort();
|
||||
assert_eq!(names, expected);
|
||||
assert_eq!(
|
||||
dialect.claims().iter().map(|claim| claim.prefix).collect::<Vec<_>>(),
|
||||
["/rustfs/admin", "/minio/admin"]
|
||||
);
|
||||
assert_eq!(dialect.claimed_operations()[0].entries().len(), 2);
|
||||
assert!(
|
||||
dialect
|
||||
.claimed_operations()
|
||||
.iter()
|
||||
.all(|operation| operation.entries().len() == 2)
|
||||
);
|
||||
let stack = GatewayStack::assemble_admin(assembly()).unwrap();
|
||||
assert_eq!(stack.service.operations().collect::<Vec<_>>(), [GetV3Info::NAME]);
|
||||
let mut names = stack.service.operations().collect::<Vec<_>>();
|
||||
names.sort();
|
||||
assert_eq!(names, expected);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -52,9 +71,10 @@ async fn native_admin_complete_response_keeps_bytes_status_and_content_type() {
|
||||
headers.insert(http::header::CONTENT_TYPE, "application/custom+json".parse().unwrap());
|
||||
headers.insert(http::header::CONTENT_LENGTH, "12".parse().unwrap());
|
||||
headers.insert("x-admin-result", "complete".parse().unwrap());
|
||||
let response = complete_response(AdminResponse::with_headers(StatusCode::ACCEPTED, Body::from("opaque bytes"), headers))
|
||||
.await
|
||||
.unwrap();
|
||||
let response =
|
||||
complete_response::<GetV3Info>(AdminResponse::with_headers(StatusCode::ACCEPTED, Body::from("opaque bytes"), headers))
|
||||
.await
|
||||
.unwrap();
|
||||
let (answer, status, headers) = response.into_parts();
|
||||
assert_eq!(status, 202);
|
||||
assert_eq!(headers[http::header::CONTENT_TYPE], "application/custom+json");
|
||||
@@ -69,8 +89,8 @@ async fn native_admin_complete_response_keeps_bytes_status_and_content_type() {
|
||||
|
||||
struct Capture(Arc<Mutex<Vec<serde_json::Value>>>);
|
||||
|
||||
impl Handler<GetV3Info> for Capture {
|
||||
async fn call(&self, request: Req<GetV3Info>) -> HandlerResult<GetV3Info> {
|
||||
impl<O: Operation<Output = WireResponse>> Handler<O> for Capture {
|
||||
async fn call(&self, request: Req<O>) -> HandlerResult<O> {
|
||||
let envelope = envelope(request.context(), &ServerContextSlot::new()).map_err(handler_error)?;
|
||||
self.0.lock().unwrap().push(serde_json::json!({
|
||||
"uri": envelope.uri().to_string(),
|
||||
@@ -101,69 +121,77 @@ async fn native_admin_envelope_preserves_raw_alias_host_facts_and_optional_req_i
|
||||
.host_resolver(PathStyleOnly)
|
||||
.dialect(&dialect().unwrap())
|
||||
.register::<GetV3Info, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3Storageinfo, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV4RuntimeCapabilities, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3ObjectDataCacheStats, _>(Arc::new(Capture(captured.clone())))
|
||||
.build()
|
||||
.unwrap(),
|
||||
};
|
||||
for injected in [false, true] {
|
||||
let mut request = signed_request(
|
||||
Signed::Header,
|
||||
Method::GET,
|
||||
"/minio/admin/v3/info",
|
||||
"detail=1",
|
||||
ROOT_ACCESS_KEY,
|
||||
ROOT_SECRET_KEY,
|
||||
);
|
||||
request.extensions_mut().insert(Some(RemoteAddr(SocketAddr::from(PEER))));
|
||||
request
|
||||
.extensions_mut()
|
||||
.insert(ClientInfo::direct(SocketAddr::from((CLIENT, 42000))));
|
||||
request.extensions_mut().insert(request_context(REQUEST_ID));
|
||||
if injected {
|
||||
request.extensions_mut().insert(ReqInfo {
|
||||
bucket: Some("preserved-bucket".to_owned()),
|
||||
..ReqInfo::default()
|
||||
});
|
||||
let paths = [
|
||||
"/minio/admin/v3/info",
|
||||
"/minio/admin/v3/storageinfo",
|
||||
"/minio/admin/v4/runtime/capabilities",
|
||||
"/minio/admin/v3/object-data-cache/stats",
|
||||
];
|
||||
for path in paths {
|
||||
for injected in [false, true] {
|
||||
let mut request = signed_request(Signed::Header, Method::GET, path, "detail=1", ROOT_ACCESS_KEY, ROOT_SECRET_KEY);
|
||||
request.extensions_mut().insert(Some(RemoteAddr(SocketAddr::from(PEER))));
|
||||
request
|
||||
.extensions_mut()
|
||||
.insert(ClientInfo::direct(SocketAddr::from((CLIENT, 42000))));
|
||||
request.extensions_mut().insert(request_context(REQUEST_ID));
|
||||
if injected {
|
||||
request.extensions_mut().insert(ReqInfo {
|
||||
bucket: Some("preserved-bucket".to_owned()),
|
||||
..ReqInfo::default()
|
||||
});
|
||||
}
|
||||
let response = stack.call(request).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.into_body().collect().await.unwrap().to_bytes(), Bytes::new());
|
||||
}
|
||||
let response = stack.call(request).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.into_body().collect().await.unwrap().to_bytes(), Bytes::new());
|
||||
}
|
||||
let observed = captured.lock().unwrap();
|
||||
for (index, value) in observed.iter().enumerate() {
|
||||
assert_eq!(value["uri"], "/minio/admin/v3/info?detail=1");
|
||||
assert_eq!(value["uri"], format!("{}?detail=1", paths[index / 2]));
|
||||
assert_eq!(value["host"], "localhost");
|
||||
assert_eq!(value["peer"], SocketAddr::from(PEER).to_string());
|
||||
assert_eq!(value["client"], IpAddr::from(CLIENT).to_string());
|
||||
assert_eq!(value["request_id"], REQUEST_ID);
|
||||
assert_eq!(value["has_info"], index == 1);
|
||||
assert_eq!(value["has_info"], index % 2 == 1);
|
||||
assert_eq!(
|
||||
value["bucket"],
|
||||
if index == 1 {
|
||||
if index % 2 == 1 {
|
||||
serde_json::json!("preserved-bucket")
|
||||
} else {
|
||||
serde_json::Value::Null
|
||||
}
|
||||
);
|
||||
}
|
||||
assert_eq!(observed.len(), 2);
|
||||
assert_eq!(observed.len(), paths.len() * 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_admin_authenticated_request_refuses_an_uninstalled_server_context() {
|
||||
let stack = assemble(assembly(), Arc::new(ScriptedIam { ready: false }), root().source()).unwrap();
|
||||
let response = stack
|
||||
.call(signed_request(
|
||||
Signed::Header,
|
||||
Method::GET,
|
||||
"/rustfs/admin/v3/info",
|
||||
"",
|
||||
ROOT_ACCESS_KEY,
|
||||
ROOT_SECRET_KEY,
|
||||
))
|
||||
.await;
|
||||
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let body = String::from_utf8(body.to_vec()).unwrap();
|
||||
assert!(body.contains("<Code>ServiceUnavailable</Code>"), "{body}");
|
||||
assert!(body.contains("<Message>server context is not ready</Message>"), "{body}");
|
||||
for path in [
|
||||
"/rustfs/admin/v3/info",
|
||||
"/minio/admin/v3/info",
|
||||
"/rustfs/admin/v3/storageinfo",
|
||||
"/minio/admin/v3/storageinfo",
|
||||
"/rustfs/admin/v4/runtime/capabilities",
|
||||
"/minio/admin/v4/runtime/capabilities",
|
||||
"/rustfs/admin/v3/object-data-cache/stats",
|
||||
"/minio/admin/v3/object-data-cache/stats",
|
||||
] {
|
||||
let response = stack
|
||||
.call(signed_request(Signed::Header, Method::GET, path, "", ROOT_ACCESS_KEY, ROOT_SECRET_KEY))
|
||||
.await;
|
||||
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let body = String::from_utf8(body.to_vec()).unwrap();
|
||||
assert!(body.contains("<Code>ServiceUnavailable</Code>"), "{body}");
|
||||
assert!(body.contains("<Message>server context is not ready</Message>"), "{body}");
|
||||
}
|
||||
}
|
||||
|
||||
+287
-4
@@ -4527,9 +4527,7 @@ mod tests {
|
||||
assert_eq!(valid.uri().query(), Some("lambdaArn="));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn native_admin_real_iam_and_legacy_contract() {
|
||||
async fn admin_fixture() -> (rustfs_test_utils::TestECStoreEnv, Arc<ServerContextSlot>, s3s::service::S3Service) {
|
||||
let env = rustfs_test_utils::TestECStoreEnv::builder()
|
||||
.prefix("native_admin_info")
|
||||
.disk_count(1)
|
||||
@@ -4549,6 +4547,9 @@ mod tests {
|
||||
("info-denied", Some("admin:ServerInfo"), true, true, false),
|
||||
("info-disabled", Some("admin:ServerInfo"), false, false, false),
|
||||
("info-proxy", Some("admin:ServerInfo"), false, true, true),
|
||||
("storage-allowed", Some("admin:StorageInfo"), false, true, false),
|
||||
("storage-denied", Some("admin:StorageInfo"), true, true, false),
|
||||
("storage-proxy", Some("admin:StorageInfo"), false, true, true),
|
||||
] {
|
||||
iam.create_user(
|
||||
key,
|
||||
@@ -4571,7 +4572,7 @@ mod tests {
|
||||
}
|
||||
let mut statements = vec![statement];
|
||||
if denied {
|
||||
statements.push(serde_json::json!({"Effect":"Deny","Action":"admin:ServerInfo"}));
|
||||
statements.push(serde_json::json!({"Effect":"Deny","Action":action}));
|
||||
}
|
||||
let document = serde_json::json!({"Version":"2012-10-17","Statement":statements});
|
||||
iam.set_policy(key, Policy::parse_config(&serde_json::to_vec(&document).unwrap()).unwrap())
|
||||
@@ -4599,6 +4600,288 @@ mod tests {
|
||||
legacy.set_route(crate::admin::make_admin_route(false, slot.clone()).unwrap());
|
||||
legacy.set_host(s3s::host::MultiDomain::new(["s3.example.test"]).unwrap());
|
||||
let legacy = legacy.build();
|
||||
(env, slot, legacy)
|
||||
}
|
||||
|
||||
const SYSTEM_READS: [(&str, &str); 3] = [
|
||||
("/v3/storageinfo", "storage"),
|
||||
("/v4/runtime/capabilities", "info"),
|
||||
("/v3/object-data-cache/stats", "info"),
|
||||
];
|
||||
|
||||
async fn owned_system_read(
|
||||
path: &str,
|
||||
key: &str,
|
||||
secret: &str,
|
||||
) -> rustfs_s3_types::S3Result<(StatusCode, HeaderMap, Bytes)> {
|
||||
use crate::admin::handlers::object_data_cache::ObjectDataCacheStatsHandler;
|
||||
use crate::admin::handlers::system::{RuntimeCapabilitiesHandler, StorageInfoHandler};
|
||||
use crate::admin::operation::{Operation as _, test_support::TestRequest};
|
||||
let request = TestRequest::new(Method::GET, format!("{path}?detail=a%2Fb"))
|
||||
.credentials(key, secret, None)
|
||||
.build();
|
||||
let response = if path.ends_with("/storageinfo") {
|
||||
StorageInfoHandler {}.call(request, matchit::Params::new()).await?
|
||||
} else if path.ends_with("/capabilities") {
|
||||
RuntimeCapabilitiesHandler {}.call(request, matchit::Params::new()).await?
|
||||
} else {
|
||||
ObjectDataCacheStatsHandler {}.call(request, matchit::Params::new()).await?
|
||||
};
|
||||
let (status, headers, body) = response.into_parts();
|
||||
Ok((status, headers, body.collect().await.unwrap().to_bytes()))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn native_admin_system_reads_owned_and_legacy_baseline() {
|
||||
let (_env, _slot, legacy) = admin_fixture().await;
|
||||
for (suffix, family) in SYSTEM_READS {
|
||||
for prefix in ["/rustfs/admin", "/minio/admin"] {
|
||||
let path = format!("{prefix}{suffix}");
|
||||
for key in [
|
||||
ROOT,
|
||||
"info-allowed",
|
||||
"storage-allowed",
|
||||
"info-no-policy",
|
||||
"info-denied",
|
||||
"storage-denied",
|
||||
] {
|
||||
let secret = if key == ROOT { ROOT_SECRET } else { USER_SECRET };
|
||||
let allowed = key == ROOT || key == format!("{family}-allowed");
|
||||
let old =
|
||||
answer(legacy.clone(), signed(&path, "detail=a%2Fb", "localhost", key, secret, Signed::Header)).await;
|
||||
let owned = owned_system_read(&path, key, secret).await;
|
||||
if allowed {
|
||||
assert_eq!(old.0, StatusCode::OK, "{key} {path}: {:?}", refusal(&old.2));
|
||||
let owned = owned.unwrap();
|
||||
assert_eq!(owned.0, old.0, "{key} {path}");
|
||||
assert_eq!(owned.1[http::header::CONTENT_TYPE], old.1[http::header::CONTENT_TYPE]);
|
||||
let old: serde_json::Value = serde_json::from_slice(&old.2).unwrap();
|
||||
let owned: serde_json::Value = serde_json::from_slice(&owned.2).unwrap();
|
||||
assert_eq!(owned, old, "{key} {path}");
|
||||
if family == "storage" {
|
||||
assert_eq!(owned.get("info").is_some(), prefix == "/rustfs/admin");
|
||||
assert_eq!(owned.get("admin_discovery").is_some(), prefix == "/rustfs/admin");
|
||||
}
|
||||
} else {
|
||||
assert_eq!(old.0, StatusCode::FORBIDDEN, "{key} {path}");
|
||||
assert_eq!(refusal(&old.2).0, "AccessDenied", "{key} {path}");
|
||||
let error = owned.unwrap_err();
|
||||
assert_eq!(error.code().as_str(), "AccessDenied", "{key} {path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn native_admin_system_reads_real_signature_iam_and_wire() {
|
||||
let (_env, slot, legacy) = admin_fixture().await;
|
||||
let native = GatewayEdgeService(GatewayStack::assemble_admin(assembly(slot.clone())).unwrap());
|
||||
let mut config = config::Config::new("127.0.0.1:9001", Vec::new());
|
||||
config.s3_stack = config::S3Stack::Gateway;
|
||||
config.console_enable = false;
|
||||
let edge = select_s3_stack(&config, legacy.clone(), || Ok(assembly(slot))).unwrap();
|
||||
let mut failures = Vec::new();
|
||||
let mut check = |condition: bool, label: String| {
|
||||
if !condition {
|
||||
failures.push(label);
|
||||
}
|
||||
};
|
||||
for (suffix, family) in SYSTEM_READS {
|
||||
for prefix in ["/rustfs/admin", "/minio/admin"] {
|
||||
let path = format!("{prefix}{suffix}");
|
||||
for host in ["localhost", "bucket.s3.example.test"] {
|
||||
for key in [
|
||||
ROOT,
|
||||
"info-allowed",
|
||||
"storage-allowed",
|
||||
"info-no-policy",
|
||||
"info-denied",
|
||||
"storage-denied",
|
||||
] {
|
||||
let secret = if key == ROOT { ROOT_SECRET } else { USER_SECRET };
|
||||
let allowed = key == ROOT || key == format!("{family}-allowed");
|
||||
let old =
|
||||
answer(legacy.clone(), signed(&path, "detail=a%2Fb", host, key, secret, Signed::Header)).await;
|
||||
let new =
|
||||
answer(edge.clone(), signed(&path, "detail=a%2Fb", host, key, secret, Signed::Header)).await;
|
||||
let label = format!("{key} {host} {path}");
|
||||
let expected = if allowed { StatusCode::OK } else { StatusCode::FORBIDDEN };
|
||||
check(
|
||||
old.0 == expected && new.0 == expected,
|
||||
format!("{label}: status legacy={} native={}", old.0, new.0),
|
||||
);
|
||||
if allowed && old.0 == expected && new.0 == expected {
|
||||
check(
|
||||
old.1.get(http::header::CONTENT_TYPE) == new.1.get(http::header::CONTENT_TYPE)
|
||||
&& new.1[http::header::CONTENT_TYPE] == "application/json",
|
||||
format!("{label}: content type"),
|
||||
);
|
||||
check(
|
||||
new.1.get("x-request-id").is_some_and(|value| value == REQUEST_ID),
|
||||
format!("{label}: request id"),
|
||||
);
|
||||
let old: serde_json::Value = serde_json::from_slice(&old.2).unwrap();
|
||||
let new: serde_json::Value = serde_json::from_slice(&new.2).unwrap();
|
||||
check(new == old, format!("{label}: complete JSON legacy={old} native={new}"));
|
||||
if family == "storage" {
|
||||
check(
|
||||
new.get("info").is_some() == (prefix == "/rustfs/admin")
|
||||
&& new.get("admin_discovery").is_some() == (prefix == "/rustfs/admin"),
|
||||
format!("{label}: raw alias"),
|
||||
);
|
||||
}
|
||||
} else if !allowed {
|
||||
check(
|
||||
refusal(&old.2).0 == "AccessDenied" && refusal(&new.2) == refusal(&old.2),
|
||||
format!("{label}: refusal"),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (label, key, secret, anonymous, malformed, form, code) in [
|
||||
(
|
||||
"unknown",
|
||||
"missing-system-user",
|
||||
USER_SECRET,
|
||||
false,
|
||||
false,
|
||||
Signed::Header,
|
||||
"InvalidAccessKeyId",
|
||||
),
|
||||
(
|
||||
"disabled",
|
||||
"info-disabled",
|
||||
USER_SECRET,
|
||||
false,
|
||||
false,
|
||||
Signed::Header,
|
||||
"InvalidAccessKeyId",
|
||||
),
|
||||
(
|
||||
"bad-signature",
|
||||
ROOT,
|
||||
"wrong-system-secret",
|
||||
false,
|
||||
false,
|
||||
Signed::Header,
|
||||
"SignatureDoesNotMatch",
|
||||
),
|
||||
("anonymous", ROOT, ROOT_SECRET, true, false, Signed::Header, "AccessDenied"),
|
||||
("malformed", ROOT, ROOT_SECRET, false, true, Signed::Header, "InvalidRequest"),
|
||||
("presigned", ROOT, ROOT_SECRET, false, false, Signed::Query, "AccessDenied"),
|
||||
] {
|
||||
let request = || {
|
||||
if anonymous || malformed {
|
||||
let mut builder = HttpRequest::builder().method(Method::GET).uri(&path).header("host", host);
|
||||
if malformed {
|
||||
builder = builder.header("authorization", "invalid");
|
||||
}
|
||||
builder.body(Empty::new()).unwrap()
|
||||
} else {
|
||||
signed(&path, "", host, key, secret, form)
|
||||
}
|
||||
};
|
||||
let old = answer(legacy.clone(), request()).await;
|
||||
let new = answer(native.clone(), request()).await;
|
||||
eprintln!(
|
||||
"system-compare {label} {path} {host}: legacy={} {:?}, native={} {:?}",
|
||||
old.0,
|
||||
refusal(&old.2),
|
||||
new.0,
|
||||
refusal(&new.2)
|
||||
);
|
||||
check(
|
||||
new.0
|
||||
== if malformed {
|
||||
StatusCode::BAD_REQUEST
|
||||
} else {
|
||||
StatusCode::FORBIDDEN
|
||||
},
|
||||
format!("{label} {path}: native status {}", new.0),
|
||||
);
|
||||
check(refusal(&new.2).0 == code, format!("{label} {path}: native code {:?}", refusal(&new.2)));
|
||||
let messages = match label {
|
||||
"disabled" => {
|
||||
Some(("check key failed", "The Access Key Id you provided does not exist in our records."))
|
||||
}
|
||||
"anonymous" => Some(("Signature is required", "the request is not allowed")),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((old_message, new_message)) = messages {
|
||||
check(
|
||||
old.0 == StatusCode::FORBIDDEN
|
||||
&& new.0 == old.0
|
||||
&& refusal(&old.2) == (code.to_owned(), old_message.to_owned())
|
||||
&& refusal(&new.2) == (code.to_owned(), new_message.to_owned()),
|
||||
format!("{label} {path} {host}: exact refusal messages"),
|
||||
);
|
||||
} else if label == "presigned" {
|
||||
check(
|
||||
old.0 == StatusCode::OK
|
||||
&& refusal(&old.2) == (String::new(), String::new())
|
||||
&& refusal(&new.2)
|
||||
== ("AccessDenied".to_owned(), "the request is not allowed".to_owned()),
|
||||
format!("{label} {path} {host}: admin signature floor"),
|
||||
);
|
||||
} else {
|
||||
check(
|
||||
new.0 == old.0 && refusal(&new.2) == refusal(&old.2),
|
||||
format!("{label} {path}: legacy refusal"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (client, peer, allowed) in [
|
||||
("10.8.7.6:7890", "203.0.113.9:4567", true),
|
||||
("203.0.113.9:7890", "10.8.7.6:4567", false),
|
||||
] {
|
||||
let key = format!("{family}-proxy");
|
||||
let request = || {
|
||||
let mut request = signed(&path, "", "localhost", &key, USER_SECRET, Signed::Header);
|
||||
request.extensions_mut().insert(Some(RemoteAddr(peer.parse().unwrap())));
|
||||
request
|
||||
.extensions_mut()
|
||||
.insert(rustfs_trusted_proxies::ClientInfo::direct(client.parse().unwrap()));
|
||||
request
|
||||
};
|
||||
let old = answer(legacy.clone(), request()).await;
|
||||
let new = answer(native.clone(), request()).await;
|
||||
let expected = if allowed { StatusCode::OK } else { StatusCode::FORBIDDEN };
|
||||
check(
|
||||
old.0 == expected && new.0 == expected,
|
||||
format!("{path}: source IP {client} peer {peer}: legacy={} native={}", old.0, new.0),
|
||||
);
|
||||
if !allowed {
|
||||
check(refusal(&old.2) == refusal(&new.2), format!("{path}: source refusal"));
|
||||
}
|
||||
}
|
||||
for query in ["lambdaArn=arn", "lambdaArn=", "lambdaArn"] {
|
||||
let old = answer(
|
||||
legacy.clone(),
|
||||
signed(&path, query, "bucket.s3.example.test", ROOT, ROOT_SECRET, Signed::Header),
|
||||
)
|
||||
.await;
|
||||
let new = answer(
|
||||
edge.clone(),
|
||||
signed(&path, query, "bucket.s3.example.test", ROOT, ROOT_SECRET, Signed::Header),
|
||||
)
|
||||
.await;
|
||||
check(
|
||||
old.0 != StatusCode::OK && new.0 == old.0 && refusal(&new.2) == refusal(&old.2),
|
||||
format!("{path}?{query}: object lambda priority"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(failures.is_empty(), "{}", failures.join("\n"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn native_admin_real_iam_and_legacy_contract() {
|
||||
let (_env, slot, legacy) = admin_fixture().await;
|
||||
let native = GatewayEdgeService(GatewayStack::assemble_admin(assembly(slot.clone())).unwrap());
|
||||
let mut failures = Vec::new();
|
||||
let mut check = |condition: bool, label: String| {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! be, and [`select_stack`], the only place a stack is chosen. The whole stack is one or the
|
||||
//! other: no request is routed between stacks by its operation, and a request the gateway stack
|
||||
//! refuses is answered by that refusal and never retried on the legacy stack. With the gateway
|
||||
//! selected, console static requests and the two signed server-info aliases use their native
|
||||
//! selected, console static requests and signed system-status reads use their native
|
||||
//! services; the legacy service receives the remaining claimed extension and control-plane routes.
|
||||
//! NOT responsible for: assembling either stack (`server/http.rs` builds the legacy service,
|
||||
//! `server/gateway_stack.rs` the gateway one), or the middleware around them.
|
||||
@@ -407,7 +407,16 @@ mod tests {
|
||||
async fn native_admin_selection_is_exact_and_host_independent() {
|
||||
let mut service = gateway_stack().with_native_admin(Some(Named("admin")));
|
||||
for host in ["localhost", "bucket.s3.example.test"] {
|
||||
for target in ["/rustfs/admin/v3/info", "/minio/admin/v3/info?detail=1"] {
|
||||
for target in [
|
||||
"/rustfs/admin/v3/info",
|
||||
"/minio/admin/v3/info?detail=1",
|
||||
"/rustfs/admin/v3/storageinfo",
|
||||
"/minio/admin/v3/storageinfo?detail=a%2Fb",
|
||||
"/rustfs/admin/v4/runtime/capabilities",
|
||||
"/minio/admin/v4/runtime/capabilities?detail=a%2Fb",
|
||||
"/rustfs/admin/v3/object-data-cache/stats",
|
||||
"/minio/admin/v3/object-data-cache/stats?detail=a%2Fb",
|
||||
] {
|
||||
let req = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri(target)
|
||||
@@ -417,6 +426,22 @@ mod tests {
|
||||
assert_eq!(answered_by(&mut service, req).await, "admin", "{host} {target}");
|
||||
}
|
||||
}
|
||||
for suffix in ["/v3/storageinfo", "/v4/runtime/capabilities", "/v3/object-data-cache/stats"] {
|
||||
for prefix in ["/rustfs/admin", "/minio/admin"] {
|
||||
for (method, tail) in [
|
||||
(Method::POST, ""),
|
||||
(Method::GET, "/"),
|
||||
(Method::GET, "-neighbor"),
|
||||
(Method::GET, "?lambdaArn=arn"),
|
||||
(Method::GET, "?lambdaArn="),
|
||||
(Method::GET, "?lambdaArn=one&lambdaArn=two"),
|
||||
(Method::GET, "?lambdaArn=%ZZ"),
|
||||
] {
|
||||
let target = format!("{prefix}{suffix}{tail}");
|
||||
assert_eq!(answered_by(&mut service, request(method, &target)).await, "legacy", "{target}");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (method, target) in [
|
||||
(Method::GET, "/rustfs/admin/v3/info/"),
|
||||
(Method::GET, "/rustfs/admin/v3/info-neighbor"),
|
||||
|
||||
Reference in New Issue
Block a user