mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ec2): apply EBS encryption by default to new volumes and root volumes (#5371)
* fix(ec2): apply EBS encryption by default to new volumes and root volumes EnableEbsEncryptionByDefault stored the flag but nothing on the volume creation path read it, so CreateVolume and the RunInstances root volume came back Encrypted=false even with the default on. CreateVolume now encrypts when the region default is on, and an explicit Encrypted=false cannot opt out, as on AWS. The RunInstances root volume follows the same rule. The setting is per region. Fixes #5370 * test(ec2): use an explicit RequestSpecification type instead of var * refactor(ec2): take Ec2EbsEncryptionService on the CDI constructor Constructor injection per AGENTS.md: Ec2EbsEncryptionService joins the other CDI-only dependencies on Ec2Service's @Inject constructor instead of being a field. The test uses a static import for assertEquals in place of the private wrapper.
This commit is contained in:
1 parent
eb3c14d414
commit
da063a82f8
2 files changed
+170
-2
No files matched your search
@@ -294,6 +294,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
private jakarta.enterprise.inject.Instance<ClusterNodeInstanceProvider> clusterNodeInstanceProviders;
|
||||
private ClusterNodeInstanceProvider testClusterNodeInstanceProvider;
|
||||
private final Ec2VolumeBlockDeviceManager volumeBlockDeviceManager;
|
||||
// Only the CDI constructor receives it; null on the hand-built constructors, which reads as
|
||||
// "encryption by default is off".
|
||||
private Ec2EbsEncryptionService ebsEncryptionService;
|
||||
private jakarta.enterprise.inject.Instance<VpcRouteTableListener> routeTableListenersInstance;
|
||||
private final List<VpcRouteTableListener> routeTableListeners = new CopyOnWriteArrayList<>();
|
||||
private jakarta.enterprise.inject.Instance<Ec2InstanceLaunchListener> instanceLaunchListenersInstance;
|
||||
@@ -428,13 +431,15 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
jakarta.enterprise.inject.Instance<ClusterNodeInstanceProvider> clusterNodeInstanceProviders,
|
||||
Ec2VolumeBlockDeviceManager volumeBlockDeviceManager,
|
||||
jakarta.enterprise.inject.Instance<VpcRouteTableListener> routeTableListenersInstance,
|
||||
jakarta.enterprise.inject.Instance<Ec2InstanceLaunchListener> instanceLaunchListenersInstance) {
|
||||
jakarta.enterprise.inject.Instance<Ec2InstanceLaunchListener> instanceLaunchListenersInstance,
|
||||
Ec2EbsEncryptionService ebsEncryptionService) {
|
||||
this(config, containerManager, portForwardManager, amiImageResolver, imageCatalog,
|
||||
instanceTypeCatalog, storageFactory, requestContextInstance, iamService, volumeBlockDeviceManager);
|
||||
this.vpcNetworkManager = vpcNetworkManager;
|
||||
this.clusterNodeInstanceProviders = clusterNodeInstanceProviders;
|
||||
this.routeTableListenersInstance = routeTableListenersInstance;
|
||||
this.instanceLaunchListenersInstance = instanceLaunchListenersInstance;
|
||||
this.ebsEncryptionService = ebsEncryptionService;
|
||||
}
|
||||
|
||||
public Ec2Service(EmulatorConfig config, Ec2ContainerManager containerManager,
|
||||
@@ -3482,6 +3487,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
rootVol.setSize(DEFAULT_ROOT_VOLUME_SIZE_GIB);
|
||||
rootVol.setState("in-use");
|
||||
rootVol.setRegion(region);
|
||||
rootVol.setEncrypted(ebsEncryptionByDefault(region));
|
||||
rootVol.setCreateTime(Instant.now());
|
||||
VolumeAttachment att = new VolumeAttachment();
|
||||
att.setVolumeId(rootVolId);
|
||||
@@ -9785,6 +9791,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
// ─── Volumes ───────────────────────────────────────────────────────────────
|
||||
|
||||
private boolean ebsEncryptionByDefault(String region) {
|
||||
return ebsEncryptionService != null && ebsEncryptionService.getEbsEncryptionByDefault(region);
|
||||
}
|
||||
|
||||
public Volume createVolume(String region, String availabilityZone, String volumeType,
|
||||
int size, boolean encrypted, int iops, Integer throughput,
|
||||
String snapshotId, List<Tag> volumeTags) {
|
||||
@@ -9796,7 +9806,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
vol.setAvailabilityZone(availabilityZone != null ? availabilityZone : region + "a");
|
||||
vol.setVolumeType(effectiveType);
|
||||
vol.setSize(size > 0 ? size : 8);
|
||||
vol.setEncrypted(encrypted);
|
||||
// With encryption by default on, AWS encrypts every new volume and the Encrypted parameter
|
||||
// cannot opt out of it.
|
||||
vol.setEncrypted(encrypted || ebsEncryptionByDefault(region));
|
||||
vol.setIops(iops > 0 ? iops : (volumeType != null && volumeType.startsWith("io") ? iops : 0));
|
||||
// Throughput is a gp3-only attribute; AWS reports 125 MiB/s by default for gp3.
|
||||
if ("gp3".equals(effectiveType)) {
|
||||
|
||||
Reference in new issue
Block a user