fix(ecs): omit readOnly from mountPoints and volumesFrom that never sent it (#6933)

A mount point or volumes-from entry registered without readOnly described
back with readOnly=false, and the Terraform AWS provider then diffed the
shape and replaced aws_ecs_task_definition on every apply. readOnly is an
optional boxed boolean in the ECS model: absence stays absent, explicit
true and false echo as sent, and the container runtime still mounts
absence as read-write.

Closes #6909

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
Matheus OliveiraandPriamo Germosen authored and GitHub committed 2026-10-30 23:10:01 -04:00
1 parent 5f327da1c8
commit 4d21ea66cf
7 files changed
+197 -10

No files matched your search

@@ -1381,7 +1381,7 @@ public class EcsJsonHandler {
for (JsonNode item : node) {
result.add(new VolumeFrom(
item.path("sourceContainer").asText(),
item.path("readOnly").asBoolean(false)));
item.hasNonNull("readOnly") ? item.get("readOnly").asBoolean() : null));
}
return result;
}
@@ -1559,7 +1559,7 @@ public class EcsJsonHandler {
result.add(new MountPoint(
item.path("sourceVolume").asText(),
item.path("containerPath").asText(),
item.path("readOnly").asBoolean(false)));
item.hasNonNull("readOnly") ? item.get("readOnly").asBoolean() : null));
}
return result;
}
@@ -300,7 +300,7 @@ public class EcsResponseWriter {
ObjectNode mpNode = objectMapper.createObjectNode();
mpNode.put("sourceVolume", mp.sourceVolume());
mpNode.put("containerPath", mp.containerPath());
mpNode.put("readOnly", mp.readOnly());
if (mp.readOnly() != null) { mpNode.put("readOnly", mp.readOnly()); }
mps.add(mpNode);
}
n.set("mountPoints", mps);
@@ -310,7 +310,7 @@ public class EcsResponseWriter {
for (VolumeFrom volumeFrom : def.getVolumesFrom()) {
ObjectNode volumeFromNode = objectMapper.createObjectNode();
volumeFromNode.put("sourceContainer", volumeFrom.sourceContainer());
volumeFromNode.put("readOnly", volumeFrom.readOnly());
if (volumeFrom.readOnly() != null) { volumeFromNode.put("readOnly", volumeFrom.readOnly()); }
volumesFrom.add(volumeFromNode);
}
n.set("volumesFrom", volumesFrom);
@@ -525,7 +525,7 @@ public class EcsContainerManager {
// rejection is not swallowed, it propagates out of startTask and is
// surfaced by EcsService as the task's stoppedReason.
hostVolumePolicy.validate(sourcePath);
if (mp.readOnly()) {
if (Boolean.TRUE.equals(mp.readOnly())) {
specBuilder.withReadOnlyBind(sourcePath, mp.containerPath());
} else {
specBuilder.withBind(sourcePath, mp.containerPath());
@@ -538,7 +538,8 @@ public class EcsContainerManager {
labels.put(ContainerStorageHelper.SERVICE_LABEL, "ecs");
lifecycleManager.ensureVolume(ephemeralVolume, labels);
}
specBuilder.withNamedVolume(ephemeralVolume, mp.containerPath(), mp.readOnly());
specBuilder.withNamedVolume(ephemeralVolume, mp.containerPath(),
Boolean.TRUE.equals(mp.readOnly()));
} else {
LOG.warnv("Skipping mountPoint with unresolved volume {0} on container {1}",
mp.sourceVolume(), def.getName());
@@ -553,7 +554,8 @@ public class EcsContainerManager {
throw new IllegalStateException("ECS volumesFrom source container "
+ volumeFrom.sourceContainer() + " has not started");
}
specBuilder.withVolumesFrom(sourceContainerId, volumeFrom.readOnly());
specBuilder.withVolumesFrom(sourceContainerId,
Boolean.TRUE.equals(volumeFrom.readOnly()));
}
}
@@ -2369,7 +2371,7 @@ public class EcsContainerManager {
lifecycleManager.ensureSharedVolume(efsVolumeName,
efsCfg.ownerUid(), efsCfg.ownerGid(), efsCfg.rootPermissions(), efsCfg.initImage());
}
specBuilder.withNamedVolume(efsVolumeName, mp.containerPath(), mp.readOnly());
specBuilder.withNamedVolume(efsVolumeName, mp.containerPath(), Boolean.TRUE.equals(mp.readOnly()));
PosixUser posixUser = accessPoint != null ? accessPoint.getPosixUser() : null;
if (posixUser != null) {
if (posixUser.getUid() == null || posixUser.getGid() == null) {
@@ -9,5 +9,5 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
* host source path is bind-mounted into the container at {@code containerPath}.
*/
@RegisterForReflection
public record MountPoint(String sourceVolume, String containerPath, boolean readOnly) {
public record MountPoint(String sourceVolume, String containerPath, Boolean readOnly) {
}
@@ -7,5 +7,5 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
* {@code {"sourceContainer": ..., "readOnly": ...}}.
*/
@RegisterForReflection
public record VolumeFrom(String sourceContainer, boolean readOnly) {
public record VolumeFrom(String sourceContainer, Boolean readOnly) {
}
@@ -1347,4 +1347,108 @@ class EcsIntegrationTest {
.body("__type", containsString("ClientException"))
.body("message", containsString("HealthCheck command is required."));
}
@Test
@Order(72)
void registerAndDescribeTaskDefinitionKeepsReadOnlyAbsentWhenItWasNeverSent() {
String arn = ecs("RegisterTaskDefinition")
.body("""
{
"family": "readonly-absent-roundtrip",
"volumes": [{"name": "v"}],
"containerDefinitions": [
{
"name": "a",
"image": "nginx:latest",
"memory": 128,
"essential": true,
"mountPoints": [{"sourceVolume": "v", "containerPath": "/a"}]
},
{
"name": "b",
"image": "nginx:latest",
"memory": 128,
"essential": false,
"volumesFrom": [{"sourceContainer": "a"}]
}
]
}
""")
.when()
.post("/")
.then()
.statusCode(200)
.body("taskDefinition.containerDefinitions[0].mountPoints[0]"
+ ".sourceVolume", equalTo("v"))
.body("taskDefinition.containerDefinitions[0].mountPoints[0]"
+ ".containerPath", equalTo("/a"))
.body("taskDefinition.containerDefinitions[1].volumesFrom[0]"
+ ".sourceContainer", equalTo("a"))
.extract()
.path("taskDefinition.taskDefinitionArn");
ecs("DescribeTaskDefinition")
.body("""
{"taskDefinition": "%s"}
""".formatted(arn))
.when()
.post("/")
.then()
.statusCode(200)
.body("taskDefinition.containerDefinitions[0].mountPoints[0]", not(hasKey("readOnly")))
.body("taskDefinition.containerDefinitions[1].volumesFrom[0]", not(hasKey("readOnly")));
}
@Test
@Order(73)
void registerAndDescribeTaskDefinitionEchoesAnExplicitReadOnly() {
String arn = ecs("RegisterTaskDefinition")
.body("""
{
"family": "readonly-explicit-roundtrip",
"volumes": [{"name": "v"}],
"containerDefinitions": [
{
"name": "a",
"image": "nginx:latest",
"memory": 128,
"essential": true,
"mountPoints": [
{"sourceVolume": "v", "containerPath": "/ro", "readOnly": true},
{"sourceVolume": "v", "containerPath": "/rw", "readOnly": false}
],
"volumesFrom": [
{"sourceContainer": "b", "readOnly": true},
{"sourceContainer": "b", "readOnly": false}
]
},
{
"name": "b",
"image": "nginx:latest",
"memory": 128,
"essential": false
}
]
}
""")
.when()
.post("/")
.then()
.statusCode(200)
.extract()
.path("taskDefinition.taskDefinitionArn");
ecs("DescribeTaskDefinition")
.body("""
{"taskDefinition": "%s"}
""".formatted(arn))
.when()
.post("/")
.then()
.statusCode(200)
.body("taskDefinition.containerDefinitions[0].mountPoints[0].readOnly", equalTo(true))
.body("taskDefinition.containerDefinitions[0].mountPoints[1].readOnly", equalTo(false))
.body("taskDefinition.containerDefinitions[0].volumesFrom[0].readOnly", equalTo(true))
.body("taskDefinition.containerDefinitions[0].volumesFrom[1].readOnly", equalTo(false));
}
}
@@ -159,6 +159,87 @@ class EcsJsonHandlerVolumesTest {
assertFalse(mps.get(1).path("readOnly").asBoolean(), "aws mount is read-write");
}
@Test
void registerTaskDefinitionOmitsReadOnlyFromMountPointsAndVolumesFromThatNeverSentIt() throws Exception {
String requestJson = """
{
"family": "td",
"containerDefinitions": [
{
"name": "a",
"image": "nginx",
"memory": 128,
"essential": true,
"mountPoints": [
{"sourceVolume": "v", "containerPath": "/a"}
]
},
{
"name": "b",
"image": "nginx",
"memory": 128,
"essential": false,
"volumesFrom": [
{"sourceContainer": "a"}
]
}
],
"volumes": [{"name": "v"}]
}
""";
JsonNode request = objectMapper.readTree(requestJson);
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
JsonNode td = objectMapper.valueToTree(response.getEntity()).path("taskDefinition");
JsonNode containerA = td.path("containerDefinitions").get(0);
JsonNode containerB = td.path("containerDefinitions").get(1);
assertTrue(containerA.path("mountPoints").get(0).path("readOnly").isMissingNode(),
"a mountPoint registered without readOnly must not gain one");
assertTrue(containerB.path("volumesFrom").get(0).path("readOnly").isMissingNode(),
"a volumesFrom entry registered without readOnly must not gain one");
}
@Test
void registerTaskDefinitionEchoesAnExplicitReadOnlyOnMountPointsAndVolumesFrom() throws Exception {
String requestJson = """
{
"family": "td-explicit-readonly",
"containerDefinitions": [
{
"name": "app",
"image": "nginx",
"memory": 128,
"essential": true,
"mountPoints": [
{"sourceVolume": "v", "containerPath": "/ro", "readOnly": true},
{"sourceVolume": "v", "containerPath": "/rw", "readOnly": false}
],
"volumesFrom": [
{"sourceContainer": "other", "readOnly": true},
{"sourceContainer": "other2", "readOnly": false}
]
}
],
"volumes": [{"name": "v"}]
}
""";
JsonNode request = objectMapper.readTree(requestJson);
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
JsonNode td = objectMapper.valueToTree(response.getEntity()).path("taskDefinition");
JsonNode definition = td.path("containerDefinitions").get(0);
JsonNode mps = definition.path("mountPoints");
JsonNode volumesFrom = definition.path("volumesFrom");
assertTrue(mps.get(0).path("readOnly").asBoolean(), "explicit readOnly true must round-trip");
assertFalse(mps.get(1).path("readOnly").asBoolean(), "explicit readOnly false must round-trip");
assertTrue(volumesFrom.get(0).path("readOnly").asBoolean(),
"explicit volumesFrom readOnly true must round-trip");
assertFalse(volumesFrom.get(1).path("readOnly").asBoolean(),
"explicit volumesFrom readOnly false must round-trip");
}
@Test
void registerTaskDefinitionRoundTripsEfsVolumeConfiguration() throws Exception {
String requestJson = """