fix(eventbridge): enforce tag resource ownership (#6326)

* fix(eventbridge): enforce tag resource ownership

* fix(eventbridge): resolve tag ARN partition from request region

* fix(eventbridge): report missing tag resources
This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-23 08:49:15 -04:00
1 parent d05399feb1
commit 1473fc9b83
3 files changed
+111 -7

No files matched your search

@@ -550,29 +550,52 @@ public class EventBridgeService implements ResourceProvider {
// ──────────────────────────── Tags ────────────────────────────
public Map<String, String> listTagsForResource(String resourceArn, String region) {
validateTagResourceArn(resourceArn, region);
String resource = AwsArnUtils.parse(resourceArn).resource();
if (resource.startsWith("event-bus/")) {
String busName = resource.substring("event-bus/".length());
String key = busKey(region, busName);
return busStore.get(key)
.map(EventBus::getTags)
.orElse(Map.of());
if (busName.isBlank()) {
throw new AwsException("ResourceNotFoundException", "Resource not found: " + resourceArn, 400);
}
return describeEventBus(busName, region).getTags();
}
if (resource.startsWith("rule/")) {
RuleRef ref = parseRuleResource(resource);
String key = ruleKey(region, ref.busName(), ref.ruleName());
return ruleStore.get(key)
.map(Rule::getTags)
.orElse(Map.of());
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"Resource not found: " + resourceArn, 400));
}
if (resource.startsWith("archive/")) {
String archiveName = resource.substring("archive/".length());
String key = archiveKey(region, archiveName);
return archiveStore.get(key)
.map(Archive::getTags)
.orElse(Map.of());
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"Archive not found: " + archiveName, 400));
}
throw new AwsException("ResourceNotFoundException", "Resource not found: " + resourceArn, 400);
}
/** EventBridge tag operations only address resources in the caller's account and Region. */
private void validateTagResourceArn(String resourceArn, String region) {
AwsArnUtils.Arn arn;
try {
arn = AwsArnUtils.parse(resourceArn);
} catch (IllegalArgumentException e) {
throw new AwsException("ResourceNotFoundException",
"Resource not found: " + resourceArn, 400);
}
if (!"events".equals(arn.service())
|| arn.partition().isBlank()
|| AwsArnUtils.isForeignPartition(arn, regionResolver.partitionForRegion(region))
|| !region.equals(arn.region())
|| arn.accountId().isBlank()
|| AwsArnUtils.isForeignAccount(arn, regionResolver.getAccountId())) {
throw new AwsException("ResourceNotFoundException",
"Resource not found: " + resourceArn, 400);
}
return Map.of();
}
/** Resolves the bus and rule name from a {@code rule/...} ARN resource segment. */
@@ -590,6 +613,7 @@ public class EventBridgeService implements ResourceProvider {
}
public void tagResource(String resourceArn, Map<String, String> tags, String region) {
validateTagResourceArn(resourceArn, region);
String resource = AwsArnUtils.parse(resourceArn).resource();
if (resource.startsWith("archive/")) {
String archiveName = resource.substring("archive/".length());
@@ -628,6 +652,7 @@ public class EventBridgeService implements ResourceProvider {
}
public void untagResource(String resourceArn, List<String> tagKeys, String region) {
validateTagResourceArn(resourceArn, region);
String resource = AwsArnUtils.parse(resourceArn).resource();
if (resource.startsWith("archive/")) {
String archiveName = resource.substring("archive/".length());