diff options
author | Alex Auvolat <alex@adnab.me> | 2024-03-01 12:35:08 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-03-01 13:21:23 +0100 |
commit | 610af71e36d58ea1ca66b98c75f105aecf92af2b (patch) | |
tree | 8181bda3e5837a1a17302aa692c2f1722de99ad5 /src/api/s3/post_object.rs | |
parent | f01883794e475f5dae3d2d4f621b020e1134fa47 (diff) | |
download | garage-610af71e36d58ea1ca66b98c75f105aecf92af2b.tar.gz garage-610af71e36d58ea1ca66b98c75f105aecf92af2b.zip |
[backport-735-v0.8.x] backport AWS signature verification refactoring
Diffstat (limited to 'src/api/s3/post_object.rs')
-rw-r--r-- | src/api/s3/post_object.rs | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/src/api/s3/post_object.rs b/src/api/s3/post_object.rs index f9eccb7f..1f2fac59 100644 --- a/src/api/s3/post_object.rs +++ b/src/api/s3/post_object.rs @@ -19,7 +19,7 @@ use crate::s3::cors::*; use crate::s3::error::*; use crate::s3::put::{get_headers, save_stream}; use crate::s3::xml as s3_xml; -use crate::signature::payload::{parse_date, verify_v4}; +use crate::signature::payload::{verify_v4, Authorization}; pub async fn handle_post_object( garage: Arc<Garage>, @@ -85,22 +85,11 @@ pub async fn handle_post_object( .get("key") .ok_or_bad_request("No key was provided")? .to_str()?; - let credential = params - .get("x-amz-credential") - .ok_or_else(|| Error::forbidden("Garage does not support anonymous access yet"))? - .to_str()?; let policy = params .get("policy") .ok_or_bad_request("No policy was provided")? .to_str()?; - let signature = params - .get("x-amz-signature") - .ok_or_bad_request("No signature was provided")? - .to_str()?; - let date = params - .get("x-amz-date") - .ok_or_bad_request("No date was provided")? - .to_str()?; + let authorization = Authorization::parse_form(¶ms)?; let key = if key.contains("${filename}") { // if no filename is provided, don't replace. This matches the behavior of AWS. @@ -113,16 +102,7 @@ pub async fn handle_post_object( key.to_owned() }; - let date = parse_date(date)?; - let api_key = verify_v4( - &garage, - "s3", - credential, - &date, - signature, - policy.as_bytes(), - ) - .await?; + let api_key = verify_v4(&garage, "s3", &authorization, policy.as_bytes()).await?; let bucket_id = garage .bucket_helper() |