From 31b48c30be5210477ec56ac31428610bba2e9f58 Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Mon, 26 Oct 2026 22:59:04 -0500 Subject: [PATCH] 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 * 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 --------- Signed-off-by: Hector Ventura --- .../services/cloudformation/CloudFormationService.java | 6 +++--- .../cloudformation/provisioners/BatchCfnProvisioner.java | 3 ++- .../provisioners/BedrockAgentCoreCfnProvisioner.java | 5 +++-- .../provisioners/IamPolicyCfnProvisioner.java | 4 ++-- tools/partition/baseline.tsv | 5 +---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java index 00e85aa583..0868281dcc 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java @@ -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())) { diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java index dfdc213ac0..8ddd759b4c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java @@ -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('/'); diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java index fcb1c013e9..6dc98aae7c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java @@ -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, diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java index 647621bcd1..6786aba578 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java @@ -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/"); } diff --git a/tools/partition/baseline.tsv b/tools/partition/baseline.tsv index eee9f42596..d6e9a589b0 100644 --- a/tools/partition/baseline.tsv +++ b/tools/partition/baseline.tsv @@ -19,12 +19,9 @@ arn-probe src/main/java/io/github/hectorvent/floci/services/appsync/graphql/reso arn-probe src/main/java/io/github/hectorvent/floci/services/batch/BatchService.java 4 arn-probe src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java 3 arn-probe src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsService.java 1 -arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java 7 -arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java 1 -arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java 2 +arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java 4 arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2InstanceCfnProvisioner.java 1 arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisioner.java 1 -arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java 1 arn-probe src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontService.java 1 arn-probe src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java 1 arn-probe src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsCrossAccountService.java 1