Skip to content

Commit

Permalink
Hack together a --allow-bucket-manipulation flag, disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshia001 committed Aug 2, 2024
1 parent 8a915be commit ab22c1c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/bin/s3-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ struct Args {

#[structopt(flatten)]
verbose: structopt_flags::QuietVerbose,

#[structopt(long)]
allow_bucket_manipulation: bool,
}

fn setup_tracing(args: &Args) {
Expand Down Expand Up @@ -108,6 +111,11 @@ async fn main() -> Result<()> {
service.set_auth(auth);
}

s3_server::DISALLOW_BUCKET_MANIPULATION.store(
!args.allow_bucket_manipulation,
std::sync::atomic::Ordering::Relaxed,
);

let server = {
let service = service.into_shared();

Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,11 @@ pub(crate) type BoxStdError = Box<dyn std::error::Error + Send + Sync + 'static>
pub(crate) use async_trait::async_trait;
pub(crate) use hyper::{Body, Method, StatusCode};
pub(crate) use mime::Mime;

// I feel *TERRIBLE* about introducing such a hack into such an otherwise well-written code base.
// The ops don't receive any kind of configuration by default, which means this is the easiest way
// way to achieve this functionality short of commenting code out. There, I said it. Now, let's get
// stuff working.
#[allow(missing_docs)]
pub static DISALLOW_BUCKET_MANIPULATION: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
10 changes: 7 additions & 3 deletions src/ops/create_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ impl S3Handler for Handler {
ctx: &mut ReqContext<'_>,
storage: &(dyn S3Storage + Send + Sync),
) -> S3Result<Response> {
let input = extract(ctx).await?;
let output = storage.create_bucket(input).await;
output.try_into_response()
if crate::DISALLOW_BUCKET_MANIPULATION.load(std::sync::atomic::Ordering::Relaxed) {
S3Result::Err(invalid_request!("Bucket creation is not allowed"))
} else {
let input = extract(ctx).await?;
let output = storage.create_bucket(input).await;
output.try_into_response()
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/ops/delete_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ impl S3Handler for Handler {
ctx: &mut ReqContext<'_>,
storage: &(dyn S3Storage + Send + Sync),
) -> S3Result<Response> {
let input = extract(ctx)?;
let output = storage.delete_bucket(input).await;
output.try_into_response()
if crate::DISALLOW_BUCKET_MANIPULATION.load(std::sync::atomic::Ordering::Relaxed) {
S3Result::Err(invalid_request!("Bucket deletion is not allowed"))
} else {
let input = extract(ctx)?;
let output = storage.delete_bucket(input).await;
output.try_into_response()
}
}
}

Expand Down

0 comments on commit ab22c1c

Please sign in to comment.