mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-18 10:43:15 +00:00
fix(admin): align accountinfo policy with IAM prepare_auth for OIDC console (#2568)
Co-authored-by: GatewayJ <8352692332qq.com> Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -134,6 +134,19 @@ impl PreparedIamAuth {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the resolved identity policy prepared for the current auth mode.
|
||||
///
|
||||
/// This is intended for read-only views (for example `/accountinfo`) so
|
||||
/// callers can reuse the same policy resolution path as authorization.
|
||||
pub fn combined_policy_for_view(&self) -> Option<&Policy> {
|
||||
match &self.mode {
|
||||
PreparedIamMode::Regular { combined_policy } => Some(combined_policy),
|
||||
PreparedIamMode::Sts { combined_policy, .. } => Some(combined_policy),
|
||||
PreparedIamMode::ServiceAccount { combined_policy, .. } => Some(combined_policy),
|
||||
PreparedIamMode::Opa | PreparedIamMode::Owner | PreparedIamMode::Deny => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Store> IamSys<T> {
|
||||
@@ -1286,6 +1299,31 @@ mod tests {
|
||||
use std::collections::HashMap;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
#[test]
|
||||
fn test_combined_policy_for_view_returns_regular_policy() {
|
||||
let policy = Policy {
|
||||
version: "2012-10-17".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
let prepared = PreparedIamAuth {
|
||||
needs_existing_object_tag: false,
|
||||
mode: PreparedIamMode::Regular { combined_policy: policy },
|
||||
};
|
||||
|
||||
let resolved = prepared.combined_policy_for_view();
|
||||
assert_eq!(resolved.map(|p| p.version.as_str()), Some("2012-10-17"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_combined_policy_for_view_returns_none_for_deny() {
|
||||
let prepared = PreparedIamAuth {
|
||||
needs_existing_object_tag: false,
|
||||
mode: PreparedIamMode::Deny,
|
||||
};
|
||||
|
||||
assert!(prepared.combined_policy_for_view().is_none());
|
||||
}
|
||||
|
||||
/// Mock Store for STS tests: either group-attached policies via parent user, or no IAM policies.
|
||||
#[derive(Clone)]
|
||||
struct StsTestMockStore {
|
||||
|
||||
Reference in New Issue
Block a user