refactor(cloudformation): check ARNs through AwsArnUtils (#6486)

* refactor(rds): read and check ARNs through AwsArnUtils

RdsQueryHandler read the region of an instance ARN and rebuilt its subnet
group ARN by splitting it; those now use regionOrDefault and parse, and the
service-local regionFromRdsArn copy is gone. Six startsWith("arn:") probes in
RdsService become isArn where the result is the same for every input: replica
link names Floci stored itself, the instance and cluster list filters, the
tag-resource region default and the cluster lookup by reference.

The seven other probes stay. They treat any value starting with arn: as an
attempted ARN, so a malformed one gets InvalidParameterValue (or its own not
found error); isArn would send it down the identifier path and change the
error.

No behaviour change. The partition baseline drops from 144 to 136.

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

* refactor(cloudformation): check ARNs through AwsArnUtils

Seven startsWith("arn:") probes become AwsArnUtils.isArn where the result is
the same for every input: the deleted-stack and live-stack lookups by ARN,
where a malformed ARN resolves to no stack either way; the change set ARN
check that only runs after resolveChangeSetName has rejected malformed ARNs;
and the Batch, Bedrock AgentCore and IAM policy provisioners' checks of
physical ids Floci minted itself.

The six other probes stay: DeleteChangeSet, DeleteStack, the change set name
resolver and the change set's stack lookup give a malformed ARN its own
ValidationError or no-op, and the EC2 instance and ECS provisioners read
template values, where isArn would change how an "arn:" value resolves.

No behaviour change. The partition baseline drops from 136 to 129.

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-26 22:59:04 -05:00
1 parent fc5598c579
commit 31b48c30be
5 files changed
+11 -12

No files matched your search

@@ -4349,7 +4349,7 @@ public class CloudFormationService implements ResourceProvider {
}
private Stack resolveDeletedStack(String stackNameOrArn, String region, String accountId) {
if (stackNameOrArn != null && stackNameOrArn.startsWith("arn:")) {
if (AwsArnUtils.isArn(stackNameOrArn)) {
DeletedStackEntry deleted = deletedStacks.get(stackNameOrArn);
if (deleted != null) {
if (deleted.isExpired(now())) {
@@ -4455,7 +4455,7 @@ public class CloudFormationService implements ResourceProvider {
String region, String accountId) {
ChangeSet changeSet = stack.getChangeSets().get(
resolveChangeSetName(changeSetNameOrArn, region, accountId));
if (changeSet == null || (changeSetNameOrArn != null && changeSetNameOrArn.startsWith("arn:")
if (changeSet == null || (AwsArnUtils.isArn(changeSetNameOrArn)
&& !changeSetNameOrArn.equals(changeSet.getChangeSetId()))) {
return null;
}
@@ -4648,7 +4648,7 @@ public class CloudFormationService implements ResourceProvider {
}
// If input looks like an ARN, extract the stack name and retry
if (stackNameOrArn != null && stackNameOrArn.startsWith("arn:")) {
if (AwsArnUtils.isArn(stackNameOrArn)) {
try {
AwsArnUtils.Arn arn = AwsArnUtils.parse(stackNameOrArn);
if (!accountId.equals(arn.accountId()) || !region.equals(arn.region())) {
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.batch.BatchService;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
@@ -472,7 +473,7 @@ public class BatchCfnProvisioner implements CfnResourceProvisioner {
return recorded;
}
String priorId = ctx.priorPhysicalId();
if (priorId == null || !priorId.startsWith("arn:")) {
if (!AwsArnUtils.isArn(priorId)) {
return null;
}
int slash = priorId.lastIndexOf('/');
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreControlService;
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreControlService.EndpointLocation;
@@ -355,7 +356,7 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
/** The memory a prior physical id names, or null when it names none (gone, or a dispatcher stub). */
private Memory findMemory(String arn, String region) {
if (!arn.startsWith("arn:")) {
if (!AwsArnUtils.isArn(arn)) {
return null;
}
try {
@@ -398,7 +399,7 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
physicalId));
case MEMORY -> {
// A dispatcher stub from before this provisioner existed is not an ARN and names no memory.
if (!physicalId.startsWith("arn:")) {
if (!AwsArnUtils.isArn(physicalId)) {
return;
}
CfnDeletes.safeDelete("AgentCore memory", physicalId,
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
@@ -343,8 +344,7 @@ public class IamPolicyCfnProvisioner implements CfnResourceProvisioner {
}
private boolean isIamManagedPolicyArn(String physicalId) {
return physicalId != null
&& physicalId.startsWith("arn:")
return AwsArnUtils.isArn(physicalId)
&& physicalId.contains(":iam::")
&& physicalId.contains(":policy/");
}