mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eks): populate cluster request IAM conditions (#8336)
* fix(eks): populate cluster request IAM conditions * fix(eks): read cluster conditions through the generated table and refuse mistyped flags
This commit is contained in:
1 parent
aa2adac677
commit
259a0737e7
18 files changed
+1747
-14
No files matched your search
@@ -335,10 +335,11 @@ public class IamConditionContextResolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* The keys a request for {@code action} carries in its own members, such as a Redshift DbUser or the record names
|
||||
* of a Route 53 change batch, read as its namespace's protocol carries them (a Query form, an XML body), from the
|
||||
* table in {@code request-condition-keys.json}; null when it carries none, or is sent in a protocol no reader here
|
||||
* reads yet.
|
||||
* The keys a request for {@code action} carries in its own members, such as a Redshift DbUser, the record names
|
||||
* of a Route 53 change batch or an EKS cluster's endpoint access, read as its namespace's protocol carries them
|
||||
* (a Query form, an XML or JSON body), from the table in {@code request-condition-keys.json}; null when it
|
||||
* carries none, or is sent in a protocol no reader here reads yet. A member left out, or given a JSON null, names
|
||||
* nothing, so an update takes no value from what the resource already has.
|
||||
*/
|
||||
private Map<String, List<String>> requestMemberConditions(String action, ContainerRequestContext ctx) {
|
||||
List<String> keys = RequestConditionKeys.requestKeys(action);
|
||||
@@ -360,12 +361,39 @@ public class IamConditionContextResolver {
|
||||
return null;
|
||||
}
|
||||
values = member -> read.getOrDefault(member, List.of());
|
||||
} else if ("json".equals(protocol) || "rest-json".equals(protocol)) {
|
||||
JsonNode body = PassedRoles.jsonBody(ctx);
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
values = member -> jsonValues(body, member.split("\\."), 0, new ArrayList<>());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return requestConditions(action, values, requestConditionSpelling(namespace));
|
||||
}
|
||||
|
||||
/**
|
||||
* The scalar values at {@code path} in a JSON body, a member path as the table writes it, {@code *} stepping into
|
||||
* every element of a list or map; a JSON null, a structure or a list where the path ends names nothing.
|
||||
*/
|
||||
private static List<String> jsonValues(JsonNode node, String[] path, int step, List<String> found) {
|
||||
if (node == null || node.isNull() || node.isMissingNode()) {
|
||||
return found;
|
||||
}
|
||||
if (step == path.length) {
|
||||
if (node.isValueNode()) {
|
||||
found.add(node.asText());
|
||||
}
|
||||
return found;
|
||||
}
|
||||
if ("*".equals(path[step])) {
|
||||
node.forEach(element -> jsonValues(element, path, step + 1, found));
|
||||
return found;
|
||||
}
|
||||
return jsonValues(node.get(path[step]), path, step + 1, found);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every value {@code values} reads for each member the table names for each key {@code action} takes, spelled by
|
||||
* {@code spelling} as the namespace's service spells the member's shape; null when there are none.
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package io.floci.aws.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
import io.floci.aws.services.eks.model.Addon;
|
||||
@@ -59,20 +63,36 @@ public class EksController {
|
||||
private final EksAccessEntryService accessEntries;
|
||||
private final EksPodIdentityAssociationService podIdentityAssociations;
|
||||
private final EksAddonService addons;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public EksController(EksService eksService, EksAccessEntryService accessEntries,
|
||||
EksPodIdentityAssociationService podIdentityAssociations,
|
||||
EksAddonService addons) {
|
||||
EksAddonService addons, ObjectMapper objectMapper) {
|
||||
this.eksService = eksService;
|
||||
this.accessEntries = accessEntries;
|
||||
this.podIdentityAssociations = podIdentityAssociations;
|
||||
this.addons = addons;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* The body is checked against its botocore shape before it is bound, as EKS refuses a member of the wrong JSON
|
||||
* type: bound first, a number for a boolean member would reach the cluster as {@code true}. A body that passes
|
||||
* the check but still does not bind is refused the same way.
|
||||
*/
|
||||
@POST
|
||||
@Path("/clusters")
|
||||
public Response createCluster(CreateClusterRequest request) {
|
||||
public Response createCluster(JsonNode body) {
|
||||
CreateClusterRequest request = null;
|
||||
if (body != null) {
|
||||
EksRequestShapes.check("CreateCluster", body);
|
||||
try {
|
||||
request = objectMapper.treeToValue(body, CreateClusterRequest.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", e.getOriginalMessage(), 400);
|
||||
}
|
||||
}
|
||||
Cluster cluster = eksService.createCluster(request);
|
||||
return Response.ok(Map.of("cluster", toClusterResponse(cluster))).build();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.floci.aws.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.floci.aws.core.common.RequestShapeCheck;
|
||||
import io.floci.aws.core.common.RequestShapeCheck.ByPosition;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Rejects an EKS request body member of the wrong JSON type before the operation reads it, so a member the model
|
||||
* types as a boolean, such as {@code resourcesVpcConfig.endpointPublicAccess}, is never a number Floci would read
|
||||
* as {@code true} while the IAM condition key of the same member carries no value. The body shapes come from the
|
||||
* vendored {@code aws/eks-request-shapes.json}, generated from botocore's EKS model by
|
||||
* {@code tools/aws/regen_eks_shapes.py}, and are walked by {@link RequestShapeCheck}.
|
||||
*
|
||||
* <p>EKS's own wording has not been measured. It answers as the REST JSON deserializer API Gateway and SES v2 were
|
||||
* measured to, a {@code SerializationException} naming the JSON token it could not convert, and only a boolean
|
||||
* member's scalar is checked: a structure, list or map of the wrong kind is refused too, any other scalar is left to
|
||||
* the operation, as before.
|
||||
*/
|
||||
final class EksRequestShapes {
|
||||
|
||||
static final String RESOURCE_NAME = "aws/eks-request-shapes.json";
|
||||
|
||||
private static final RequestShapeCheck.Messages MESSAGES = new RequestShapeCheck.Messages(
|
||||
"SerializationException",
|
||||
"Start of structure or map found where not expected.",
|
||||
"Start of list found where not expected",
|
||||
ByPosition.same("Expected null"),
|
||||
ByPosition.same("Expected list or null"),
|
||||
ByPosition.same("Expected map or null"),
|
||||
"%s can not be converted to a %s",
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
Set.of("boolean"));
|
||||
|
||||
private static final RequestShapeCheck.Operations OPERATIONS =
|
||||
new RequestShapeCheck.Operations(RESOURCE_NAME, "EKS request shapes", MESSAGES);
|
||||
|
||||
private EksRequestShapes() {
|
||||
}
|
||||
|
||||
/** Checks an EKS request body against the body shape of {@code operation}. */
|
||||
static void check(String operation, JsonNode request) {
|
||||
OPERATIONS.check(operation, request);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user