mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 13:53:12 +00:00
fix(policy): preserve IAM policy readback shape (#3431)
This commit is contained in:
@@ -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}")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user