mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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.
This commit is contained in:
1 parent
3027145979
commit
30c37a129c
6 files changed
+138
-7
No files matched your search
+61
@@ -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<String, WorkloadEstimate> 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());
|
||||
}
|
||||
}
|
||||
+29
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user