refactor: read ARN resources through AwsArnUtils in EventBridge, Pipes and three more (#7145)

* refactor: read ARN resources through AwsArnUtils in EventBridge, Pipes and three more

Archive, replay and Pipes event-bus targets, Pipes Kinesis sources, MicroVM image and network
connector tags, Cloud Map tags and ECS service registries cut an ARN at its last '/' or ':'
by hand. They now read the resource with AwsArnUtils.resourceIfArnFor, which also checks the
service. A Pipes Kinesis source given as a stream-consumer ARN names its stream instead of
"consumer:timestamp", and an ECS registryArn that is not a Cloud Map service ARN is ignored
with the existing warning.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(lambda): read a MicroVM tag target the same way for IAM and the tag paths

TagResource takes only an ARN, and a network connector without a version. LambdaMicrovmsService.taggedResource is now the one reader for both the tag paths and ResourceArnBuilder, so a version-qualified connector is refused instead of reaching the bare connector while IAM checks another resource.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-31 20:36:16 -04:00
1 parent cf17be9dd0
commit c865784540
13 files changed
+137 -62

No files matched your search

@@ -456,18 +456,16 @@ class IamRestRouteEnforcementIntegrationTest {
}
@Test
void aMicrovmImageTaggedThroughATargetWithoutTheArnPrefixIsCheckedAsTheImage() {
// Lambda tags the image any target holding :microvm-image: names, read by its fourth field and
// its last, so a Deny on the image applies however the target is spelled.
void aMicrovmImageTagTargetWithoutTheArnPrefixIsRefusedAndTagsNothing() {
// TagResource takes only an ARN, so a target without arn: names no image, whatever it holds.
String user = user("route-image-tags");
String image = microvmImage("route-tagged-image-" + suffix());
String target = "/2017-03-31/tags/x:y:z:us-east-1:microvm-image:" + image.substring(image.lastIndexOf(':') + 1);
String body = "{\"Tags\":{\"team\":\"a\"}}";
policy(user, allow("lambda:TagResource", "*") + "," + deny("lambda:TagResource", image));
refused(as(user, "lambda").body(body).post(target).then(), "lambda:TagResource");
policy(user, allow("lambda:TagResource", "*"));
as(user, "lambda").body(body).post(target).then().statusCode(204);
as(user, "lambda").body("{\"Tags\":{\"team\":\"a\"}}").post(target).then()
.statusCode(400).body(containsString("InvalidParameterValueException"));
admin().get("/2017-03-31/tags/" + image).then().statusCode(200).body("Tags.size()", equalTo(0));
}
/** Creates a MicroVM image as the account's admin, removed afterwards, and returns its ARN. */
@@ -2106,10 +2106,13 @@ class ResourceArnBuilderTest {
when(uriInfo.getPath()).thenReturn("/2017-03-31/tags/" + arn);
assertEquals(arn, builder.build("lambda", ctx, "us-east-1", "000000000000"), arn);
}
// The MicroVM tag handler takes a target without the arn: prefix too, and reads it the same way.
// A version-qualified connector is no tag target, so it stays as written rather than naming the connector.
String qualified = "arn:aws:lambda:eu-west-1:111122223333:network-connector:nc-1:1";
when(uriInfo.getPath()).thenReturn("/2017-03-31/tags/" + qualified);
assertEquals(qualified, builder.build("lambda", ctx, "us-east-1", "000000000000"));
// A target without the arn: prefix names no resource.
when(uriInfo.getPath()).thenReturn("/2017-03-31/tags/x:y:z:eu-west-1:microvm-image:img");
assertEquals("arn:aws:lambda:eu-west-1:000000000000:microvm-image:img",
builder.build("lambda", ctx, "us-east-1", "000000000000"));
assertEquals("*", builder.build("lambda", ctx, "us-east-1", "000000000000"));
when(uriInfo.getPath()).thenReturn("/2017-03-31/tags/shared");
assertEquals("*", builder.build("lambda", ctx, "us-east-1", "000000000000"));
// A streaming invoke is an invoke: its qualifier and the account its function ARN names count.
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.lambdamicrovms;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import org.junit.jupiter.api.Test;
@@ -7,6 +8,8 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -15,6 +18,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -58,4 +62,22 @@ class LambdaMicrovmsServiceTest {
assertEquals(updates + 1, service.getConnector(REGION, created.id).latestVersion);
assertEquals(updates + 1, service.listConnectorVersions(REGION, created.id).size());
}
@Test
void aVersionQualifiedConnectorIsNotATagTarget() {
RegionResolver regionResolver = mock(RegionResolver.class);
when(regionResolver.getAccountId()).thenReturn(ACCOUNT_ID);
LambdaMicrovmsService service = new LambdaMicrovmsService(regionResolver, mock(StorageFactory.class));
LambdaMicrovmsService.NetworkConnector created = service.createConnector(REGION, ACCOUNT_ID, "tagged",
List.of("subnet-00000000000000001"), List.of("sg-00000000000000000"),
"arn:aws:iam::000000000000:role/operator", "token", List.of("WebFunction"), "IPv4");
String qualified = created.arn + ":1";
assertEquals(Optional.of("network-connector:" + created.id), LambdaMicrovmsService.taggedResource(created.arn));
assertEquals(Optional.empty(), LambdaMicrovmsService.taggedResource(qualified));
AwsException refused = assertThrows(AwsException.class,
() -> service.tagResource(REGION, qualified, Map.of("team", "a")));
assertEquals("ValidationException", refused.getErrorCode());
assertEquals(Map.of(), service.listTags(REGION, created.arn));
}
}
@@ -768,4 +768,12 @@ class PipesPollerTest {
.findFirst()
.orElseThrow();
}
@Test
void kinesisStreamNameReadsTheStreamOfAStreamOrConsumerArn() {
assertEquals("orders", PipesPoller.kinesisStreamName("arn:aws:kinesis:us-east-1:111111111111:stream/orders"));
assertEquals("orders", PipesPoller.kinesisStreamName(
"arn:aws-cn:kinesis:cn-north-1:111111111111:stream/orders/consumer/reader:1700000000"));
assertEquals("orders", PipesPoller.kinesisStreamName("orders"));
}
}