mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(globalaccelerator): give resource-tag conditions the tags of the accelerator a request names (#8847)
The generated request resources give Global Accelerator's accelerator, listener and endpointgroup types the aws:ResourceTag/ key, but no service answered the globalaccelerator namespace's stored tags, so a condition on their tags saw none. GlobalAcceleratorService now answers it: it finds the resource under the ARN itself, in the request's account, in place, as the tag handlers do, and reads the tags stored under that ARN. TagResource and UntagResource now run one at a time, so two tag calls never lose one's tags.
This commit is contained in:
1 parent
f89fa536f0
commit
e5ddc9fffc
5 files changed
+132
-11
No files matched your search
+46
@@ -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.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.globalaccelerator.model.Accelerator;
|
||||
import io.floci.aws.services.globalaccelerator.model.AcceleratorAttributes;
|
||||
@@ -12,12 +13,14 @@ import io.floci.aws.services.globalaccelerator.model.EndpointGroup;
|
||||
import io.floci.aws.services.globalaccelerator.model.Listener;
|
||||
import io.floci.aws.services.globalaccelerator.model.PortOverride;
|
||||
import io.floci.aws.services.globalaccelerator.model.PortRange;
|
||||
import io.floci.aws.testing.InMemoryStorageFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.assertFalse;
|
||||
@@ -51,6 +54,49 @@ class GlobalAcceleratorServiceTest {
|
||||
service = new GlobalAcceleratorService(storageFactory, regionResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* IAM's lookup reads the tags of the accelerator or the listener the ARN names, as the tag calls leave them, and
|
||||
* nothing for a deleted accelerator, another account's or an unknown ARN.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheResourceTheArnNames() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, false, Map.of("team", "web"));
|
||||
String arn = accelerator.getAcceleratorArn();
|
||||
service.tagResource(arn, Map.of("team", "data", "env", "dev"));
|
||||
service.untagResource(arn, List.of("env"));
|
||||
Listener listener = service.createListener(arn, portRange(80, 80), "TCP", null);
|
||||
service.tagResource(listener.getListenerArn(), Map.of("team", "ops"));
|
||||
Accelerator deleted = service.createAccelerator("gone", null, null, false, Map.of("team", "data"));
|
||||
service.deleteAccelerator(deleted.getAcceleratorArn());
|
||||
|
||||
assertEquals("globalaccelerator", service.namespace());
|
||||
assertEquals(Map.of("team", "data"), service.storedTags(arn));
|
||||
assertEquals(Map.of("team", "ops"), service.storedTags(listener.getListenerArn()));
|
||||
assertTrue(service.storedTags(deleted.getAcceleratorArn()).isEmpty());
|
||||
assertTrue(service.storedTags(arn.replace(ACCOUNT, "111122223333")).isEmpty());
|
||||
assertTrue(service.storedTags(arn + "0").isEmpty());
|
||||
assertTrue(service.storedTags("arn:aws:s3:::edge").isEmpty());
|
||||
}
|
||||
|
||||
/** An accelerator stored before storage was account-aware is read in place: the lookup migrates nothing. */
|
||||
@Test
|
||||
void storedTagsReadAPreAccountAwareAcceleratorInPlace() {
|
||||
InMemoryStorage<String, Accelerator> rawAccelerators = new InMemoryStorage<>();
|
||||
InMemoryStorage<String, Map<String, String>> rawTags = new InMemoryStorage<>();
|
||||
GlobalAcceleratorService legacyState = new GlobalAcceleratorService(new InMemoryStorageFactory(ACCOUNT)
|
||||
.withStore("globalaccelerator-accelerators.json", rawAccelerators)
|
||||
.withStore("globalaccelerator-tags.json", rawTags), new RegionResolver("us-east-1", ACCOUNT));
|
||||
String arn = "arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/legacy";
|
||||
Accelerator legacy = new Accelerator();
|
||||
legacy.setAcceleratorArn(arn);
|
||||
rawAccelerators.put(arn, legacy);
|
||||
rawTags.put(arn, Map.of("team", "data"));
|
||||
|
||||
assertEquals(Map.of("team", "data"), legacyState.storedTags(arn));
|
||||
assertEquals(Set.of(arn), rawAccelerators.keys());
|
||||
assertEquals(Set.of(arn), rawTags.keys());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceleratorArnCarriesAnEmptyRegionSegment() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, Map.of());
|
||||
|
||||
+35
-5
@@ -1612,11 +1612,7 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void anAcceleratorIsCheckedOnItsArnNotOnAnEndpointGroupOfIt() {
|
||||
String arn = adminJson("globalaccelerator", "GlobalAccelerator_V20180706.CreateAccelerator")
|
||||
.body("{\"Name\":\"res-accelerator\",\"IdempotencyToken\":\"" + suffix() + "\",\"Enabled\":false}")
|
||||
.post("/").then().statusCode(200).extract().path("Accelerator.AcceleratorArn");
|
||||
cleanup.register(() -> adminJson("globalaccelerator", "GlobalAccelerator_V20180706.DeleteAccelerator")
|
||||
.body("{\"AcceleratorArn\":\"" + arn + "\"}").post("/"));
|
||||
String arn = accelerator(null);
|
||||
assertTrue(arn.startsWith("arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/"), arn);
|
||||
|
||||
User user = user("res-accelerator");
|
||||
@@ -1632,6 +1628,40 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
.body(not(containsString("not authorized")));
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Global Accelerator holds on the accelerator a request names,
|
||||
* as TagResource leaves them, so an allow on one team's tag lets the caller describe that team's accelerator and
|
||||
* not another's.
|
||||
*/
|
||||
@Test
|
||||
void aGlobalAcceleratorResourceTagConditionReadsTheTagsOfTheAccelerator() {
|
||||
String web = "[{\"Key\":\"team\",\"Value\":\"web\"}]";
|
||||
String tagged = accelerator(web);
|
||||
String other = accelerator(web);
|
||||
adminJson("globalaccelerator", "GlobalAccelerator_V20180706.TagResource")
|
||||
.body("{\"ResourceArn\":\"" + tagged + "\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"data\"}]}")
|
||||
.post("/").then().statusCode(200);
|
||||
|
||||
User user = user("res-accelerator-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":\"globalaccelerator:DescribeAccelerator\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
send(user, "globalaccelerator", "GlobalAccelerator_V20180706.DescribeAccelerator", "1.1",
|
||||
"{\"AcceleratorArn\":\"" + tagged + "\"}").statusCode(200);
|
||||
refusedJson(send(user, "globalaccelerator", "GlobalAccelerator_V20180706.DescribeAccelerator", "1.1",
|
||||
"{\"AcceleratorArn\":\"" + other + "\"}"), "globalaccelerator:DescribeAccelerator");
|
||||
}
|
||||
|
||||
/** The ARN of a disabled accelerator an administrator creates, with the {@code tags} list if any, deleted after. */
|
||||
private String accelerator(String tags) {
|
||||
String arn = adminJson("globalaccelerator", "GlobalAccelerator_V20180706.CreateAccelerator")
|
||||
.body("{\"Name\":\"res-accelerator\",\"IdempotencyToken\":\"" + suffix() + "\",\"Enabled\":false"
|
||||
+ (tags == null ? "" : ",\"Tags\":" + tags) + "}")
|
||||
.post("/").then().statusCode(200).extract().path("Accelerator.AcceleratorArn");
|
||||
cleanup.register(() -> adminJson("globalaccelerator", "GlobalAccelerator_V20180706.DeleteAccelerator")
|
||||
.body("{\"AcceleratorArn\":\"" + arn + "\"}").post("/"));
|
||||
return arn;
|
||||
}
|
||||
|
||||
/** A Timestream for InfluxDB parameter group is checked on {@code db-parameter-group/<id>}, the id it was given. */
|
||||
@Test
|
||||
void aParameterGroupIsCheckedOnTheArnItsIdGives() {
|
||||
|
||||
Reference in new issue
Block a user