mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(core): read an ARN's resource after its fifth colon, not its last (#5939)
* fix(core): read an ARN's resource after its fifth colon, not its last Four places cut an ARN by hand and got the wrong resource for a legal name: - A VPC flow log's S3 destination took everything after the last ':' as the bucket, so a prefix with a colon (arn:aws:s3:::bkt/logs:2024/) named bucket 2024. It now takes the S3 resource through AwsArnUtils. - Glue's TagResource and UntagResource split the ARN on every ':', so a job, table or other name containing one was looked up by the text before it and answered EntityNotFoundException. The split stops at six parts. - KMS resolved an alias ARN at its last ':', so alias/team:payments resolved as payments. The alias name is now the ARN's resource. - A Kinesis event source mapping read the stream name after the last '/', so a stream-consumer ARN gave the consumer segment. It now reads the segment after stream/, as KinesisJsonHandler does. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(core): parse only KMS alias ARNs and drop only a consumer suffix Review follow-ups: - KMS read the alias name from any ARN containing ":alias/", so another service's ARN naming the same alias resolved a local KMS alias. Only a KMS ARN is now read that way; anything else keeps the old reading and finds no alias. - The Kinesis poller dropped everything after the stream segment, so a malformed suffix (stream/orders/not-a-consumer) still named stream orders. It now drops only a /consumer/ suffix, so a malformed ARN names no stream. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
d951fd532c
commit
fc1488d17a
8 files changed
+65
-7
No files matched your search
@@ -255,4 +255,11 @@ class FlowLogServiceTest {
|
||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8).trim();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bucketComesFromTheS3ArnEvenWhenThePrefixHasAColon() {
|
||||
assertEquals("bkt", FlowLogService.bucketFromArn("arn:aws:s3:::bkt/logs:2024/"));
|
||||
assertEquals("bkt", FlowLogService.bucketFromArn("arn:aws-cn:s3:::bkt"));
|
||||
assertEquals("bkt", FlowLogService.bucketFromArn("bkt/prefix"));
|
||||
}
|
||||
}
|
||||
@@ -436,4 +436,14 @@ class GlueJobRunServiceTest {
|
||||
return AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsReachAJobWhoseNameContainsAColon() {
|
||||
createJob("nightly:etl", null, null);
|
||||
String arn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":job/nightly:etl";
|
||||
|
||||
glueService.tagResource(arn, Map.of("team", "data"), REGION);
|
||||
|
||||
assertEquals(Map.of("team", "data"), glueService.getTags(arn, REGION));
|
||||
}
|
||||
}
|
||||
@@ -4035,4 +4035,17 @@ class KmsServiceTest {
|
||||
assertEquals(List.of("alias/aws/s3"), aliases.stream().map(KmsAlias::getAliasName).toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aliasArnResolvesAnAliasNameContainingAColon() {
|
||||
KmsKey key = kmsService.createKey(null, REGION);
|
||||
kmsService.createAlias("alias/team:payments", key.getKeyId(), REGION);
|
||||
|
||||
String aliasArn = "arn:aws:kms:" + REGION + ":000000000000:alias/team:payments";
|
||||
assertEquals(key.getKeyId(), kmsService.describeKey(aliasArn, REGION).getKeyId());
|
||||
|
||||
// Another service's ARN naming the same alias is not a KMS alias ARN.
|
||||
assertThrows(AwsException.class, () -> kmsService.describeKey(
|
||||
"arn:aws:sns:" + REGION + ":000000000000:alias/team:payments", REGION));
|
||||
}
|
||||
}
|
||||
+10
@@ -469,4 +469,14 @@ class KinesisEventSourcePollerTest {
|
||||
verify(kinesisService, never()).getShardIterator(anyString(), anyString(), anyString(), any(), anyString());
|
||||
verify(kinesisService, never()).getRecords(anyString(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void streamNameComesFromAStreamOrAConsumerArn() {
|
||||
assertEquals("orders", KinesisEventSourcePoller.streamNameFromArn(
|
||||
"arn:aws:kinesis:us-east-1:000000000000:stream/orders"));
|
||||
assertEquals("orders", KinesisEventSourcePoller.streamNameFromArn(
|
||||
"arn:aws:kinesis:us-east-1:000000000000:stream/orders/consumer/reader:1700000000"));
|
||||
assertEquals("orders/not-a-consumer", KinesisEventSourcePoller.streamNameFromArn(
|
||||
"arn:aws:kinesis:us-east-1:000000000000:stream/orders/not-a-consumer"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user