From 77565a9c60a4c3d421a37d9bc5faba2e5bf34bc2 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:19:08 -0400 Subject: [PATCH] fix(timestream-influxdb): give resource-tag conditions the tags of the resource a request names (#8803) The generated request resources give Timestream for InfluxDB's db-instance, db-cluster, db-parameter-group and db-backup types the aws:ResourceTag/ key, but no service answered the timestream-influxdb namespace's stored tags, so a condition on such a resource's tags saw none. TimestreamInfluxDbService now answers it: storedTags reads the resource the ARN's type and id name, under the Region the ARN names, in the request's account, where the handlers read, in place, and matched on the whole ARN. Tag calls already run one at a time and give the resource a new map; the tags fields are now volatile. --- docs/services/iam.md | 7 +-- .../aws/core/common/StoredResourceArns.java | 7 +-- .../TimestreamInfluxDbService.java | 41 +++++++++++++++- .../timestreaminfluxdb/model/DbBackup.java | 2 +- .../timestreaminfluxdb/model/DbCluster.java | 2 +- .../timestreaminfluxdb/model/DbInstance.java | 2 +- .../model/DbParameterGroup.java | 2 +- ...estResourceEnforcementIntegrationTest.java | 39 +++++++++++++-- .../TimestreamInfluxDbServiceTest.java | 47 +++++++++++++++++++ 9 files changed, 134 insertions(+), 15 deletions(-) diff --git a/docs/services/iam.md b/docs/services/iam.md index 4819e7473b..0b4876763b 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -3315,9 +3315,10 @@ floci populates: Payment Cryptography for its keys, Resource Explorer for its indexes and views, Application Auto Scaling for its scalable targets, ECS for its clusters, task definitions, services, capacity providers, tasks and container instances, ACM for its certificates, Firehose for its delivery streams, Cognito for its user pools and identity - pools, OpenSearch for its domains, Signer for its signing profiles, Access Analyzer for its analyzers, Managed - Service for Apache Flink for its applications, and S3 Vectors for its vector buckets and indexes. Tag keys differing - only in case are one condition key holding every value. + pools, OpenSearch for its domains, Signer for its signing profiles, Access Analyzer for its analyzers, Managed Service + for Apache Flink for its applications, S3 Vectors for its vector buckets and indexes, and Timestream for InfluxDB for + its DB instances, DB clusters, parameter groups and backups. 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 abd94907e2..396335d63e 100644 --- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java +++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java @@ -47,9 +47,10 @@ import java.util.Optional; * 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 or an identity pool; OpenSearch, for the tags of a domain; Signer, for * the tags of a signing profile; Access Analyzer, for the tags of an analyzer; Managed Service for Apache Flink, for - * the tags of an application; S3 Vectors, for the tags of a vector bucket or an index); 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.

+ * the tags of an application; S3 Vectors, for the tags of a vector bucket or an index; Timestream for InfluxDB, for the + * tags of a DB instance, a DB cluster, a parameter group or a backup); 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.

