diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-17 11:53:13 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-04 12:46:41 +0100 |
commit | b1cfd16913e6957739958ef729b87c1bf3674a5d (patch) | |
tree | 781245de967e0c7a14cbdc0f2a610787f3b852d4 /src/model/bucket_alias_table.rs | |
parent | 5db600e2316b80102e3fd4df9e8974c9586aec9c (diff) | |
download | garage-b1cfd16913e6957739958ef729b87c1bf3674a5d.tar.gz garage-b1cfd16913e6957739958ef729b87c1bf3674a5d.zip |
New buckets for 0.6.0: small fixes, including:
- ensure bucket names are correct aws s3 names
- when making aliases, ensure timestamps of links in both ways are the
same
- fix small remarks by trinity
- don't have a separate website_access field
Diffstat (limited to 'src/model/bucket_alias_table.rs')
-rw-r--r-- | src/model/bucket_alias_table.rs | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/model/bucket_alias_table.rs b/src/model/bucket_alias_table.rs index 52484c5b..904a5255 100644 --- a/src/model/bucket_alias_table.rs +++ b/src/model/bucket_alias_table.rs @@ -8,7 +8,7 @@ use garage_util::data::*; /// in the global namespace. #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct BucketAlias { - pub name: String, + name: String, pub state: crdt::Lww<crdt::Deletable<AliasParams>>, } @@ -22,15 +22,22 @@ impl AutoCrdt for AliasParams { } impl BucketAlias { - pub fn new(name: String, bucket_id: Uuid) -> Self { - BucketAlias { - name, - state: crdt::Lww::new(crdt::Deletable::present(AliasParams { bucket_id })), + pub fn new(name: String, bucket_id: Uuid) -> Option<Self> { + if !is_valid_bucket_name(&name) { + None + } else { + Some(BucketAlias { + name, + state: crdt::Lww::new(crdt::Deletable::present(AliasParams { bucket_id })), + }) } } pub fn is_deleted(&self) -> bool { self.state.get().is_deleted() } + pub fn name(&self) -> &str { + &self.name + } } impl Crdt for BucketAlias { @@ -62,3 +69,29 @@ impl TableSchema for BucketAliasTable { filter.apply(entry.is_deleted()) } } + +/// Check if a bucket name is valid. +/// +/// The requirements are listed here: +/// +/// <https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html> +/// +/// In the case of Garage, bucket names must not be hex-encoded +/// 32 byte string, which is excluded thanks to the +/// maximum length of 63 bytes given in the spec. +pub fn is_valid_bucket_name(n: &str) -> bool { + // Bucket names must be between 3 and 63 characters + n.len() >= 3 && n.len() <= 63 + // Bucket names must be composed of lowercase letters, numbers, + // dashes and dots + && n.chars().all(|c| matches!(c, '.' | '-' | 'a'..='z' | '0'..='9')) + // Bucket names must start and end with a letter or a number + && !n.starts_with(&['-', '.'][..]) + && !n.ends_with(&['-', '.'][..]) + // Bucket names must not be formated as an IP address + && n.parse::<std::net::IpAddr>().is_err() + // Bucket names must not start wih "xn--" + && !n.starts_with("xn--") + // Bucket names must not end with "-s3alias" + && !n.ends_with("-s3alias") +} |