fix(logs): resolve trailing-colon query ARNs (#5954)

* fix(logs): resolve trailing-colon query ARNs

* fix(logs): constrain trailing-colon ARN normalization
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-18 20:46:27 -04:00
1 parent 678c5b82a6
commit 916e72570e
3 files changed
+221 -1

No files matched your search

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudwatch.logs.model.AccountPolicy;
@@ -22,12 +23,15 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ApplicationScoped
public class CloudWatchLogsHandler {
private static final Pattern LOG_GROUP_NAME = Pattern.compile("[._/#A-Za-z0-9-]+");
private static final Pattern QUERY_LOG_GROUP_ARN_WITH_COLON = Pattern.compile("arn:"
+ AwsArnUtils.PARTITION_REGEX + ":logs:[a-z0-9-]+:[0-9]{12}:log-group:(" + LOG_GROUP_NAME.pattern() + "):");
private final CloudWatchLogsService logsService;
private final CloudWatchLogsCrossAccountService crossAccountService;
@@ -397,7 +401,7 @@ public class CloudWatchLogsHandler {
if (request.has("logGroupName")) {
logGroupNames.add(extractLogGroupNameFromArn(request.path("logGroupName").asText()));
}
request.path("logGroupIdentifiers").forEach(n -> logGroupNames.add(extractLogGroupNameFromArn(n.asText())));
request.path("logGroupIdentifiers").forEach(n -> logGroupNames.add(resolveQueryLogGroupName(n.asText())));
long startTime = request.path("startTime").asLong();
long endTime = request.path("endTime").asLong();
@@ -410,6 +414,18 @@ public class CloudWatchLogsHandler {
return Response.ok(response).build();
}
private static String resolveQueryLogGroupName(String identifier) {
// Grafana strips only the '*' from DescribeLogGroups' ARN. Keep this tolerance identifier-only.
Matcher arn = QUERY_LOG_GROUP_ARN_WITH_COLON.matcher(identifier == null ? "" : identifier);
if (arn.matches()) {
String name = arn.group(1);
if (name.length() <= 512) {
return name;
}
}
return extractLogGroupNameFromArn(identifier);
}
/**
* Counts how many of the three mutually exclusive StartQuery log-group selector <em>fields</em> the
* request carries: {@code logGroupName}, {@code logGroupNames}, {@code logGroupIdentifiers}. A field