mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-06 21:33:14 +00:00
Merge branch 'main' of github.com:rustfs/s3-rustfs into feature/observability-metrics
# Conflicts: # .github/workflows/build.yml # .github/workflows/ci.yml # Cargo.lock # Cargo.toml # appauth/src/token.rs # crates/config/src/config.rs # crates/event-notifier/examples/simple.rs # crates/event-notifier/src/global.rs # crates/event-notifier/src/lib.rs # crates/event-notifier/src/notifier.rs # crates/event-notifier/src/store.rs # crates/filemeta/src/filemeta.rs # crates/notify/examples/webhook.rs # crates/utils/Cargo.toml # ecstore/Cargo.toml # ecstore/src/cmd/bucket_replication.rs # ecstore/src/config/com.rs # ecstore/src/disk/error.rs # ecstore/src/disk/mod.rs # ecstore/src/set_disk.rs # ecstore/src/store_api.rs # ecstore/src/store_list_objects.rs # iam/Cargo.toml # iam/src/manager.rs # policy/Cargo.toml # rustfs/src/admin/rpc.rs # rustfs/src/main.rs # rustfs/src/storage/mod.rs
This commit is contained in:
+39
-38
@@ -1,26 +1,25 @@
|
||||
use super::{GroupInfo, MappedPolicy, Store, UserType};
|
||||
use crate::error::{Error, Result, is_err_config_not_found};
|
||||
use crate::{
|
||||
cache::{Cache, CacheEntity},
|
||||
error::{is_err_no_such_policy, is_err_no_such_user},
|
||||
get_global_action_cred,
|
||||
manager::{extract_jwt_claims, get_default_policyes},
|
||||
};
|
||||
use common::error::{Error, Result};
|
||||
use ecstore::{
|
||||
config::{
|
||||
com::{delete_config, read_config, read_config_with_metadata, save_config},
|
||||
error::is_err_config_not_found,
|
||||
RUSTFS_CONFIG_PREFIX,
|
||||
com::{delete_config, read_config, read_config_with_metadata, save_config},
|
||||
},
|
||||
store::ECStore,
|
||||
store_api::{ObjectInfo, ObjectOptions},
|
||||
store_list_objects::{ObjectInfoOrErr, WalkOptions},
|
||||
utils::path::{path_join_buf, SLASH_SEPARATOR},
|
||||
};
|
||||
use futures::future::join_all;
|
||||
use lazy_static::lazy_static;
|
||||
use policy::{auth::UserIdentity, policy::PolicyDoc};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use rustfs_utils::path::{SLASH_SEPARATOR, path_join_buf};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use tokio::sync::broadcast::{self, Receiver as B_Receiver};
|
||||
use tokio::sync::mpsc::{self, Sender};
|
||||
@@ -153,7 +152,7 @@ impl ObjectStore {
|
||||
let _ = sender
|
||||
.send(StringOrErr {
|
||||
item: None,
|
||||
err: Some(err),
|
||||
err: Some(err.into()),
|
||||
})
|
||||
.await;
|
||||
return;
|
||||
@@ -207,13 +206,13 @@ impl ObjectStore {
|
||||
let mut futures = Vec::with_capacity(names.len());
|
||||
|
||||
for name in names {
|
||||
let policy_name = ecstore::utils::path::dir(name);
|
||||
let policy_name = rustfs_utils::path::dir(name);
|
||||
futures.push(async move {
|
||||
match self.load_policy(&policy_name).await {
|
||||
Ok(p) => Ok(p),
|
||||
Err(err) => {
|
||||
if !is_err_no_such_policy(&err) {
|
||||
Err(Error::msg(std::format!("load policy doc failed: {}", err)))
|
||||
Err(Error::other(format!("load policy doc failed: {}", err)))
|
||||
} else {
|
||||
Ok(PolicyDoc::default())
|
||||
}
|
||||
@@ -239,13 +238,13 @@ impl ObjectStore {
|
||||
let mut futures = Vec::with_capacity(names.len());
|
||||
|
||||
for name in names {
|
||||
let user_name = ecstore::utils::path::dir(name);
|
||||
let user_name = rustfs_utils::path::dir(name);
|
||||
futures.push(async move {
|
||||
match self.load_user_identity(&user_name, user_type).await {
|
||||
Ok(res) => Ok(res),
|
||||
Err(err) => {
|
||||
if !is_err_no_such_user(&err) {
|
||||
Err(Error::msg(std::format!("load user failed: {}", err)))
|
||||
Err(Error::other(format!("load user failed: {}", err)))
|
||||
} else {
|
||||
Ok(UserIdentity::default())
|
||||
}
|
||||
@@ -272,7 +271,7 @@ impl ObjectStore {
|
||||
.await
|
||||
.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -296,7 +295,7 @@ impl ObjectStore {
|
||||
Ok(p) => Ok(p),
|
||||
Err(err) => {
|
||||
if !is_err_no_such_policy(&err) {
|
||||
Err(Error::msg(std::format!("load mapped policy failed: {}", err)))
|
||||
Err(Error::other(format!("load mapped policy failed: {}", err)))
|
||||
} else {
|
||||
Ok(MappedPolicy::default())
|
||||
}
|
||||
@@ -369,10 +368,12 @@ impl Store for ObjectStore {
|
||||
let mut data = serde_json::to_vec(&item)?;
|
||||
data = Self::encrypt_data(&data)?;
|
||||
|
||||
save_config(self.object_api.clone(), path.as_ref(), data).await
|
||||
save_config(self.object_api.clone(), path.as_ref(), data).await?;
|
||||
Ok(())
|
||||
}
|
||||
async fn delete_iam_config(&self, path: impl AsRef<str> + Send) -> Result<()> {
|
||||
delete_config(self.object_api.clone(), path.as_ref()).await
|
||||
delete_config(self.object_api.clone(), path.as_ref()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn save_user_identity(
|
||||
@@ -390,7 +391,7 @@ impl Store for ObjectStore {
|
||||
.await
|
||||
.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -403,7 +404,7 @@ impl Store for ObjectStore {
|
||||
.await
|
||||
.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchUser(name.to_owned()))
|
||||
Error::NoSuchUser(name.to_owned())
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -412,7 +413,7 @@ impl Store for ObjectStore {
|
||||
if u.credentials.is_expired() {
|
||||
let _ = self.delete_iam_config(get_user_identity_path(name, user_type)).await;
|
||||
let _ = self.delete_iam_config(get_mapped_policy_path(name, user_type, false)).await;
|
||||
return Err(Error::new(crate::error::Error::NoSuchUser(name.to_owned())));
|
||||
return Err(Error::NoSuchUser(name.to_owned()));
|
||||
}
|
||||
|
||||
if u.credentials.access_key.is_empty() {
|
||||
@@ -430,7 +431,7 @@ impl Store for ObjectStore {
|
||||
let _ = self.delete_iam_config(get_mapped_policy_path(name, user_type, false)).await;
|
||||
}
|
||||
warn!("extract_jwt_claims failed: {}", err);
|
||||
return Err(Error::new(crate::error::Error::NoSuchUser(name.to_owned())));
|
||||
return Err(Error::NoSuchUser(name.to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -463,7 +464,7 @@ impl Store for ObjectStore {
|
||||
}
|
||||
|
||||
if let Some(item) = v.item {
|
||||
let name = ecstore::utils::path::dir(&item);
|
||||
let name = rustfs_utils::path::dir(&item);
|
||||
self.load_user(&name, user_type, m).await?;
|
||||
}
|
||||
}
|
||||
@@ -476,7 +477,7 @@ impl Store for ObjectStore {
|
||||
.await
|
||||
.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchUser(name.to_owned()))
|
||||
Error::NoSuchUser(name.to_owned())
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -491,7 +492,7 @@ impl Store for ObjectStore {
|
||||
async fn delete_group_info(&self, name: &str) -> Result<()> {
|
||||
self.delete_iam_config(get_group_info_path(name)).await.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -501,7 +502,7 @@ impl Store for ObjectStore {
|
||||
async fn load_group(&self, name: &str, m: &mut HashMap<String, GroupInfo>) -> Result<()> {
|
||||
let u: GroupInfo = self.load_iam_config(get_group_info_path(name)).await.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -525,7 +526,7 @@ impl Store for ObjectStore {
|
||||
}
|
||||
|
||||
if let Some(item) = v.item {
|
||||
let name = ecstore::utils::path::dir(&item);
|
||||
let name = rustfs_utils::path::dir(&item);
|
||||
self.load_group(&name, m).await?;
|
||||
}
|
||||
}
|
||||
@@ -539,7 +540,7 @@ impl Store for ObjectStore {
|
||||
async fn delete_policy_doc(&self, name: &str) -> Result<()> {
|
||||
self.delete_iam_config(get_policy_doc_path(name)).await.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -552,7 +553,7 @@ impl Store for ObjectStore {
|
||||
.await
|
||||
.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -589,7 +590,7 @@ impl Store for ObjectStore {
|
||||
}
|
||||
|
||||
if let Some(item) = v.item {
|
||||
let name = ecstore::utils::path::dir(&item);
|
||||
let name = rustfs_utils::path::dir(&item);
|
||||
self.load_policy_doc(&name, m).await?;
|
||||
}
|
||||
}
|
||||
@@ -613,7 +614,7 @@ impl Store for ObjectStore {
|
||||
.await
|
||||
.map_err(|err| {
|
||||
if is_err_config_not_found(&err) {
|
||||
Error::new(crate::error::Error::NoSuchPolicy)
|
||||
Error::NoSuchPolicy
|
||||
} else {
|
||||
err
|
||||
}
|
||||
@@ -689,7 +690,7 @@ impl Store for ObjectStore {
|
||||
continue;
|
||||
}
|
||||
|
||||
let policy_name = ecstore::utils::path::dir(&policies_list[idx]);
|
||||
let policy_name = rustfs_utils::path::dir(&policies_list[idx]);
|
||||
|
||||
info!("load policy: {}", policy_name);
|
||||
|
||||
@@ -705,7 +706,7 @@ impl Store for ObjectStore {
|
||||
continue;
|
||||
}
|
||||
|
||||
let policy_name = ecstore::utils::path::dir(&policies_list[idx]);
|
||||
let policy_name = rustfs_utils::path::dir(&policies_list[idx]);
|
||||
info!("load policy: {}", policy_name);
|
||||
policy_docs_cache.insert(policy_name, p);
|
||||
}
|
||||
@@ -733,7 +734,7 @@ impl Store for ObjectStore {
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = ecstore::utils::path::dir(&item_name_list[idx]);
|
||||
let name = rustfs_utils::path::dir(&item_name_list[idx]);
|
||||
info!("load reg user: {}", name);
|
||||
user_items_cache.insert(name, p);
|
||||
}
|
||||
@@ -747,7 +748,7 @@ impl Store for ObjectStore {
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = ecstore::utils::path::dir(&item_name_list[idx]);
|
||||
let name = rustfs_utils::path::dir(&item_name_list[idx]);
|
||||
info!("load reg user: {}", name);
|
||||
user_items_cache.insert(name, p);
|
||||
}
|
||||
@@ -763,10 +764,10 @@ impl Store for ObjectStore {
|
||||
let mut items_cache = CacheEntity::default();
|
||||
|
||||
for item in item_name_list.iter() {
|
||||
let name = ecstore::utils::path::dir(item);
|
||||
let name = rustfs_utils::path::dir(item);
|
||||
info!("load group: {}", name);
|
||||
if let Err(err) = self.load_group(&name, &mut items_cache).await {
|
||||
return Err(Error::msg(std::format!("load group failed: {}", err)));
|
||||
return Err(Error::other(format!("load group failed: {}", err)));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -827,7 +828,7 @@ impl Store for ObjectStore {
|
||||
info!("load group policy: {}", name);
|
||||
if let Err(err) = self.load_mapped_policy(name, UserType::Reg, true, &mut items_cache).await {
|
||||
if !is_err_no_such_policy(&err) {
|
||||
return Err(Error::msg(std::format!("load group policy failed: {}", err)));
|
||||
return Err(Error::other(format!("load group policy failed: {}", err)));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -842,11 +843,11 @@ impl Store for ObjectStore {
|
||||
let mut items_cache = HashMap::default();
|
||||
|
||||
for item in item_name_list.iter() {
|
||||
let name = ecstore::utils::path::dir(item);
|
||||
let name = rustfs_utils::path::dir(item);
|
||||
info!("load svc user: {}", name);
|
||||
if let Err(err) = self.load_user(&name, UserType::Svc, &mut items_cache).await {
|
||||
if !is_err_no_such_user(&err) {
|
||||
return Err(Error::msg(std::format!("load svc user failed: {}", err)));
|
||||
return Err(Error::other(format!("load svc user failed: {}", err)));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -860,7 +861,7 @@ impl Store for ObjectStore {
|
||||
.await
|
||||
{
|
||||
if !is_err_no_such_policy(&err) {
|
||||
return Err(Error::msg(std::format!("load_mapped_policy failed: {}", err)));
|
||||
return Err(Error::other(format!("load_mapped_policy failed: {}", err)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -879,7 +880,7 @@ impl Store for ObjectStore {
|
||||
for item in item_name_list.iter() {
|
||||
info!("load sts user path: {}", item);
|
||||
|
||||
let name = ecstore::utils::path::dir(item);
|
||||
let name = rustfs_utils::path::dir(item);
|
||||
info!("load sts user: {}", name);
|
||||
if let Err(err) = self.load_user(&name, UserType::Sts, &mut sts_items_cache).await {
|
||||
info!("load sts user failed: {}", err);
|
||||
|
||||
Reference in New Issue
Block a user