From 30c37a129cb4bf71cb72e8fd7a9502aedb2f3b07 Mon Sep 17 00:00:00 2001
From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
Date: Fri, 20 Nov 2026 17:24:41 -0400
Subject: [PATCH] fix(bcm-pricing-calculator): give resource-tag conditions the
tags of the workload estimate a request names (#9112)
The generated request resources give Pricing Calculator's workload
estimate type the aws:ResourceTag/ key, but no service answered the bcm-
pricing-calculator namespace's stored tags, so a condition on an
estimate's tags saw none. BcmPricingCalculatorService now answers it: a
workload estimate records no ARN, so storedTags takes the ARN only when
it is the one the estimate's account and id give in the request's
partition, which has no Region, then reads the estimate by its id, in
the request's account, in place. An estimate's tags are the ones it was
created with, which nothing changes. The package now builds that ARN to
compare, so partition/smoke-exemptions.tsv gets a row saying why it
needs no partition smoke case.
---
docs/services/iam.md | 6 +-
.../aws/core/common/StoredResourceArns.java | 6 +-
.../BcmPricingCalculatorService.java | 42 ++++++++++++-
.../BcmPricingCalculatorStoredTagsTest.java | 61 +++++++++++++++++++
...estResourceEnforcementIntegrationTest.java | 29 +++++++++
.../resources/partition/smoke-exemptions.tsv | 1 +
6 files changed, 138 insertions(+), 7 deletions(-)
create mode 100644 src/test/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorStoredTagsTest.java
diff --git a/docs/services/iam.md b/docs/services/iam.md
index eba7f57ccc..b88e6ad648 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -3540,9 +3540,9 @@ floci populates:
Load Balancing for its load balancers, target groups, listeners and rules and its Classic Load Balancers, SQS for its
queues, SNS for its topics, Kinesis Data Streams for its streams and consumers, EventBridge Pipes for its pipes,
Aurora DSQL for its clusters, EKS for its clusters, node groups, Fargate profiles, add-ons, Pod Identity
- associations and access entries, Resource Groups for its groups and CloudWatch Logs for its log groups,
- destinations, delivery sources, delivery destinations and deliveries. Tag keys differing only in case are one
- condition key holding every value.
+ associations and access entries, Resource Groups for its groups, CloudWatch Logs for its log groups,
+ destinations, delivery sources, delivery destinations and deliveries, and Pricing Calculator for its workload
+ estimates. 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 f583ab918f..627393e01d 100644
--- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
+++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
@@ -63,9 +63,9 @@ import java.util.Optional;
* for the tags of a cluster; EKS, for the tags of a cluster, a node group, a Fargate profile, an add-on, a Pod Identity
* association or an access entry; Resource Groups, for the tags of a group; CloudWatch Logs, for a delivery, the
* delivery destinations of a delivery source and the tags of a log group, a destination, a delivery source, a
- * delivery destination or a delivery); 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.
+ * delivery destination or a delivery; Pricing Calculator, for the tags of a workload estimate); 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/bcmpricingcalculator/BcmPricingCalculatorService.java b/src/main/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorService.java
index d4204d7761..fde2560bac 100644
--- a/src/main/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorService.java
+++ b/src/main/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorService.java
@@ -4,9 +4,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.core.common.StoredResourceArns;
import io.floci.aws.core.common.UuidShapes;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.bcmpricingcalculator.model.WorkloadEstimate;
@@ -22,11 +25,12 @@ import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
import java.util.regex.Pattern;
@ApplicationScoped
-public class BcmPricingCalculatorService {
+public class BcmPricingCalculatorService implements StoredResourceArns {
private static final Pattern NAME = Pattern.compile("[a-zA-Z0-9-]+");
private static final Pattern ACCOUNT = Pattern.compile("\\d{12}");
private static final List RATE_TYPES = List.of(
@@ -37,6 +41,9 @@ public class BcmPricingCalculatorService {
public record UsageError(String key, String errorCode, String errorMessage) {}
public record UsageBatchResult(List items, List errors) {}
+ private static final String NAMESPACE = "bcm-pricing-calculator";
+ private static final String WORKLOAD_ESTIMATE = "workload-estimate/";
+
private final StorageBackend estimates;
private final StorageBackend usages;
private final RegionResolver regionResolver;
@@ -102,6 +109,39 @@ public class BcmPricingCalculatorService {
return estimate;
}
+ @Override
+ public String namespace() {
+ return NAMESPACE;
+ }
+
+ /** A request names a workload estimate by its id: nothing to find. */
+ @Override
+ public Optional find(String type, List names, String region) {
+ return Optional.empty();
+ }
+
+ /**
+ * The tags of the workload estimate whose ARN is {@code arn}, in the request's account, where the handlers read: an
+ * ARN of another account names none. A workload estimate records no ARN, so the ARN has to be the one its account
+ * and id give in the request's partition, which has no Region; the estimate is read in place by its id, one stored
+ * before storage was account-aware included. Its tags are the ones it was created with, which nothing changes.
+ */
+ @Override
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, NAMESPACE)) {
+ return Map.of();
+ }
+ String account = regionResolver.getAccountId();
+ String resource = AwsArnUtils.parse(arn).resource();
+ if (!resource.startsWith(WORKLOAD_ESTIMATE)
+ || !arn.equals(regionResolver.buildGlobalArn(NAMESPACE, account, resource))) {
+ return Map.of();
+ }
+ return new LinkedHashMap<>(AccountAwareStorageBackend
+ .readInAccount(estimates, account, resource.substring(WORKLOAD_ESTIMATE.length()))
+ .map(WorkloadEstimate::getTags).orElse(Map.of()));
+ }
+
public WorkloadEstimate get(String id) {
validateId(id);
return estimates.get(id).orElseThrow(() -> notFound(id));
diff --git a/src/test/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorStoredTagsTest.java b/src/test/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorStoredTagsTest.java
new file mode 100644
index 0000000000..a1da35c5c1
--- /dev/null
+++ b/src/test/java/io/floci/aws/services/bcmpricingcalculator/BcmPricingCalculatorStoredTagsTest.java
@@ -0,0 +1,61 @@
+package io.floci.aws.services.bcmpricingcalculator;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.core.storage.InMemoryStorage;
+import io.floci.aws.services.bcmpricingcalculator.model.WorkloadEstimate;
+import io.floci.aws.testing.InMemoryStorageFactory;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** IAM's lookup of the tags Pricing Calculator holds on a workload estimate. */
+class BcmPricingCalculatorStoredTagsTest {
+
+ private static final String REGION = "us-east-1";
+ private static final String ACCOUNT = "000000000000";
+ private static final String ESTIMATES = "arn:aws:bcm-pricing-calculator::000000000000:workload-estimate/";
+
+ /**
+ * The lookup reads the tags a workload estimate was created with, under the ARN its account and id give, which has
+ * no Region, and nothing for another account's, a regional, another partition's, an unknown estimate's or another
+ * service's ARN.
+ */
+ @Test
+ void storedTagsAreTheTagsOfTheWorkloadEstimateTheArnNames() {
+ BcmPricingCalculatorService service = service(new InMemoryStorageFactory(ACCOUNT));
+ String id = service.create("stored-tags", null, null, Map.of("team", "data")).getId();
+
+ assertEquals("bcm-pricing-calculator", service.namespace());
+ assertEquals(Map.of("team", "data"), service.storedTags(ESTIMATES + id));
+ assertTrue(service.storedTags((ESTIMATES + id).replace(ACCOUNT, "111122223333")).isEmpty());
+ assertTrue(service.storedTags((ESTIMATES + id).replace("calculator::", "calculator:" + REGION + ":"))
+ .isEmpty());
+ assertTrue(service.storedTags((ESTIMATES + id).replace("arn:aws:", "arn:aws-cn:")).isEmpty());
+ assertTrue(service.storedTags(ESTIMATES + "00000000-0000-0000-0000-000000000000").isEmpty());
+ assertTrue(service.storedTags("arn:aws:ec2:us-east-1:000000000000:instance/i-0123456789abcdef0").isEmpty());
+ }
+
+ /** A workload estimate stored before storage was account-aware is read in place: the lookup migrates nothing. */
+ @Test
+ void storedTagsReadAPreAccountAwareEstimateInPlace() {
+ InMemoryStorage raw = new InMemoryStorage<>();
+ BcmPricingCalculatorService service =
+ service(new InMemoryStorageFactory(ACCOUNT).withStore("workload-estimates.json", raw));
+ WorkloadEstimate legacy = new WorkloadEstimate();
+ legacy.setId("legacy-estimate");
+ legacy.setTags(Map.of("team", "data"));
+ raw.put("legacy-estimate", legacy);
+
+ assertEquals(Map.of("team", "data"), service.storedTags(ESTIMATES + "legacy-estimate"));
+ assertEquals(Set.of("legacy-estimate"), raw.keys());
+ }
+
+ private BcmPricingCalculatorService service(InMemoryStorageFactory storage) {
+ return new BcmPricingCalculatorService(storage, new RegionResolver(REGION, ACCOUNT), null, new ObjectMapper());
+ }
+}
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 3052e04e84..9ef4dc95ed 100644
--- a/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
@@ -1758,6 +1758,35 @@ class IamRequestResourceEnforcementIntegrationTest {
"{\"identifier\":\"" + UUID.randomUUID() + "\"}"), "bcm-pricing-calculator:GetWorkloadEstimate");
}
+ /**
+ * An {@code aws:ResourceTag} condition reads the tags Pricing Calculator holds on the workload estimate a request
+ * names by its id, the ones it was created with, so an allow on one team's tag lets the caller read that team's
+ * estimate and not another's.
+ */
+ @Test
+ void aPricingCalculatorResourceTagConditionReadsTheTagsOfTheWorkloadEstimate() {
+ String tagged = workloadEstimate("data");
+ String other = workloadEstimate("web");
+
+ User user = user("res-estimate-team");
+ user.policy("{\"Effect\":\"Allow\",\"Action\":\"bcm-pricing-calculator:GetWorkloadEstimate\","
+ + "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
+ send(user, "bcm-pricing-calculator", "AWSBCMPricingCalculator.GetWorkloadEstimate", "1.0",
+ "{\"identifier\":\"" + tagged + "\"}").statusCode(200);
+ refusedJson(send(user, "bcm-pricing-calculator", "AWSBCMPricingCalculator.GetWorkloadEstimate", "1.0",
+ "{\"identifier\":\"" + other + "\"}"), "bcm-pricing-calculator:GetWorkloadEstimate");
+ }
+
+ /** A workload estimate an administrator creates, tagged with {@code team}, deleted after the test; its id. */
+ private String workloadEstimate(String team) {
+ String id = adminJson("bcm-pricing-calculator", "AWSBCMPricingCalculator.CreateWorkloadEstimate", "1.0")
+ .body("{\"name\":\"res-estimate-" + team + "\",\"clientToken\":\"" + suffix() + "\",\"tags\":"
+ + "{\"team\":\"" + team + "\"}}").post("/").then().statusCode(200).extract().path("id");
+ cleanup.register(() -> adminJson("bcm-pricing-calculator", "AWSBCMPricingCalculator.DeleteWorkloadEstimate",
+ "1.0").body("{\"identifier\":\"" + id + "\"}").post("/").then().statusCode(200));
+ return id;
+ }
+
/**
* A Cost Explorer anomaly monitor or subscription is checked on its ARN, which carries no Region, and a list of
* them on each ARN its list gives.
diff --git a/src/test/resources/partition/smoke-exemptions.tsv b/src/test/resources/partition/smoke-exemptions.tsv
index 8621d15d81..2b89de47a9 100644
--- a/src/test/resources/partition/smoke-exemptions.tsv
+++ b/src/test/resources/partition/smoke-exemptions.tsv
@@ -5,6 +5,7 @@
account the one ARN it builds is the member account an IAM check names, in the partition of the caller's organization's own ARN, and it never reaches the wire, so a case has nothing to assert
appintegrations no non-commercial partition publishes the service, so a case would be skipped in every partition
athena the only ARNs it builds are the default workgroup and data catalog an IAM check names for a request naming none, in the request Region's partition, and they never reach the wire, so a case has nothing to assert
+bcmpricingcalculator the only ARN it builds is the workload estimate's own, in the request's partition, which an IAM tag lookup compares against the ARN a request names, and it never reaches the wire, so a case has nothing to assert
budgets the only ARN it builds is the budget's or budget action's own, in the request's partition, which an IAM tag lookup compares against the ARN a request names, and it never reaches the wire, so a case has nothing to assert
cloudformation covered by PartitionArnMintingIntegrationTest (all partitions)
cloudhsmv2 the only ARN on the wire is the automatic backup's, and a backup is never removed (DeleteBackup only marks it), so a case would leak state into the shared emulator