feat(gateway): serve bucket CORS, encryption and tagging reads

Share bucket-scoped authorization and persisted configuration reads across
both stacks. Carry the stored configurations in gateway responses and
preserve the operation-specific errors for missing configs.

On RustFS 993464fbb, 120 scoped tests passed, including both refusal
matrices and six new tests with 24 refusal and 12 success cases.
Live HTTP checks covered response documents, operation counts and
authorization-denial audit records. Both feature configurations passed
Clippy, and formatting, script tests and source guards passed.

Changing each IAM action or resource admitted a forbidden read.
Duplicating each edge count and changing each stored output failed its
test. Returning 404 for missing encryption failed the 400 assertion.
Suppressing gateway denial audit removed all nine expected records.
Runtime verification used single-node debug servers.
This commit is contained in:
overtrue
2026-11-15 22:48:03 +08:00
parent 993464fbbb
commit 292974baff
8 changed files with 337 additions and 82 deletions
+17 -21
View File
@@ -15,8 +15,6 @@
//! Bucket CORS configuration use-case operations.
use super::*;
use crate::app::storage_api::s3::dto::GetBucketCorsInput;
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Result};
use rustfs_gateway_types::cors_tagging::parse_cors;
use rustfs_gateway_types::persistence::serialize_cors_dto;
@@ -64,26 +62,30 @@ impl DefaultBucketUsecase {
.await
}
#[instrument(level = "debug", skip(self, req))]
pub async fn execute_get_bucket_cors(&self, req: S3Request<GetBucketCorsInput>) -> S3Result<PersistedCorsConfiguration> {
let GetBucketCorsInput { bucket, .. } = req.input;
/// Returns the stored bucket CORS configuration after checking the bucket exists.
///
/// # Errors
///
/// Returns `InternalError` if the store is uninitialized, `NoSuchCORSConfiguration`
/// if the configuration is absent, or the storage error from either lookup.
#[instrument(level = "debug", skip(self, bucket))]
pub async fn execute_get_bucket_cors(&self, bucket: &str) -> rustfs_s3_types::S3Result<PersistedCorsConfiguration> {
let Some(store) = self.object_store() else {
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
return Err(rustfs_s3_types::s3_error!(InternalError, "Not init"));
};
store
.get_bucket_info(&bucket, &BucketOptions::default())
.get_bucket_info(bucket, &BucketOptions::default())
.await
.map_err(ApiError::from)?;
let cors_configuration = match metadata_sys::get_cors_config(&bucket).await {
let cors_configuration = match metadata_sys::get_cors_config(bucket).await {
Ok((config, _)) => config,
Err(err) => {
if err == StorageError::ConfigNotFound {
return Err(S3Error::with_message(
S3ErrorCode::NoSuchCORSConfiguration,
"The CORS configuration does not exist".to_string(),
return Err(rustfs_s3_types::s3_error!(
NoSuchCORSConfiguration,
"The CORS configuration does not exist"
));
}
warn!(
@@ -154,7 +156,7 @@ impl DefaultBucketUsecase {
#[cfg(test)]
mod tests {
use super::*;
use crate::app::bucket_usecase::test_support::{build_request, gateway_bucket, owned_envelope};
use crate::app::bucket_usecase::test_support::{gateway_bucket, owned_envelope};
use http::Method;
#[tokio::test]
@@ -174,16 +176,10 @@ mod tests {
#[tokio::test]
async fn execute_get_bucket_cors_returns_internal_error_when_store_uninitialized() {
let input = GetBucketCorsInput::builder()
.bucket("test-bucket".to_string())
.build()
.unwrap();
let req = build_request(input, Method::GET);
let usecase = DefaultBucketUsecase::without_context();
let err = usecase.execute_get_bucket_cors(req).await.unwrap_err();
assert_eq!(err.code(), &S3ErrorCode::InternalError);
let err = usecase.execute_get_bucket_cors("test-bucket").await.unwrap_err();
assert_eq!(err.code(), &rustfs_s3_types::S3ErrorCode::InternalError);
}
#[tokio::test]
+21 -20
View File
@@ -16,10 +16,10 @@
use super::*;
use crate::app::storage_api::s3::dto::{
DeleteBucketEncryptionInput, DeleteBucketEncryptionOutput, GetBucketEncryptionInput, PutBucketEncryptionInput,
PutBucketEncryptionOutput, ServerSideEncryption,
DeleteBucketEncryptionInput, DeleteBucketEncryptionOutput, PutBucketEncryptionInput, PutBucketEncryptionOutput,
ServerSideEncryption,
};
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result, s3_error};
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result};
/// Refuse a default-encryption configuration the write path could not honour
/// as written. `bucket_default_write_sse` falls back to AES256 for any
@@ -93,26 +93,33 @@ impl DefaultBucketUsecase {
Ok(S3Response::with_status(DeleteBucketEncryptionOutput::default(), StatusCode::NO_CONTENT))
}
/// Returns the stored bucket encryption configuration after checking the bucket exists.
///
/// # Errors
///
/// Returns `InternalError` if the store is uninitialized, `ServerSideEncryptionConfigurationNotFoundError`
/// if the configuration is absent, or the storage error from either lookup.
pub async fn execute_get_bucket_encryption(
&self,
req: S3Request<GetBucketEncryptionInput>,
) -> S3Result<Option<PersistedBucketEncryptionConfiguration>> {
let GetBucketEncryptionInput { bucket, .. } = req.input;
bucket: &str,
) -> rustfs_s3_types::S3Result<PersistedBucketEncryptionConfiguration> {
let Some(store) = self.object_store() else {
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
return Err(rustfs_s3_types::s3_error!(InternalError, "Not init"));
};
store
.get_bucket_info(&bucket, &BucketOptions::default())
.get_bucket_info(bucket, &BucketOptions::default())
.await
.map_err(ApiError::from)?;
let server_side_encryption_configuration = match metadata_sys::get_sse_config(&bucket).await {
Ok((cfg, _)) => Some(cfg),
let server_side_encryption_configuration = match metadata_sys::get_sse_config(bucket).await {
Ok((cfg, _)) => cfg,
Err(err) => {
if err == StorageError::ConfigNotFound {
return Err(s3_error!(ServerSideEncryptionConfigurationNotFoundError));
return Err(rustfs_s3_types::s3_error!(
ServerSideEncryptionConfigurationNotFoundError,
"The server-side encryption configuration was not found."
));
}
warn!(
component = LOG_COMPONENT_APP,
@@ -257,16 +264,10 @@ mod tests {
#[tokio::test]
async fn execute_get_bucket_encryption_returns_internal_error_when_store_uninitialized() {
let input = GetBucketEncryptionInput::builder()
.bucket("test-bucket".to_string())
.build()
.unwrap();
let req = build_request(input, Method::GET);
let usecase = DefaultBucketUsecase::without_context();
let err = usecase.execute_get_bucket_encryption(req).await.unwrap_err();
assert_eq!(err.code(), &S3ErrorCode::InternalError);
let err = usecase.execute_get_bucket_encryption("test-bucket").await.unwrap_err();
assert_eq!(err.code(), &rustfs_s3_types::S3ErrorCode::InternalError);
}
#[tokio::test]
+15 -17
View File
@@ -17,7 +17,7 @@
use super::*;
use crate::app::storage_api::s3::dto;
use crate::app::storage_api::s3::dto::{
DeleteBucketTaggingInput, DeleteBucketTaggingOutput, GetBucketTaggingInput, PutBucketTaggingInput, PutBucketTaggingOutput,
DeleteBucketTaggingInput, DeleteBucketTaggingOutput, PutBucketTaggingInput, PutBucketTaggingOutput,
};
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result};
@@ -49,24 +49,28 @@ impl DefaultBucketUsecase {
Ok(S3Response::new(DeleteBucketTaggingOutput {}))
}
#[instrument(level = "debug", skip(self, req))]
pub async fn execute_get_bucket_tagging(&self, req: S3Request<GetBucketTaggingInput>) -> S3Result<PersistedTagging> {
let GetBucketTaggingInput { bucket, .. } = req.input;
/// Returns the stored bucket tagging configuration after checking the bucket exists.
///
/// # Errors
///
/// Returns `InternalError` if the store is uninitialized, `NoSuchTagSet`
/// if the configuration is absent, or the storage error from either lookup.
#[instrument(level = "debug", skip(self, bucket))]
pub async fn execute_get_bucket_tagging(&self, bucket: &str) -> rustfs_s3_types::S3Result<PersistedTagging> {
let Some(store) = self.object_store() else {
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
return Err(rustfs_s3_types::s3_error!(InternalError, "Not init"));
};
store
.get_bucket_info(&bucket, &BucketOptions::default())
.get_bucket_info(bucket, &BucketOptions::default())
.await
.map_err(ApiError::from)?;
let tagging = match metadata_sys::get_tagging_config(&bucket).await {
let tagging = match metadata_sys::get_tagging_config(bucket).await {
Ok((tags, _)) => tags,
Err(err) => {
if err == StorageError::ConfigNotFound {
return Err(S3Error::with_message(S3ErrorCode::NoSuchTagSet, "The TagSet does not exist".to_string()));
return Err(rustfs_s3_types::s3_error!(NoSuchTagSet, "The TagSet does not exist"));
}
warn!(
component = LOG_COMPONENT_APP,
@@ -140,16 +144,10 @@ mod tests {
#[tokio::test]
async fn execute_get_bucket_tagging_returns_internal_error_when_store_uninitialized() {
let input = GetBucketTaggingInput::builder()
.bucket("test-bucket".to_string())
.build()
.unwrap();
let req = build_request(input, Method::GET);
let usecase = DefaultBucketUsecase::without_context();
let err = usecase.execute_get_bucket_tagging(req).await.unwrap_err();
assert_eq!(err.code(), &S3ErrorCode::InternalError);
let err = usecase.execute_get_bucket_tagging("test-bucket").await.unwrap_err();
assert_eq!(err.code(), &rustfs_s3_types::S3ErrorCode::InternalError);
}
#[test]
@@ -17,16 +17,79 @@
use super::access::authorize_bucket_config_mutation;
use super::{OpRow, Served, row};
use crate::app::RequestEnvelope;
use crate::app::bucket_usecase::DefaultBucketUsecase;
use crate::app::{RequestEnvelope, dto_values};
use crate::runtime_sources::AppContext;
use crate::storage_api::server::http::access::authorize_bucket_request;
use rustfs_gateway::{Req, Resp, dto};
use rustfs_gateway_types::persistence::{parse_bucket_encryption_dto, parse_cors_dto, parse_tagging_dto};
use rustfs_policy::policy::action::{Action, S3Action};
use rustfs_s3_ops::S3Operation;
use rustfs_s3_types::S3Result;
use std::sync::Arc;
pub(super) const ROWS: &[OpRow] = &[row::<dto::PutBucketCors>(), row::<dto::DeleteBucketCors>()];
pub(super) const ROWS: &[OpRow] = &[
row::<dto::GetBucketCors>(),
row::<dto::GetBucketEncryption>(),
row::<dto::GetBucketTagging>(),
row::<dto::PutBucketCors>(),
row::<dto::DeleteBucketCors>(),
];
impl Served for dto::GetBucketCors {
const METRIC: S3Operation = S3Operation::GetBucketCors;
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
let action = Action::S3Action(S3Action::GetBucketCorsAction);
Ok(authorize_bucket_request(envelope, request.input().bucket.as_str(), action).await?)
}
async fn execute(context: Option<Arc<AppContext>>, _envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
let stored = DefaultBucketUsecase::with_context(context)
.execute_get_bucket_cors(request.input().bucket.as_str())
.await?;
let config = dto_values::stored_config(&stored, parse_cors_dto)?;
Ok(Resp::new(dto::GetBucketCorsOutput {
cors_rules: config.cors_rules,
}))
}
}
impl Served for dto::GetBucketEncryption {
const METRIC: S3Operation = S3Operation::GetBucketEncryption;
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
let action = Action::S3Action(S3Action::GetBucketEncryptionAction);
Ok(authorize_bucket_request(envelope, request.input().bucket.as_str(), action).await?)
}
async fn execute(context: Option<Arc<AppContext>>, _envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
let stored = DefaultBucketUsecase::with_context(context)
.execute_get_bucket_encryption(request.input().bucket.as_str())
.await?;
let config = dto_values::stored_config(&stored, parse_bucket_encryption_dto)?;
Ok(Resp::new(dto::GetBucketEncryptionOutput {
server_side_encryption_configuration: Some(config),
}))
}
}
impl Served for dto::GetBucketTagging {
const METRIC: S3Operation = S3Operation::GetBucketTagging;
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
let action = Action::S3Action(S3Action::GetBucketTaggingAction);
Ok(authorize_bucket_request(envelope, request.input().bucket.as_str(), action).await?)
}
async fn execute(context: Option<Arc<AppContext>>, _envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
let stored = DefaultBucketUsecase::with_context(context)
.execute_get_bucket_tagging(request.input().bucket.as_str())
.await?;
let config = dto_values::stored_config(&stored, parse_tagging_dto)?;
Ok(Resp::new(dto::GetBucketTaggingOutput { tag_set: config.tag_set }))
}
}
impl Served for dto::PutBucketCors {
const METRIC: S3Operation = S3Operation::PutBucketCors;
+6 -12
View File
@@ -3626,20 +3626,16 @@ impl S3Access for FS {
///
/// This method returns `Ok(())` by default.
async fn get_bucket_cors(&self, req: &mut S3Request<GetBucketCorsInput>) -> S3Result<()> {
let req_info = ext_req_info_mut(&mut req.extensions)?;
req_info.bucket = Some(req.input.bucket.clone());
authorize_request(req, Action::S3Action(S3Action::GetBucketCorsAction)).await
let bucket = req.input.bucket.clone();
authorize_bucket_request(req, &bucket, Action::S3Action(S3Action::GetBucketCorsAction)).await
}
/// Checks whether the GetBucketEncryption request has accesses to the resources.
///
/// This method returns `Ok(())` by default.
async fn get_bucket_encryption(&self, req: &mut S3Request<GetBucketEncryptionInput>) -> S3Result<()> {
let req_info = ext_req_info_mut(&mut req.extensions)?;
req_info.bucket = Some(req.input.bucket.clone());
authorize_request(req, Action::S3Action(S3Action::GetBucketEncryptionAction)).await
let bucket = req.input.bucket.clone();
authorize_bucket_request(req, &bucket, Action::S3Action(S3Action::GetBucketEncryptionAction)).await
}
/// Checks whether the GetBucketIntelligentTieringConfiguration request has accesses to the resources.
@@ -3754,10 +3750,8 @@ impl S3Access for FS {
///
/// This method returns `Ok(())` by default.
async fn get_bucket_tagging(&self, req: &mut S3Request<GetBucketTaggingInput>) -> S3Result<()> {
let req_info = ext_req_info_mut(&mut req.extensions)?;
req_info.bucket = Some(req.input.bucket.clone());
authorize_request(req, Action::S3Action(S3Action::GetBucketTaggingAction)).await
let bucket = req.input.bucket.clone();
authorize_bucket_request(req, &bucket, Action::S3Action(S3Action::GetBucketTaggingAction)).await
}
/// Checks whether the GetBucketVersioning request has accesses to the resources.
@@ -84,7 +84,7 @@ impl FS {
) -> S3Result<S3Response<GetBucketCorsOutput>> {
record_s3_op(S3Operation::GetBucketCors);
let usecase = s3_api::bucket_usecase_for(self);
let cors_configuration = usecase.execute_get_bucket_cors(req).await?;
let cors_configuration = usecase.execute_get_bucket_cors(&req.input.bucket).await?;
let cors_configuration: CORSConfiguration = persisted_to_s3s(&cors_configuration)?;
Ok(S3Response::new(GetBucketCorsOutput {
cors_rules: Some(cors_configuration.cors_rules),
@@ -97,14 +97,9 @@ impl FS {
) -> S3Result<S3Response<GetBucketEncryptionOutput>> {
record_s3_op(S3Operation::GetBucketEncryption);
let usecase = s3_api::bucket_usecase_for(self);
let server_side_encryption_configuration = usecase
.execute_get_bucket_encryption(req)
.await?
.as_ref()
.map(persisted_to_s3s::<_, ServerSideEncryptionConfiguration>)
.transpose()?;
let config = usecase.execute_get_bucket_encryption(&req.input.bucket).await?;
Ok(S3Response::new(GetBucketEncryptionOutput {
server_side_encryption_configuration,
server_side_encryption_configuration: Some(persisted_to_s3s(&config)?),
}))
}
@@ -115,7 +110,7 @@ impl FS {
) -> S3Result<S3Response<GetBucketTaggingOutput>> {
record_s3_op(S3Operation::GetBucketTagging);
let usecase = s3_api::bucket_usecase_for(self);
let tagging = usecase.execute_get_bucket_tagging(req).await?;
let tagging = usecase.execute_get_bucket_tagging(&req.input.bucket).await?;
Ok(S3Response::new(GetBucketTaggingOutput {
tag_set: tagging_to_s3s(&tagging).tag_set,
}))
@@ -26,14 +26,42 @@ use aws_sdk_s3::config::interceptors::{
use aws_sdk_s3::config::{ConfigBag, Intercept, RuntimeComponents};
use aws_sdk_s3::error::BoxError;
use aws_sdk_s3::operation::put_bucket_cors::builders::PutBucketCorsFluentBuilder;
use aws_sdk_s3::types::{CorsConfiguration, CorsRule};
use aws_sdk_s3::types::{CorsConfiguration, CorsRule, ServerSideEncryption};
use futures::future::BoxFuture;
use rustfs::app::context::get_global_app_context;
use rustfs::embedded::RustFSServer;
use rustfs_ecstore::api::bucket::metadata_sys;
use rustfs_s3_ops::S3Operation;
use std::sync::{Arc, Mutex};
const GET_CORS: MatrixRow = MatrixRow {
operation: "GetBucketCors",
metric: S3Operation::GetBucketCors,
has_error_body: true,
call: get_bucket_cors,
};
const GET_ENCRYPTION: MatrixRow = MatrixRow {
operation: "GetBucketEncryption",
metric: S3Operation::GetBucketEncryption,
has_error_body: true,
call: get_bucket_encryption,
};
const GET_TAGGING: MatrixRow = MatrixRow {
operation: "GetBucketTagging",
metric: S3Operation::GetBucketTagging,
has_error_body: true,
call: get_bucket_tagging,
};
pub(super) const ENCRYPTION_MATRIX_BUCKET: &str = "config-read-encryption-matrix";
pub(crate) const MATRIX: &[MatrixRow] = &[
GET_CORS,
MatrixRow {
call: get_bucket_encryption_in_matrix,
..GET_ENCRYPTION
},
GET_TAGGING,
MatrixRow {
operation: "PutBucketCors",
metric: S3Operation::PutBucketCors,
@@ -185,6 +213,183 @@ const PERSISTED_CORS: &str = concat!(
"<CORSRule><AllowedMethod>HEAD</AllowedMethod><AllowedOrigin>*</AllowedOrigin></CORSRule></CORSConfiguration>",
);
const PERSISTED_ENCRYPTION: &str = concat!(
"<ServerSideEncryptionConfiguration><Rule><ApplyServerSideEncryptionByDefault>",
"<SSEAlgorithm>AES256</SSEAlgorithm></ApplyServerSideEncryptionByDefault>",
"<BucketKeyEnabled>false</BucketKeyEnabled></Rule></ServerSideEncryptionConfiguration>",
);
const PERSISTED_TAGS: &str = concat!(
"<Tagging><TagSet><Tag><Key>alpha</Key><Value>blue team</Value></Tag>",
"<Tag><Key>empty</Key><Value></Value></Tag></TagSet></Tagging>",
);
pub(super) async fn store_read_configs(bucket: &str, encryption_bucket: &str) {
let metadata = get_global_app_context()
.expect("embedded server context")
.bucket_metadata()
.handle()
.expect("bucket metadata system");
for (bucket, file, document) in [
(bucket, "cors.xml", PERSISTED_CORS),
(encryption_bucket, "bucket-encryption.xml", PERSISTED_ENCRYPTION),
(bucket, "tagging.xml", PERSISTED_TAGS),
] {
metadata
.read()
.await
.update(bucket, file, document.as_bytes().to_vec())
.await
.expect("store the bucket configuration");
}
}
fn get_bucket_cors<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
Box::pin(async move {
outcome(client.get_bucket_cors().bucket(bucket).send().await.map(|config| {
assert_eq!(config.cors_rules(), cors_document().cors_rules(), "stored CORS rules");
}))
})
}
fn get_bucket_encryption<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
Box::pin(async move {
outcome(client.get_bucket_encryption().bucket(bucket).send().await.map(|output| {
let config = output.server_side_encryption_configuration().expect("stored encryption");
let [rule] = config.rules() else { panic!("expected one rule: {:?}", config.rules()) };
let default = rule.apply_server_side_encryption_by_default().expect("stored algorithm");
assert_eq!(default.sse_algorithm(), &ServerSideEncryption::Aes256);
assert_eq!(default.kms_master_key_id(), None);
assert_eq!(rule.bucket_key_enabled(), Some(false));
}))
})
}
fn get_bucket_encryption_in_matrix<'a>(client: &'a Client, _bucket: &'a str) -> BoxFuture<'a, Outcome> {
get_bucket_encryption(client, ENCRYPTION_MATRIX_BUCKET)
}
fn get_bucket_tagging<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
Box::pin(async move {
outcome(client.get_bucket_tagging().bucket(bucket).send().await.map(|output| {
let tags: Vec<_> = output.tag_set().iter().map(|tag| (tag.key(), tag.value())).collect();
assert_eq!(tags, [("alpha", "blue team"), ("empty", "")], "stored tag keys and values");
}))
})
}
const READ_GRANTED: &str = "config-read-granted";
const READ_OTHER: &str = "config-read-other";
const READ_EMPTY: &str = "config-read-empty";
const READ_MISSING: &str = "config-read-missing";
const READ_RESERVED: &str = "config-read-stored-s3alias";
fn assert_read_error(result: Outcome, code: &str, status: u16, case: &str) {
let error = result.expect_err(case);
assert_eq!((error.code.as_deref(), error.status), (Some(code), Some(status)), "{case}");
}
async fn configuration_read(
server: RustFSServer,
operation: MatrixRow,
action: &str,
other_action: &str,
missing_config: (&str, u16),
) {
for bucket in [READ_GRANTED, READ_OTHER, READ_EMPTY, READ_RESERVED] {
create_bucket_in_the_store(bucket).await;
}
for bucket in [READ_GRANTED, READ_OTHER, READ_RESERVED] {
store_read_configs(bucket, bucket).await;
}
let endpoint = server.endpoint();
let root = s3_client(&endpoint, server.access_key(), server.secret_key());
let call = operation.call;
assert_eq!(call(&root, READ_RESERVED).await, Ok(()), "stored reserved-shaped bucket");
assert_read_error(call(&root, READ_MISSING).await, "NoSuchBucket", 404, "missing bucket");
assert_read_error(call(&root, READ_EMPTY).await, missing_config.0, missing_config.1, "missing configuration");
create_user_allowed_on_one_bucket("config-reader", action, READ_GRANTED).await;
create_user_allowed_on_one_bucket("config-other-reader", other_action, READ_GRANTED).await;
let reader = s3_client(&endpoint, "config-reader", USER_SECRET_KEY);
let other_reader = s3_client(&endpoint, "config-other-reader", USER_SECRET_KEY);
let handled_count = || {
rustfs_io_metrics::s3_op_metrics_snapshot()
.into_iter()
.find(|metric| metric.op == operation.metric.as_str())
.map_or(0, |metric| metric.total)
};
let before = handled_count();
assert_read_error(call(&other_reader, READ_GRANTED).await, "AccessDenied", 403, "wrong IAM action");
assert_read_error(call(&reader, READ_OTHER).await, "AccessDenied", 403, "wrong IAM resource");
assert_eq!(handled_count(), before, "authorization refusals do not reach the edge counter");
assert_eq!(call(&reader, READ_GRANTED).await, Ok(()), "allowed IAM action and resource");
assert_eq!(handled_count() - before, 1, "the admitted edge counts once");
server.shutdown().await;
}
async fn cors_read(server: RustFSServer) {
configuration_read(
server,
GET_CORS,
"s3:GetBucketCors",
"s3:GetBucketTagging",
("NoSuchCORSConfiguration", 404),
)
.await;
}
async fn encryption_read(server: RustFSServer) {
configuration_read(
server,
GET_ENCRYPTION,
"s3:GetBucketEncryption",
"s3:GetBucketCors",
("ServerSideEncryptionConfigurationNotFoundError", 400),
)
.await;
}
async fn tagging_read(server: RustFSServer) {
configuration_read(
server,
GET_TAGGING,
"s3:GetBucketTagging",
"s3:GetBucketEncryption",
("NoSuchTagSet", 404),
)
.await;
}
#[test]
fn the_gateway_stack_reads_bucket_cors() {
with_stack(GATEWAY, cors_read);
}
#[test]
fn the_legacy_stack_reads_bucket_cors() {
with_stack(LEGACY, cors_read);
}
#[test]
fn the_gateway_stack_reads_bucket_encryption() {
with_stack(GATEWAY, encryption_read);
}
#[test]
fn the_legacy_stack_reads_bucket_encryption() {
with_stack(LEGACY, encryption_read);
}
#[test]
fn the_gateway_stack_reads_bucket_tagging() {
with_stack(GATEWAY, tagging_read);
}
#[test]
fn the_legacy_stack_reads_bucket_tagging() {
with_stack(LEGACY, tagging_read);
}
const CORS_BUCKET: &str = "gateway-stack-cors";
const CORS_GRANTED_BUCKET: &str = "gateway-stack-cors-granted";
/// A name RustFS creates and the AWS bucket grammar refuses (reserved suffix).
@@ -352,6 +352,9 @@ fn operations_that_answer_every_caller_alike_do_so_on_the_legacy_stack() {
/// each caller it cannot admit with the code the legacy stack answers, counted once.
async fn every_served_operation_serves_root_and_refuses_the_callers_it_cannot_admit(server: RustFSServer) {
create_bucket_in_the_store(MATRIX_BUCKET).await;
// Default encryption would change the object writes in the matrix bucket.
create_bucket_in_the_store(bucket_configs::ENCRYPTION_MATRIX_BUCKET).await;
bucket_configs::store_read_configs(MATRIX_BUCKET, bucket_configs::ENCRYPTION_MATRIX_BUCKET).await;
create_bucket_in_the_store(object_meta::MATRIX_BUCKET).await;
create_bucket_in_the_store(object_misc::MATRIX_BUCKET).await;
create_bucket_in_the_store(object_read::MATRIX_BUCKET).await;