mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 04:52:36 +00:00
feat(gateway): serve encryption, policy, and tagging deletes
Share the three generation-fenced deletes across both S3 stacks. Keep
their existing IAM actions and use the shared IAM scope for tag deletion.
Add six focused tests covering 21 refusals and nine successes, and add the
three operations to the refusal matrix. Substituting IAM actions and
buckets, removing the tagging scope, and suppressing the gateway counter
fail the authorization and metrics checks. The storage tests detect a
lost fence, a skipped write, missing reload or replication calls, omitted
scanner invalidation, and a changed audit status.
Verified on 4294c41cc with scoped nextest, both Clippy modes, script tests,
quick checks, and local CLI comparisons. Peer network delivery was
outside the local checks.
This commit is contained in:
@@ -125,6 +125,8 @@ mod core;
|
||||
#[cfg(any(test, feature = "gateway-stack"))]
|
||||
pub(crate) use self::core::requested_location_constraint;
|
||||
mod cors;
|
||||
#[cfg(test)]
|
||||
mod delete_config_tests;
|
||||
mod encryption;
|
||||
#[cfg(test)]
|
||||
mod guards;
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
// 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.
|
||||
|
||||
//! Bucket configuration delete tests over the shared use case and durable metadata.
|
||||
|
||||
use super::*;
|
||||
use crate::app::bucket_usecase::test_support::build_request;
|
||||
use crate::app::gating_test_env::{run_large_stack_test, shared_gating_ambient};
|
||||
use crate::app::runtime_sources::ServerContextSlot;
|
||||
use crate::app::storage_api::bucket_usecase::helper::MutationCompletionProbe;
|
||||
use crate::app::storage_api::owned_parity::authorize_bucket_config_mutation;
|
||||
use crate::site_replication::hooks::BUCKET_META_HOOK_CALLS;
|
||||
use http::Method;
|
||||
use rustfs_credentials::Credentials;
|
||||
use rustfs_s3_types::{S3ErrorCode, S3Result};
|
||||
use serial_test::serial;
|
||||
use std::{cell::RefCell, sync::Mutex};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Config {
|
||||
Encryption,
|
||||
Policy,
|
||||
Tagging,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
async fn seed(self, bucket: &str) {
|
||||
match self {
|
||||
Self::Encryption => {
|
||||
metadata_sys::update(
|
||||
bucket,
|
||||
BUCKET_SSECONFIG,
|
||||
b"<ServerSideEncryptionConfiguration><Rule><ApplyServerSideEncryptionByDefault>\
|
||||
<SSEAlgorithm>AES256</SSEAlgorithm></ApplyServerSideEncryptionByDefault></Rule></ServerSideEncryptionConfiguration>"
|
||||
.to_vec(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
Self::Policy => {
|
||||
metadata_sys::update(bucket, BUCKET_POLICY_CONFIG, br#"{"Version":"2012-10-17","Statement":[]}"#.to_vec()).await
|
||||
}
|
||||
Self::Tagging => {
|
||||
let tags = rustfs_gateway_types::cors_tagging::parse_tagging(
|
||||
b"<Tagging><TagSet><Tag><Key>team</Key><Value>storage</Value></Tag></TagSet></Tagging>",
|
||||
)
|
||||
.expect("valid tagging fixture");
|
||||
metadata_sys::update_s3_tagging_config(bucket, Some(tags), None).await
|
||||
}
|
||||
}
|
||||
.expect("seed bucket configuration");
|
||||
}
|
||||
|
||||
async fn stored(self, bucket: &str) -> Vec<u8> {
|
||||
let metadata = metadata_sys::get_global_bucket_metadata_sys()
|
||||
.expect("initialized metadata system")
|
||||
.read()
|
||||
.await
|
||||
.get_config_from_disk(bucket)
|
||||
.await
|
||||
.expect("read bucket metadata from disk");
|
||||
match self {
|
||||
Self::Encryption => metadata.encryption_config_xml,
|
||||
Self::Policy => metadata.policy_config_json,
|
||||
Self::Tagging => metadata.tagging_config_xml,
|
||||
}
|
||||
}
|
||||
|
||||
async fn execute(self, usecase: &DefaultBucketUsecase, envelope: RequestEnvelope, bucket: &str) -> S3Result<()> {
|
||||
match self {
|
||||
Self::Encryption => usecase.execute_delete_bucket_encryption(envelope, bucket).await,
|
||||
Self::Policy => usecase.execute_delete_bucket_policy(envelope, bucket).await,
|
||||
Self::Tagging => usecase.execute_delete_bucket_tagging(envelope, bucket).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_delete(config: Config, stale: bool) {
|
||||
let (subresource, action, operation, reload, replicated, audit_status) = match config {
|
||||
Config::Encryption => (
|
||||
"encryption",
|
||||
S3Action::PutBucketEncryptionAction,
|
||||
S3Operation::DeleteBucketEncryption,
|
||||
"delete bucket encryption",
|
||||
"sse-config",
|
||||
204,
|
||||
),
|
||||
Config::Policy => (
|
||||
"policy",
|
||||
S3Action::DeleteBucketPolicyAction,
|
||||
S3Operation::DeleteBucketPolicy,
|
||||
"delete bucket policy",
|
||||
"policy",
|
||||
200,
|
||||
),
|
||||
Config::Tagging => (
|
||||
"tagging",
|
||||
S3Action::PutBucketTaggingAction,
|
||||
S3Operation::DeleteBucketTagging,
|
||||
"delete bucket tagging",
|
||||
"tags",
|
||||
200,
|
||||
),
|
||||
};
|
||||
let context = shared_gating_ambient().await;
|
||||
let store = context.object_store();
|
||||
let bucket = format!("config-delete-{}", uuid::Uuid::new_v4().simple());
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("create bucket");
|
||||
let server = ServerContextSlot::new();
|
||||
assert!(server.install(Arc::clone(&context)));
|
||||
let mut request = build_request((), Method::DELETE);
|
||||
request.uri = format!("/{bucket}?{subresource}").parse().expect("request URI");
|
||||
request.extensions.insert(Arc::clone(&server));
|
||||
request.extensions.insert(ReqInfo {
|
||||
cred: Some(Credentials {
|
||||
access_key: "config-delete-owner".to_owned(),
|
||||
..Default::default()
|
||||
}),
|
||||
is_owner: true,
|
||||
..Default::default()
|
||||
});
|
||||
request.extensions.insert(request_context::RequestContext {
|
||||
request_id: "bucket-config-delete".to_owned(),
|
||||
x_amz_request_id: "bucket-config-delete".to_owned(),
|
||||
trace_id: None,
|
||||
span_id: None,
|
||||
start_time: std::time::Instant::now(),
|
||||
});
|
||||
let mut envelope = RequestEnvelope::from_s3s(&request);
|
||||
authorize_bucket_config_mutation(&server, &mut envelope, &bucket, Action::S3Action(action))
|
||||
.await
|
||||
.expect("capture authorized bucket incarnation");
|
||||
if stale {
|
||||
store
|
||||
.delete_bucket(&bucket, &DeleteBucketOptions::default())
|
||||
.await
|
||||
.expect("delete authorized bucket");
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("recreate bucket");
|
||||
}
|
||||
config.seed(&bucket).await;
|
||||
let seeded = config.stored(&bucket).await;
|
||||
assert!(!seeded.is_empty(), "durable configuration fixture");
|
||||
|
||||
let before = rustfs_scanner::scanner_dirty_usage_bucket_generation(&bucket);
|
||||
let maintenance_before = rustfs_scanner::scanner_maintenance_generation();
|
||||
let audits = MutationCompletionProbe::install(&bucket);
|
||||
let reloads = Arc::new(Mutex::new(Vec::new()));
|
||||
let observe = Arc::clone(&reloads);
|
||||
let usecase = DefaultBucketUsecase::with_context(Some(context));
|
||||
let (result, hooks) = BUCKET_META_HOOK_CALLS
|
||||
.scope(RefCell::default(), async {
|
||||
let result = BUCKET_METADATA_RELOAD_PROBE
|
||||
.scope(
|
||||
(
|
||||
bucket.clone(),
|
||||
Box::new(move |completed, label, maintenance| {
|
||||
let replication_calls = BUCKET_META_HOOK_CALLS.with(|calls| calls.borrow().len());
|
||||
observe
|
||||
.lock()
|
||||
.expect("reload entries")
|
||||
.push((completed, label, maintenance, replication_calls));
|
||||
}),
|
||||
),
|
||||
config.execute(&usecase, envelope, &bucket),
|
||||
)
|
||||
.await;
|
||||
(result, BUCKET_META_HOOK_CALLS.with(RefCell::take))
|
||||
})
|
||||
.await;
|
||||
|
||||
let stored = config.stored(&bucket).await;
|
||||
let after = rustfs_scanner::scanner_dirty_usage_bucket_generation(&bucket);
|
||||
let reloads = reloads.lock().expect("reload entries");
|
||||
let entries = audits.audits.lock().expect("audit entries");
|
||||
assert!(audits.events.lock().expect("event entries").is_empty());
|
||||
let audit = entries
|
||||
.iter()
|
||||
.map(|entry| (entry.api.name.as_deref(), entry.api.status_code))
|
||||
.collect::<Vec<_>>();
|
||||
if stale {
|
||||
assert_eq!(
|
||||
(
|
||||
result.err().map(|err| err.code().clone()),
|
||||
stored,
|
||||
reloads.len(),
|
||||
hooks.len(),
|
||||
after,
|
||||
audit
|
||||
),
|
||||
(
|
||||
Some(S3ErrorCode::NoSuchBucket),
|
||||
seeded,
|
||||
0,
|
||||
0,
|
||||
before,
|
||||
vec![(Some(operation.as_str()), Some(404))]
|
||||
),
|
||||
"{operation:?} must refuse the stale authorization and preserve replacement bytes"
|
||||
);
|
||||
} else {
|
||||
result.expect("authorized delete");
|
||||
assert!(stored.is_empty(), "{operation:?} must remove the durable configuration");
|
||||
assert_eq!(*reloads, [(false, reload, false, 0), (true, reload, false, 0)]);
|
||||
let [hook] = hooks.as_slice() else { panic!("{operation:?}: expected one replication call") };
|
||||
assert_eq!((&hook.bucket, hook.item_type.as_str()), (&bucket, replicated));
|
||||
assert_eq!(hook.scanner_maintenance_generation, maintenance_before);
|
||||
assert_eq!(rustfs_scanner::scanner_maintenance_generation(), maintenance_before);
|
||||
if matches!(config, Config::Tagging) {
|
||||
assert!(after > hook.scanner_generation);
|
||||
} else {
|
||||
assert_eq!(after, hook.scanner_generation);
|
||||
}
|
||||
assert_eq!(audit, [(Some(operation.as_str()), Some(audit_status))]);
|
||||
assert_eq!(entries[0].request_id.as_deref(), Some("bucket-config-delete"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn encryption_delete_fences_recreated_bucket_and_orders_callbacks() {
|
||||
run_large_stack_test("delete-encryption", || async {
|
||||
check_delete(Config::Encryption, false).await;
|
||||
check_delete(Config::Encryption, true).await;
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn policy_delete_fences_recreated_bucket_and_orders_callbacks() {
|
||||
run_large_stack_test("delete-policy", || async {
|
||||
check_delete(Config::Policy, false).await;
|
||||
check_delete(Config::Policy, true).await;
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn tagging_delete_fences_recreated_bucket_and_orders_callbacks() {
|
||||
run_large_stack_test("delete-tagging", || async {
|
||||
check_delete(Config::Tagging, false).await;
|
||||
check_delete(Config::Tagging, true).await;
|
||||
});
|
||||
}
|
||||
@@ -15,10 +15,7 @@
|
||||
//! Bucket default-encryption use-case operations.
|
||||
|
||||
use super::*;
|
||||
use crate::app::storage_api::s3::dto::{
|
||||
DeleteBucketEncryptionInput, DeleteBucketEncryptionOutput, PutBucketEncryptionInput, PutBucketEncryptionOutput,
|
||||
ServerSideEncryption,
|
||||
};
|
||||
use crate::app::storage_api::s3::dto::{PutBucketEncryptionInput, PutBucketEncryptionOutput, ServerSideEncryption};
|
||||
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result};
|
||||
|
||||
/// Refuse a default-encryption configuration the write path could not honour
|
||||
@@ -62,35 +59,43 @@ fn validate_bucket_encryption_configuration(config: &PersistedBucketEncryptionCo
|
||||
}
|
||||
|
||||
impl DefaultBucketUsecase {
|
||||
pub async fn execute_delete_bucket_encryption(
|
||||
pub(crate) async fn execute_delete_bucket_encryption(
|
||||
&self,
|
||||
req: S3Request<DeleteBucketEncryptionInput>,
|
||||
) -> S3Result<S3Response<DeleteBucketEncryptionOutput>> {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&req, &req.input.bucket)?;
|
||||
let request_context = req.extensions.get::<request_context::RequestContext>().cloned();
|
||||
let DeleteBucketEncryptionInput { bucket, .. } = req.input;
|
||||
envelope: RequestEnvelope,
|
||||
bucket: &str,
|
||||
) -> rustfs_s3_types::S3Result<()> {
|
||||
RequestEnvelope::audit_only_operation(
|
||||
envelope,
|
||||
S3Operation::DeleteBucketEncryption,
|
||||
StatusCode::NO_CONTENT,
|
||||
|envelope| async move {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&envelope, bucket)?;
|
||||
let request_context = envelope.request_context().cloned();
|
||||
|
||||
let Some(store) = self.object_store() else {
|
||||
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
|
||||
};
|
||||
let Some(store) = self.object_store() else {
|
||||
return Err(rustfs_s3_types::s3_error!(InternalError, "Not init"));
|
||||
};
|
||||
|
||||
store
|
||||
.get_bucket_info(&bucket, &BucketOptions::default())
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
store
|
||||
.get_bucket_info(bucket, &BucketOptions::default())
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
|
||||
delete_bucket_config_for_incarnation(&bucket, BUCKET_SSECONFIG, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
delete_bucket_config_for_incarnation(bucket, BUCKET_SSECONFIG, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
|
||||
notify_bucket_metadata_reload(bucket.clone(), "delete bucket encryption", request_context, false).await;
|
||||
notify_bucket_metadata_reload(bucket.to_owned(), "delete bucket encryption", request_context, false).await;
|
||||
|
||||
let item = sr_bucket_meta_item(bucket.clone(), "sse-config");
|
||||
if let Err(err) = site_replication_bucket_meta_hook(item).await {
|
||||
warn!(bucket = %bucket, error = ?err, "site replication bucket encryption delete hook failed");
|
||||
}
|
||||
let item = sr_bucket_meta_item(bucket.to_owned(), "sse-config");
|
||||
if let Err(err) = site_replication_bucket_meta_hook(item).await {
|
||||
warn!(bucket = %bucket, error = ?err, "site replication bucket encryption delete hook failed");
|
||||
}
|
||||
|
||||
Ok(S3Response::with_status(DeleteBucketEncryptionOutput::default(), StatusCode::NO_CONTENT))
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns the stored bucket encryption configuration after checking the bucket exists.
|
||||
|
||||
@@ -15,43 +15,43 @@
|
||||
//! Bucket policy and policy status use-case operations.
|
||||
|
||||
use super::*;
|
||||
use crate::app::storage_api::s3::dto::{
|
||||
DeleteBucketPolicyInput, DeleteBucketPolicyOutput, PutBucketPolicyInput, PutBucketPolicyOutput,
|
||||
};
|
||||
use crate::app::storage_api::s3::dto::{PutBucketPolicyInput, PutBucketPolicyOutput};
|
||||
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result, s3_error};
|
||||
use rustfs_policy::policy::Validator;
|
||||
|
||||
impl DefaultBucketUsecase {
|
||||
pub async fn execute_delete_bucket_policy(
|
||||
pub(crate) async fn execute_delete_bucket_policy(
|
||||
&self,
|
||||
req: S3Request<DeleteBucketPolicyInput>,
|
||||
) -> S3Result<S3Response<DeleteBucketPolicyOutput>> {
|
||||
record_s3_op(S3Operation::DeleteBucketPolicy);
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&req, &req.input.bucket)?;
|
||||
let request_context = req.extensions.get::<request_context::RequestContext>().cloned();
|
||||
let DeleteBucketPolicyInput { bucket, .. } = req.input;
|
||||
envelope: RequestEnvelope,
|
||||
bucket: &str,
|
||||
) -> rustfs_s3_types::S3Result<()> {
|
||||
RequestEnvelope::audit_only_operation(envelope, S3Operation::DeleteBucketPolicy, StatusCode::OK, |envelope| async move {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&envelope, bucket)?;
|
||||
let request_context = envelope.request_context().cloned();
|
||||
|
||||
let Some(store) = self.object_store() else {
|
||||
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
|
||||
};
|
||||
let Some(store) = self.object_store() else {
|
||||
return Err(rustfs_s3_types::s3_error!(InternalError, "Not init"));
|
||||
};
|
||||
|
||||
store
|
||||
.get_bucket_info(&bucket, &BucketOptions::default())
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
store
|
||||
.get_bucket_info(bucket, &BucketOptions::default())
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
|
||||
delete_bucket_config_for_incarnation(&bucket, BUCKET_POLICY_CONFIG, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
delete_bucket_config_for_incarnation(bucket, BUCKET_POLICY_CONFIG, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
|
||||
notify_bucket_metadata_reload(bucket.clone(), "delete bucket policy", request_context, false).await;
|
||||
notify_bucket_metadata_reload(bucket.to_owned(), "delete bucket policy", request_context, false).await;
|
||||
|
||||
let item = sr_bucket_meta_item(bucket.clone(), "policy");
|
||||
if let Err(err) = site_replication_bucket_meta_hook(item).await {
|
||||
warn!(bucket = %bucket, error = ?err, "site replication bucket policy delete hook failed");
|
||||
}
|
||||
let item = sr_bucket_meta_item(bucket.to_owned(), "policy");
|
||||
if let Err(err) = site_replication_bucket_meta_hook(item).await {
|
||||
warn!(bucket = %bucket, error = ?err, "site replication bucket policy delete hook failed");
|
||||
}
|
||||
|
||||
Ok(S3Response::new(DeleteBucketPolicyOutput {}))
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// The stored policy document, verbatim.
|
||||
@@ -242,6 +242,7 @@ impl DefaultBucketUsecase {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::bucket_usecase::test_support::{build_request, s3_op_total};
|
||||
use crate::app::storage_api::s3::dto::DeleteBucketPolicyInput;
|
||||
use http::Method;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -252,10 +253,12 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let req = build_request(input, Method::DELETE);
|
||||
let usecase = DefaultBucketUsecase::without_context();
|
||||
let fs = crate::storage::ecfs::FS::new();
|
||||
let before = s3_op_total(S3Operation::DeleteBucketPolicy);
|
||||
|
||||
let err = usecase.execute_delete_bucket_policy(req).await.unwrap_err();
|
||||
let err = crate::app::storage_api::s3::S3::delete_bucket_policy(&fs, req)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), &S3ErrorCode::InternalError);
|
||||
assert_eq!(s3_op_total(S3Operation::DeleteBucketPolicy), before + 1);
|
||||
}
|
||||
|
||||
@@ -16,37 +16,39 @@
|
||||
|
||||
use super::*;
|
||||
use crate::app::storage_api::s3::dto;
|
||||
use crate::app::storage_api::s3::dto::{
|
||||
DeleteBucketTaggingInput, DeleteBucketTaggingOutput, PutBucketTaggingInput, PutBucketTaggingOutput,
|
||||
};
|
||||
use crate::app::storage_api::s3::dto::{PutBucketTaggingInput, PutBucketTaggingOutput};
|
||||
use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result};
|
||||
|
||||
impl DefaultBucketUsecase {
|
||||
#[instrument(level = "debug", skip(self, req))]
|
||||
pub async fn execute_delete_bucket_tagging(
|
||||
#[instrument(level = "debug", skip(self, envelope))]
|
||||
pub(crate) async fn execute_delete_bucket_tagging(
|
||||
&self,
|
||||
req: S3Request<DeleteBucketTaggingInput>,
|
||||
) -> S3Result<S3Response<DeleteBucketTaggingOutput>> {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&req, &req.input.bucket)?;
|
||||
let request_context = req.extensions.get::<request_context::RequestContext>().cloned();
|
||||
let DeleteBucketTaggingInput { bucket, .. } = req.input;
|
||||
envelope: RequestEnvelope,
|
||||
bucket: &str,
|
||||
) -> rustfs_s3_types::S3Result<()> {
|
||||
RequestEnvelope::audit_only_operation(envelope, S3Operation::DeleteBucketTagging, StatusCode::OK, |envelope| async move {
|
||||
let expected_incarnation_id = bucket_config_mutation_incarnation(&envelope, bucket)?;
|
||||
let request_context = envelope.request_context().cloned();
|
||||
|
||||
metadata_sys::update_s3_tagging_config(&bucket, None, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
metadata_sys::update_s3_tagging_config(bucket, None, expected_incarnation_id)
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
|
||||
notify_bucket_metadata_reload(bucket.clone(), "delete bucket tagging", request_context, false).await;
|
||||
notify_bucket_metadata_reload(bucket.to_owned(), "delete bucket tagging", request_context, false).await;
|
||||
|
||||
let item = sr_bucket_meta_item(bucket.clone(), "tags");
|
||||
if let Err(err) = site_replication_bucket_meta_hook(item).await {
|
||||
warn!(bucket = %bucket, error = ?err, "site replication bucket tagging delete hook failed");
|
||||
}
|
||||
let item = sr_bucket_meta_item(bucket.to_owned(), "tags");
|
||||
if let Err(err) = site_replication_bucket_meta_hook(item).await {
|
||||
warn!(bucket = %bucket, error = ?err, "site replication bucket tagging delete hook failed");
|
||||
}
|
||||
|
||||
rustfs_scanner::record_dirty_usage_bucket_from_producer(
|
||||
&bucket,
|
||||
rustfs_scanner::SegmentInvalidationProducerIdentity::BucketMetadata,
|
||||
);
|
||||
Ok(S3Response::new(DeleteBucketTaggingOutput {}))
|
||||
rustfs_scanner::record_dirty_usage_bucket_from_producer(
|
||||
bucket,
|
||||
rustfs_scanner::SegmentInvalidationProducerIdentity::BucketMetadata,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns the stored bucket tagging configuration after checking the bucket exists.
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
use crate::app::RequestEnvelope;
|
||||
use crate::runtime_sources::ServerContextSlot;
|
||||
use crate::storage_api::server::http::access::{
|
||||
VerifiedSignature, admit_operation, authorize_bucket_config_mutation as authorize_config_mutation, resolve_req_info,
|
||||
VerifiedSignature, admit_operation, authorize_bucket_config_mutation as authorize_config_mutation,
|
||||
authorize_bucket_tag_deletion as authorize_tag_deletion, resolve_req_info,
|
||||
};
|
||||
use rustfs_gateway::sig::{SigFamily, SigLocation};
|
||||
use rustfs_gateway::{RequestContextView, RequestPrincipal};
|
||||
@@ -70,11 +71,20 @@ pub(super) async fn authorize_bucket_config_mutation(
|
||||
bucket: &str,
|
||||
action: Action,
|
||||
) -> S3Result<()> {
|
||||
let server_ctx = envelope
|
||||
let server_ctx = require_server_context(envelope)?;
|
||||
Ok(authorize_config_mutation(&server_ctx, envelope, bucket, action).await?)
|
||||
}
|
||||
|
||||
pub(super) async fn authorize_bucket_tag_deletion(envelope: &mut RequestEnvelope, bucket: &str) -> S3Result<()> {
|
||||
let server_ctx = require_server_context(envelope)?;
|
||||
Ok(authorize_tag_deletion(&server_ctx, envelope, bucket).await?)
|
||||
}
|
||||
|
||||
fn require_server_context(envelope: &RequestEnvelope) -> S3Result<Arc<ServerContextSlot>> {
|
||||
envelope
|
||||
.server_context()
|
||||
.cloned()
|
||||
.ok_or_else(|| rustfs_s3_types::s3_error!(InternalError, "the request carries no server context"))?;
|
||||
Ok(authorize_config_mutation(&server_ctx, envelope, bucket, action).await?)
|
||||
.ok_or_else(|| rustfs_s3_types::s3_error!(InternalError, "the request carries no server context"))
|
||||
}
|
||||
|
||||
/// The gateway's verdict as the access markers read it: a SigV4 signature in the header or the
|
||||
|
||||
@@ -33,6 +33,7 @@ pub(super) const ROWS: &[OpRow] = &[
|
||||
row::<dto::GetBucketVersioning>(),
|
||||
row::<dto::PutBucketVersioning>(),
|
||||
row::<dto::GetBucketPolicy>(),
|
||||
row::<dto::DeleteBucketPolicy>(),
|
||||
row::<dto::GetBucketPolicyStatus>(),
|
||||
row::<dto::GetBucketAcl>(),
|
||||
row::<dto::PutBucketAcl>(),
|
||||
@@ -75,6 +76,22 @@ impl Served for dto::PutBucketVersioning {
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::DeleteBucketPolicy {
|
||||
const METRIC: S3Operation = S3Operation::DeleteBucketPolicy;
|
||||
|
||||
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
|
||||
let action = Action::S3Action(S3Action::DeleteBucketPolicyAction);
|
||||
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>> {
|
||||
DefaultBucketUsecase::with_context(context)
|
||||
.execute_delete_bucket_policy(envelope, request.input().bucket.as_str())
|
||||
.await?;
|
||||
Ok(Resp::new(dto::DeleteBucketPolicyOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::GetBucketPolicy {
|
||||
const METRIC: S3Operation = S3Operation::GetBucketPolicy;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//! The gateway operations of migration batch A1 (rustfs/backlog#2765): bucket CORS, tagging, public access block and encryption.
|
||||
//! The stored CORS document is applied to requests by `ConditionalCorsLayer`, not by the gateway.
|
||||
|
||||
use super::access::authorize_bucket_config_mutation;
|
||||
use super::access::{authorize_bucket_config_mutation, authorize_bucket_tag_deletion};
|
||||
use super::{OpRow, Served, row};
|
||||
use crate::app::bucket_usecase::DefaultBucketUsecase;
|
||||
use crate::app::{RequestEnvelope, dto_values};
|
||||
@@ -33,7 +33,9 @@ use std::sync::Arc;
|
||||
pub(super) const ROWS: &[OpRow] = &[
|
||||
row::<dto::GetBucketCors>(),
|
||||
row::<dto::GetBucketEncryption>(),
|
||||
row::<dto::DeleteBucketEncryption>(),
|
||||
row::<dto::GetBucketTagging>(),
|
||||
row::<dto::DeleteBucketTagging>(),
|
||||
row::<dto::PutBucketCors>(),
|
||||
row::<dto::DeleteBucketCors>(),
|
||||
row::<dto::GetPublicAccessBlock>(),
|
||||
@@ -60,6 +62,22 @@ impl Served for dto::GetBucketCors {
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::DeleteBucketEncryption {
|
||||
const METRIC: S3Operation = S3Operation::DeleteBucketEncryption;
|
||||
|
||||
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
|
||||
let action = Action::S3Action(S3Action::PutBucketEncryptionAction);
|
||||
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>> {
|
||||
DefaultBucketUsecase::with_context(context)
|
||||
.execute_delete_bucket_encryption(envelope, request.input().bucket.as_str())
|
||||
.await?;
|
||||
Ok(Resp::new(dto::DeleteBucketEncryptionOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::GetBucketEncryption {
|
||||
const METRIC: S3Operation = S3Operation::GetBucketEncryption;
|
||||
|
||||
@@ -79,6 +97,21 @@ impl Served for dto::GetBucketEncryption {
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::DeleteBucketTagging {
|
||||
const METRIC: S3Operation = S3Operation::DeleteBucketTagging;
|
||||
|
||||
async fn authorize(envelope: &mut RequestEnvelope, request: &Req<Self>) -> S3Result<()> {
|
||||
authorize_bucket_tag_deletion(envelope, request.input().bucket.as_str()).await
|
||||
}
|
||||
|
||||
async fn execute(context: Option<Arc<AppContext>>, envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
|
||||
DefaultBucketUsecase::with_context(context)
|
||||
.execute_delete_bucket_tagging(envelope, request.input().bucket.as_str())
|
||||
.await?;
|
||||
Ok(Resp::new(dto::DeleteBucketTaggingOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Served for dto::GetBucketTagging {
|
||||
const METRIC: S3Operation = S3Operation::GetBucketTagging;
|
||||
|
||||
|
||||
@@ -573,6 +573,21 @@ pub(crate) async fn authorize_bucket_config_mutation<R: AuthorizationRequest + ?
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Authorizes tag deletion under the IAM repair scope for unreadable stored tags.
|
||||
pub(crate) async fn authorize_bucket_tag_deletion<R: AuthorizationRequest + ?Sized>(
|
||||
server_ctx: &ServerContextSlot,
|
||||
req: &mut R,
|
||||
bucket: &str,
|
||||
) -> S3Result<()> {
|
||||
rustfs_iam::sys::with_bucket_tag_deletion(authorize_bucket_config_mutation(
|
||||
server_ctx,
|
||||
req,
|
||||
bucket,
|
||||
Action::S3Action(S3Action::PutBucketTaggingAction),
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct CopySourceBucketGenerationGuard {
|
||||
bucket: String,
|
||||
@@ -3519,13 +3534,7 @@ impl S3Access for FS {
|
||||
/// This method returns `Ok(())` by default.
|
||||
async fn delete_bucket_tagging(&self, req: &mut S3Request<DeleteBucketTaggingInput>) -> S3Result<()> {
|
||||
let bucket = req.input.bucket.clone();
|
||||
rustfs_iam::sys::with_bucket_tag_deletion(authorize_bucket_config_mutation(
|
||||
self.server_ctx(),
|
||||
req,
|
||||
&bucket,
|
||||
Action::S3Action(S3Action::PutBucketTaggingAction),
|
||||
))
|
||||
.await
|
||||
authorize_bucket_tag_deletion(self.server_ctx(), req, &bucket).await
|
||||
}
|
||||
|
||||
/// Checks whether the DeleteBucketWebsite request has accesses to the resources.
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
//! 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::app::RequestEnvelope;
|
||||
use crate::storage::ecfs::*;
|
||||
use crate::storage::helper::audit_only_operation;
|
||||
use crate::storage::persisted_from_s3s;
|
||||
@@ -35,8 +36,11 @@ impl FS {
|
||||
&self,
|
||||
req: S3Request<DeleteBucketPolicyInput>,
|
||||
) -> S3Result<S3Response<DeleteBucketPolicyOutput>> {
|
||||
let usecase = s3_api::bucket_usecase_for(self);
|
||||
audit_only_operation(req, S3Operation::DeleteBucketPolicy, |req| usecase.execute_delete_bucket_policy(req)).await
|
||||
record_s3_op(S3Operation::DeleteBucketPolicy);
|
||||
s3_api::bucket_usecase_for(self)
|
||||
.execute_delete_bucket_policy(RequestEnvelope::from_s3s(&req), &req.input.bucket)
|
||||
.await?;
|
||||
Ok(S3Response::new(DeleteBucketPolicyOutput::default()))
|
||||
}
|
||||
|
||||
pub(in crate::storage::ecfs) async fn get_bucket_acl_edge(
|
||||
|
||||
@@ -50,11 +50,10 @@ impl FS {
|
||||
&self,
|
||||
req: S3Request<DeleteBucketEncryptionInput>,
|
||||
) -> S3Result<S3Response<DeleteBucketEncryptionOutput>> {
|
||||
let usecase = s3_api::bucket_usecase_for(self);
|
||||
audit_only_operation(req, S3Operation::DeleteBucketEncryption, |req| {
|
||||
usecase.execute_delete_bucket_encryption(req)
|
||||
})
|
||||
.await
|
||||
s3_api::bucket_usecase_for(self)
|
||||
.execute_delete_bucket_encryption(RequestEnvelope::from_s3s(&req), &req.input.bucket)
|
||||
.await?;
|
||||
Ok(S3Response::with_status(DeleteBucketEncryptionOutput::default(), StatusCode::NO_CONTENT))
|
||||
}
|
||||
|
||||
#[instrument(name = "delete_bucket_tagging", level = "debug", skip(self, req))]
|
||||
@@ -62,8 +61,10 @@ impl FS {
|
||||
&self,
|
||||
req: S3Request<DeleteBucketTaggingInput>,
|
||||
) -> S3Result<S3Response<DeleteBucketTaggingOutput>> {
|
||||
let usecase = s3_api::bucket_usecase_for(self);
|
||||
audit_only_operation(req, S3Operation::DeleteBucketTagging, |req| usecase.execute_delete_bucket_tagging(req)).await
|
||||
s3_api::bucket_usecase_for(self)
|
||||
.execute_delete_bucket_tagging(RequestEnvelope::from_s3s(&req), &req.input.bucket)
|
||||
.await?;
|
||||
Ok(S3Response::new(DeleteBucketTaggingOutput::default()))
|
||||
}
|
||||
|
||||
#[instrument(name = "delete_public_access_block", level = "debug", skip(self, req))]
|
||||
|
||||
@@ -159,7 +159,7 @@ pub(crate) mod access_consumer {
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) use super::super::access::{
|
||||
AccessMarkers, VerifiedSignature, admit_operation, authorize_bucket_config_mutation, authorize_bucket_request,
|
||||
authorize_object_request, resolve_req_info,
|
||||
authorize_bucket_tag_deletion, authorize_object_request, resolve_req_info,
|
||||
};
|
||||
pub(crate) use super::super::access::{
|
||||
AuthorizationRequest, BucketConfigMutationSnapshot, BucketGenerationGuard, CopySourceBucketGenerationGuard,
|
||||
|
||||
@@ -239,7 +239,7 @@ pub(crate) mod server {
|
||||
pub(crate) use crate::storage::storage_api::access_consumer::access_owned;
|
||||
pub(crate) use crate::storage::storage_api::access_consumer::{
|
||||
AccessMarkers, VerifiedSignature, admit_operation, authorize_bucket_config_mutation, authorize_bucket_request,
|
||||
authorize_object_request, resolve_req_info,
|
||||
authorize_bucket_tag_deletion, authorize_object_request, resolve_req_info,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -75,8 +75,32 @@ pub(crate) const MATRIX: &[MatrixRow] = &[
|
||||
has_error_body: true,
|
||||
call: put_empty_bucket_notification,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "DeleteBucketPolicy",
|
||||
metric: S3Operation::DeleteBucketPolicy,
|
||||
has_error_body: true,
|
||||
call: delete_bucket_policy,
|
||||
},
|
||||
];
|
||||
|
||||
pub(super) fn delete_bucket_policy<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move {
|
||||
let status = super::bucket_configs::StatusCapture::default();
|
||||
outcome(
|
||||
client
|
||||
.delete_bucket_policy()
|
||||
.bucket(bucket)
|
||||
.customize()
|
||||
.interceptor(status.clone())
|
||||
.send()
|
||||
.await
|
||||
.map(|_| {
|
||||
assert_eq!(status.take(), Some(204));
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn get_bucket_versioning<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move { outcome(client.get_bucket_versioning().bucket(bucket).send().await) })
|
||||
}
|
||||
|
||||
@@ -92,8 +92,213 @@ pub(crate) const MATRIX: &[MatrixRow] = &[
|
||||
has_error_body: true,
|
||||
call: delete_bucket_cors,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "DeleteBucketEncryption",
|
||||
metric: S3Operation::DeleteBucketEncryption,
|
||||
has_error_body: true,
|
||||
call: delete_bucket_encryption,
|
||||
},
|
||||
MatrixRow {
|
||||
operation: "DeleteBucketTagging",
|
||||
metric: S3Operation::DeleteBucketTagging,
|
||||
has_error_body: true,
|
||||
call: delete_bucket_tagging,
|
||||
},
|
||||
];
|
||||
|
||||
fn delete_bucket_encryption<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move {
|
||||
let status = StatusCapture::default();
|
||||
outcome(
|
||||
client
|
||||
.delete_bucket_encryption()
|
||||
.bucket(bucket)
|
||||
.customize()
|
||||
.interceptor(status.clone())
|
||||
.send()
|
||||
.await
|
||||
.map(|_| {
|
||||
assert_eq!(status.take(), Some(204));
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn delete_bucket_tagging<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move {
|
||||
let status = StatusCapture::default();
|
||||
outcome(
|
||||
client
|
||||
.delete_bucket_tagging()
|
||||
.bucket(bucket)
|
||||
.customize()
|
||||
.interceptor(status.clone())
|
||||
.send()
|
||||
.await
|
||||
.map(|_| {
|
||||
assert_eq!(status.take(), Some(204));
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async fn bucket_configuration_deletes_authorize_the_existing_action_and_bucket(server: RustFSServer) {
|
||||
const ALLOWED: &str = "config-delete-authorized";
|
||||
const OTHER: &str = "config-delete-other";
|
||||
const READER: &str = "config-delete-reader";
|
||||
for bucket in [ALLOWED, OTHER] {
|
||||
create_bucket_in_the_store(bucket).await;
|
||||
}
|
||||
create_user_allowed_on_one_bucket(READER, "s3:ListBucket", ALLOWED).await;
|
||||
let endpoint = server.endpoint();
|
||||
let reader = s3_client(&endpoint, READER, USER_SECRET_KEY);
|
||||
type Delete = for<'a> fn(&'a Client, &'a str) -> BoxFuture<'a, Outcome>;
|
||||
let deletes: [(&str, &str, Delete); 3] = [
|
||||
("config-delete-sse", "s3:PutBucketEncryption", delete_bucket_encryption),
|
||||
(
|
||||
"config-delete-policy",
|
||||
"s3:DeleteBucketPolicy",
|
||||
super::bucket_access::delete_bucket_policy,
|
||||
),
|
||||
("config-delete-tags", "s3:PutBucketTagging", delete_bucket_tagging),
|
||||
];
|
||||
for (user, action, delete) in deletes {
|
||||
create_user_allowed_on_one_bucket(user, action, ALLOWED).await;
|
||||
let writer = s3_client(&endpoint, user, USER_SECRET_KEY);
|
||||
assert_read_error(delete(&reader, ALLOWED).await, "AccessDenied", 403, action);
|
||||
assert_read_error(delete(&writer, OTHER).await, "AccessDenied", 403, action);
|
||||
assert_eq!(delete(&writer, ALLOWED).await, Ok(()), "{action} on the authorized bucket");
|
||||
}
|
||||
server.shutdown().await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gateway_bucket_configuration_deletes_authorize_the_existing_action_and_bucket() {
|
||||
with_stack(GATEWAY, bucket_configuration_deletes_authorize_the_existing_action_and_bucket);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_bucket_configuration_deletes_authorize_the_existing_action_and_bucket() {
|
||||
with_stack(LEGACY, bucket_configuration_deletes_authorize_the_existing_action_and_bucket);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_deletion_reaches_opa_with_unreadable_tags_on_both_stacks() {
|
||||
const STACK: &str = "RUSTFS_TEST_TAG_REPAIR_STACK";
|
||||
match std::env::var(STACK).as_deref() {
|
||||
Ok("gateway") => with_stack(GATEWAY, tag_deletion_reaches_opa_with_unreadable_tags),
|
||||
Ok("legacy") => with_stack(LEGACY, tag_deletion_reaches_opa_with_unreadable_tags),
|
||||
_ => {
|
||||
// The IAM plug-in is process-wide, so isolate it from the other embedded tests.
|
||||
for stack in ["gateway", "legacy"] {
|
||||
let output = std::process::Command::new(std::env::current_exe().expect("test executable"))
|
||||
.args([
|
||||
"--exact",
|
||||
"bucket_configs::tag_deletion_reaches_opa_with_unreadable_tags_on_both_stacks",
|
||||
])
|
||||
.env(STACK, stack)
|
||||
.env("NO_PROXY", "127.0.0.1,localhost")
|
||||
.env("no_proxy", "127.0.0.1,localhost")
|
||||
.output()
|
||||
.expect("run isolated OPA test");
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(
|
||||
output.status.success() && stdout.contains("test result: ok. 1 passed;"),
|
||||
"{stack} OPA test failed:\n{stdout}\n{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn tag_deletion_reaches_opa_with_unreadable_tags(server: RustFSServer) {
|
||||
use rustfs_iam::{store::object::ObjectStore, sys::IamSys};
|
||||
use rustfs_policy::policy::opa::{Args, AuthZPlugin};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
const BUCKET: &str = "config-delete-opa";
|
||||
const ACTOR: &str = "config-delete-opa-user";
|
||||
const UNREADABLE_TAGS: &[u8] = b"<Tagging><TagSet>";
|
||||
create_bucket_in_the_store(BUCKET).await;
|
||||
super::create_user_without_a_policy(ACTOR).await;
|
||||
let context = get_global_app_context().expect("application context");
|
||||
let metadata_system = context.bucket_metadata().handle().expect("bucket metadata system");
|
||||
let mut metadata = metadata_system
|
||||
.read()
|
||||
.await
|
||||
.get_config_from_disk(BUCKET)
|
||||
.await
|
||||
.expect("bucket metadata");
|
||||
metadata.tagging_config_xml = UNREADABLE_TAGS.to_vec();
|
||||
metadata.tagging_config = None;
|
||||
metadata
|
||||
.save_with_store(context.object_store())
|
||||
.await
|
||||
.expect("persist unreadable tags");
|
||||
metadata_system.write().await.set(BUCKET.to_owned(), Arc::new(metadata)).await;
|
||||
|
||||
let decisions = Arc::new(AtomicUsize::new(0));
|
||||
let record = Arc::clone(&decisions);
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.expect("bind OPA fixture");
|
||||
let url = format!("http://{}/decision", listener.local_addr().expect("OPA fixture address"));
|
||||
let router = axum::Router::new().route(
|
||||
"/decision",
|
||||
axum::routing::post(move |axum::Json(payload): axum::Json<serde_json::Value>| async move {
|
||||
record.fetch_add(1, Ordering::Relaxed);
|
||||
assert_eq!(payload["input"]["resource"]["bucket"], BUCKET);
|
||||
assert_eq!(payload["input"]["action"], "s3:PutBucketTagging");
|
||||
axum::Json(serde_json::json!({"result": true}))
|
||||
}),
|
||||
);
|
||||
let opa = tokio::spawn(async move { axum::serve(listener, router).await.expect("serve OPA fixture") });
|
||||
IamSys::<ObjectStore>::set_policy_plugin_client(AuthZPlugin::new(Args {
|
||||
url,
|
||||
auth_token: String::new(),
|
||||
}))
|
||||
.await;
|
||||
|
||||
let client = s3_client(&server.endpoint(), ACTOR, USER_SECRET_KEY);
|
||||
let client = Client::from_conf(
|
||||
client
|
||||
.config()
|
||||
.to_builder()
|
||||
.retry_config(aws_sdk_s3::config::retry::RetryConfig::disabled())
|
||||
.build(),
|
||||
);
|
||||
assert_read_error(
|
||||
get_bucket_tagging(&client, BUCKET).await,
|
||||
"InternalError",
|
||||
500,
|
||||
"read with unreadable tags",
|
||||
);
|
||||
assert_eq!(decisions.load(Ordering::Relaxed), 0, "ordinary authorization cannot read the tags");
|
||||
|
||||
let deletion = delete_bucket_tagging(&client, BUCKET).await;
|
||||
assert_eq!(
|
||||
decisions.load(Ordering::Relaxed),
|
||||
1,
|
||||
"tag deletion reaches OPA before storage checks the tags"
|
||||
);
|
||||
assert_read_error(deletion, "ServiceUnavailable", 503, "storage refuses to rewrite unreadable tags");
|
||||
let stored = metadata_system
|
||||
.read()
|
||||
.await
|
||||
.get_config_from_disk(BUCKET)
|
||||
.await
|
||||
.expect("reload durable metadata");
|
||||
assert_eq!(stored.tagging_config_xml, UNREADABLE_TAGS);
|
||||
assert_read_error(
|
||||
get_bucket_tagging(&client, BUCKET).await,
|
||||
"InternalError",
|
||||
500,
|
||||
"read after the refused delete",
|
||||
);
|
||||
assert_eq!(decisions.load(Ordering::Relaxed), 1);
|
||||
opa.abort();
|
||||
server.shutdown().await;
|
||||
}
|
||||
|
||||
fn put_bucket_cors<'a>(client: &'a Client, bucket: &'a str) -> BoxFuture<'a, Outcome> {
|
||||
Box::pin(async move { outcome(put_cors(client, bucket, cors_document()).send().await) })
|
||||
}
|
||||
|
||||
@@ -400,6 +400,8 @@ async fn every_served_operation_serves_root_and_refuses_the_callers_it_cannot_ad
|
||||
| S3Operation::PutBucketRequestPayment
|
||||
| S3Operation::PutBucketWebsite
|
||||
| S3Operation::DeleteBucketWebsite
|
||||
| S3Operation::DeleteBucketEncryption
|
||||
| S3Operation::DeleteBucketTagging
|
||||
) {
|
||||
"unknown"
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user