* *

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 diff --git a/src/main/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbService.java b/src/main/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbService.java index 0720d3e7a2..b2072619fd 100644 --- a/src/main/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbService.java +++ b/src/main/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbService.java @@ -10,6 +10,7 @@ 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.Resettable; +import io.floci.aws.core.common.StoredResourceArns; import io.floci.aws.core.storage.AccountAwareStorageBackend; import io.floci.aws.core.storage.StorageFactory; import io.floci.aws.services.secretsmanager.SecretsManagerService; @@ -50,7 +51,7 @@ import static io.floci.aws.services.timestreaminfluxdb.TimestreamInfluxDbValidat import static io.floci.aws.services.timestreaminfluxdb.TimestreamInfluxDbValidation.validation; @ApplicationScoped -public class TimestreamInfluxDbService implements Resettable { +public class TimestreamInfluxDbService implements Resettable, StoredResourceArns { static final String ENGINE_V2 = "INFLUXDB_V2"; static final String ENGINE_V3_CORE = "INFLUXDB_V3_CORE"; @@ -785,6 +786,44 @@ public class TimestreamInfluxDbService implements Resettable { saveTags(arn, tags); } + @Override + public String namespace() { + return "timestream-influxdb"; + } + + /** A request names a resource by the id Timestream for InfluxDB minted, which its ARN ends in: nothing to find. */ + @Override + public Optional find(String type, List names, String region) { + return Optional.empty(); + } + + /** + * The tags of the DB instance, DB cluster, parameter group or backup whose ARN is {@code arn}, in the request's + * account, where the handlers read: an ARN of another account names none. Read in place under the Region the ARN + * names and the resource's id, a resource stored before storage was account-aware included, and matched on the + * whole ARN. Tag calls run one at a time and give the resource a new map, so the read is of one whole set. + */ + @Override + public Map storedTags(String arn) { + Matcher matcher = arn == null ? null : TimestreamInfluxDbValidation.ARN.matcher(arn); + if (matcher == null || !matcher.matches() || !matcher.group(2).equals(regionResolver.getAccountId())) { + return Map.of(); + } + String account = matcher.group(2); + String storageKey = key(matcher.group(1), matcher.group(4)); + Optional> tags = switch (matcher.group(3)) { + case "db-instance" -> AccountAwareStorageBackend.readInAccount(instances, account, storageKey) + .filter(instance -> arn.equals(instance.getArn())).map(DbInstance::getTags); + case "db-cluster" -> AccountAwareStorageBackend.readInAccount(clusters, account, storageKey) + .filter(cluster -> arn.equals(cluster.getArn())).map(DbCluster::getTags); + case "db-parameter-group" -> AccountAwareStorageBackend.readInAccount(parameterGroups, account, storageKey) + .filter(group -> arn.equals(group.getArn())).map(DbParameterGroup::getTags); + default -> AccountAwareStorageBackend.readInAccount(backups, account, storageKey) + .filter(backup -> arn.equals(backup.getArn())).map(DbBackup::getTags); + }; + return new LinkedHashMap<>(tags.orElse(Map.of())); + } + /** * Starts the InfluxDB containers of resources persisted by a previous run. Their volumes still * hold the data and CLI configuration, so the image skips its setup mode and needs no credentials. diff --git a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbBackup.java b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbBackup.java index 45dddeee88..773c534f26 100644 --- a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbBackup.java +++ b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbBackup.java @@ -38,7 +38,7 @@ public class DbBackup { private String influxAuthParametersSecretArn; private JsonNode maintenanceSchedule; private JsonNode dbBackupConfigurations; - private Map tags = new LinkedHashMap<>(); + private volatile Map tags = new LinkedHashMap<>(); private String accountId; private String region; private boolean dataCaptured; diff --git a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbCluster.java b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbCluster.java index 583c2e2614..619bc8db6d 100644 --- a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbCluster.java +++ b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbCluster.java @@ -36,7 +36,7 @@ public class DbCluster { private JsonNode dbBackupConfigurations; private String kmsKeyId; private Instant createdAt; - private Map tags = new LinkedHashMap<>(); + private volatile Map tags = new LinkedHashMap<>(); private String accountId; private String region; private String containerId; diff --git a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbInstance.java b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbInstance.java index f26cb69d30..fdc2d0bfe5 100644 --- a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbInstance.java +++ b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbInstance.java @@ -38,7 +38,7 @@ public class DbInstance { private String kmsKeyId; private String engineType; private Instant createdAt; - private Map tags = new LinkedHashMap<>(); + private volatile Map tags = new LinkedHashMap<>(); private String accountId; private String region; private String containerId; diff --git a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbParameterGroup.java b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbParameterGroup.java index b391fd9b82..5776ccedf2 100644 --- a/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbParameterGroup.java +++ b/src/main/java/io/floci/aws/services/timestreaminfluxdb/model/DbParameterGroup.java @@ -16,7 +16,7 @@ public class DbParameterGroup { private JsonNode parameters; private String engineType; private Instant createdAt; - private Map tags = new LinkedHashMap<>(); + private volatile Map tags = new LinkedHashMap<>(); public DbParameterGroup() { } 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 44f60cc41d..000015d78c 100644 --- a/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java @@ -1584,10 +1584,8 @@ class IamRequestResourceEnforcementIntegrationTest { /** A Timestream for InfluxDB parameter group is checked on {@code db-parameter-group/}, the id it was given. */ @Test void aParameterGroupIsCheckedOnTheArnItsIdGives() { - String id = adminJson("timestream-influxdb", "AmazonTimestreamInfluxDB.CreateDbParameterGroup", "1.0") - .body("{\"name\":\"res-group-" + suffix() + "\"}").post("/").then().statusCode(200).extract() - .path("id"); - String arn = "arn:aws:timestream-influxdb:" + REGION + ":" + ACCOUNT + ":db-parameter-group/" + id; + String id = influxParameterGroup(null); + String arn = influxParameterGroupArn(id); User user = user("res-group"); user.policy(allowOn("timestream-influxdb:GetDbParameterGroup", arn)); @@ -1597,6 +1595,39 @@ class IamRequestResourceEnforcementIntegrationTest { "{\"identifier\":\"res" + suffix() + "\"}"), "timestream-influxdb:GetDbParameterGroup"); } + /** + * An {@code aws:ResourceTag} condition reads the tags Timestream for InfluxDB holds on the resource a request + * names, as TagResource leaves them, so an allow on one team's tag lets the caller read that team's parameter group + * and not another's. + */ + @Test + void aTimestreamInfluxDbResourceTagConditionReadsTheTagsOfTheParameterGroup() { + String tagged = influxParameterGroup("{\"team\":\"web\"}"); + String other = influxParameterGroup("{\"team\":\"web\"}"); + adminJson("timestream-influxdb", "AmazonTimestreamInfluxDB.TagResource", "1.0") + .body("{\"resourceArn\":\"" + influxParameterGroupArn(tagged) + "\",\"tags\":{\"team\":\"data\"}}") + .post("/").then().statusCode(200); + + User user = user("res-group-tags"); + user.policy("{\"Effect\":\"Allow\",\"Action\":\"timestream-influxdb:GetDbParameterGroup\",\"Resource\":\"*\"," + + "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}"); + send(user, "timestream-influxdb", "AmazonTimestreamInfluxDB.GetDbParameterGroup", "1.0", + "{\"identifier\":\"" + tagged + "\"}").statusCode(200); + refusedJson(send(user, "timestream-influxdb", "AmazonTimestreamInfluxDB.GetDbParameterGroup", "1.0", + "{\"identifier\":\"" + other + "\"}"), "timestream-influxdb:GetDbParameterGroup"); + } + + /** The id of a parameter group an administrator creates, with the {@code tags} object if any. */ + private static String influxParameterGroup(String tags) { + return adminJson("timestream-influxdb", "AmazonTimestreamInfluxDB.CreateDbParameterGroup", "1.0") + .body("{\"name\":\"res-group-" + suffix() + "\"" + (tags == null ? "" : ",\"tags\":" + tags) + "}") + .post("/").then().statusCode(200).extract().path("id"); + } + + private static String influxParameterGroupArn(String id) { + return "arn:aws:timestream-influxdb:" + REGION + ":" + ACCOUNT + ":db-parameter-group/" + id; + } + /** A Timestream for InfluxDB cluster reboot is checked on each member instance its {@code instanceIds} names. */ @Test void aClusterRebootIsCheckedOnTheInstancesItNames() { diff --git a/src/test/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbServiceTest.java b/src/test/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbServiceTest.java index cdde600040..51735f98d3 100644 --- a/src/test/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbServiceTest.java +++ b/src/test/java/io/floci/aws/services/timestreaminfluxdb/TimestreamInfluxDbServiceTest.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.services.secretsmanager.SecretsManagerService; import io.floci.aws.services.secretsmanager.model.Secret; import io.floci.aws.services.timestreaminfluxdb.TimestreamInfluxDbService.RestoreResult; @@ -24,6 +25,7 @@ import org.mockito.ArgumentCaptor; 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.assertNull; @@ -339,6 +341,51 @@ class TimestreamInfluxDbServiceTest { verify(containerManager).restore("container-1", backupId); } + /** + * IAM's lookup reads the tags of the resource the ARN names, as the tag calls leave them, and nothing for another + * account's, another Region's or an unknown resource. + */ + @Test + void storedTagsAreTheTagsOfTheResourceTheArnNames() throws Exception { + DbInstance instance = createInstance("tagged-db", null); + String instanceArn = instance.getArn(); + service.tagResource(json("{\"resourceArn\":\"" + instanceArn + + "\",\"tags\":{\"team\":\"data\",\"env\":\"dev\"}}")); + service.untagResource(json("{\"resourceArn\":\"" + instanceArn + "\",\"tagKeys\":[\"env\"]}")); + DbParameterGroup group = service.createDbParameterGroup( + json("{\"name\":\"tagged-group\",\"tags\":{\"team\":\"web\"}}"), REGION); + + assertEquals("timestream-influxdb", service.namespace()); + assertEquals(Map.of("team", "data"), service.storedTags(instanceArn)); + assertEquals(Map.of("team", "web"), service.storedTags(group.getArn())); + assertTrue(service.storedTags(instanceArn.replace(ACCOUNT, "111122223333")).isEmpty()); + assertTrue(service.storedTags(instanceArn.replace(REGION, "us-west-2")).isEmpty()); + assertTrue(service.storedTags(instanceArn.replace("db-instance/", "db-cluster/")).isEmpty()); + assertTrue(service.storedTags(group.getArn().replace(group.getId(), "missing123")).isEmpty()); + assertTrue(service.storedTags("arn:aws:timestream:us-east-1:000000000000:database/db").isEmpty()); + } + + /** A parameter group stored before storage was account-aware is read in place: the lookup migrates nothing. */ + @Test + void storedTagsReadAPreAccountAwareRecordInPlace() { + InMemoryStorage raw = new InMemoryStorage<>(); + TimestreamInfluxDbService legacyState = new TimestreamInfluxDbService( + AccountAwareStorageBackend.inMemory(ACCOUNT), + AccountAwareStorageBackend.inMemory(ACCOUNT), + new AccountAwareStorageBackend<>(raw, null, ACCOUNT), + AccountAwareStorageBackend.inMemory(ACCOUNT), + new RegionResolver(REGION, ACCOUNT), mock(SecretsManagerService.class), objectMapper, containerManager, + true, Runnable::run); + DbParameterGroup legacy = new DbParameterGroup(); + legacy.setId("legacy1234"); + legacy.setArn("arn:aws:timestream-influxdb:us-east-1:000000000000:db-parameter-group/legacy1234"); + legacy.setTags(Map.of("team", "data")); + raw.put(REGION + ":legacy1234", legacy); + + assertEquals(Map.of("team", "data"), legacyState.storedTags(legacy.getArn())); + assertEquals(Set.of(REGION + ":legacy1234"), raw.keys()); + } + @Test void tagsBeyondTheQuotaAreRejected() throws Exception { String arn = createInstance("quota-db", null).getArn();