From 5544a119d30e8244d17a9488dcfdad94a6668dfd Mon Sep 17 00:00:00 2001 From: Allen Sanborn Date: Thu, 15 Oct 2026 15:39:12 -0500 Subject: [PATCH] fix(ec2): ignore NoDevice block device mappings at launch (#5739) A RunInstances or CreateFleet BlockDeviceMapping with NoDevice set removes its device regardless of the other values it carries. The root volume type resolution and the VolumeType validation read Ebs on such entries, so a request that removed a template's gp3 root still got gp3, and a removed mapping naming an unknown VolumeType failed with InvalidParameterValue. Drop NoDevice entries before both, on the request-only and template-merged paths alike. --- docs/services/ec2.md | 3 +- .../floci/services/ec2/Ec2Service.java | 13 ++++---- .../services/ec2/Ec2IntegrationTest.java | 32 +++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/docs/services/ec2.md b/docs/services/ec2.md index f6e3b72dc8..57ca31cf39 100644 --- a/docs/services/ec2.md +++ b/docs/services/ec2.md @@ -683,7 +683,8 @@ members it sets, and the rest keep the template's values; devices only one side given. An Auto Scaling group launching from a template gets the template's mappings the same way. The root volume's type comes from the mapping for the AMI's root device, else from the AMI's own root mapping, else `gp3`, and `CreateImage` records that type on the new AMI's root -mapping. A mapping naming a `VolumeType` outside the service model's enum fails with +mapping. A mapping with `NoDevice` set removes its device whatever else it names, so it sets no +type and its `VolumeType` is not checked. A mapping naming a `VolumeType` outside the service model's enum fails with `InvalidParameterValue`, as `ModifyVolume` does. Template versions are not checked when they are stored, so a template naming an unknown `VolumeType` is accepted by `CreateLaunchTemplate` and fails at launch. diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java index 1b8a272437..a9325c52b0 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java +++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java @@ -3359,12 +3359,13 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab validateArchitectureCompatibility(region, imageId, effectiveInstanceType); int count = Math.min(maxCount, Math.max(minCount, 1)); String architecture = architectureFor(region, imageId, effectiveInstanceType); - if (blockDeviceMappings != null) { - blockDeviceMappings.stream() - .filter(m -> m.getEbs() != null && m.getEbs().getVolumeType() != null) - .forEach(m -> requireValidVolumeType(m.getEbs().getVolumeType())); - } - String rootVolumeType = rootVolumeTypeFor(findImageForCapture(region, imageId), blockDeviceMappings); + // An entry with NoDevice set removes its device whatever else it names, as on AWS. + List mappedDevices = blockDeviceMappings == null ? List.of() + : blockDeviceMappings.stream().filter(m -> m.getNoDevice() == null).toList(); + mappedDevices.stream() + .filter(m -> m.getEbs() != null && m.getEbs().getVolumeType() != null) + .forEach(m -> requireValidVolumeType(m.getEbs().getVolumeType())); + String rootVolumeType = rootVolumeTypeFor(findImageForCapture(region, imageId), mappedDevices); List launched = new ArrayList<>(); // Resolving the AMI, building the instances that depend on it and publishing them is one // step. A DeregisterImage releases the captured layer only when no live instance resolves diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java index 707c74d9e1..b002d77a37 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java @@ -5778,6 +5778,38 @@ class Ec2IntegrationTest { .body(containsString("Value (gp9) for parameter volumeType is invalid. Unknown volume type.")); } + @Test + @Order(335) + void runInstancesNoDeviceRootMappingFallsBackToAmiRootVolumeType() { + String templateId = given() + .formParam("Action", "CreateLaunchTemplate") + .formParam("LaunchTemplateName", "gp3-root-nodevice-template") + .formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvda") + .formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp3") + .header("Authorization", AUTH_HEADER) + .when() + .post("/") + .then() + .statusCode(200) + .extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId"); + + // NoDevice removes the template's root mapping, so the AMI's gp2 root applies. + assertEquals("gp2", rootVolumeType(launch(Map.of( + "LaunchTemplate.LaunchTemplateId", templateId, + "BlockDeviceMapping.1.DeviceName", "/dev/xvda", + "BlockDeviceMapping.1.NoDevice", "")))); + } + + @Test + @Order(336) + void runInstancesIgnoresVolumeTypeOnANoDeviceMapping() { + // The device is removed regardless of the assigned value, so gp9 is never validated. + assertEquals("gp2", rootVolumeType(launch(Map.of( + "BlockDeviceMapping.1.DeviceName", "/dev/xvda", + "BlockDeviceMapping.1.NoDevice", "", + "BlockDeviceMapping.1.Ebs.VolumeType", "gp9")))); + } + private String launch(Map params) { return given() .formParam("Action", "RunInstances")