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:
1 parent
86f253b7da
commit
c6b46a7347
4 files changed
+60
-16
No files matched your search
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import RuntimeSection from "./RuntimeSection";
|
||||
import type { AuthBridgeStatus, Project } from "../../../../lib/types";
|
||||
import { launchTypePatch } from "../../../../lib/awsWorkspace";
|
||||
import { awsProject } from "../../../../test/awsFixtures";
|
||||
|
||||
// The auth-bridge row owns its own IPC — see `AuthBridgeRow.tsx` for why it
|
||||
@@ -196,4 +197,23 @@ describe("RuntimeSection — Docker and VPN on AWS follow the launch type", () =
|
||||
expect(screen.getByRole("switch", { name: VPN })).toBeEnabled();
|
||||
expect(screen.getByRole("switch", { name: "Allow container spawning" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("saves the flags when toggled on EC2", () => {
|
||||
const p = awsProject({ vpn_support_enabled: false, allow_docker_access: false });
|
||||
renderSection({ ...p, aws: { ...p.aws!, launch_type: "ec2" } });
|
||||
fireEvent.click(screen.getByRole("switch", { name: VPN }));
|
||||
expect(save).toHaveBeenCalledWith({ vpn_support_enabled: true });
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Allow container spawning" }));
|
||||
expect(save).toHaveBeenCalledWith({ allow_docker_access: true });
|
||||
});
|
||||
|
||||
it("launchTypePatch clears Docker and VPN when switching to Fargate", () => {
|
||||
const p = awsProject({ allow_docker_access: true, vpn_support_enabled: true });
|
||||
const toFargate = launchTypePatch(p, "fargate");
|
||||
expect(toFargate).toMatchObject({ allow_docker_access: false, vpn_support_enabled: false });
|
||||
expect(toFargate.aws?.launch_type).toBe("fargate");
|
||||
const toEc2 = launchTypePatch(p, "ec2");
|
||||
expect(toEc2.allow_docker_access).toBeUndefined();
|
||||
expect(toEc2.aws?.launch_type).toBe("ec2");
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import type {
|
||||
AwsWorkspaceConfig,
|
||||
DetectedEnvironment,
|
||||
GatewaySettings,
|
||||
LaunchType,
|
||||
Project,
|
||||
RepoSource,
|
||||
UnsavedWork,
|
||||
@@ -238,3 +239,15 @@ export function localEndpointProblem(url: string, gatewayPort: number | null): s
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The save patch for switching an AWS project's launch type. Docker access and
|
||||
* VPN need EC2 (Rust refuses them on Fargate), so switching to Fargate turns
|
||||
* them off in the same save. Task 6's launch-type control must use this. */
|
||||
export function launchTypePatch(project: Project, launch_type: LaunchType): Partial<Project> {
|
||||
const patch: Partial<Project> = { aws: { ...project.aws!, launch_type } };
|
||||
if (launch_type !== "ec2") {
|
||||
patch.allow_docker_access = false;
|
||||
patch.vpn_support_enabled = false;
|
||||
}
|
||||
return patch;
|
||||
}
|
||||
Reference in new issue
Block a user