mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(route53): check Route 53's requests under IAM enforcement (#8090)
Under IAM enforcement no Route 53 request but the delegation set calls
was checked: Route 53's model was not among the vendored REST routes,
and its namespace's request resources were not read, so no other
request was mapped to an action and the filter let it through. A
caller with no permissions could create, change and delete hosted
zones, record sets, health checks and tags.
Route 53's routes are now vendored and its requests read, now that
REST-XML path and query members are. Two generator changes name what
the rules did not:
- a path segment in ies names the type in y, so a bare Id after it is
that type's: ListTrafficPolicyVersions's, in
/trafficpolicies/{Id}/versions, is the traffic policy's, as the rule
for path labels already reads UpdateHostedZoneComment's hosted zone
and the other traffic policy calls;
- a member whose enum lists two or more of the action's types picks
the type: Route 53's tag calls, by ResourceType.
RequestResources drops a leading /<type>/ from an id, the path Route 53
returns its ids under, so a delegation set or hosted zone named that
way is the same resource. The delegation set calls go through the
vendored routes like the rest, and their hand-built action map and ARN
builder are gone.
Co-authored-by: mrfelek <17274927+mrfelek@users.noreply.github.com>
This commit is contained in:
1 parent
282b53cacc
commit
6b1ba4387a
12 files changed
+451
-59
No files matched your search
@@ -461,7 +461,9 @@ public final class RequestResources {
|
||||
* handler then acts on the caller's resource of that name, and it is named as an ARN the request gives is; for
|
||||
* a member naming one resource for each of a list's structures, each in the account and Region of the ARN its
|
||||
* structure gives, the request's for a name (a {@code PutEvents} entry, on the bus it names). Each value is read
|
||||
* up to the resource's {@code before} character, when it has one (a CodeBuild build id's project). A type
|
||||
* up to the resource's {@code before} character, when it has one (a CodeBuild build id's project), and without the
|
||||
* type's own path when it begins with one, as Route 53 returns its ids ({@code /hostedzone/Z1} names hosted zone
|
||||
* {@code Z1}). A type
|
||||
* whose service mints an id after its name is the caller's resource {@code stored} finds under that name, or
|
||||
* else has that id open.
|
||||
*/
|
||||
@@ -479,7 +481,8 @@ public final class RequestResources {
|
||||
boolean given = false;
|
||||
for (Map.Entry<String, RequestResourceMembers.Member> variable : resource.fill().entrySet()) {
|
||||
List<String> values = read(resource, form, body, variable.getValue()).stream()
|
||||
.map(value -> before(value, resource.before())).toList();
|
||||
.map(value -> withoutTypePath(before(value, resource.before()), resource.types().getFirst()))
|
||||
.toList();
|
||||
if (values.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -525,6 +528,12 @@ public final class RequestResources {
|
||||
}
|
||||
}
|
||||
|
||||
/** The value without a leading {@code /<type>/}, the path a service may return an id of that type under. */
|
||||
static String withoutTypePath(String value, String type) {
|
||||
String path = "/" + type + "/";
|
||||
return value.length() > path.length() && value.startsWith(path) ? value.substring(path.length()) : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The account the resource is in: the one its account member gives, the request's without one or with a JSON null
|
||||
* for it; null when that member holds no account id, which its handler refuses.
|
||||
|
||||
@@ -11,7 +11,6 @@ import io.floci.aws.core.common.SignedServiceRoute;
|
||||
import io.floci.aws.core.common.WireProtocol;
|
||||
import io.floci.aws.services.dynamodb.DynamoDbPartiQLParser;
|
||||
import io.floci.aws.services.eks.EksController;
|
||||
import io.floci.aws.services.route53.Route53Controller;
|
||||
import io.floci.aws.services.s3.S3BucketSubresources;
|
||||
import io.floci.aws.services.s3.S3ObjectActions;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -44,12 +43,6 @@ import java.util.regex.Pattern;
|
||||
@ApplicationScoped
|
||||
public class IamActionRegistry {
|
||||
|
||||
private static final Map<String, String> ROUTE53_DELEGATION_ACTIONS = Map.of(
|
||||
"createReusableDelegationSet", "route53:CreateReusableDelegationSet",
|
||||
"getReusableDelegationSet", "route53:GetReusableDelegationSet",
|
||||
"listReusableDelegationSets", "route53:ListReusableDelegationSets",
|
||||
"deleteReusableDelegationSet", "route53:DeleteReusableDelegationSet");
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(IamActionRegistry.class);
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
@@ -656,11 +649,6 @@ public class IamActionRegistry {
|
||||
|
||||
/** The serving method identifies these actions even when path encoding or matrix parameters vary. */
|
||||
public String resolveMatchedRoute(String credentialScope, ResourceInfo resourceInfo) {
|
||||
if ("route53".equals(credentialScope) && resourceInfo != null
|
||||
&& Route53Controller.class.equals(resourceInfo.getResourceClass())
|
||||
&& resourceInfo.getResourceMethod() != null) {
|
||||
return ROUTE53_DELEGATION_ACTIONS.get(resourceInfo.getResourceMethod().getName());
|
||||
}
|
||||
if (resourceInfo == null || resourceInfo.getResourceClass() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -240,10 +240,6 @@ public class ResourceArnBuilder {
|
||||
case "dsql" -> List.of(buildDsqlArn(path, ctx, region, accountId, partition));
|
||||
case "eks" -> List.of(buildEksArn(path, ctx, region, accountId));
|
||||
case "apigateway" -> List.of(buildApiGatewayArn(ctx, region, partition));
|
||||
case "route53" -> "route53:GetReusableDelegationSet".equals(operation)
|
||||
|| "route53:DeleteReusableDelegationSet".equals(operation)
|
||||
? List.of(buildRoute53DelegationSetArn(ctx, partition))
|
||||
: namedResources(credentialScope, operation, ctx, region, accountId, partition);
|
||||
case "bedrock" -> List.of(buildBedrockArn(path, ctx));
|
||||
default -> namedResources(credentialScope, operation, ctx, region, accountId, partition);
|
||||
};
|
||||
@@ -276,17 +272,6 @@ public class ResourceArnBuilder {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String buildRoute53DelegationSetArn(ContainerRequestContext ctx, String partition) {
|
||||
String id = ctx.getUriInfo().getPathParameters().getFirst("Id");
|
||||
if (id == null) {
|
||||
return "*";
|
||||
}
|
||||
if (id.startsWith("/delegationset/")) {
|
||||
id = id.substring(15);
|
||||
}
|
||||
return AwsArnUtils.Arn.global(partition, "route53", "", "delegationset/" + id).toString();
|
||||
}
|
||||
|
||||
private String buildResourceGroupArn(ContainerRequestContext ctx, String region, String accountId) {
|
||||
JsonNode body = readJsonBody(ctx);
|
||||
if (body == null) {
|
||||
|
||||
Reference in new issue
Block a user