fix(policy): preserve IAM policy readback shape (#3431)

This commit is contained in:
GatewayJ
2026-06-14 16:36:28 +08:00
committed by GitHub
parent fc17e75fb2
commit 3928117c8f
4 changed files with 173 additions and 164 deletions
+10 -4
View File
@@ -21,7 +21,7 @@ use rustfs_iam::store::Store as IamStore;
use rustfs_madmin::{
InfoAccessKeyResp, InfoServiceAccountResp, LDAPSpecificAccessKeyInfo, OpenIDSpecificAccessKeyInfo, ServiceAccountInfo,
};
use rustfs_policy::policy::Policy;
use rustfs_policy::policy::{DEFAULT_VERSION, Policy};
use s3s::{S3Result, s3_error};
use std::collections::HashMap;
use time::OffsetDateTime;
@@ -236,7 +236,10 @@ pub(crate) async fn build_info_service_account_resp<T: IamStore>(
};
let policy = effective_policy
.map(|policy| {
.map(|mut policy| {
if policy.version.is_empty() {
policy.version = DEFAULT_VERSION.to_owned();
}
serde_json::to_string_pretty(&policy).map_err(|e| {
debug!("marshal policy failed, e: {:?}", e);
s3_error!(InternalError, "marshal policy failed")
@@ -891,7 +894,10 @@ mod tests {
assert_eq!(resp.open_id_specific_info.display_name.as_deref(), Some("RustFS User"));
assert_eq!(resp.open_id_specific_info.display_name_claim.as_deref(), Some("name"));
assert_eq!(resp.open_id_specific_info.config_name, None);
assert_eq!(resp.info.policy, Some("{\n \"Version\": \"\",\n \"Statement\": []\n}".to_string()));
assert_eq!(
resp.info.policy,
Some("{\n \"Version\": \"2012-10-17\",\n \"Statement\": []\n}".to_string())
);
let body = serde_json::to_value(&resp).expect("serialize openid sts response");
assert_eq!(body.get("userType").and_then(|v| v.as_str()), Some("STS"));
@@ -929,7 +935,7 @@ mod tests {
assert_eq!(body.get("description").and_then(|v| v.as_str()), Some("openid derived temporary account"));
assert_eq!(
body.get("policy").and_then(|v| v.as_str()),
Some("{\n \"Version\": \"\",\n \"Statement\": []\n}")
Some("{\n \"Version\": \"2012-10-17\",\n \"Statement\": []\n}")
);
}
}