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:
GatewayJ
2026-04-17 13:38:18 +08:00
committed by GitHub
parent 478720d2ee
commit f255b8a9f1
2 changed files with 56 additions and 45 deletions
+38
View File
@@ -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 {