fix(rds): reject tag ARNs from another partition (#5419)

* fix(rds): reject tag ARNs from another partition

A tag request must identify the resource in the current account, region
and partition. An ARN from another partition must not read or change a
same-named local resource.

* fix(rds): preserve tagging in custom regions

* fix(rds): preserve event tags in custom regions

* fix(rds): repair saved custom-region event ARNs

* fix(rds): preserve restored proxy target group partitions
This commit is contained in:
David Phillips authored and GitHub committed 2026-10-10 17:25:27 -04:00
1 parent 3cdc9ef22d
commit 60837956de
4 files changed
+212 -9

No files matched your search

@@ -275,10 +275,15 @@ public class RegionResolver {
* {@link #buildGlobalArn(String, String)}.
*/
public String buildArn(String service, String region, String resource) {
return buildArn(service, region, getAccountId(), resource);
}
/** Mints an ARN for an explicit owner, including during background restoration. */
public String buildArn(String service, String region, String accountId, String resource) {
if (region == null || region.isBlank()) {
return buildGlobalArn(service, resource);
return buildGlobalArn(service, accountId, resource);
}
return new AwsArnUtils.Arn(partitionForRegion(region), service, region, getAccountId(), resource).toString();
return new AwsArnUtils.Arn(partitionForRegion(region), service, region, accountId, resource).toString();
}
/** Mints a regionless ARN ({@code arn:<partition>:iam::<account>:...}) in the request's partition. */
@@ -2283,6 +2283,9 @@ public class RdsService implements Resettable, ResourceProvider {
if (!"rds".equals(arn.service())) {
throw new AwsException("InvalidParameterValue", "Invalid resource name: " + resourceName, 400);
}
if (!regionResolver.partitionForRegion(effectiveRegion).equals(arn.partition())) {
throw new AwsException("InvalidParameterValue", "Invalid resource name: " + resourceName, 400);
}
if (!effectiveRegion.equals(arn.region())) {
throw new AwsException("InvalidParameterValue",
"ResourceName is not in region " + effectiveRegion + ": " + resourceName, 400);
@@ -7103,7 +7106,7 @@ public class RdsService implements Resettable, ResourceProvider {
}
try {
AwsArnUtils.Arn arn = AwsArnUtils.parse(targetGroup.getTargetGroupArn());
return AwsRegions.partitionFor(region).equals(arn.partition())
return regionResolver.partitionForRegion(region).equals(arn.partition())
&& "rds".equals(arn.service())
&& Objects.equals(accountId, arn.accountId())
&& Objects.equals(region, arn.region())
@@ -8017,9 +8020,8 @@ public class RdsService implements Resettable, ResourceProvider {
targetGroup = new DbProxyTargetGroup();
targetGroup.setDbProxyName(proxy.getDbProxyName());
targetGroup.setTargetGroupName("default");
targetGroup.setTargetGroupArn(AwsArnUtils.Arn.of("rds",
region,
accountId, "target-group:prx-tg-" + randomResourceSuffix()).toString());
targetGroup.setTargetGroupArn(regionResolver.buildArn("rds", region,
accountId, "target-group:prx-tg-" + randomResourceSuffix()));
targetGroup.setDefaultTargetGroup(true);
targetGroup.setCreatedAt(now);
targetGroup.setUpdatedAt(now);
@@ -8587,7 +8589,7 @@ public class RdsService implements Resettable, ResourceProvider {
String resourceType, String resourceId) {
try {
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
return AwsRegions.partitionFor(region).equals(parsed.partition())
return regionResolver.partitionForRegion(region).equals(parsed.partition())
&& "rds".equals(parsed.service())
&& Objects.equals(accountId, parsed.accountId())
&& Objects.equals(region, parsed.region())
@@ -9184,8 +9186,8 @@ public class RdsService implements Resettable, ResourceProvider {
// The model documents the subscription as created but inactive when Enabled is false, and
// says nothing about a default, so an omitted Enabled activates it as the console does.
subscription.setEnabled(enabled == null || enabled);
subscription.setEventSubscriptionArn(AwsArnUtils.Arn.of("rds", region, accountId,
"es:" + subscriptionName).toString());
subscription.setEventSubscriptionArn(regionResolver.buildArn("rds", region,
"es:" + subscriptionName));
subscription.setTags(tags == null ? new LinkedHashMap<>() : new LinkedHashMap<>(tags));
eventSubscriptions.put(key, subscription);
return subscription;
@@ -9297,6 +9299,7 @@ public class RdsService implements Resettable, ResourceProvider {
}
String prefix = eventSubscriptionKey(region, "");
List<EventSubscription> all = eventSubscriptions.scan(k -> k.startsWith(prefix)).stream()
.map(subscription -> normalizeEventSubscriptionArn(region, subscription))
.sorted(Comparator.comparing(EventSubscription::getCustSubscriptionId))
.toList();
// The marker is the last name of the previous page and the next page starts after it.
@@ -9319,10 +9322,29 @@ public class RdsService implements Resettable, ResourceProvider {
private EventSubscription requireEventSubscription(String region, String subscriptionName) {
return eventSubscriptions.get(eventSubscriptionKey(region, subscriptionName))
.map(subscription -> normalizeEventSubscriptionArn(region, subscription))
.orElseThrow(() -> new AwsException("SubscriptionNotFound",
"Subscription " + subscriptionName + " not found.", 404));
}
private EventSubscription normalizeEventSubscriptionArn(String region, EventSubscription subscription) {
String accountId = subscription.getCustomerAwsId();
String name = subscription.getCustSubscriptionId();
if (accountId == null || name == null) {
return subscription;
}
String resource = "es:" + name;
String legacyArn = AwsArnUtils.Arn.of("rds", region, accountId, resource).toString();
String expectedArn = regionResolver.buildArn("rds", region, accountId, resource);
// Earlier versions minted custom-region subscriptions with the catalog's fallback
// partition. Repair only that exact legacy identity, preserving its stored owner.
if (legacyArn.equals(subscription.getEventSubscriptionArn()) && !legacyArn.equals(expectedArn)) {
subscription.setEventSubscriptionArn(expectedArn);
eventSubscriptions.put(eventSubscriptionKey(region, name), subscription);
}
return subscription;
}
// ── Cluster endpoints ─────────────────────────────────────────────────────
private static final int MAX_CUSTOM_ENDPOINTS_PER_CLUSTER = 5;