fix(opensearch): give resource-tag conditions the tags of the domain a request names (#8762)

The generated request resources give OpenSearch's domain type the
aws:ResourceTag/ key, but no service answered the es namespace's stored
tags, so a condition on a domain's tags saw none. OpenSearchService now
answers it: storedTags reads the domain in the request's account, where
the tag handlers read, in place under the key the ARN gives or the name
a domain was stored under before its key named the Region, and matched
on the whole ARN. AddTags and RemoveTags changed the domain's map in
place with no lock; they now give it a new map one call at a time, and
the tags field is volatile.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 12:38:44 -04:00
1 parent 2517edb471
commit 2b3c22a3a5
6 files changed
+120 -11

No files matched your search

@@ -813,6 +813,35 @@ class IamRestRouteEnforcementIntegrationTest {
as(user, "es").get("/2021-01-01/opensearch/domain/other-" + domain).then().statusCode(409);
}
/**
* An {@code aws:ResourceTag} condition reads the tags OpenSearch holds on the domain a request names in its path,
* as a tag call leaves them, so an allow on one team's tag lets the caller describe that team's domain and not
* another's.
*/
@Test
void anOpenSearchResourceTagConditionReadsTheTagsOfTheDomain() {
String tagged = openSearchDomain("web");
String other = openSearchDomain("web");
adminOf("es").body("{\"ARN\":\"arn:aws:es:us-east-1:" + ACCOUNT + ":domain/" + tagged
+ "\",\"TagList\":[{\"Key\":\"team\",\"Value\":\"data\"}]}").post("/2021-01-01/tags").then()
.statusCode(200);
String user = user("route-domain-tags");
policy(user, onTeam("Allow", "es:DescribeDomain", "data"));
request(user, "es", "GET", "/2021-01-01/opensearch/domain/" + tagged, null).statusCode(200);
refused(request(user, "es", "GET", "/2021-01-01/opensearch/domain/" + other, null), "es:DescribeDomain");
}
/** The name of an OpenSearch domain an administrator creates tagged with the team, deleted after the test. */
private String openSearchDomain(String team) {
String name = "route-tags-" + suffix();
adminOf("es").body("{\"DomainName\":\"" + name + "\",\"EngineVersion\":\"OpenSearch_2.11\",\"TagList\":"
+ "[{\"Key\":\"team\",\"Value\":\"" + team + "\"}]}").post("/2021-01-01/opensearch/domain").then()
.statusCode(200);
cleanup.register(() -> adminOf("es").delete("/2021-01-01/opensearch/domain/" + name));
return name;
}
/**
* An Access Analyzer request naming its analyzer, in its path or its body, is checked on that analyzer, the ARN
* Access Analyzer gives it: a caller with no grant is refused, a grant scoped to the analyzer lets
@@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@@ -215,6 +216,37 @@ class OpenSearchServiceTest {
assertEquals(EU_WEST_1, service.describeDomain("dual-region", EU_WEST_1).getRegion());
}
/**
* IAM's tag lookup reads the tags of the domain whose ARN it is given, as tag calls leave them, a tag call giving
* the domain a new map rather than changing the one a reader holds, and those of one stored under its name from
* before keys named the Region, in place, without migrating it; nothing for an ARN of another account or Region, or
* of no domain.
*/
@Test
void storedTagsAreTheTagsOfTheDomainTheArnNamesAndTaggingPutsANewMap() {
when(domainManager.tryStartDomain(any())).thenReturn(false);
String arn = service.createDomain("tagged", "OpenSearch_2.11", null, null, Map.of("env", "dev"), US_EAST_1)
.getArn();
Map<String, String> held = service.listTags(arn);
service.addTags(arn, Map.of("team", "data"));
service.removeTags(arn, List.of("env"));
String legacyArn = AwsArnUtils.Arn.of("es", US_EAST_1, ACCOUNT, "domain/legacy").toString();
Domain legacy = new Domain();
legacy.setDomainName("legacy");
legacy.setArn(legacyArn);
legacy.setTags(Map.of("tier", "web"));
domainStore.putForAccount(ACCOUNT, "legacy", legacy);
assertEquals(Map.of("env", "dev"), held);
assertEquals(Map.of("team", "data"), service.storedTags(arn));
assertEquals(Map.of("tier", "web"), service.storedTags(legacyArn));
assertTrue(domainStore.getForAccount(ACCOUNT, "legacy").isPresent());
assertEquals(Map.of(), service.storedTags(arn.replace(":" + ACCOUNT + ":", ":111122223333:")));
assertEquals(Map.of(), service.storedTags(arn.replace(":" + US_EAST_1 + ":", ":" + EU_WEST_1 + ":")));
assertEquals(Map.of(), service.storedTags(arn + "0"));
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::tagged"));
}
@Test
void sameNameInTheSameRegionStillConflicts() {
when(domainManager.tryStartDomain(any())).thenReturn(false);