mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
fix(iam): set iam: condition keys from a table generated from the Service Reference (#6762)
This commit is contained in:
1 parent
0c549d267b
commit
967e87d7f7
12 files changed
+708
-15
No files matched your search
+12
-7
@@ -209,14 +209,19 @@ public class IamConditionContextResolver {
|
||||
}
|
||||
|
||||
private static Map<String, List<String>> iamConditionContext(String action, ContainerRequestContext ctx) {
|
||||
return switch (action) {
|
||||
case "iam:AttachRolePolicy", "iam:DetachRolePolicy", "iam:AttachUserPolicy",
|
||||
"iam:DetachUserPolicy", "iam:AttachGroupPolicy", "iam:DetachGroupPolicy" -> {
|
||||
String policyArn = formParameters(ctx).get("PolicyArn");
|
||||
yield policyArn == null ? null : Map.of("iam:PolicyARN", List.of(policyArn));
|
||||
Map<String, String> members = IamConditionKeys.members(action);
|
||||
if (members.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> form = formParameters(ctx);
|
||||
Map<String, List<String>> conditions = new LinkedHashMap<>();
|
||||
members.forEach((key, member) -> {
|
||||
String value = form.get(member);
|
||||
if (value != null) {
|
||||
conditions.put(key, List.of(value));
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
});
|
||||
return conditions.isEmpty() ? null : conditions;
|
||||
}
|
||||
|
||||
public static Map<String, List<String>> withGlobalContext(Map<String, List<String>> serviceContext,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The {@code iam:} condition keys an IAM request carries in its own members, generated from the
|
||||
* AWS Service Reference and pinned botocore by {@code tools/aws/regen_iam_condition_keys.py}.
|
||||
*/
|
||||
final class IamConditionKeys {
|
||||
|
||||
private static final Map<String, Map<String, String>> MEMBERS = VendoredResources.read(
|
||||
"aws/iam-condition-keys.json", "IAM condition keys", input -> {
|
||||
JsonNode read = new ObjectMapper().readTree(input).path("read");
|
||||
if (!read.isArray() || read.isEmpty()) {
|
||||
throw new IllegalStateException("Malformed IAM condition key table");
|
||||
}
|
||||
Map<String, Map<String, String>> members = new LinkedHashMap<>();
|
||||
for (JsonNode entry : read) {
|
||||
if (!entry.path("action").isTextual() || !entry.path("key").isTextual()
|
||||
|| !entry.path("member").isTextual()) {
|
||||
throw new IllegalStateException("Malformed IAM condition key entry: " + entry);
|
||||
}
|
||||
members.computeIfAbsent(entry.get("action").asText(), action -> new LinkedHashMap<>())
|
||||
.put(entry.get("key").asText(), entry.get("member").asText());
|
||||
}
|
||||
members.replaceAll((action, keys) -> Map.copyOf(keys));
|
||||
return Map.copyOf(members);
|
||||
});
|
||||
|
||||
private IamConditionKeys() {}
|
||||
|
||||
/** Each condition key a request for {@code action} carries, to the member that holds it; empty when none. */
|
||||
static Map<String, String> members(String action) {
|
||||
return MEMBERS.getOrDefault(action, Map.of());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user