mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-30 08:49:26 +00:00
fix(iam): add correctly named policy APIs (#5457)
This commit is contained in:
@@ -556,7 +556,7 @@ where
|
|||||||
Ok(now)
|
Ok(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_polices(&self, bucket_name: &str) -> Result<HashMap<String, Policy>> {
|
pub async fn list_policies(&self, bucket_name: &str) -> Result<HashMap<String, Policy>> {
|
||||||
let mut m = HashMap::new();
|
let mut m = HashMap::new();
|
||||||
|
|
||||||
self.api.load_policy_docs(&mut m).await?;
|
self.api.load_policy_docs(&mut m).await?;
|
||||||
@@ -588,6 +588,15 @@ where
|
|||||||
Ok(filtered)
|
Ok(filtered)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Backward-compatible misspelling retained until the next breaking release.
|
||||||
|
#[deprecated(
|
||||||
|
since = "1.0.0",
|
||||||
|
note = "use list_policies instead; this alias will be removed in the next breaking release"
|
||||||
|
)]
|
||||||
|
pub async fn list_polices(&self, bucket_name: &str) -> Result<HashMap<String, Policy>> {
|
||||||
|
self.list_policies(bucket_name).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn merge_policies(&self, name: &str) -> (String, Policy) {
|
pub async fn merge_policies(&self, name: &str) -> (String, Policy) {
|
||||||
let mut policies = Vec::new();
|
let mut policies = Vec::new();
|
||||||
let mut to_merge = Vec::new();
|
let mut to_merge = Vec::new();
|
||||||
@@ -2184,7 +2193,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_default_policyes() -> HashMap<String, PolicyDoc> {
|
pub fn get_default_policies() -> HashMap<String, PolicyDoc> {
|
||||||
let default_policies = &DEFAULT_POLICIES;
|
let default_policies = &DEFAULT_POLICIES;
|
||||||
default_policies
|
default_policies
|
||||||
.iter()
|
.iter()
|
||||||
@@ -2201,6 +2210,15 @@ pub fn get_default_policyes() -> HashMap<String, PolicyDoc> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Backward-compatible misspelling retained until the next breaking release.
|
||||||
|
#[deprecated(
|
||||||
|
since = "1.0.0",
|
||||||
|
note = "use get_default_policies instead; this alias will be removed in the next breaking release"
|
||||||
|
)]
|
||||||
|
pub fn get_default_policyes() -> HashMap<String, PolicyDoc> {
|
||||||
|
get_default_policies()
|
||||||
|
}
|
||||||
|
|
||||||
fn set_default_canned_policies(policies: &mut HashMap<String, PolicyDoc>) {
|
fn set_default_canned_policies(policies: &mut HashMap<String, PolicyDoc>) {
|
||||||
let default_policies = &DEFAULT_POLICIES;
|
let default_policies = &DEFAULT_POLICIES;
|
||||||
for (k, v) in default_policies.iter() {
|
for (k, v) in default_policies.iter() {
|
||||||
@@ -2900,7 +2918,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_default_policies() {
|
fn test_get_default_policies() {
|
||||||
let policies = get_default_policyes();
|
let policies = get_default_policies();
|
||||||
|
|
||||||
// Should contain some default policies
|
// Should contain some default policies
|
||||||
assert!(!policies.is_empty());
|
assert!(!policies.is_empty());
|
||||||
@@ -2913,6 +2931,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
|
fn deprecated_get_default_policyes_matches_current_api() {
|
||||||
|
assert_eq!(get_default_policyes().len(), get_default_policies().len());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_token_signing_key() {
|
fn test_get_token_signing_key() {
|
||||||
// This function returns the global action credential's secret key
|
// This function returns the global action credential's secret key
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use crate::{
|
|||||||
cache::{Cache, CacheEntity},
|
cache::{Cache, CacheEntity},
|
||||||
error::{is_err_no_such_policy, is_err_no_such_user},
|
error::{is_err_no_such_policy, is_err_no_such_user},
|
||||||
keyring,
|
keyring,
|
||||||
manager::{extract_jwt_claims, extract_jwt_claims_allow_missing_exp, get_default_policyes},
|
manager::{extract_jwt_claims, extract_jwt_claims_allow_missing_exp, get_default_policies},
|
||||||
root_credentials,
|
root_credentials,
|
||||||
};
|
};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
@@ -1127,7 +1127,7 @@ impl Store for ObjectStore {
|
|||||||
let cache_snapshot = cache.snapshot();
|
let cache_snapshot = cache.snapshot();
|
||||||
let listed_config_items = self.list_all_iamconfig_items().await?;
|
let listed_config_items = self.list_all_iamconfig_items().await?;
|
||||||
|
|
||||||
let mut policy_docs_cache = CacheEntity::new(get_default_policyes());
|
let mut policy_docs_cache = CacheEntity::new(get_default_policies());
|
||||||
|
|
||||||
if let Some(policies_list) = listed_config_items.get(POLICIES_LIST_KEY) {
|
if let Some(policies_list) = listed_config_items.get(POLICIES_LIST_KEY) {
|
||||||
// Load in fixed-size chunks so each policy is fetched exactly once.
|
// Load in fixed-size chunks so each policy is fetched exactly once.
|
||||||
|
|||||||
+20
-5
@@ -18,7 +18,7 @@ use crate::error::is_err_no_such_temp_account;
|
|||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::federation::OIDC_VIRTUAL_PARENT_CLAIM;
|
use crate::federation::OIDC_VIRTUAL_PARENT_CLAIM;
|
||||||
use crate::manager::extract_jwt_claims;
|
use crate::manager::extract_jwt_claims;
|
||||||
use crate::manager::get_default_policyes;
|
use crate::manager::get_default_policies;
|
||||||
use crate::manager::{IamCache, IamSyncMetricsSnapshot};
|
use crate::manager::{IamCache, IamSyncMetricsSnapshot};
|
||||||
use crate::store::GroupInfo;
|
use crate::store::GroupInfo;
|
||||||
use crate::store::MappedPolicy;
|
use crate::store::MappedPolicy;
|
||||||
@@ -249,7 +249,7 @@ impl<T: Store> IamSys<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_policy(&self, name: &str, notify: bool) -> Result<()> {
|
pub async fn delete_policy(&self, name: &str, notify: bool) -> Result<()> {
|
||||||
for k in get_default_policyes().keys() {
|
for k in get_default_policies().keys() {
|
||||||
if k == name {
|
if k == name {
|
||||||
return Err(Error::other("system policy can not be deleted"));
|
return Err(Error::other("system policy can not be deleted"));
|
||||||
}
|
}
|
||||||
@@ -291,8 +291,17 @@ impl<T: Store> IamSys<T> {
|
|||||||
self.store.api.load_mapped_policies(user_type, is_group, m).await
|
self.store.api.load_mapped_policies(user_type, is_group, m).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn list_policies(&self, bucket_name: &str) -> Result<HashMap<String, Policy>> {
|
||||||
|
self.store.list_policies(bucket_name).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Backward-compatible misspelling retained until the next breaking release.
|
||||||
|
#[deprecated(
|
||||||
|
since = "1.0.0",
|
||||||
|
note = "use list_policies instead; this alias will be removed in the next breaking release"
|
||||||
|
)]
|
||||||
pub async fn list_polices(&self, bucket_name: &str) -> Result<HashMap<String, Policy>> {
|
pub async fn list_polices(&self, bucket_name: &str) -> Result<HashMap<String, Policy>> {
|
||||||
self.store.list_polices(bucket_name).await
|
self.list_policies(bucket_name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_policy_docs(&self, bucket_name: &str) -> Result<HashMap<String, PolicyDoc>> {
|
pub async fn list_policy_docs(&self, bucket_name: &str) -> Result<HashMap<String, PolicyDoc>> {
|
||||||
@@ -1683,11 +1692,17 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::cache::{Cache, CacheEntity};
|
use crate::cache::{Cache, CacheEntity};
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::manager::get_default_policyes;
|
use crate::manager::get_default_policies;
|
||||||
use crate::store::{GroupInfo, MappedPolicy, Store, UserType};
|
use crate::store::{GroupInfo, MappedPolicy, Store, UserType};
|
||||||
use rustfs_credentials::{Credentials, init_global_action_credentials};
|
use rustfs_credentials::{Credentials, init_global_action_credentials};
|
||||||
use rustfs_policy::auth::{UserIdentity, get_new_credentials_with_metadata};
|
use rustfs_policy::auth::{UserIdentity, get_new_credentials_with_metadata};
|
||||||
use rustfs_policy::policy::Args;
|
use rustfs_policy::policy::Args;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
|
fn deprecated_list_polices_api_is_available() {
|
||||||
|
let _ = IamSys::<StsTestMockStore>::list_polices;
|
||||||
|
}
|
||||||
use rustfs_policy::policy::action::{Action, AdminAction, S3Action};
|
use rustfs_policy::policy::action::{Action, AdminAction, S3Action};
|
||||||
use rustfs_policy::policy::policy_uses_existing_object_tag_conditions;
|
use rustfs_policy::policy::policy_uses_existing_object_tag_conditions;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -1925,7 +1940,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn load_all(&self, cache: &Cache) -> Result<()> {
|
async fn load_all(&self, cache: &Cache) -> Result<()> {
|
||||||
let mut policy_docs = get_default_policyes();
|
let mut policy_docs = get_default_policies();
|
||||||
let custom_claim_policy =
|
let custom_claim_policy =
|
||||||
Policy::parse_config(CUSTOM_STS_CLAIM_POLICY_JSON.as_bytes()).expect("custom STS claim policy should parse");
|
Policy::parse_config(CUSTOM_STS_CLAIM_POLICY_JSON.as_bytes()).expect("custom STS claim policy should parse");
|
||||||
policy_docs.insert(CUSTOM_STS_CLAIM_POLICY.to_string(), PolicyDoc::new(custom_claim_policy));
|
policy_docs.insert(CUSTOM_STS_CLAIM_POLICY.to_string(), PolicyDoc::new(custom_claim_policy));
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ impl Operation for ListCannedPolicies {
|
|||||||
return Err(s3_error!(InternalError, "iam is not initialized"));
|
return Err(s3_error!(InternalError, "iam is not initialized"));
|
||||||
};
|
};
|
||||||
|
|
||||||
let policies = iam_store.list_polices(&query.bucket).await.map_err(|e| {
|
let policies = iam_store.list_policies(&query.bucket).await.map_err(|e| {
|
||||||
warn!(
|
warn!(
|
||||||
component = LOG_COMPONENT_ADMIN,
|
component = LOG_COMPONENT_ADMIN,
|
||||||
subsystem = LOG_SUBSYSTEM_POLICY,
|
subsystem = LOG_SUBSYSTEM_POLICY,
|
||||||
|
|||||||
@@ -724,7 +724,7 @@ impl Operation for ExportIam {
|
|||||||
match file {
|
match file {
|
||||||
ALL_POLICIES_FILE => {
|
ALL_POLICIES_FILE => {
|
||||||
let policies: HashMap<String, rustfs_policy::policy::Policy> = iam_store
|
let policies: HashMap<String, rustfs_policy::policy::Policy> = iam_store
|
||||||
.list_polices("")
|
.list_policies("")
|
||||||
.await
|
.await
|
||||||
.map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, e.to_string()))?;
|
.map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, e.to_string()))?;
|
||||||
let json_str = serde_json::to_vec(&policies)
|
let json_str = serde_json::to_vec(&policies)
|
||||||
|
|||||||
Reference in New Issue
Block a user