mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 04:52:36 +00:00
feat(gateway): serve bucket ACL and logging writes
Route PutBucketAcl and PutBucketLogging through shared bucket use cases.
Preserve the ACL response for header-only requests and the bucket lookup
before the XML policy refusal. Write logging configuration using the
authorized bucket incarnation and the existing persistence format.
Verify 111 focused tests on 4294c41cc, including the storage access suite,
and run both Clippy modes, script tests, and local wire comparisons. The
wire matrix exercises 15 refusal cases and seven successful writes on
each stack.
Change both IAM actions and resources, audit statuses, and counters in
the fault cohort. Reverse ACL lookup and XML policy checks, drop policy
presence, corrupt logging bytes, reverse logging conversion order, and
remove the incarnation guard. The regressions detect each fault, and
the stale-authorization test reads the replacement bucket from disk.
This commit is contained in:
@@ -17,6 +17,25 @@
|
||||
use super::*;
|
||||
|
||||
impl DefaultBucketUsecase {
|
||||
pub(crate) async fn execute_put_bucket_acl(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
bucket: &str,
|
||||
has_xml_policy: bool,
|
||||
) -> rustfs_s3_types::S3Result<()> {
|
||||
RequestEnvelope::audit_only_operation(envelope, S3Operation::PutBucketAcl, StatusCode::OK, |_| async move {
|
||||
self.ensure_config_bucket(bucket).await?;
|
||||
if has_xml_policy {
|
||||
return Err(rustfs_s3_types::s3_error!(
|
||||
NotImplemented,
|
||||
"ACL XML grants are not supported; use canned ACL headers or omit ACL"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// RustFS has one owner and no ACL storage: every bucket answers that owner with full control.
|
||||
pub async fn execute_get_bucket_acl(
|
||||
&self,
|
||||
|
||||
@@ -12,13 +12,37 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Bucket logging configuration reads shared by the S3 edges.
|
||||
//! Bucket logging configuration shared by the S3 edges.
|
||||
|
||||
use super::{ApiError, DefaultBucketUsecase, StorageError, metadata_sys};
|
||||
use super::{
|
||||
ApiError, DefaultBucketUsecase, S3Operation, StatusCode, StorageError, bucket_config_mutation_incarnation, metadata_sys,
|
||||
update_bucket_config_for_incarnation,
|
||||
};
|
||||
use crate::app::RequestEnvelope;
|
||||
use crate::app::storage_api::bucket_usecase::bucket::metadata::BUCKET_LOGGING_CONFIG;
|
||||
use rustfs_gateway_types::persistence::PersistedBucketLoggingStatus;
|
||||
use rustfs_s3_types::S3Result;
|
||||
|
||||
impl DefaultBucketUsecase {
|
||||
pub(crate) async fn execute_put_bucket_logging(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
bucket: &str,
|
||||
serialize_configuration: impl FnOnce() -> S3Result<Vec<u8>> + Send,
|
||||
) -> S3Result<()> {
|
||||
RequestEnvelope::audit_only_operation(envelope, S3Operation::PutBucketLogging, StatusCode::OK, |envelope| async move {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&envelope, bucket)?;
|
||||
self.ensure_config_bucket(bucket).await?;
|
||||
|
||||
let data = serialize_configuration()?;
|
||||
update_bucket_config_for_incarnation(bucket, BUCKET_LOGGING_CONFIG, data, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn execute_get_bucket_logging(&self, bucket: &str) -> S3Result<PersistedBucketLoggingStatus> {
|
||||
self.ensure_config_bucket(bucket).await?;
|
||||
match metadata_sys::get_logging_config(bucket).await {
|
||||
@@ -28,3 +52,101 @@ impl DefaultBucketUsecase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::bucket_usecase::test_support::build_request;
|
||||
use crate::app::bucket_usecase::{BucketOperations, DeleteBucketOptions, MakeBucketOptions};
|
||||
use crate::app::gating_test_env::{run_large_stack_test, shared_gating_ambient};
|
||||
use crate::app::runtime_sources::ServerContextSlot;
|
||||
use crate::app::storage_api::owned_parity::{ReqInfo, authorize_bucket_config_mutation};
|
||||
use http::Method;
|
||||
use rustfs_credentials::Credentials;
|
||||
use rustfs_policy::policy::action::{Action, S3Action};
|
||||
use rustfs_s3_types::S3ErrorCode;
|
||||
use serial_test::serial;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn put_bucket_logging_checks_bucket_before_serializing() {
|
||||
run_large_stack_test("put-bucket-logging-lookup", || async {
|
||||
let context = shared_gating_ambient().await;
|
||||
let bucket = format!("logging-missing-{}", uuid::Uuid::new_v4().simple());
|
||||
let usecase = DefaultBucketUsecase::with_context(Some(context));
|
||||
let request = build_request((), Method::PUT);
|
||||
let envelope = RequestEnvelope::from_s3s(&request);
|
||||
let error = usecase
|
||||
.execute_put_bucket_logging(envelope, &bucket, || {
|
||||
Err(rustfs_s3_types::s3_error!(MalformedXML, "invalid logging configuration"))
|
||||
})
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(error.code(), &S3ErrorCode::NoSuchBucket);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn put_bucket_logging_preserves_replacement_bytes_after_stale_authorization() {
|
||||
run_large_stack_test("put-bucket-logging-incarnation", || async {
|
||||
const ORIGINAL: &[u8] = b"<BucketLoggingStatus></BucketLoggingStatus>";
|
||||
const UPDATE: &[u8] = b"<BucketLoggingStatus><LoggingEnabled><TargetBucket>other-bucket</TargetBucket><TargetPrefix>logs/</TargetPrefix></LoggingEnabled></BucketLoggingStatus>";
|
||||
let context = shared_gating_ambient().await;
|
||||
let store = context.object_store();
|
||||
let bucket = format!("logging-stale-{}", uuid::Uuid::new_v4().simple());
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("create original bucket");
|
||||
let server = ServerContextSlot::new();
|
||||
assert!(server.install(Arc::clone(&context)));
|
||||
let mut request = build_request((), Method::PUT);
|
||||
request.uri = format!("/{bucket}?logging").parse().expect("logging request URI");
|
||||
request.extensions.insert(Arc::clone(&server));
|
||||
request.extensions.insert(ReqInfo {
|
||||
cred: Some(Credentials {
|
||||
access_key: "logging-owner".to_owned(),
|
||||
..Default::default()
|
||||
}),
|
||||
is_owner: true,
|
||||
..Default::default()
|
||||
});
|
||||
let mut envelope = RequestEnvelope::from_s3s(&request);
|
||||
authorize_bucket_config_mutation(&server, &mut envelope, &bucket, Action::S3Action(S3Action::PutBucketLoggingAction))
|
||||
.await
|
||||
.expect("snapshot the original bucket incarnation");
|
||||
|
||||
store
|
||||
.delete_bucket(&bucket, &DeleteBucketOptions::default())
|
||||
.await
|
||||
.expect("delete original bucket");
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("create replacement bucket");
|
||||
metadata_sys::update(&bucket, BUCKET_LOGGING_CONFIG, ORIGINAL.to_vec())
|
||||
.await
|
||||
.expect("seed replacement logging config");
|
||||
|
||||
let usecase = DefaultBucketUsecase::with_context(Some(context));
|
||||
let result = usecase
|
||||
.execute_put_bucket_logging(envelope, &bucket, || Ok(UPDATE.to_vec()))
|
||||
.await;
|
||||
let stored = metadata_sys::get_global_bucket_metadata_sys()
|
||||
.expect("initialized metadata system")
|
||||
.read()
|
||||
.await
|
||||
.get_config_from_disk(&bucket)
|
||||
.await
|
||||
.expect("replacement metadata")
|
||||
.logging_config_xml;
|
||||
assert_eq!(
|
||||
(result.err().map(|err| err.code().clone()), stored.as_slice()),
|
||||
(Some(S3ErrorCode::NoSuchBucket), ORIGINAL),
|
||||
"the stale authorization must leave the replacement configuration intact"
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -945,7 +945,7 @@ pub(crate) mod bucket {
|
||||
|
||||
pub(crate) mod metadata {
|
||||
pub(crate) use crate::storage::storage_api::{
|
||||
BUCKET_ACCELERATE_CONFIG, BUCKET_REQUEST_PAYMENT_CONFIG, BUCKET_WEBSITE_CONFIG,
|
||||
BUCKET_ACCELERATE_CONFIG, BUCKET_LOGGING_CONFIG, BUCKET_REQUEST_PAYMENT_CONFIG, BUCKET_WEBSITE_CONFIG,
|
||||
};
|
||||
pub(crate) const BUCKET_CORS_CONFIG: &str = crate::storage::storage_api::ecstore_bucket::metadata::BUCKET_CORS_CONFIG;
|
||||
pub(crate) const BUCKET_LIFECYCLE_CONFIG: &str =
|
||||
|
||||
@@ -35,6 +35,7 @@ pub(super) const ROWS: &[OpRow] = &[
|
||||
row::<dto::GetBucketPolicy>(),
|
||||
row::<dto::GetBucketPolicyStatus>(),
|
||||
row::<dto::GetBucketAcl>(),
|
||||
row::<dto::PutBucketAcl>(),
|
||||
row::<dto::GetBucketNotificationConfiguration>(),
|
||||
row::<dto::PutBucketNotificationConfiguration>(),
|
||||
];
|
||||
@@ -122,6 +123,23 @@ impl Served for dto::GetBucketAcl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::PutBucketAcl {
|
||||
const METRIC: S3Operation = S3Operation::PutBucketAcl;
|
||||
|
||||
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
|
||||
let action = Action::S3Action(S3Action::PutBucketAclAction);
|
||||
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 input = request.into_input();
|
||||
DefaultBucketUsecase::with_context(context)
|
||||
.execute_put_bucket_acl(envelope, input.bucket.as_str(), input.access_control_policy.is_some())
|
||||
.await?;
|
||||
Ok(Resp::new(dto::PutBucketAclOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::GetBucketNotificationConfiguration {
|
||||
const METRIC: S3Operation = S3Operation::GetBucketNotificationConfiguration;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::storage_api::server::http::access::authorize_bucket_request;
|
||||
use rustfs_gateway::{Req, Resp, dto};
|
||||
use rustfs_gateway_types::persistence::{
|
||||
parse_accelerate, parse_bucket_logging_dto, parse_request_payment, parse_website, parse_website_dto,
|
||||
serialize_accelerate_dto, serialize_request_payment_dto, serialize_website_dto,
|
||||
serialize_accelerate_dto, serialize_bucket_logging_dto, serialize_request_payment_dto, serialize_website_dto,
|
||||
};
|
||||
use rustfs_policy::policy::action::{Action, S3Action};
|
||||
use rustfs_s3_ops::S3Operation;
|
||||
@@ -41,6 +41,7 @@ pub(super) const ROWS: &[OpRow] = &[
|
||||
row::<dto::GetBucketRequestPayment>(),
|
||||
row::<dto::GetBucketWebsite>(),
|
||||
row::<dto::GetBucketLogging>(),
|
||||
row::<dto::PutBucketLogging>(),
|
||||
row::<dto::PutBucketAccelerateConfiguration>(),
|
||||
row::<dto::PutBucketRequestPayment>(),
|
||||
row::<dto::PutBucketWebsite>(),
|
||||
@@ -206,6 +207,26 @@ impl Served for dto::GetBucketLogging {
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::PutBucketLogging {
|
||||
const METRIC: S3Operation = S3Operation::PutBucketLogging;
|
||||
|
||||
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
|
||||
let action = Action::S3Action(S3Action::PutBucketLoggingAction);
|
||||
authorize_bucket_config_mutation(envelope, request.input().bucket.as_str(), action).await
|
||||
}
|
||||
|
||||
async fn execute(context: Option<Arc<AppContext>>, envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
|
||||
let input = request.into_input();
|
||||
DefaultBucketUsecase::with_context(context)
|
||||
.execute_put_bucket_logging(envelope, input.bucket.as_str(), || {
|
||||
serialize_bucket_logging_dto(&input.bucket_logging_status)
|
||||
.map_err(|err| rustfs_s3_types::s3_error!(MalformedXML, "{err}"))
|
||||
})
|
||||
.await?;
|
||||
Ok(Resp::new(dto::PutBucketLoggingOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::PutBucketAccelerateConfiguration {
|
||||
const METRIC: S3Operation = S3Operation::PutBucketAccelerateConfiguration;
|
||||
|
||||
|
||||
@@ -3991,10 +3991,8 @@ impl S3Access for FS {
|
||||
///
|
||||
/// This method returns `Ok(())` by default.
|
||||
async fn put_bucket_acl(&self, req: &mut S3Request<PutBucketAclInput>) -> 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::PutBucketAclAction)).await
|
||||
let bucket = req.input.bucket.clone();
|
||||
authorize_bucket_request(req, &bucket, Action::S3Action(S3Action::PutBucketAclAction)).await
|
||||
}
|
||||
|
||||
/// Checks whether the PutBucketAnalyticsConfiguration request has accesses to the resources.
|
||||
|
||||
@@ -19,12 +19,10 @@
|
||||
//! former trait method bodies, unchanged; the batch that moves these operations onto the gateway
|
||||
//! owns this file and is the only one that edits it.
|
||||
|
||||
use crate::error::ApiError;
|
||||
use crate::storage::ecfs::*;
|
||||
use crate::storage::helper::audit_only_operation;
|
||||
use crate::storage::persisted_from_s3s;
|
||||
use crate::storage::s3_api::{self, NotificationDestination};
|
||||
use crate::storage::storage_api::ecfs_consumer::contract::bucket::{BucketOperations, BucketOptions};
|
||||
use rustfs_gateway_types::compat::s3s_5761ddfe::generated::ops::{
|
||||
get_bucket_acl, get_bucket_notification_configuration, get_bucket_policy, get_bucket_policy_status, get_bucket_versioning,
|
||||
};
|
||||
@@ -32,36 +30,6 @@ use rustfs_io_metrics::record_s3_op;
|
||||
use rustfs_s3_ops::S3Operation;
|
||||
use tracing::instrument;
|
||||
|
||||
/// Handler bodies that [`S3`] runs through `audit_only_operation`.
|
||||
impl FS {
|
||||
async fn put_bucket_acl_inner(&self, req: S3Request<PutBucketAclInput>) -> S3Result<S3Response<PutBucketAclOutput>> {
|
||||
let PutBucketAclInput {
|
||||
bucket,
|
||||
access_control_policy,
|
||||
..
|
||||
} = req.input;
|
||||
record_s3_op(S3Operation::PutBucketAcl);
|
||||
|
||||
let Some(store) = self.server_ctx.object_store() else {
|
||||
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
|
||||
};
|
||||
|
||||
store
|
||||
.get_bucket_info(&bucket, &BucketOptions::default())
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
|
||||
if access_control_policy.is_some() {
|
||||
return Err(s3_error!(
|
||||
NotImplemented,
|
||||
"ACL XML grants are not supported; use canned ACL headers or omit ACL"
|
||||
));
|
||||
}
|
||||
|
||||
Ok(S3Response::new(PutBucketAclOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl FS {
|
||||
pub(in crate::storage::ecfs) async fn delete_bucket_policy_edge(
|
||||
&self,
|
||||
@@ -145,7 +113,12 @@ impl FS {
|
||||
&self,
|
||||
req: S3Request<PutBucketAclInput>,
|
||||
) -> S3Result<S3Response<PutBucketAclOutput>> {
|
||||
audit_only_operation(req, S3Operation::PutBucketAcl, |req| self.put_bucket_acl_inner(req)).await
|
||||
record_s3_op(S3Operation::PutBucketAcl);
|
||||
let envelope = RequestEnvelope::from_s3s(&req);
|
||||
s3_api::bucket_usecase_for(self)
|
||||
.execute_put_bucket_acl(envelope, &req.input.bucket, req.input.access_control_policy.is_some())
|
||||
.await?;
|
||||
Ok(S3Response::new(PutBucketAclOutput::default()))
|
||||
}
|
||||
|
||||
pub(in crate::storage::ecfs) async fn put_bucket_notification_configuration_edge(
|
||||
|
||||
@@ -20,13 +20,10 @@
|
||||
//! former trait method bodies, unchanged; the batch that moves these operations onto the gateway
|
||||
//! owns this file and is the only one that edits it.
|
||||
|
||||
use crate::storage::access::bucket_config_mutation_incarnation;
|
||||
use crate::storage::ecfs::*;
|
||||
use crate::storage::helper::audit_only_operation;
|
||||
use crate::storage::s3_api;
|
||||
use crate::storage::storage_api::ecfs_consumer::contract::bucket::{BucketOperations, BucketOptions};
|
||||
use crate::storage::storage_api::ecstore_bucket::utils::serialize as serialize_bucket_config;
|
||||
use crate::storage::{BUCKET_LOGGING_CONFIG, update_bucket_metadata_config_if_incarnation};
|
||||
use crate::storage::{persisted_from_s3s, persisted_to_s3s};
|
||||
use rustfs_gateway_types::compat::s3s_5761ddfe::generated::ops::{create_bucket, delete_bucket, head_bucket};
|
||||
use rustfs_gateway_types::compat::s3s_5761ddfe::get_bucket_location;
|
||||
@@ -34,40 +31,6 @@ use rustfs_io_metrics::record_s3_op;
|
||||
use rustfs_s3_ops::S3Operation;
|
||||
use tracing::instrument;
|
||||
|
||||
/// Handler bodies that [`S3`] runs through `audit_only_operation`.
|
||||
impl FS {
|
||||
async fn put_bucket_logging_inner(
|
||||
&self,
|
||||
req: S3Request<PutBucketLoggingInput>,
|
||||
) -> S3Result<S3Response<PutBucketLoggingOutput>> {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&req, &req.input.bucket)?;
|
||||
record_s3_op(S3Operation::PutBucketLogging);
|
||||
let Some(store) = self.server_ctx.object_store() else {
|
||||
return Err(s3_error!(InternalError, "Not init"));
|
||||
};
|
||||
store
|
||||
.get_bucket_info(&req.input.bucket, &BucketOptions::default())
|
||||
.await
|
||||
.map_err(crate::error::ApiError::from)?;
|
||||
|
||||
let bucket_logging_status = persisted_from_s3s::<_, rustfs_gateway_types::persistence::PersistedBucketLoggingStatus>(
|
||||
&req.input.bucket_logging_status,
|
||||
)?;
|
||||
let logging_config = serialize_bucket_config(&bucket_logging_status)
|
||||
.map_err(|err| S3Error::with_message(S3ErrorCode::MalformedXML, format!("{err}")))?;
|
||||
update_bucket_metadata_config_if_incarnation(
|
||||
&req.input.bucket,
|
||||
BUCKET_LOGGING_CONFIG,
|
||||
logging_config,
|
||||
expected_incarnation_id,
|
||||
)
|
||||
.await
|
||||
.map_err(crate::error::ApiError::from)?;
|
||||
|
||||
Ok(S3Response::new(PutBucketLoggingOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl FS {
|
||||
#[instrument(
|
||||
name = "create_bucket",
|
||||
@@ -234,7 +197,16 @@ impl FS {
|
||||
&self,
|
||||
req: S3Request<PutBucketLoggingInput>,
|
||||
) -> S3Result<S3Response<PutBucketLoggingOutput>> {
|
||||
audit_only_operation(req, S3Operation::PutBucketLogging, |req| self.put_bucket_logging_inner(req)).await
|
||||
record_s3_op(S3Operation::PutBucketLogging);
|
||||
let envelope = RequestEnvelope::from_s3s(&req);
|
||||
s3_api::bucket_usecase_for(self)
|
||||
.execute_put_bucket_logging(envelope, &req.input.bucket, || {
|
||||
let config: rustfs_gateway_types::persistence::PersistedBucketLoggingStatus =
|
||||
persisted_from_s3s(&req.input.bucket_logging_status)?;
|
||||
serialize_bucket_config(&config).map_err(|err| rustfs_s3_types::s3_error!(MalformedXML, "{err}"))
|
||||
})
|
||||
.await?;
|
||||
Ok(S3Response::new(PutBucketLoggingOutput::default()))
|
||||
}
|
||||
|
||||
pub(in crate::storage::ecfs) async fn put_bucket_request_payment_edge(
|
||||
|
||||
@@ -48,7 +48,7 @@ pub(crate) mod storage_api;
|
||||
pub(crate) use ecfs_extend::*;
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use storage_api::{
|
||||
BUCKET_ACCELERATE_CONFIG, BUCKET_LOGGING_CONFIG, BUCKET_REQUEST_PAYMENT_CONFIG, BUCKET_TABLE_CATALOG_META_PREFIX,
|
||||
BUCKET_ACCELERATE_CONFIG, BUCKET_REQUEST_PAYMENT_CONFIG, BUCKET_TABLE_CATALOG_META_PREFIX,
|
||||
BUCKET_TABLE_CATALOG_TABLE_BUCKETS_PREFIX, BUCKET_TABLE_CONFIG, BUCKET_TABLE_RESERVED_PREFIX, BUCKET_VERSIONING_CONFIG,
|
||||
BUCKET_WEBSITE_CONFIG, BucketBandwidthMonitor, BucketMetadata, BucketVersioningSys, CheckPartsResp, CollectMetricsOpts,
|
||||
DEFAULT_READ_BUFFER_SIZE, DailyAllTierStats, DeleteOptions, DiskError, DiskInfo, DiskInfoOptions, DiskResult, DiskStore,
|
||||
|
||||
@@ -20,7 +20,7 @@ use aws_sdk_s3::error::SdkError;
|
||||
use aws_sdk_s3::operation::put_bucket_versioning::{
|
||||
PutBucketVersioningError, PutBucketVersioningOutput, builders::PutBucketVersioningFluentBuilder,
|
||||
};
|
||||
use aws_sdk_s3::types::{BucketVersioningStatus, VersioningConfiguration};
|
||||
use aws_sdk_s3::types::{AccessControlPolicy, BucketCannedAcl, BucketVersioningStatus, VersioningConfiguration};
|
||||
use futures::future::BoxFuture;
|
||||
use rustfs::app::context::get_global_app_context;
|
||||
use rustfs::embedded::RustFSServer;
|
||||
@@ -57,6 +57,12 @@ pub(crate) const MATRIX: &[MatrixRow] = &[
|
||||
has_error_body: true,
|
||||
call: get_bucket_acl,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "PutBucketAcl",
|
||||
metric: S3Operation::PutBucketAcl,
|
||||
has_error_body: true,
|
||||
call: put_bucket_acl,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "GetBucketNotificationConfiguration",
|
||||
metric: S3Operation::GetBucketNotificationConfiguration,
|
||||
@@ -94,6 +100,10 @@ fn get_bucket_policy_status<'a>(client: &'a Client, bucket: &'a str) -> BoxFutur
|
||||
Box::pin(async move { outcome(client.get_bucket_policy_status().bucket(bucket).send().await) })
|
||||
}
|
||||
|
||||
fn put_bucket_acl<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move { outcome(client.put_bucket_acl().bucket(bucket).send().await) })
|
||||
}
|
||||
|
||||
fn get_bucket_acl<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move { outcome(client.get_bucket_acl().bucket(bucket).send().await) })
|
||||
}
|
||||
@@ -270,6 +280,82 @@ fn the_legacy_stack_answers_the_bucket_acl() {
|
||||
with_stack(LEGACY, get_bucket_acl_answers_the_owner_with_full_control);
|
||||
}
|
||||
|
||||
async fn bucket_acl_mutations(server: RustFSServer) {
|
||||
use super::{USER_SECRET_KEY, anonymous_client, create_user_allowed_on_one_bucket};
|
||||
|
||||
const BUCKET: &str = "bucket-acl-write-s3alias";
|
||||
const OTHER: &str = "bucket-acl-write-other";
|
||||
const MISSING: &str = "bucket-acl-write-missing";
|
||||
const WRITER: &str = "bucketaclwriter";
|
||||
const READER: &str = "bucketaclreader";
|
||||
const UNSUPPORTED: &str = "ACL XML grants are not supported; use canned ACL headers or omit ACL";
|
||||
|
||||
for bucket in [BUCKET, OTHER] {
|
||||
create_bucket_in_the_store(bucket).await;
|
||||
}
|
||||
create_user_allowed_on_one_bucket(WRITER, "s3:PutBucketAcl", BUCKET).await;
|
||||
create_user_allowed_on_one_bucket(READER, "s3:GetBucketAcl", BUCKET).await;
|
||||
let endpoint = server.endpoint();
|
||||
let root = s3_client(&endpoint, server.access_key(), server.secret_key());
|
||||
let writer = s3_client(&endpoint, WRITER, USER_SECRET_KEY);
|
||||
let reader = s3_client(&endpoint, READER, USER_SECRET_KEY);
|
||||
let anonymous = anonymous_client(&endpoint).await;
|
||||
|
||||
let before = root.get_bucket_acl().bucket(BUCKET).send().await.expect("original ACL");
|
||||
assert_eq!(put_bucket_acl(&writer, BUCKET).await, Ok(()));
|
||||
writer
|
||||
.put_bucket_acl()
|
||||
.bucket(BUCKET)
|
||||
.acl(BucketCannedAcl::PublicRead)
|
||||
.send()
|
||||
.await
|
||||
.expect("accept canned ACL header");
|
||||
writer
|
||||
.put_bucket_acl()
|
||||
.bucket(BUCKET)
|
||||
.grant_read("id=\"fixture-owner\"")
|
||||
.send()
|
||||
.await
|
||||
.expect("accept grant header");
|
||||
|
||||
for (client, bucket) in [(&writer, OTHER), (&reader, BUCKET), (&anonymous, BUCKET)] {
|
||||
let err = put_bucket_acl(client, bucket).await.expect_err("permission required");
|
||||
assert_eq!((err.code.as_deref(), err.status), (Some("AccessDenied"), Some(403)));
|
||||
}
|
||||
for (client, bucket, expected) in [
|
||||
(&writer, BUCKET, ("NotImplemented", 501)),
|
||||
(&root, MISSING, ("NoSuchBucket", 404)),
|
||||
(&reader, BUCKET, ("AccessDenied", 403)),
|
||||
] {
|
||||
let error = client
|
||||
.put_bucket_acl()
|
||||
.bucket(bucket)
|
||||
.access_control_policy(AccessControlPolicy::builder().build())
|
||||
.send()
|
||||
.await
|
||||
.expect_err("XML policy");
|
||||
assert_eq!(refusal(&error), (Some(expected.0.to_owned()), Some(expected.1)));
|
||||
if expected.1 == 501 {
|
||||
assert_eq!(error.as_service_error().and_then(|error| error.meta().message()), Some(UNSUPPORTED));
|
||||
}
|
||||
}
|
||||
let after = root.get_bucket_acl().bucket(BUCKET).send().await.expect("current ACL");
|
||||
assert_eq!(after.owner(), before.owner());
|
||||
assert_eq!(after.grants(), before.grants());
|
||||
|
||||
server.shutdown().await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gateway_stack_preserves_bucket_acl_write_behavior() {
|
||||
with_stack(GATEWAY, bucket_acl_mutations);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legacy_stack_preserves_bucket_acl_write_behavior() {
|
||||
with_stack(LEGACY, bucket_acl_mutations);
|
||||
}
|
||||
|
||||
const QUEUE_NOTIFICATION: &str = r#"<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><QueueConfiguration><Id>a2-queue</Id><Queue>arn:rustfs:sqs:us-east-1:1:webhook</Queue><Event>s3:ObjectCreated:*</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>logs/</Value></FilterRule></S3Key></Filter></QueueConfiguration></NotificationConfiguration>"#;
|
||||
|
||||
/// GetBucketNotificationConfiguration answers an empty configuration when none is stored, the
|
||||
|
||||
@@ -20,8 +20,8 @@ use super::{
|
||||
};
|
||||
use aws_sdk_s3::Client;
|
||||
use aws_sdk_s3::types::{
|
||||
AccelerateConfiguration, BucketAccelerateStatus, BucketLocationConstraint, CreateBucketConfiguration, IndexDocument, Payer,
|
||||
RequestPaymentConfiguration, WebsiteConfiguration,
|
||||
AccelerateConfiguration, BucketAccelerateStatus, BucketLocationConstraint, BucketLoggingStatus, CreateBucketConfiguration,
|
||||
IndexDocument, LoggingEnabled, Payer, RequestPaymentConfiguration, WebsiteConfiguration,
|
||||
};
|
||||
use futures::future::BoxFuture;
|
||||
use rustfs::embedded::RustFSServer;
|
||||
@@ -86,6 +86,12 @@ pub(crate) const MATRIX: &[MatrixRow] = &[
|
||||
has_error_body: true,
|
||||
call: get_bucket_logging,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "PutBucketLogging",
|
||||
metric: S3Operation::PutBucketLogging,
|
||||
has_error_body: true,
|
||||
call: put_bucket_logging,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "PutBucketAccelerateConfiguration",
|
||||
metric: S3Operation::PutBucketAccelerateConfiguration,
|
||||
@@ -516,6 +522,108 @@ fn the_legacy_stack_reads_core_bucket_configurations() {
|
||||
with_stack(LEGACY, |server| core_configuration_reads(server, false));
|
||||
}
|
||||
|
||||
fn put_bucket_logging<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move {
|
||||
let enabled = LoggingEnabled::builder()
|
||||
.target_bucket("logging-target")
|
||||
.target_prefix("café & tea/")
|
||||
.build()
|
||||
.expect("logging target and prefix");
|
||||
let status = BucketLoggingStatus::builder().logging_enabled(enabled).build();
|
||||
outcome(
|
||||
client
|
||||
.put_bucket_logging()
|
||||
.bucket(bucket)
|
||||
.bucket_logging_status(status)
|
||||
.send()
|
||||
.await,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async fn bucket_logging_mutations(server: RustFSServer) {
|
||||
const BUCKET: &str = "logging-write-granted-s3alias";
|
||||
const OTHER: &str = "logging-write-other";
|
||||
const MISSING: &str = "logging-write-missing";
|
||||
const WRITER: &str = "bucketloggingwriter";
|
||||
const READER: &str = "bucketloggingreader";
|
||||
|
||||
for bucket in [BUCKET, OTHER] {
|
||||
create_bucket_in_the_store(bucket).await;
|
||||
}
|
||||
create_user_allowed_on_one_bucket(WRITER, "s3:PutBucketLogging", BUCKET).await;
|
||||
create_user_allowed_on_one_bucket(READER, "s3:GetBucketLogging", BUCKET).await;
|
||||
let endpoint = server.endpoint();
|
||||
let root = s3_client(&endpoint, server.access_key(), server.secret_key());
|
||||
let writer = s3_client(&endpoint, WRITER, USER_SECRET_KEY);
|
||||
let reader = s3_client(&endpoint, READER, USER_SECRET_KEY);
|
||||
let anonymous = anonymous_client(&endpoint).await;
|
||||
|
||||
assert_eq!(put_bucket_logging(&writer, BUCKET).await, Ok(()), "grant on the requested bucket");
|
||||
for (client, bucket, expected) in [
|
||||
(&writer, OTHER, ("AccessDenied", 403)),
|
||||
(&reader, BUCKET, ("AccessDenied", 403)),
|
||||
(&anonymous, BUCKET, ("AccessDenied", 403)),
|
||||
(&root, MISSING, ("NoSuchBucket", 404)),
|
||||
] {
|
||||
let error = put_bucket_logging(client, bucket).await.expect_err("logging write refusal");
|
||||
assert_eq!((error.code.as_deref(), error.status), (Some(expected.0), Some(expected.1)));
|
||||
}
|
||||
let stored = metadata_sys::get_config_from_disk(BUCKET)
|
||||
.await
|
||||
.expect("durable logging config");
|
||||
assert_eq!(
|
||||
stored.logging_config_xml,
|
||||
"<BucketLoggingStatus><LoggingEnabled><TargetBucket>logging-target</TargetBucket><TargetPrefix>café & tea/</TargetPrefix></LoggingEnabled></BucketLoggingStatus>".as_bytes()
|
||||
);
|
||||
let response = reader
|
||||
.get_bucket_logging()
|
||||
.bucket(BUCKET)
|
||||
.send()
|
||||
.await
|
||||
.expect("read logging config");
|
||||
let enabled = response.logging_enabled().expect("logging is enabled");
|
||||
assert_eq!((enabled.target_bucket(), enabled.target_prefix()), ("logging-target", "café & tea/"));
|
||||
assert!(
|
||||
metadata_sys::get_config_from_disk(OTHER)
|
||||
.await
|
||||
.expect("untouched bucket")
|
||||
.logging_config_xml
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
writer
|
||||
.put_bucket_logging()
|
||||
.bucket(BUCKET)
|
||||
.bucket_logging_status(BucketLoggingStatus::builder().build())
|
||||
.send()
|
||||
.await
|
||||
.expect("disable logging");
|
||||
let stored = metadata_sys::get_config_from_disk(BUCKET)
|
||||
.await
|
||||
.expect("durable disabled logging config");
|
||||
assert_eq!(stored.logging_config_xml, b"<BucketLoggingStatus></BucketLoggingStatus>");
|
||||
let response = reader
|
||||
.get_bucket_logging()
|
||||
.bucket(BUCKET)
|
||||
.send()
|
||||
.await
|
||||
.expect("read disabled logging config");
|
||||
assert!(response.logging_enabled().is_none());
|
||||
|
||||
server.shutdown().await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gateway_stack_mutates_bucket_logging() {
|
||||
with_stack(GATEWAY, bucket_logging_mutations);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legacy_stack_mutates_bucket_logging() {
|
||||
with_stack(LEGACY, bucket_logging_mutations);
|
||||
}
|
||||
|
||||
fn put_bucket_accelerate_configuration<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move {
|
||||
let config = AccelerateConfiguration::builder()
|
||||
|
||||
Reference in New Issue
Block a user