fix(appconfig): isolate resources and sessions by region (#7621)

Scope AppConfig stores, sessions and deployment cursors to the request's
account and region. Keep legacy keys in the configured default region.
Adapt the source change to current deployment and CloudFormation behavior,
and cover storage reloads and SDK routing.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Jackson PriceandAndre Kurait authored and GitHub committed 2026-11-05 16:13:12 -04:00
1 parent 36fbc33a2f
commit a884257311
17 files changed
+587 -42

No files matched your search

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.appconfig.model.Application;
@@ -33,8 +34,9 @@ public class AppConfigDataService {
@Inject
public AppConfigDataService(StorageFactory storageFactory, AppConfigService appConfigService,
ObjectMapper objectMapper) {
this.sessionStore = storageFactory.create("appconfigdata", "appconfigdata-sessions.json", new TypeReference<>() {});
ObjectMapper objectMapper, RegionResolver regions) {
this.sessionStore = new AppConfigStorage<>(storageFactory, regions,
"appconfigdata", "appconfigdata-sessions.json", new TypeReference<>() {});
this.appConfigService = appConfigService;
this.objectMapper = objectMapper;
}
@@ -2,9 +2,9 @@ package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.core.storage.StorageOperations;
@@ -46,6 +46,7 @@ public class AppConfigService {
private final StorageBackend<String, Deployment> deploymentStore;
private final StorageBackend<String, String> activeConfigStore; // envId::profileId -> versionNumber
private final Clock clock;
private final RegionResolver regions;
private final Map<String, DeploymentPageToken> deploymentPageTokens = new ConcurrentHashMap<>();
private static final int MAX_DEPLOYMENT_PAGE_TOKENS = 1000;
private static final int MAX_MONITORS = 5;
@@ -54,19 +55,27 @@ public class AppConfigService {
private static final Pattern ROLE_ARN = Pattern.compile("arn:" + AwsArnUtils.PARTITION_REGEX + ":iam::\\d{12}:role/.*");
@Inject
public AppConfigService(StorageFactory storageFactory, EmulatorConfig config) {
this(storageFactory, config, Clock.systemUTC());
public AppConfigService(StorageFactory storageFactory, RegionResolver regions) {
this(storageFactory, regions, Clock.systemUTC());
}
AppConfigService(StorageFactory storageFactory, EmulatorConfig config, Clock clock) {
AppConfigService(StorageFactory storageFactory, RegionResolver regions, Clock clock) {
this.clock = clock;
this.applicationStore = storageFactory.create("appconfig", "appconfig-applications.json", new TypeReference<>() {});
this.environmentStore = storageFactory.create("appconfig", "appconfig-environments.json", new TypeReference<>() {});
this.profileStore = storageFactory.create("appconfig", "appconfig-profiles.json", new TypeReference<>() {});
this.strategyStore = storageFactory.create("appconfig", "appconfig-strategies.json", new TypeReference<>() {});
this.versionStore = storageFactory.create("appconfig", "appconfig-versions.json", new TypeReference<>() {});
this.deploymentStore = storageFactory.create("appconfig", "appconfig-deployments.json", new TypeReference<>() {});
this.activeConfigStore = storageFactory.create("appconfig", "appconfig-active-configs.json", new TypeReference<>() {});
this.regions = regions;
this.applicationStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-applications.json", new TypeReference<>() {});
this.environmentStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-environments.json", new TypeReference<>() {});
this.profileStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-profiles.json", new TypeReference<>() {});
this.strategyStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-strategies.json", new TypeReference<>() {});
this.versionStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-versions.json", new TypeReference<>() {});
this.deploymentStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-deployments.json", new TypeReference<>() {});
this.activeConfigStore = new AppConfigStorage<>(storageFactory, regions,
"appconfig", "appconfig-active-configs.json", new TypeReference<>() {});
}
// ──────────────────────────── Application ────────────────────────────
@@ -192,7 +201,7 @@ public class AppConfigService {
StorageOperations.deleteByPrefix(deploymentStore, appId + "::" + envId + "::");
StorageOperations.deleteByPrefix(activeConfigStore, envId + "::");
String deploymentScope = appId + "::" + envId;
String deploymentScope = deploymentScope(appId, envId);
deploymentPageTokens.entrySet().removeIf(entry -> entry.getValue().scope().equals(deploymentScope));
environmentStore.delete(envId);
}
@@ -694,7 +703,7 @@ public class AppConfigService {
throw new AwsException("BadRequestException", "max_results must be between 1 and 50", 400);
}
String scope = appId + "::" + envId;
String scope = deploymentScope(appId, envId);
Integer afterDeploymentNumber = null;
if (nextToken != null) {
DeploymentPageToken token = deploymentPageTokens.get(nextToken);
@@ -783,6 +792,10 @@ public class AppConfigService {
return token;
}
private String deploymentScope(String appId, String envId) {
return regions.getAccountId() + "/" + regions.getRegion() + "/" + appId + "::" + envId;
}
private record DeploymentPageToken(String scope, int lastDeploymentNumber) {
}
@@ -0,0 +1,116 @@
package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
/**
* Region view of a factory-owned account store. Older, regionless keys belong only to
* the configured default region; new writes always record their region explicitly.
*/
final class AppConfigStorage<V> implements StorageBackend<String, V> {
private final StorageBackend<String, V> delegate;
private final RegionResolver regions;
AppConfigStorage(StorageFactory factory, RegionResolver regions, String service, String file,
TypeReference<Map<String, V>> type) {
this.delegate = factory.create(service, file, type);
this.regions = regions;
}
@Override
public void put(String key, V value) {
if (!logicalKey(key)) {
throw new IllegalArgumentException("AppConfig storage keys cannot contain a region prefix");
}
delegate.put(prefix() + key, value);
if (defaultRegion() && delegate.get(key).isPresent()) {
delegate.delete(key);
}
}
@Override
public Optional<V> get(String key) {
if (!logicalKey(key)) {
return Optional.empty();
}
return delegate.get(prefix() + key)
.or(() -> defaultRegion() ? delegate.get(key) : Optional.empty());
}
@Override
public void delete(String key) {
if (logicalKey(key)) {
if (defaultRegion()) {
delegate.delete(key);
}
delegate.delete(prefix() + key);
}
}
@Override
public List<V> scan(Predicate<String> keyFilter) {
List<V> values = new ArrayList<>();
for (String key : keys()) {
if (keyFilter.test(key)) {
get(key).ifPresent(values::add);
}
}
return values;
}
@Override
public Set<String> keys() {
String prefix = prefix();
boolean includeLegacy = defaultRegion();
Set<String> keys = new HashSet<>();
for (String stored : delegate.keys()) {
if (stored.startsWith(prefix)) {
String key = stored.substring(prefix.length());
if (logicalKey(key)) {
keys.add(key);
}
} else if (includeLegacy && logicalKey(stored)) {
keys.add(stored);
}
}
return keys;
}
@Override
public void clear() {
keys().forEach(this::delete);
}
@Override
public void flush() {
delegate.flush();
}
@Override
public void load() {
delegate.load();
}
private String prefix() {
return regions.getRegion() + "/";
}
private boolean defaultRegion() {
return regions.getRegion().equals(regions.getDefaultRegion());
}
private static boolean logicalKey(String key) {
// Resource IDs, configuration tokens and the service's "::" composite keys contain no slash.
return key != null && !key.contains("/");
}
}