mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 15:49:33 -05:00
fix(iam): check the EventBridge Scheduler and Pipes routes (#6044)
Under IAM enforcement no Scheduler or Pipes route was mapped to an IAM action, so every call to either went unchecked, and the roles they take with it. - Every Scheduler and Pipes route is mapped, tagging at /tags as well as /tags/<arn>, and IamRestRouteCoverageTest now checks every operation of both models. Each request is checked against the resource the Service Reference gives: schedule/<group>/<name>, the group read where Scheduler reads it (the body's GroupName on a create or an update, groupName otherwise, else default), schedule-group/<name>, pipe/<name>, the ARN a tagging route names, and * where the request names none. Scheduler and Pipes ARNs are minted in the request's partition, as those services mint theirs. - SchedulerController joins the Scheduler descriptor, so a schedule request is checked as Scheduler whatever scope signs it. Otherwise one signed for another service was checked by that service's rules. - The shared tagging routes, /tags and /v1/tags, hand a request to the service its ARN names, so it is checked as that service, against the ARN the controller acts on: the body's resourceArn on POST /tags, the query's on the other bare routes. Otherwise a Pipes grant could tag a schedule group, a scope with no tagging rule went unchecked, and a query ARN could stand in for the body's. - iam:PassRole: CreateSchedule and UpdateSchedule pass the target's RoleArn to scheduler.amazonaws.com, and CreatePipe and UpdatePipe their RoleArn to pipes.amazonaws.com, as the Scheduler user guide's example policies and the EventBridge user guide say.
This commit is contained in:
1 parent
6be05b9cbe
commit
77c5d74a7d
15 files changed
+521
-12
No files matched your search
@@ -786,11 +786,37 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
|| resourceInfo == null || resourceInfo.getResourceClass() == null) {
|
||||
return null;
|
||||
}
|
||||
return catalog.byResourceClass(resourceInfo.getResourceClass())
|
||||
Class<?> resourceClass = resourceInfo.getResourceClass();
|
||||
if (SharedTagsController.class.equals(resourceClass) || V1TagsController.class.equals(resourceClass)) {
|
||||
return taggedServiceAuthorization(ctx);
|
||||
}
|
||||
return catalog.byResourceClass(resourceClass)
|
||||
.map(descriptor -> resolveRestAuthorization(descriptor, ctx))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A shared tagging route hands the request to the service its ARN names, so it is checked as that
|
||||
* service whatever scope it is signed with. A service with no rule for the route leaves it unchecked, as
|
||||
* any route no rule maps; an ARN naming no service Floci serves, which the controller refuses, is left
|
||||
* to the signing scope.
|
||||
*/
|
||||
private ResolvedAuthorization taggedServiceAuthorization(ContainerRequestContext ctx) {
|
||||
String arn = arnBuilder.taggedArn(ctx);
|
||||
if (!AwsArnUtils.isArn(arn)) {
|
||||
return null;
|
||||
}
|
||||
String service = AwsArnUtils.parse(arn).service();
|
||||
return catalog.byCredentialScope(service)
|
||||
.map(descriptor -> {
|
||||
ResolvedAuthorization authorization = resolveRestAuthorization(descriptor, ctx);
|
||||
return authorization != null
|
||||
? authorization
|
||||
: new ResolvedAuthorization(catalog.canonicalCredentialScope(service), null);
|
||||
})
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses a request whose {@code Authorization} header this filter cannot read a credential
|
||||
* from: an empty one, one naming no access key (a Bearer token, SigV2, a credential without the
|
||||
@@ -1452,7 +1478,10 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
};
|
||||
}
|
||||
|
||||
/** Logs and Secrets Manager targets depend on the serving operation and the request's partition. */
|
||||
/**
|
||||
* Logs and Secrets Manager targets depend on the serving operation and the request's partition;
|
||||
* Scheduler and Pipes targets on the request's partition, which those services mint their ARNs in.
|
||||
*/
|
||||
private List<String> targetResources(String credentialScope, String action, ContainerRequestContext ctx,
|
||||
String region, String accountId) {
|
||||
if ("logs".equals(credentialScope)) {
|
||||
@@ -1461,6 +1490,9 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
if ("secretsmanager".equals(credentialScope)) {
|
||||
return arnBuilder.buildSecretsManagerResources(action, ctx, region, accountId, requestPartition());
|
||||
}
|
||||
if ("scheduler".equals(credentialScope) || "pipes".equals(credentialScope)) {
|
||||
return arnBuilder.buildResources(credentialScope, ctx, region, accountId, requestPartition());
|
||||
}
|
||||
return arnBuilder.buildResources(credentialScope, ctx, region, accountId);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ final class PassedRoles {
|
||||
private static final String ECS_TASKS = ServicePrincipals.of("ecs-tasks");
|
||||
private static final String STATES = ServicePrincipals.of("states");
|
||||
private static final String EVENTS = ServicePrincipals.of("events");
|
||||
private static final String SCHEDULER = ServicePrincipals.of("scheduler");
|
||||
private static final String PIPES = ServicePrincipals.of("pipes");
|
||||
private static final String CLOUDFORMATION = ServicePrincipals.of("cloudformation");
|
||||
|
||||
private static final String STACK_SET_ADMINISTRATION_ROLE = "AWSCloudFormationStackSetAdministrationRole";
|
||||
@@ -111,6 +113,8 @@ final class PassedRoles {
|
||||
case "states:CreateStateMachine", "states:UpdateStateMachine" -> fromJson(ctx, STATES, "roleArn");
|
||||
case "events:PutRule" -> fromJson(ctx, EVENTS, "RoleArn");
|
||||
case "events:PutTargets" -> fromJson(ctx, EVENTS, "Targets", "[]", "RoleArn");
|
||||
case "scheduler:CreateSchedule", "scheduler:UpdateSchedule" -> fromJson(ctx, SCHEDULER, "Target", "RoleArn");
|
||||
case "pipes:CreatePipe", "pipes:UpdatePipe" -> fromJson(ctx, PIPES, "RoleArn");
|
||||
case "cloudformation:CreateStack", "cloudformation:UpdateStack", "cloudformation:DeleteStack",
|
||||
"cloudformation:CreateChangeSet", "cloudformation:ContinueUpdateRollback" ->
|
||||
fromForm(ctx, CLOUDFORMATION, "RoleARN");
|
||||
|
||||
@@ -66,6 +66,7 @@ import io.github.hectorvent.floci.services.s3.S3Controller;
|
||||
import io.github.hectorvent.floci.services.s3tables.S3TablesController;
|
||||
import io.github.hectorvent.floci.services.s3vectors.S3VectorsController;
|
||||
import io.github.hectorvent.floci.services.sagemaker.SageMakerRuntimeController;
|
||||
import io.github.hectorvent.floci.services.scheduler.SchedulerController;
|
||||
import io.github.hectorvent.floci.services.securityhub.SecurityHubController;
|
||||
import io.github.hectorvent.floci.services.ses.SesAccountController;
|
||||
import io.github.hectorvent.floci.services.ses.SesConfigurationSetController;
|
||||
@@ -256,7 +257,7 @@ public class ResolvedServiceCatalog {
|
||||
descriptor("scheduler", "scheduler", config.services().scheduler().enabled(), true,
|
||||
"scheduler", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of(), Set.of("scheduler"), Set.of(), Set.of()),
|
||||
Set.of(), Set.of("scheduler"), Set.of(), Set.of(SchedulerController.class)),
|
||||
descriptor("logs", "cloudwatchlogs", config.services().cloudwatchlogs().enabled(), true,
|
||||
"cloudwatchlogs", storageMode(config.storage().services().cloudwatchlogs().mode(), config.storage().mode()),
|
||||
config.storage().services().cloudwatchlogs().flushIntervalMs(), null, ServiceProtocol.JSON,
|
||||
|
||||
@@ -141,6 +141,33 @@ public class IamActionRegistry {
|
||||
rule("apigateway", "PATCH", ".*", "apigateway:PATCH"),
|
||||
rule("apigateway", "DELETE", ".*", "apigateway:DELETE"),
|
||||
|
||||
// ── EventBridge Scheduler ──────────────────────────────────────────────
|
||||
rule("scheduler", "GET", "^/schedules/[^/]+$", "scheduler:GetSchedule"),
|
||||
rule("scheduler", "POST", "^/schedules/[^/]+$", "scheduler:CreateSchedule"),
|
||||
rule("scheduler", "PUT", "^/schedules/[^/]+$", "scheduler:UpdateSchedule"),
|
||||
rule("scheduler", "DELETE", "^/schedules/[^/]+$", "scheduler:DeleteSchedule"),
|
||||
rule("scheduler", "GET", "^/schedules$", "scheduler:ListSchedules"),
|
||||
rule("scheduler", "GET", "^/schedule-groups/[^/]+$", "scheduler:GetScheduleGroup"),
|
||||
rule("scheduler", "POST", "^/schedule-groups/[^/]+$", "scheduler:CreateScheduleGroup"),
|
||||
rule("scheduler", "DELETE", "^/schedule-groups/[^/]+$", "scheduler:DeleteScheduleGroup"),
|
||||
rule("scheduler", "GET", "^/schedule-groups$", "scheduler:ListScheduleGroups"),
|
||||
// Tagging is served at /tags/<arn> and at /tags, naming the ARN in the query or the body.
|
||||
rule("scheduler", "GET", "^/tags(/.+)?$", "scheduler:ListTagsForResource"),
|
||||
rule("scheduler", "POST", "^/tags(/.+)?$", "scheduler:TagResource"),
|
||||
rule("scheduler", "DELETE", "^/tags(/.+)?$", "scheduler:UntagResource"),
|
||||
|
||||
// ── EventBridge Pipes ──────────────────────────────────────────────────
|
||||
rule("pipes", "POST", "^/v1/pipes/[^/]+/start$", "pipes:StartPipe"),
|
||||
rule("pipes", "POST", "^/v1/pipes/[^/]+/stop$", "pipes:StopPipe"),
|
||||
rule("pipes", "GET", "^/v1/pipes/[^/]+$", "pipes:DescribePipe"),
|
||||
rule("pipes", "POST", "^/v1/pipes/[^/]+$", "pipes:CreatePipe"),
|
||||
rule("pipes", "PUT", "^/v1/pipes/[^/]+$", "pipes:UpdatePipe"),
|
||||
rule("pipes", "DELETE", "^/v1/pipes/[^/]+$", "pipes:DeletePipe"),
|
||||
rule("pipes", "GET", "^/v1/pipes$", "pipes:ListPipes"),
|
||||
rule("pipes", "GET", "^/tags(/.+)?$", "pipes:ListTagsForResource"),
|
||||
rule("pipes", "POST", "^/tags(/.+)?$", "pipes:TagResource"),
|
||||
rule("pipes", "DELETE", "^/tags(/.+)?$", "pipes:UntagResource"),
|
||||
|
||||
// ── SES v2 ─────────────────────────────────────────────────────────────
|
||||
// SES v1 is a Query API and resolves from its Action like any other; v2 is REST-JSON under
|
||||
// /v2/email, so every operation needs its own rule. One rule per operation in the SES v2
|
||||
|
||||
@@ -94,6 +94,16 @@ public class ResourceArnBuilder {
|
||||
|
||||
public List<String> buildResources(String credentialScope, ContainerRequestContext ctx,
|
||||
String region, String accountId) {
|
||||
return buildResources(credentialScope, ctx, region, accountId, AwsRegions.partitionFor(region));
|
||||
}
|
||||
|
||||
/**
|
||||
* The resources a request is checked against. Scheduler and Pipes ARNs are minted in {@code partition},
|
||||
* the request's, as those services mint theirs, so a Region no partition publishes gets the deployment's
|
||||
* partition rather than {@code aws}.
|
||||
*/
|
||||
public List<String> buildResources(String credentialScope, ContainerRequestContext ctx,
|
||||
String region, String accountId, String partition) {
|
||||
if (credentialScope == null) {
|
||||
return List.of("*");
|
||||
}
|
||||
@@ -109,6 +119,8 @@ public class ResourceArnBuilder {
|
||||
case "kms" -> List.of(buildKmsArn(path, region, accountId));
|
||||
case "iam" -> buildIamArns(ctx, region, accountId);
|
||||
case "resource-groups" -> List.of(buildResourceGroupArn(ctx, region, accountId));
|
||||
case "scheduler" -> List.of(buildSchedulerArn(path, ctx, region, accountId, partition));
|
||||
case "pipes" -> List.of(buildPipesArn(path, ctx, region, accountId, partition));
|
||||
default -> List.of("*");
|
||||
};
|
||||
}
|
||||
@@ -703,6 +715,87 @@ public class ResourceArnBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource of an EventBridge Scheduler route: {@code schedule/<group>/<name>}, the group read where
|
||||
* Scheduler reads it, the body's {@code GroupName} on a create or an update and {@code groupName}
|
||||
* otherwise, and {@code default} when the request names none; {@code schedule-group/<name>}; or the
|
||||
* ARN a tagging route names. The list routes name no resource.
|
||||
*/
|
||||
private String buildSchedulerArn(String path, ContainerRequestContext ctx, String region, String accountId,
|
||||
String partition) {
|
||||
String schedule = segmentAfterPrefix(path, "/schedules/");
|
||||
if (schedule != null) {
|
||||
String group;
|
||||
if ("POST".equalsIgnoreCase(ctx.getMethod()) || "PUT".equalsIgnoreCase(ctx.getMethod())) {
|
||||
JsonNode body = readJsonBody(ctx);
|
||||
group = body == null ? null : body.path("GroupName").asText(null);
|
||||
} else {
|
||||
group = ctx.getUriInfo().getQueryParameters().getFirst("groupName");
|
||||
}
|
||||
if (group == null || group.isBlank()) {
|
||||
group = "default";
|
||||
}
|
||||
return new AwsArnUtils.Arn(partition, "scheduler", region, accountId,
|
||||
"schedule/" + group + "/" + schedule).toString();
|
||||
}
|
||||
String scheduleGroup = segmentAfterPrefix(path, "/schedule-groups/");
|
||||
if (scheduleGroup != null) {
|
||||
return new AwsArnUtils.Arn(partition, "scheduler", region, accountId,
|
||||
"schedule-group/" + scheduleGroup).toString();
|
||||
}
|
||||
return taggedResource(ctx);
|
||||
}
|
||||
|
||||
/** The resource of an EventBridge Pipes route: {@code pipe/<name>}, or the ARN a tagging route names. */
|
||||
private String buildPipesArn(String path, ContainerRequestContext ctx, String region, String accountId,
|
||||
String partition) {
|
||||
String pipe = segmentAfterPrefix(path, "/v1/pipes/");
|
||||
if (pipe != null) {
|
||||
return new AwsArnUtils.Arn(partition, "pipes", region, accountId, "pipe/" + pipe).toString();
|
||||
}
|
||||
return taggedResource(ctx);
|
||||
}
|
||||
|
||||
/** The ARN a shared tagging route names, or {@code *} for any other route. */
|
||||
private String taggedResource(ContainerRequestContext ctx) {
|
||||
String arn = taggedArn(ctx);
|
||||
return arn != null && arn.startsWith("arn:") ? arn : "*";
|
||||
}
|
||||
|
||||
/**
|
||||
* The ARN a shared tagging route acts on, read where its controller reads it: after {@code /tags/} or
|
||||
* {@code /v1/tags/} in the path; on {@code POST /tags}, the body's {@code resourceArn}; and on the other
|
||||
* bare routes, the {@code resourceArn} query parameter. Null for any other route, or when the request
|
||||
* names none.
|
||||
*/
|
||||
public String taggedArn(ContainerRequestContext ctx) {
|
||||
String path = ctx.getUriInfo().getPath();
|
||||
for (String route : List.of("/tags", "/v1/tags")) {
|
||||
if (path.startsWith(route + "/")) {
|
||||
return path.substring(route.length() + 1);
|
||||
}
|
||||
}
|
||||
if ("/tags".equals(path) && "POST".equalsIgnoreCase(ctx.getMethod())) {
|
||||
JsonNode body = readJsonBody(ctx);
|
||||
return body == null ? null : body.path("resourceArn").asText(null);
|
||||
}
|
||||
if ("/tags".equals(path) || "/v1/tags".equals(path)) {
|
||||
return ctx.getUriInfo().getQueryParameters().getFirst("resourceArn");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The path segment right after {@code prefix}, or null when the path doesn't start with it or names none. */
|
||||
private static String segmentAfterPrefix(String path, String prefix) {
|
||||
if (!path.startsWith(prefix)) {
|
||||
return null;
|
||||
}
|
||||
String rest = path.substring(prefix.length());
|
||||
int slash = rest.indexOf('/');
|
||||
String segment = slash < 0 ? rest : rest.substring(0, slash);
|
||||
return segment.isEmpty() ? null : segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource of a Lambda Web Functions route. An action on a revision or an endpoint is evaluated
|
||||
* against that child's ARN; an action on the function, a create of a revision or endpoint, the list of
|
||||
|
||||
Reference in new issue
Block a user