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.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 22:19:08 -04:00
1 parent f06695cf08
commit 77565a9c60
9 files changed
+134 -15

No files matched your search

+4 -3
View File
@@ -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
@@ -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<StoredResourceArns>} for
* the namespace a request or an ARN is of, so IAM never depends on that service directly.</p>
* 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<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
@@ -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<String> find(String type, List<String> 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<String, String> 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<Map<String, String>> 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.
@@ -38,7 +38,7 @@ public class DbBackup {
private String influxAuthParametersSecretArn;
private JsonNode maintenanceSchedule;
private JsonNode dbBackupConfigurations;
private Map<String, String> tags = new LinkedHashMap<>();
private volatile Map<String, String> tags = new LinkedHashMap<>();
private String accountId;
private String region;
private boolean dataCaptured;
@@ -36,7 +36,7 @@ public class DbCluster {
private JsonNode dbBackupConfigurations;
private String kmsKeyId;
private Instant createdAt;
private Map<String, String> tags = new LinkedHashMap<>();
private volatile Map<String, String> tags = new LinkedHashMap<>();
private String accountId;
private String region;
private String containerId;
@@ -38,7 +38,7 @@ public class DbInstance {
private String kmsKeyId;
private String engineType;
private Instant createdAt;
private Map<String, String> tags = new LinkedHashMap<>();
private volatile Map<String, String> tags = new LinkedHashMap<>();
private String accountId;
private String region;
private String containerId;
@@ -16,7 +16,7 @@ public class DbParameterGroup {
private JsonNode parameters;
private String engineType;
private Instant createdAt;
private Map<String, String> tags = new LinkedHashMap<>();
private volatile Map<String, String> tags = new LinkedHashMap<>();
public DbParameterGroup() {
}
@@ -1584,10 +1584,8 @@ class IamRequestResourceEnforcementIntegrationTest {
/** A Timestream for InfluxDB parameter group is checked on {@code db-parameter-group/<id>}, 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() {
@@ -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<String, DbParameterGroup> raw = new InMemoryStorage<>();
TimestreamInfluxDbService legacyState = new TimestreamInfluxDbService(
AccountAwareStorageBackend.<DbInstance>inMemory(ACCOUNT),
AccountAwareStorageBackend.<DbCluster>inMemory(ACCOUNT),
new AccountAwareStorageBackend<>(raw, null, ACCOUNT),
AccountAwareStorageBackend.<DbBackup>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();