From e5ddc9fffc2cc7a6fd66eafd42fb3722c61ca61b Mon Sep 17 00:00:00 2001
From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
Date: Wed, 18 Nov 2026 07:10:51 -0400
Subject: [PATCH] fix(globalaccelerator): give resource-tag conditions the tags
of the accelerator a request names (#8847)
The generated request resources give Global Accelerator's accelerator,
listener and endpointgroup types the aws:ResourceTag/ key, but no
service answered the globalaccelerator namespace's stored tags, so a
condition on their tags saw none. GlobalAcceleratorService now answers
it: it finds the resource under the ARN itself, in the request's
account, in place, as the tag handlers do, and reads the tags stored
under that ARN. TagResource and UntagResource now run one at a time, so
two tag calls never lose one's tags.
---
docs/services/iam.md | 4 +-
.../aws/core/common/StoredResourceArns.java | 3 +-
.../GlobalAcceleratorService.java | 50 +++++++++++++++++--
.../GlobalAcceleratorServiceTest.java | 46 +++++++++++++++++
...estResourceEnforcementIntegrationTest.java | 40 +++++++++++++--
5 files changed, 132 insertions(+), 11 deletions(-)
diff --git a/docs/services/iam.md b/docs/services/iam.md
index 5ec5d567d5..d2a4b38402 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -3382,8 +3382,8 @@ floci populates:
for Apache Flink for its applications, S3 Vectors for its vector buckets and indexes, Timestream for InfluxDB for its
DB instances, DB clusters, parameter groups and backups, CloudTrail for its trails, Budgets for its budgets and budget
actions, AWS FIS for its experiment templates, experiments and actions, CodePipeline for its pipelines, webhooks and
- custom action types, and DataSync for its agents, locations and tasks. Tag keys differing only in case are one
- condition key holding every value.
+ custom action types, DataSync for its agents, locations and tasks, and Global Accelerator for its accelerators,
+ listeners and endpoint groups. Tag keys differing only in case are one condition key holding every value.
- EC2 resource keys such as a network interface's `ec2:Vpc`, `ec2:Subnet`, `ec2:AvailabilityZone` and
`ec2:NetworkInterfaceID`: for every action on a resource EC2 holds, the members of the resource the
key names, an ARN for a key the Service Reference types as one. `resourceKeys` in
diff --git a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
index 759b765264..6025db352d 100644
--- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
+++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
@@ -51,7 +51,8 @@ import java.util.Optional;
* tags of a DB instance, a DB cluster, a parameter group or a backup; CloudTrail, for the tags of a trail; Budgets, for
* the tags of a budget or a budget action; AWS FIS, for the tags of an experiment template, an experiment or an action;
* CodePipeline, for the tags of a pipeline, a webhook or a custom action type; DataSync, for the tags of an agent, a
- * location or a task); looked up lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
+ * location or a task; Global Accelerator, for the tags of an accelerator, a listener or an endpoint group); looked up
+ * lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
* {@code Instance} for the namespace a request or an ARN is of, so IAM never depends on that
* service directly.
*
diff --git a/src/main/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorService.java b/src/main/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorService.java
index 054a21545b..69a0c11699 100644
--- a/src/main/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorService.java
+++ b/src/main/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorService.java
@@ -2,10 +2,13 @@ package io.floci.aws.services.globalaccelerator;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
+import io.floci.aws.core.common.AwsArnUtils;
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.core.common.RegionResolver;
+import io.floci.aws.core.common.StoredResourceArns;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.globalaccelerator.model.Accelerator;
@@ -26,6 +29,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
@@ -46,7 +50,7 @@ import java.util.regex.Pattern;
* from the address ranges Global Accelerator advertises but route no traffic.
*/
@ApplicationScoped
-public class GlobalAcceleratorService {
+public class GlobalAcceleratorService implements StoredResourceArns {
private static final Logger LOG = Logger.getLogger(GlobalAcceleratorService.class);
private static final String ID_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
@@ -414,7 +418,11 @@ public class GlobalAcceleratorService {
return tags.get(resourceArn).orElseGet(LinkedHashMap::new);
}
- public void tagResource(String resourceArn, Map newTags) {
+ /**
+ * Stores a new map holding the resource's tags and {@code newTags}. Tag calls run one at a time, so two of them
+ * never lose one's tags.
+ */
+ public synchronized void tagResource(String resourceArn, Map newTags) {
requireResourceExists(resourceArn);
if (newTags == null || newTags.isEmpty()) {
throw new AwsException("InvalidArgumentException", "Tags is required.", 400);
@@ -424,7 +432,8 @@ public class GlobalAcceleratorService {
tags.put(resourceArn, existing);
}
- public void untagResource(String resourceArn, List tagKeys) {
+ /** Stores a new map without {@code tagKeys}, one tag call at a time, as {@link #tagResource}. */
+ public synchronized void untagResource(String resourceArn, List tagKeys) {
requireResourceExists(resourceArn);
if (tagKeys == null || tagKeys.isEmpty()) {
throw new AwsException("InvalidArgumentException", "TagKeys is required.", 400);
@@ -434,6 +443,41 @@ public class GlobalAcceleratorService {
tags.put(resourceArn, existing);
}
+ @Override
+ public String namespace() {
+ return "globalaccelerator";
+ }
+
+ /** A request names an accelerator, a listener or an endpoint group by its ARN: nothing to find. */
+ @Override
+ public Optional find(String type, List names, String region) {
+ return Optional.empty();
+ }
+
+ /**
+ * The tags of the accelerator, the listener or the endpoint group whose ARN is {@code arn}, in the request's
+ * account, where the tag handlers read: an ARN of another account names none. The resource is found in place under
+ * the ARN itself, which it and its tags are stored under, as the tag handlers find it, a resource stored before
+ * storage was account-aware included, so tags left for a resource since deleted read nothing. A cross-account
+ * attachment's ARN reads nothing, Floci holding none. Tag calls store a new map, so the read is of one whole set.
+ */
+ @Override
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, "globalaccelerator")) {
+ return Map.of();
+ }
+ String account = regionResolver.getAccountId();
+ if (!AwsArnUtils.parse(arn).accountId().equals(account)) {
+ return Map.of();
+ }
+ StorageBackend resources = arn.contains(ENDPOINT_GROUP_SEGMENT) ? endpointGroups
+ : arn.contains(LISTENER_SEGMENT) ? listeners : accelerators;
+ if (AccountAwareStorageBackend.readInAccount(resources, account, arn).isEmpty()) {
+ return Map.of();
+ }
+ return new LinkedHashMap<>(AccountAwareStorageBackend.readInAccount(tags, account, arn).orElse(Map.of()));
+ }
+
private List listenersOf(String acceleratorArn) {
return listeners.scan(key -> key.startsWith(acceleratorArn + LISTENER_SEGMENT));
}
diff --git a/src/test/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorServiceTest.java b/src/test/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorServiceTest.java
index 683e446c43..17b0e12fbc 100644
--- a/src/test/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorServiceTest.java
+++ b/src/test/java/io/floci/aws/services/globalaccelerator/GlobalAcceleratorServiceTest.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
+import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.globalaccelerator.model.Accelerator;
import io.floci.aws.services.globalaccelerator.model.AcceleratorAttributes;
@@ -12,12 +13,14 @@ import io.floci.aws.services.globalaccelerator.model.EndpointGroup;
import io.floci.aws.services.globalaccelerator.model.Listener;
import io.floci.aws.services.globalaccelerator.model.PortOverride;
import io.floci.aws.services.globalaccelerator.model.PortRange;
+import io.floci.aws.testing.InMemoryStorageFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -51,6 +54,49 @@ class GlobalAcceleratorServiceTest {
service = new GlobalAcceleratorService(storageFactory, regionResolver);
}
+ /**
+ * IAM's lookup reads the tags of the accelerator or the listener the ARN names, as the tag calls leave them, and
+ * nothing for a deleted accelerator, another account's or an unknown ARN.
+ */
+ @Test
+ void storedTagsAreTheTagsOfTheResourceTheArnNames() {
+ Accelerator accelerator = service.createAccelerator("edge", null, null, false, Map.of("team", "web"));
+ String arn = accelerator.getAcceleratorArn();
+ service.tagResource(arn, Map.of("team", "data", "env", "dev"));
+ service.untagResource(arn, List.of("env"));
+ Listener listener = service.createListener(arn, portRange(80, 80), "TCP", null);
+ service.tagResource(listener.getListenerArn(), Map.of("team", "ops"));
+ Accelerator deleted = service.createAccelerator("gone", null, null, false, Map.of("team", "data"));
+ service.deleteAccelerator(deleted.getAcceleratorArn());
+
+ assertEquals("globalaccelerator", service.namespace());
+ assertEquals(Map.of("team", "data"), service.storedTags(arn));
+ assertEquals(Map.of("team", "ops"), service.storedTags(listener.getListenerArn()));
+ assertTrue(service.storedTags(deleted.getAcceleratorArn()).isEmpty());
+ assertTrue(service.storedTags(arn.replace(ACCOUNT, "111122223333")).isEmpty());
+ assertTrue(service.storedTags(arn + "0").isEmpty());
+ assertTrue(service.storedTags("arn:aws:s3:::edge").isEmpty());
+ }
+
+ /** An accelerator stored before storage was account-aware is read in place: the lookup migrates nothing. */
+ @Test
+ void storedTagsReadAPreAccountAwareAcceleratorInPlace() {
+ InMemoryStorage rawAccelerators = new InMemoryStorage<>();
+ InMemoryStorage> rawTags = new InMemoryStorage<>();
+ GlobalAcceleratorService legacyState = new GlobalAcceleratorService(new InMemoryStorageFactory(ACCOUNT)
+ .withStore("globalaccelerator-accelerators.json", rawAccelerators)
+ .withStore("globalaccelerator-tags.json", rawTags), new RegionResolver("us-east-1", ACCOUNT));
+ String arn = "arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/legacy";
+ Accelerator legacy = new Accelerator();
+ legacy.setAcceleratorArn(arn);
+ rawAccelerators.put(arn, legacy);
+ rawTags.put(arn, Map.of("team", "data"));
+
+ assertEquals(Map.of("team", "data"), legacyState.storedTags(arn));
+ assertEquals(Set.of(arn), rawAccelerators.keys());
+ assertEquals(Set.of(arn), rawTags.keys());
+ }
+
@Test
void acceleratorArnCarriesAnEmptyRegionSegment() {
Accelerator accelerator = service.createAccelerator("edge", null, null, null, Map.of());
diff --git a/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java b/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
index 50f0b8b749..7aa39f5b59 100644
--- a/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
@@ -1612,11 +1612,7 @@ class IamRequestResourceEnforcementIntegrationTest {
*/
@Test
void anAcceleratorIsCheckedOnItsArnNotOnAnEndpointGroupOfIt() {
- String arn = adminJson("globalaccelerator", "GlobalAccelerator_V20180706.CreateAccelerator")
- .body("{\"Name\":\"res-accelerator\",\"IdempotencyToken\":\"" + suffix() + "\",\"Enabled\":false}")
- .post("/").then().statusCode(200).extract().path("Accelerator.AcceleratorArn");
- cleanup.register(() -> adminJson("globalaccelerator", "GlobalAccelerator_V20180706.DeleteAccelerator")
- .body("{\"AcceleratorArn\":\"" + arn + "\"}").post("/"));
+ String arn = accelerator(null);
assertTrue(arn.startsWith("arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/"), arn);
User user = user("res-accelerator");
@@ -1632,6 +1628,40 @@ class IamRequestResourceEnforcementIntegrationTest {
.body(not(containsString("not authorized")));
}
+ /**
+ * An {@code aws:ResourceTag} condition reads the tags Global Accelerator holds on the accelerator a request names,
+ * as TagResource leaves them, so an allow on one team's tag lets the caller describe that team's accelerator and
+ * not another's.
+ */
+ @Test
+ void aGlobalAcceleratorResourceTagConditionReadsTheTagsOfTheAccelerator() {
+ String web = "[{\"Key\":\"team\",\"Value\":\"web\"}]";
+ String tagged = accelerator(web);
+ String other = accelerator(web);
+ adminJson("globalaccelerator", "GlobalAccelerator_V20180706.TagResource")
+ .body("{\"ResourceArn\":\"" + tagged + "\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"data\"}]}")
+ .post("/").then().statusCode(200);
+
+ User user = user("res-accelerator-tags");
+ user.policy("{\"Effect\":\"Allow\",\"Action\":\"globalaccelerator:DescribeAccelerator\",\"Resource\":\"*\","
+ + "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
+ send(user, "globalaccelerator", "GlobalAccelerator_V20180706.DescribeAccelerator", "1.1",
+ "{\"AcceleratorArn\":\"" + tagged + "\"}").statusCode(200);
+ refusedJson(send(user, "globalaccelerator", "GlobalAccelerator_V20180706.DescribeAccelerator", "1.1",
+ "{\"AcceleratorArn\":\"" + other + "\"}"), "globalaccelerator:DescribeAccelerator");
+ }
+
+ /** The ARN of a disabled accelerator an administrator creates, with the {@code tags} list if any, deleted after. */
+ private String accelerator(String tags) {
+ String arn = adminJson("globalaccelerator", "GlobalAccelerator_V20180706.CreateAccelerator")
+ .body("{\"Name\":\"res-accelerator\",\"IdempotencyToken\":\"" + suffix() + "\",\"Enabled\":false"
+ + (tags == null ? "" : ",\"Tags\":" + tags) + "}")
+ .post("/").then().statusCode(200).extract().path("Accelerator.AcceleratorArn");
+ cleanup.register(() -> adminJson("globalaccelerator", "GlobalAccelerator_V20180706.DeleteAccelerator")
+ .body("{\"AcceleratorArn\":\"" + arn + "\"}").post("/"));
+ return arn;
+ }
+
/** A Timestream for InfluxDB parameter group is checked on {@code db-parameter-group/}, the id it was given. */
@Test
void aParameterGroupIsCheckedOnTheArnItsIdGives() {