fix(emr): scope Studio list markers to their account, Region and filters (#8740)

ListStudios used one constant namespace for its markers, and
ListStudioSessionMappings its Studio and identity type joined with
String.valueOf. A marker from another account or Region therefore
resumed this one's listing at its cursor, and an absent filter could
not be told apart from the text "null".

Both now scope their markers as ListNotebookExecutions does (#8705): a
JSON list of the operation, the account, the Region and each filter, so
any other marker is refused with InvalidRequestException "Invalid
Marker.". The JSON list moves from EmrNotebookExecutionService to
EmrService.listingNamespace, which all three listings use.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 10:05:23 -04:00
1 parent 76413ce74a
commit 6618ae3de6
5 files changed
+92 -21

No files matched your search

@@ -1,6 +1,5 @@
package io.floci.aws.services.emr;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.AwsArnUtils;
@@ -21,7 +20,6 @@ import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -274,19 +272,11 @@ public class EmrNotebookExecutionService {
return execution;
}
/**
* What a marker resumes only: the account, the Region and each filter, an absent one told apart from any value, as
* a JSON list.
*/
// What a marker resumes only: the account, the Region and each filter, EmrService.listingNamespace.
private String listingNamespace(String editorId, String status, Instant from, Instant to, String engineId) {
List<String> parts = Arrays.asList("ListNotebookExecutions", regionResolver.getAccountId(),
return EmrService.listingNamespace("ListNotebookExecutions", regionResolver.getAccountId(),
regionResolver.getRegion(), editorId, status, from != null ? from.toString() : null,
to != null ? to.toString() : null, engineId);
try {
return EmrService.SNAPSHOT_MAPPER.writeValueAsString(parts);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot write a listing's namespace", e);
}
}
// The execution's cluster as it now stands, or null once it is gone; any other failure is the caller's.
@@ -1610,6 +1610,21 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
.findFirst();
}
/**
* What a listing's marker resumes only, as a JSON list: the operation, the account, the Region and each filter, an
* absent filter told apart from any value. A marker from another account, Region or filter is then refused, rather
* than resuming this listing at its cursor.
*/
static String listingNamespace(String operation, String accountId, String region, String... filters) {
List<String> parts = new ArrayList<>(Arrays.asList(operation, accountId, region));
parts.addAll(Arrays.asList(filters));
try {
return SNAPSHOT_MAPPER.writeValueAsString(parts);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot write a listing's namespace", e);
}
}
static AwsException invalid(String message) {
return new AwsException("InvalidRequestException", message, 400);
}
@@ -162,8 +162,10 @@ public class EmrStudioService {
List<EmrStudio> studios = store.scan(key -> true).stream()
.filter(studio -> regionResolver.getRegion().equals(studio.getRegion()))
.toList();
// A marker resumes only the listing of its account and Region.
PaginatedResult<EmrStudio> page = Pagination.paginate(studios,
studio -> String.format("%020d", studio.getSequence()), PAGE_SIZE, marker, "ListStudios",
studio -> String.format("%020d", studio.getSequence()), PAGE_SIZE, marker,
EmrService.listingNamespace("ListStudios", regionResolver.getAccountId(), regionResolver.getRegion()),
token -> EmrService.invalid("Invalid Marker."));
return new PaginatedResult<>(page.items().stream().map(EmrStudioService::copy).toList(), page.nextToken());
}
@@ -341,8 +343,10 @@ public class EmrStudioService {
}
}
}
String namespace = String.join("|", "ListStudioSessionMappings", String.valueOf(studioId),
String.valueOf(identityType));
// A marker resumes only the listing of its account, Region, Studio and identity type, an absent filter told
// apart from the text "null".
String namespace = EmrService.listingNamespace("ListStudioSessionMappings", regionResolver.getAccountId(),
regionResolver.getRegion(), studioId, identityType);
PaginatedResult<StudioMapping> page = Pagination.paginate(mappings, StudioMapping::cursor, PAGE_SIZE, marker,
namespace, token -> EmrService.invalid("Invalid Marker."));
return new PaginatedResult<>(page.items().stream()