fix(aws): refuse Docker/VPN on Fargate without grandfathering; launchTypePatch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-16 12:56:18 -08:00
1 parent 86f253b7da
commit c6b46a7347
4 files changed
+60 -16

No files matched your search

+20 -15
View File
@@ -1248,16 +1248,13 @@ fn validate_aws_update(
crate::models::validate_region(&place.region)?;
crate::aws::tofu_modules::validate_environment_name(&place.environment)?;
crate::models::validate_aws_workspace(cfg)?;
// Docker access and VPN need the user's own instance (E6, E7);
// Fargate refuses them. Grandfather a value the stored project
// already had on AWS so an old row can still be saved.
// Docker access and VPN need the user's own instance (E6, E7).
if cfg.launch_type != crate::models::LaunchType::Ec2 {
let was_aws = stored.aws.is_some();
if project.allow_docker_access && !(was_aws && stored.allow_docker_access) {
return Err("Docker access on AWS needs the EC2 launch type".into());
if project.allow_docker_access {
return Err("Docker access on AWS needs the EC2 launch type; turn it off first".into());
}
if project.vpn_support_enabled && !(was_aws && stored.vpn_support_enabled) {
return Err("VPN support on AWS needs the EC2 launch type".into());
if project.vpn_support_enabled {
return Err("VPN support on AWS needs the EC2 launch type; turn it off first".into());
}
}
// Q6: forwarded over loopback, TCP only, never a reserved port
@@ -2918,13 +2915,21 @@ mod tests {
p.allow_docker_access = docker;
p.vpn_support_enabled = vpn;
assert!(validate_aws_update(&stored, &p, &hosts).is_err());
// A value the AWS project already had is grandfathered.
let mut old = stored.clone();
old.allow_docker_access = docker;
old.vpn_support_enabled = vpn;
assert!(validate_aws_update(&old, &old, &hosts).is_ok());
p.aws.as_mut().unwrap().launch_type = LaunchType::Ec2;
assert!(validate_aws_update(&stored, &p, &hosts).is_ok());
// Already stored that way on Fargate: still refused (no grandfathering).
assert!(validate_aws_update(&p, &p, &hosts).is_err());
// Ec2 -> Fargate with the flags still on: refused.
let mut ec2 = p.clone();
ec2.aws.as_mut().unwrap().launch_type = LaunchType::Ec2;
assert!(validate_aws_update(&ec2, &ec2, &hosts).is_ok());
assert!(validate_aws_update(&ec2, &p, &hosts).is_err());
// Local -> AWS(Fargate) with the flags on: refused.
let mut local = stored.clone();
local.host_id = None;
local.aws_placement = None;
local.aws = None;
local.allow_docker_access = docker;
local.vpn_support_enabled = vpn;
assert!(validate_aws_update(&local, &p, &hosts).is_err());
}
}
+7 -1
View File
@@ -735,7 +735,8 @@ pub fn ec2_instance_spec(instance_type: &str) -> Option<(u32, u32)> {
"c7i" | "c7g" => 2,
"r7i" | "r7g" => 8,
"t3" | "t4g" => {
// Burstable: 2 vCPU with 8 GiB (large), then no 4xlarge exists.
// Burstable families: memory is 4 GiB per vCPU at xlarge and above,
// 8 GiB at large; AWS offers no 4xlarge in these families.
return match size {
"large" => Some((2048, 8192)),
"xlarge" => Some((4096, 16384)),
@@ -761,6 +762,11 @@ pub enum Fit {
/// Check an EC2 config's reservations against `instance_type`, less the agent
/// and OS reserve. A Fargate config always fits (no instance involved).
///
/// Nominal sizes only: ECS registers less memory than the instance's nominal
/// (the ECS-optimized AMI reserves some, e.g. ~7.5 GiB on an 8 GiB type), so a
/// later task should leave headroom or use the container instance's
/// registered memory.
pub fn fits_instance(cfg: &AwsWorkspaceConfig, instance_type: &str) -> Fit {
if cfg.launch_type != LaunchType::Ec2 {
return Fit::Ok;