fix(efs): implement UpdateFileSystemProtection and report protection on describe (#2842)

A file system's replication overwrite protection was missing in two ways that
compound: the operation that sets it did not exist, and the field that reports
it never reached the wire.

UpdateFileSystemProtection had no route, so the terraform AWS provider's PUT to
/2015-02-01/file-systems/{id}/protection fell through to the S3 handler and came
back as an XML error body, which the SDK reported as "deserialization failed,
invalid character '<'". Every consumer of gruntwork's terraform-aws-data-storage
EFS module hits this rather than only those who opt in, because the module emits
the aws_efs_file_system `protection` block unconditionally.

Separately, protection was never reported. createFileSystem left the field null,
and FileSystem's accessor was named getFileSystemProtectionDescription() -- the
*shape* name. Under UpperCamelCaseStrategy the accessor name is the JSON key, so
even a populated field would have gone out as FileSystemProtectionDescription
rather than the member name FileSystemProtection that FileSystemDescription
actually declares.

So:
  - add UpdateFileSystemProtection (PUT .../{FileSystemId}/protection), returning
    FileSystemProtectionDescription, 404 for an unknown file system
  - default new file systems to ENABLED, which is what AWS documents
  - apply that default on read as well, so file systems in a store written before
    protection was modelled describe the same as one created today
  - rename the accessor to getFileSystemProtection()/setFileSystemProtection()

Authority: efs/2015-02-01/service-2.json -- operations.UpdateFileSystemProtection,
shapes.FileSystemDescription.members.FileSystemProtection.

Verified three ways: EfsIntegrationTest 13/13; a real AWS SDK round trip
(create -> describe reports ENABLED -> update DISABLED -> describe reports
DISABLED), which only passes if the wire names match the model; and
terraform-aws-data-storage/examples/efs, previously FLOCI_UNIMPLEMENTED at
apply, now OK through destroy.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-09-01 10:00:34 -04:00
1 parent 7513b2241b
commit db182b3048
6 files changed
+132 -3

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ The EFS emulator provides a metadata control plane for file systems, mount targe
| `CreateFileSystem` | - |
| `DescribeFileSystems` | - |
| `UpdateFileSystem` | - |
| `UpdateFileSystemProtection` | - |
| `DeleteFileSystem` | - |
| `CreateTags` | - |
| `DescribeTags` | - |
@@ -56,6 +56,14 @@ public class EfsController {
return Response.status(202).entity(fs).build();
}
@PUT
@Path("/file-systems/{FileSystemId}/protection")
public Response updateFileSystemProtection(@Context HttpHeaders headers, @PathParam("FileSystemId") String fileSystemId, UpdateFileSystemProtectionRequest request) {
String region = regionResolver.resolveRegion(headers);
FileSystemProtectionDescription protection = efsService.updateFileSystemProtection(region, fileSystemId, request);
return Response.ok(protection).build();
}
@DELETE
@Path("/file-systems/{FileSystemId}")
public Response deleteFileSystem(@Context HttpHeaders headers, @PathParam("FileSystemId") String fileSystemId) {
@@ -112,6 +112,10 @@ public class EfsService implements Resettable {
size.setValueInStandard(0L);
fs.setSizeInBytes(size);
// "Replication overwrite protection is ENABLED by default" -- the file system is
// writeable and cannot be a replication destination until something disables it.
fs.setFileSystemProtection(protection(ReplicationOverwriteProtection.ENABLED));
fileSystemStore.put(regionKey, fs);
BackupPolicy bp = new BackupPolicy();
@@ -134,7 +138,7 @@ public class EfsService implements Resettable {
fs.setName(tag.getValue());
});
}
return fs;
return withDefaultProtection(fs);
})
.sorted(Comparator.comparing(FileSystem::getFileSystemId))
.collect(Collectors.toList());
@@ -181,9 +185,40 @@ public class EfsService implements Resettable {
if (fs == null) {
throw EfsException.fileSystemNotFound(fileSystemId);
}
return withDefaultProtection(fs);
}
private static FileSystemProtectionDescription protection(ReplicationOverwriteProtection value) {
FileSystemProtectionDescription description = new FileSystemProtectionDescription();
description.setReplicationOverwriteProtection(value);
return description;
}
/**
* AWS always reports a protection status; there is no such thing as a file system
* without one. Applied on read as well as on create so that file systems already in
* a persisted store -- written before protection was modelled -- describe the same
* as one created today, rather than omitting the field.
*/
private static FileSystem withDefaultProtection(FileSystem fs) {
if (fs.getFileSystemProtection() == null) {
fs.setFileSystemProtection(protection(ReplicationOverwriteProtection.ENABLED));
}
return fs;
}
public FileSystemProtectionDescription updateFileSystemProtection(
String region, String fileSystemId, UpdateFileSystemProtectionRequest request) {
synchronized (lockFor(regionKey(region, fileSystemId))) {
FileSystem fs = getFileSystem(region, fileSystemId);
if (request != null && request.getReplicationOverwriteProtection() != null) {
fs.setFileSystemProtection(protection(request.getReplicationOverwriteProtection()));
fileSystemStore.put(regionKey(region, fileSystemId), fs);
}
return fs.getFileSystemProtection();
}
}
public FileSystem updateFileSystem(String region, String fileSystemId, UpdateFileSystemRequest request) {
synchronized (lockFor(regionKey(region, fileSystemId))) {
FileSystem fs = getFileSystem(region, fileSystemId);
@@ -88,11 +88,16 @@ public class FileSystem {
this.fileSystemId = fileSystemId;
}
public FileSystemProtectionDescription getFileSystemProtectionDescription() {
// The wire name is FileSystemProtection, not FileSystemProtectionDescription --
// FileSystemProtectionDescription is the *shape* name, and the member on
// FileSystemDescription that carries it is called FileSystemProtection. Because
// UpperCamelCaseStrategy derives the JSON key from the accessor, the old
// getFileSystemProtectionDescription() name put the shape name on the wire.
public FileSystemProtectionDescription getFileSystemProtection() {
return fileSystemProtection;
}
public void setFileSystemProtectionDescription(FileSystemProtectionDescription fileSystemProtection) {
public void setFileSystemProtection(FileSystemProtectionDescription fileSystemProtection) {
this.fileSystemProtection = fileSystemProtection;
}
@@ -0,0 +1,22 @@
package io.github.hectorvent.floci.services.efs.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
@JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class)
@RegisterForReflection
public class UpdateFileSystemProtectionRequest {
private ReplicationOverwriteProtection replicationOverwriteProtection;
public ReplicationOverwriteProtection getReplicationOverwriteProtection() {
return replicationOverwriteProtection;
}
public void setReplicationOverwriteProtection(
ReplicationOverwriteProtection replicationOverwriteProtection) {
this.replicationOverwriteProtection = replicationOverwriteProtection;
}
}
@@ -46,6 +46,7 @@ class EfsIntegrationTest {
.body("FileSystemId", startsWith("fs-"))
.body("Encrypted", equalTo(true))
.body("NumberOfMountTargets", equalTo(0))
.body("FileSystemProtection.ReplicationOverwriteProtection", equalTo("ENABLED"))
.body("Tags[0].Value", equalTo("MyFS"))
.extract().jsonPath().getString("FileSystemId");
}
@@ -200,6 +201,63 @@ class EfsIntegrationTest {
@Test
@Order(10)
void describeReportsProtectionEnabledByDefault() {
given()
.queryParam("FileSystemId", fileSystemId)
.when()
.get("/2015-02-01/file-systems")
.then()
.statusCode(200)
.body("FileSystems[0].FileSystemProtection.ReplicationOverwriteProtection",
equalTo("ENABLED"));
}
@Test
@Order(11)
void updateFileSystemProtection() {
given()
.contentType("application/json")
.body("""
{
"ReplicationOverwriteProtection": "DISABLED"
}
""")
.when()
.put("/2015-02-01/file-systems/" + fileSystemId + "/protection")
.then()
.statusCode(200)
.body("ReplicationOverwriteProtection", equalTo("DISABLED"));
// The change has to survive the round trip, not just echo back: the terraform
// provider reads protection back through DescribeFileSystems.
given()
.queryParam("FileSystemId", fileSystemId)
.when()
.get("/2015-02-01/file-systems")
.then()
.statusCode(200)
.body("FileSystems[0].FileSystemProtection.ReplicationOverwriteProtection",
equalTo("DISABLED"));
}
@Test
@Order(12)
void updateFileSystemProtectionOnMissingFileSystemIs404() {
given()
.contentType("application/json")
.body("""
{
"ReplicationOverwriteProtection": "DISABLED"
}
""")
.when()
.put("/2015-02-01/file-systems/fs-does-not-exist/protection")
.then()
.statusCode(404);
}
@Test
@Order(13)
void deleteResources() {
given()
.contentType("application/json")