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

@@ -45,9 +45,9 @@ import java.util.Optional;
* key value store a name names and the tags of any resource it tags; ECS, for the revision a task definition
* reference resolves to, its default cluster and the tags of a cluster, a task definition, a service, a capacity
* provider, a task or a container instance; ACM, for the tags of a certificate; Firehose, for the tags of a delivery
* stream; Cognito, for the tags of a user pool); looked up lazily by {@code ResourceArnBuilder} and
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
* ARN is of, so IAM never depends on that service directly.</p>
* stream; Cognito, for the tags of a user pool; OpenSearch, for the tags of a domain); looked up lazily by
* {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for
* the namespace a request or an ARN is of, so IAM never depends on that service directly.</p>
*
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
@@ -6,6 +6,7 @@ import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.AwsRegions;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.StoredResourceArns;
import io.floci.aws.core.common.docker.ContainerStorageHelper;
import io.floci.aws.core.resource.ExplorerResource;
import io.floci.aws.core.resource.ResourceProvider;
@@ -33,6 +34,7 @@ import java.security.SecureRandom;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -50,7 +52,7 @@ import java.util.concurrent.TimeUnit;
* region from the domain's ARN, which has always carried it.
*/
@ApplicationScoped
public class OpenSearchService implements ResourceProvider {
public class OpenSearchService implements ResourceProvider, StoredResourceArns {
private static final Logger LOG = Logger.getLogger(OpenSearchService.class);
@@ -352,9 +354,12 @@ public class OpenSearchService implements ResourceProvider {
return domain;
}
public void addTags(String arn, Map<String, String> tags) {
/** Gives the domain a new map, its tags with {@code tags} added, one tag call at a time. */
public synchronized void addTags(String arn, Map<String, String> tags) {
Domain domain = findByArn(arn);
domain.getTags().putAll(tags);
Map<String, String> merged = new HashMap<>(domain.getTags());
merged.putAll(tags);
domain.setTags(merged);
putDomain(domain);
}
@@ -362,12 +367,55 @@ public class OpenSearchService implements ResourceProvider {
return findByArn(arn).getTags();
}
public void removeTags(String arn, List<String> tagKeys) {
/** Gives the domain a new map, its tags without {@code tagKeys}, one tag call at a time. */
public synchronized void removeTags(String arn, List<String> tagKeys) {
Domain domain = findByArn(arn);
tagKeys.forEach(domain.getTags()::remove);
Map<String, String> kept = new HashMap<>(domain.getTags());
tagKeys.forEach(kept::remove);
domain.setTags(kept);
putDomain(domain);
}
@Override
public String namespace() {
return "es";
}
/** A request names a domain by its name, which its ARN carries whole, so there is nothing to find. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
/**
* The tags of the domain whose ARN is {@code arn}, in the request's account, where the tag handlers read: an ARN of
* another account names none. Read in place under the key the ARN gives, or the name a domain was stored under
* before its key named the Region, a record from before storage was account-aware included, as {@link #findByArn}
* finds it, and matched on the whole ARN. A tag call stores a new map, so the read is of one whole set.
*/
@Override
public Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, "es")) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
String account = parsed.accountId();
if (!account.equals(regionResolver.getAccountId()) || !parsed.resource().startsWith("domain/")) {
return Map.of();
}
String domainName = parsed.resource().substring("domain/".length());
Map<String, String> tags = new LinkedHashMap<>();
AccountAwareStorageBackend.readInAccount(domainStore, account, storageKey(parsed.region(), domainName))
.or(() -> AccountAwareStorageBackend.readInAccount(domainStore, account, domainName))
.filter(domain -> arn.equals(domain.getArn()))
.ifPresent(domain -> domain.getTags().forEach((key, value) -> {
if (key != null && value != null) {
tags.put(key, value);
}
}));
return tags;
}
public Domain upgradeDomain(String domainName, String targetVersion, String region) {
Domain domain = describeDomain(domainName, region);
if (targetVersion == null || targetVersion.isBlank()) {
@@ -81,7 +81,7 @@ public class Domain {
private String endpoint = "";
@JsonProperty("Tags")
private Map<String, String> tags = new HashMap<>();
private volatile Map<String, String> tags = new HashMap<>();
@JsonProperty("ContainerId")
private String containerId;