fix(glue): give resource-tag conditions the tags of the Glue resource a request names (#8582)

Since #8529 the generated request resources give Glue's types
aws:ResourceTag/ keys, but no StoredResourceArns answered for the glue
namespace, so a condition on a job's, a connection's or a registry's
tags saw none. GlueStoredResourceArns now answers storedTags from
GlueService.storedTags: a schema registry's or a schema's tags from the
schema registry, any other resource's from the tags applied to its ARN,
which Glue drops when it deletes the resource, each read in the account
and Region the ARN names, a pre-multi-account entry of the default
account in place, through AccountAwareStorageBackend.readInAccount.
Only string values are taken, as TagResource keeps the request's map
as given. Deleting a table or a user-defined function, directly or with
its database, now drops the tags applied to its ARN as Glue's other
deletes do, so one recreated under the same name starts with none.
Tagging a resource through the shared tag store now puts a new tag map
in place of the old one, so the lookup always copies one whole set.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-16 09:44:48 -04:00
1 parent 6eb66cd6bf
commit 2842fe4eeb
12 files changed
+273 -16

No files matched your search

@@ -30,9 +30,9 @@ import java.util.Optional;
* or a change set; S3 Tables, for the table a request names by its table bucket, namespace and name, and the tags of a
* table bucket or a table; Lambda, for the layer version a layer version ARN selects, the image of a MicroVM and the
* execution of a callback, and the tags of a function, an event source mapping, a web function, a MicroVM image or a
* network connector); 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>
* network connector; Glue, for the tags of a resource it tags); 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
@@ -453,8 +453,13 @@ public class GlueService {
.map(Table::getName)
.toList();
tableNames.forEach(tableName -> deleteTable(name, tableName));
List<String> functionArns = functionStore.scan(k -> true).stream()
.filter(function -> databaseName.equals(function.getDatabaseName()))
.map(function -> userDefinedFunctionArn(region, databaseName, function.getFunctionName()))
.toList();
StorageOperations.deleteMatchingAtomically(functionStore,
function -> databaseName.equals(function.getDatabaseName()));
resourceGroupsTaggingService.deleteResources(functionArns, region);
databaseStore.delete(databaseName);
resourceGroupsTaggingService.deleteResources(List.of(databaseArn(region, databaseName)), region);
LOG.infov("Deleted Glue Database: {0}", name);
@@ -806,9 +811,12 @@ public class GlueService {
}
public synchronized void deleteTable(String databaseName, String tableName) {
getTable(databaseName, tableName);
Table table = getTable(databaseName, tableName);
String key = tableKey(databaseName, tableName);
tableStore.delete(key);
String region = regionResolver.getRegion();
resourceGroupsTaggingService.deleteResources(
List.of(tableArn(region, table.getDatabaseName(), table.getName())), region);
tableVersionStore.keys().stream()
.filter(versionKey -> versionKey.startsWith(key + ":"))
.forEach(tableVersionStore::delete);
@@ -1370,8 +1378,11 @@ public class GlueService {
}
public synchronized void deleteUserDefinedFunction(String databaseName, String functionName) {
getUserDefinedFunction(databaseName, functionName);
UserDefinedFunction function = getUserDefinedFunction(databaseName, functionName);
functionStore.delete(functionKey(databaseName, functionName));
String region = regionResolver.getRegion();
resourceGroupsTaggingService.deleteResources(List.of(
userDefinedFunctionArn(region, function.getDatabaseName(), function.getFunctionName())), region);
}
private void validateSchemaReference(Table table) {
@@ -1709,6 +1720,14 @@ public class GlueService {
return regionResolver.buildArn("glue", region, "database/" + databaseName);
}
private String tableArn(String region, String databaseName, String tableName) {
return regionResolver.buildArn("glue", region, "table/" + databaseName + "/" + tableName);
}
private String userDefinedFunctionArn(String region, String databaseName, String functionName) {
return regionResolver.buildArn("glue", region, "userDefinedFunction/" + databaseName + "/" + functionName);
}
private String jobArn(String region, String jobName) {
return regionResolver.buildArn("glue", region, "job/" + jobName);
}
@@ -3238,6 +3257,30 @@ public class GlueService {
}
}
/**
* The tags of the resource stored under {@code arn}, in the account and Region it names: a registry's or a schema's
* from the schema registry, any other resource's from the tags applied to its ARN, which Glue drops when it deletes
* the resource; read in place and empty for an ARN naming nothing tagged. Only string values are tags: TagResource
* keeps the request's map as given.
*/
public Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, "glue")) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
String resource = parsed.resource();
Map<String, ?> applied = resource.startsWith("registry/") || resource.startsWith("schema/")
? schemaRegistryService.storedTags(arn)
: resourceGroupsTaggingService.storedTags(parsed.accountId(), parsed.region(), arn);
Map<String, String> tags = new LinkedHashMap<>();
applied.forEach((key, value) -> {
if (value instanceof String text) {
tags.put(key, text);
}
});
return tags;
}
private void validateArn(String arn) {
if (!AwsArnUtils.looksLikeArn(arn)) {
throw new AwsException("InvalidInputException", "Invalid ARN", 400);
@@ -0,0 +1,37 @@
package io.floci.aws.services.glue;
import io.floci.aws.core.common.StoredResourceArns;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/** What IAM asks Glue of the resources a request names: the tags of the resource an ARN names. */
@ApplicationScoped
public class GlueStoredResourceArns implements StoredResourceArns {
private final GlueService glue;
@Inject
public GlueStoredResourceArns(GlueService glue) {
this.glue = glue;
}
@Override
public String namespace() {
return "glue";
}
/** Glue mints no id into an ARN a request names by its name, so there is nothing to find. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
@Override
public Map<String, String> storedTags(String arn) {
return glue.storedTags(arn);
}
}
@@ -1,9 +1,11 @@
package io.floci.aws.services.glue.schemaregistry;
import com.fasterxml.jackson.core.type.TypeReference;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.Digests;
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.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
@@ -628,6 +630,33 @@ public class GlueSchemaRegistryService {
resource.persist();
}
/**
* A copy of the tags of the registry or the schema stored under {@code arn} in the account it names, matched on the
* whole ARN and read in place; empty for an ARN naming nothing stored, or any other resource.
*/
public Map<String, String> storedTags(String arn) {
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
String resource = parsed.resource();
Map<String, String> tags = null;
if (resource.startsWith("registry/")) {
tags = AccountAwareStorageBackend.readInAccount(registryStore, parsed.accountId(),
resource.substring("registry/".length()))
.filter(registry -> arn.equals(registry.getRegistryArn()))
.map(Registry::getTags)
.orElse(null);
} else if (resource.startsWith("schema/")) {
String[] names = resource.substring("schema/".length()).split("/", 2);
if (names.length == 2) {
tags = AccountAwareStorageBackend.readInAccount(schemaStore, parsed.accountId(),
schemaKey(names[0], names[1]))
.filter(schema -> arn.equals(schema.getSchemaArn()))
.map(Schema::getTags)
.orElse(null);
}
}
return tags == null ? Map.of() : new LinkedHashMap<>(tags);
}
public Map<String, String> getTags(String resourceArn) {
TaggedResource resource = resolveTaggedResource(resourceArn);
Map<String, String> tags = resource.getTags();
@@ -33,7 +33,7 @@ public class Registry {
private Instant updatedTime;
@JsonProperty("Tags")
private Map<String, String> tags;
private volatile Map<String, String> tags;
public Registry() {}
@@ -54,7 +54,7 @@ public class Schema {
private Instant updatedTime;
@JsonProperty("Tags")
private Map<String, String> tags;
private volatile Map<String, String> tags;
public Schema() {}
@@ -9,7 +9,9 @@ import io.floci.aws.core.common.TagHandler;
import io.floci.aws.core.resource.ExplorerResource;
import io.floci.aws.core.resource.ResourceProvider;
import io.floci.aws.core.resource.SupportedResourceType;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackedMap;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.resourcegroupstagging.model.ResourceTagMapping;
import jakarta.annotation.PostConstruct;
@@ -29,6 +31,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -50,6 +53,8 @@ public class ResourceGroupsTaggingService implements Resettable {
// region::arn → ResourceTagMapping
private Map<String, ResourceTagMapping> store = new ConcurrentHashMap<>();
/** The backend of {@link #store}, read in another account than the caller's. */
private StorageBackend<String, ResourceTagMapping> storage;
@Inject
public ResourceGroupsTaggingService(StorageFactory storageFactory,
@@ -80,8 +85,9 @@ public class ResourceGroupsTaggingService implements Resettable {
if (storageFactory == null) {
return; // keeps non-CDI unit tests working
}
this.store = new StorageBackedMap<>(storageFactory.create("tagging",
"tagging-resource-mappings.json", new TypeReference<Map<String, ResourceTagMapping>>() {}));
this.storage = storageFactory.create("tagging",
"tagging-resource-mappings.json", new TypeReference<Map<String, ResourceTagMapping>>() {});
this.store = new StorageBackedMap<>(storage);
}
private String key(String region, String arn) {
@@ -96,6 +102,17 @@ public class ResourceGroupsTaggingService implements Resettable {
return mapping != null ? Collections.unmodifiableMap(mapping.getTags()) : Map.of();
}
/**
* A copy of the tags applied to the resource {@code arn} names, stored in {@code accountId} and {@code region},
* read in place, a pre-multi-account mapping of the default account included; empty when none were applied.
*/
public Map<String, String> storedTags(String accountId, String region, String arn) {
String storeKey = key(region, arn);
Optional<ResourceTagMapping> mapping = storage == null ? Optional.ofNullable(store.get(storeKey))
: AccountAwareStorageBackend.readInAccount(storage, accountId, storeKey);
return mapping.<Map<String, String>>map(stored -> new LinkedHashMap<>(stored.getTags())).orElse(Map.of());
}
// ─── TagResources ──────────────────────────────────────────────────────────
// Mutators are synchronized: StorageBackedMap has no atomic computeIfAbsent, so
@@ -107,7 +124,9 @@ public class ResourceGroupsTaggingService implements Resettable {
if (mapping == null) {
mapping = new ResourceTagMapping(arn);
}
mapping.getTags().putAll(tags);
Map<String, String> next = new LinkedHashMap<>(mapping.getTags());
next.putAll(tags);
mapping.setTags(next);
// Re-put so StorageBackedMap routes the mutation through the backend
store.put(storeKey, mapping);
}
@@ -120,7 +139,9 @@ public class ResourceGroupsTaggingService implements Resettable {
String storeKey = key(region, arn);
ResourceTagMapping mapping = store.get(storeKey);
if (mapping != null) {
tagKeys.forEach(mapping.getTags()::remove);
Map<String, String> next = new LinkedHashMap<>(mapping.getTags());
tagKeys.forEach(next::remove);
mapping.setTags(next);
store.put(storeKey, mapping);
}
}
@@ -11,8 +11,9 @@ import java.util.Map;
public class ResourceTagMapping {
private String resourceArn;
// Preserves insertion order for deterministic responses
private final Map<String, String> tags = new LinkedHashMap<>();
// Preserves insertion order for deterministic responses. A stored mapping's tags are replaced, never changed in
// place, so a reader copying them sees one whole set.
private volatile Map<String, String> tags = new LinkedHashMap<>();
public ResourceTagMapping() {}
@@ -24,4 +25,5 @@ public class ResourceTagMapping {
public void setResourceArn(String resourceArn) { this.resourceArn = resourceArn; }
public Map<String, String> getTags() { return tags; }
public void setTags(Map<String, String> tags) { this.tags = tags == null ? new LinkedHashMap<>() : tags; }
}