feat: add KMS action taxonomy (#3294)

This commit is contained in:
安正超
2026-06-09 13:06:15 +08:00
committed by GitHub
parent ad9bf41fc8
commit 4fec606dc4
3 changed files with 94 additions and 27 deletions
+43
View File
@@ -698,6 +698,22 @@ pub enum StsAction {
pub enum KmsAction {
#[strum(serialize = "kms:*")]
AllActions,
#[strum(serialize = "kms:Configure")]
ConfigureAction,
#[strum(serialize = "kms:ServiceControl")]
ServiceControlAction,
#[strum(serialize = "kms:ClearCache")]
ClearCacheAction,
#[strum(serialize = "kms:GenerateDataKey")]
GenerateDataKeyAction,
#[strum(serialize = "kms:DeleteKey")]
DeleteKeyAction,
#[strum(serialize = "kms:RotateKey")]
RotateKeyAction,
#[strum(serialize = "kms:ListKeys")]
ListKeysAction,
#[strum(serialize = "kms:DescribeKey")]
DescribeKeyAction,
}
#[cfg(test)]
@@ -722,6 +738,33 @@ mod tests {
assert!(wildcard.is_match(&action));
}
#[test]
fn test_kms_action_taxonomy_parses_and_serializes() {
for (raw, expected) in [
("kms:Configure", KmsAction::ConfigureAction),
("kms:ServiceControl", KmsAction::ServiceControlAction),
("kms:ClearCache", KmsAction::ClearCacheAction),
("kms:GenerateDataKey", KmsAction::GenerateDataKeyAction),
("kms:DeleteKey", KmsAction::DeleteKeyAction),
("kms:RotateKey", KmsAction::RotateKeyAction),
("kms:ListKeys", KmsAction::ListKeysAction),
("kms:DescribeKey", KmsAction::DescribeKeyAction),
] {
let action = Action::try_from(raw).expect("Should parse KMS action");
assert_eq!(action, Action::KmsAction(expected));
assert_eq!(<&str>::from(&action), raw);
}
}
#[test]
fn test_kms_wildcard_matches_dedicated_actions() {
let wildcard = Action::try_from("kms:*").expect("Should parse KMS wildcard action");
let action = Action::try_from("kms:GenerateDataKey").expect("Should parse GenerateDataKey action");
assert!(matches!(wildcard, Action::KmsAction(KmsAction::AllActions)));
assert!(wildcard.is_match(&action));
}
#[test]
fn test_actionset_serialize_single_element() {
// Single element should serialize as array for S3 specification compliance
+22
View File
@@ -1729,6 +1729,28 @@ mod test {
);
}
#[test]
fn test_dedicated_kms_statement_without_resource_is_valid() {
let data = r#"
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["kms:GenerateDataKey"]
}
]
}
"#;
let result = Policy::parse_config(data.as_bytes());
assert!(
result.is_ok(),
"KMS-only dedicated Action statement without Resource should be valid, got: {:?}",
result.err()
);
}
#[test]
fn test_mixed_action_families_are_invalid_even_with_resource() {
let data = r#"