feat(aws): EFS storage mode

EFS storage is Hybrid plus /workspace on a second access point of the
user's own file system, rooted at /triple-c-workspaces/<owner_key>/<project>
(a sibling of the home roots) and mounted at /workspace. The workspace
access point is found by root + owner + project tags or created, waited
for before RunTask, recorded store-owned, kept when switching to Hybrid or
Ephemeral, and deleted with the home one by a discarding removal. Hybrid
and Ephemeral task definitions are byte-identical to before (pinned
fingerprints).

The entrypoint links home state for efs as for hybrid, warns when
/workspace is not mounted, and marks a clone in progress in its own
.git/config so a clone a killed task cut short is redone on the next start
while existing repositories are still skipped.

The EFS segment is enabled in HostSection, with a note when /workspace
files remain on an access point after switching away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-15 21:44:17 -08:00
1 parent cbaf6209fd
commit 5477c2cea5
20 files changed
+790 -100

No files matched your search

+8 -1
View File
@@ -396,7 +396,14 @@ docker exec stdout → tokio task → emit("terminal-output-{sessionId}") → li
every terminal's env and the files hold private keys). Repos clone in the background after the agent
starts (terminals are usable before they arrive). Hybrid storage mounts EFS at `/mnt/triple-c-home`
and symlinks `~/.claude`, `~/.claude.json`, `~/.ssh` into it (mounting over `/home/claude` would hide
the image's tooling); root never follows those links outside the mount (`aws_hybrid_ssh_dir`). On
the image's tooling); root never follows those links outside the mount (`aws_hybrid_ssh_dir`). EFS storage
is Hybrid plus a second access point (root `/triple-c-workspaces/<owner_key>/<project>`, a sibling of
the home roots) mounted straight at `/workspace`; the entrypoint links home state the same way
(`aws_storage_links_home`) and never creates or chowns `/workspace`. Because `/workspace` then
outlives the task, `clone_repos` marks a clone in progress in its own `.git/config`
(`triplec.cloning`) and redoes one a killed task left marked; a repo without the mark is skipped.
Switching EFS → Hybrid/Ephemeral keeps `workspace_access_point_id` (store-owned) until "Remove AWS
resources" with discard deletes both access points. On
TERM the hook pushes unsaved work to a `triple-c/wip/<stamp>` branch via a temporary index (the
user's index is untouched; needs the task definition's `stopTimeout` raised, 120 s) unless the stop
marker says the app handled it. The idle watcher runs as root under a supervisor and signals the
+20 -10
View File
@@ -18,7 +18,7 @@ use super::environments::{knowable, parse_environment_record, EnvironmentInfo, K
use super::error::{classify_sdk_error, AwsError};
use super::tasks::{find_project_task, TaskApi, STOP_REASON};
use super::tofu_modules::{
access_point_root, environment_cluster_name, environment_parameter_name, project_secret_name, task_family,
access_point_root, workspace_access_point_root, environment_cluster_name, environment_parameter_name, project_secret_name, task_family,
user_file_system_token, user_role_names,
};
use super::workspace::WorkspaceApi;
@@ -234,15 +234,18 @@ pub struct RemoveRequest<'a> {
/// missed it).
pub stored_task_arn: Option<&'a str>,
pub stored_access_point_id: Option<&'a str>,
/// Delete the EFS access point (ruling R9). The files stay on the
/// user's own file system (only their task role can read it) until
/// offboarding destroys it; a later start of the same project gets a new
/// access point onto the same directory.
/// The EFS-mode `/workspace` access point the store has (kept after a
/// switch to Hybrid or Ephemeral, Q1).
pub stored_workspace_access_point_id: Option<&'a str>,
/// Delete the EFS access points, home and `/workspace` (ruling R9). The
/// files stay on the user's own file system (only their task role can
/// read it) until offboarding destroys it; a later start of the same
/// project gets new access points onto the same directories.
pub discard_data: bool,
}
/// Stop the project's task, delete its secret (no recovery window, R10) and,
/// with `discard_data`, delete its access point (not the files, R9). Task definition revisions
/// with `discard_data`, delete its access points (not the files, R9). Task definition revisions
/// are left registered (R8). A task that can't be stopped stops the removal (nothing
/// billed may be left running); the rest is attempted in full and every
/// failure reported.
@@ -288,20 +291,27 @@ pub async fn remove_workspace_resources<T: TaskApi, W: WorkspaceApi, R: RuntimeA
failures.push(format!("secret {secret}: {e}"));
}
// 4. The access point, only when asked.
// 4. The access points (home, and EFS mode's `/workspace`), only when asked.
if req.discard_data {
let mut ids: Vec<String> = req.stored_access_point_id.map(String::from).into_iter().collect();
let mut ids: Vec<String> = [req.stored_access_point_id, req.stored_workspace_access_point_id]
.into_iter()
.flatten()
.map(String::from)
.collect();
let token = user_file_system_token(req.env, req.owner_key);
match work.find_file_system(&token).await {
Ok(Some(fs)) if fs.owner.as_deref() == Some(req.owner_user_id) => {
let root = access_point_root(req.owner_key, req.project_id);
let roots = [
access_point_root(req.owner_key, req.project_id),
workspace_access_point_root(req.owner_key, req.project_id),
];
match work.access_points(&fs.id).await {
Ok(points) => ids.extend(
points
.into_iter()
.filter(|a| {
a.file_system_id == fs.id
&& a.root_path.as_deref() == Some(root.as_str())
&& a.root_path.as_ref().is_some_and(|r| roots.contains(r))
&& a.owner.as_deref() == Some(req.owner_user_id)
&& a.project.as_deref() == Some(req.project_id)
})
+58 -1
View File
@@ -5,7 +5,7 @@ use aws_sdk_ecs::operation::run_task::RunTaskInput;
use super::*;
use crate::aws::tasks::TaskInfo;
use crate::aws::tofu_modules::owner_key;
use crate::aws::tofu_modules::{owner_key, workspace_access_point_root};
use crate::aws::workspace::{AccessPointRef, FileSystemRef, TaskDefinitionRef};
const REGION: &str = "eu-west-1";
@@ -288,6 +288,7 @@ async fn removal_stops_the_task_leaves_the_revisions_and_schedules_the_secret()
project_id: PROJECT,
stored_task_arn: Some(&t0),
stored_access_point_id: Some("fsap-stored"),
stored_workspace_access_point_id: None,
discard_data: false,
};
remove_workspace_resources(&fake, &fake, &fake, &r).await.unwrap();
@@ -323,9 +324,65 @@ async fn a_failed_step_is_reported_but_the_rest_still_runs() {
project_id: PROJECT,
stored_task_arn: None,
stored_access_point_id: Some("fsap-1"),
stored_workspace_access_point_id: None,
discard_data: true,
};
let e = remove_workspace_resources(&fake, &fake, &fake, &r).await.unwrap_err();
assert!(e.to_string().contains("secret"), "{e}");
assert!(fake.calls().contains(&"delete-ap fsap-1".to_string()));
}
#[tokio::test]
async fn removal_with_discard_deletes_both_access_points_and_without_keeps_both() {
let ap = |id: &str, root: String| AccessPointRef {
id: id.into(),
file_system_id: "fs-1".into(),
root_path: Some(root),
owner: Some(USER.into()),
project: Some(PROJECT.into()),
state: Some("available".into()),
};
let points = vec![
ap("fsap-home", access_point_root(&ok(), PROJECT)),
ap("fsap-ws", workspace_access_point_root(&ok(), PROJECT)),
AccessPointRef {
owner: Some("AROAOTHER:mallory".into()),
..ap("fsap-foreign", workspace_access_point_root(&ok(), PROJECT))
},
AccessPointRef {
project: Some("another".into()),
..ap("fsap-other-project", workspace_access_point_root(&ok(), PROJECT))
},
];
let key = ok();
let mut r = RemoveRequest {
env: "dev",
region: REGION,
owner_user_id: USER,
owner_key: &key,
project_id: PROJECT,
stored_task_arn: None,
stored_access_point_id: Some("fsap-home"),
// Kept in the store after switching EFS -> Hybrid.
stored_workspace_access_point_id: Some("fsap-ws-stored"),
discard_data: false,
};
let keep = Fake { access_points: points.clone(), ..Default::default() };
remove_workspace_resources(&keep, &keep, &keep, &r).await.unwrap();
assert!(
keep.calls().iter().all(|c| !c.starts_with("delete-ap")),
"{:?}",
keep.calls()
);
r.discard_data = true;
let discard = Fake { access_points: points, ..Default::default() };
remove_workspace_resources(&discard, &discard, &discard, &r).await.unwrap();
let mut deleted: Vec<String> = discard
.calls()
.into_iter()
.filter_map(|c| c.strip_prefix("delete-ap ").map(String::from))
.collect();
deleted.sort();
assert_eq!(deleted, vec!["fsap-home", "fsap-ws", "fsap-ws-stored"]);
}
+11
View File
@@ -202,6 +202,17 @@ pub fn access_point_root(owner_key: &str, project_id: &str) -> String {
format!("/triple-c/{owner_key}/{}", project_component(project_id))
}
/// The root of the project's EFS-mode `/workspace` access point (Q1):
/// `/triple-c-workspaces/<owner_key>/<project>`, a sibling tree of the home
/// roots (under [`access_point_root`] it would sit inside the home access
/// point). At most 100 characters.
pub fn workspace_access_point_root(owner_key: &str, project_id: &str) -> String {
format!(
"/triple-c-workspaces/{owner_key}/{}",
project_component(project_id)
)
}
/// The container's `awslogs-stream-prefix`; ECS names the stream
/// `<prefix>/workspace/<task id>`.
pub fn log_stream_prefix(owner_key: &str, project_id: &str) -> String {
+81 -36
View File
@@ -1,5 +1,6 @@
//! A project's AWS resources, made ready before its task runs: the project
//! secret, the EFS access point (Hybrid storage) and the task definition.
//! secret, the EFS access points (Hybrid: home; EFS: home and `/workspace`)
//! and the task definition.
//!
//! **Everything project-shaped goes in the secret (P1).** Every workspace user
//! has `ecs:Describe*` on `*`, so a task definition's `environment`, tags and
@@ -43,7 +44,7 @@ use super::error::{classify_sdk_error, AwsError};
use super::identity::CallerIdentity;
use super::tofu_modules::{
access_point_root, log_stream_prefix, owner_key, project_secret_name, task_family,
user_file_system_token, user_role_names,
user_file_system_token, user_role_names, workspace_access_point_root,
};
use crate::host::ssm::AGENT_PORT;
use crate::models::project::{validate_aws_workspace, Arch, RepoSource, StorageMode};
@@ -59,6 +60,9 @@ pub const CONTAINER_NAME: &str = "workspace";
/// Where a Hybrid project's access point is mounted (P4).
pub const HOME_MOUNT_PATH: &str = "/mnt/triple-c-home";
const HOME_VOLUME: &str = "home";
/// Where an EFS-mode project's second access point is mounted (Q1).
pub const WORKSPACE_MOUNT_PATH: &str = "/workspace";
const WORKSPACE_VOLUME: &str = "workspace";
/// Secrets Manager's `SecretString` limit.
pub const MAX_SECRET_BYTES: usize = 65_536;
/// At most this many of a family's newest revisions are described when
@@ -184,7 +188,7 @@ fn payload_map(
match storage {
StorageMode::Ephemeral => "ephemeral",
StorageMode::Hybrid => "hybrid",
StorageMode::Efs => "efs", // Task 3
StorageMode::Efs => "efs",
}
.into(),
);
@@ -212,7 +216,7 @@ fn serialize_payload(m: &BTreeMap<String, String>) -> Result<String, String> {
/// The project secret's JSON (P1, R1): every env pair, then the payload's own
/// keys (`TRIPLEC_AGENT_TOKEN`, `TRIPLEC_FILES` = `{"ssh/<f>"|"ca/<f>": base64}`,
/// `TRIPLEC_REPOS`, `TRIPLEC_WIP_PUSH` = `1`/`0`, `TRIPLEC_IDLE_STOP_MINUTES`
/// when on, `TRIPLEC_STORAGE` = `ephemeral`/`hybrid`), keys sorted. Fails
/// when on, `TRIPLEC_STORAGE` = `ephemeral`/`hybrid`/`efs`), keys sorted. Fails
/// when it would exceed 65,536 bytes.
#[cfg_attr(not(test), allow(dead_code))]
pub fn project_secret_payload(
@@ -255,9 +259,11 @@ pub struct WorkspacePlan {
pub secret_arn: String,
/// Sorted (the payload's key order).
pub secret_keys: Vec<String>,
/// Both set for Hybrid, both `None` for Ephemeral.
/// Both set for Hybrid and EFS, both `None` for Ephemeral.
pub file_system_id: Option<String>,
pub access_point_id: Option<String>,
/// The `/workspace` access point; used only when `storage` is EFS.
pub workspace_access_point_id: Option<String>,
pub tags: Vec<(String, String)>,
}
@@ -328,7 +334,14 @@ pub fn task_definition_request(plan: &WorkspacePlan) -> RegisterTaskDefinitionIn
fn build_request(plan: &WorkspacePlan) -> RegisterTaskDefinitionInput {
const BUILT: &str = "every required field is set";
let hybrid = match (&plan.storage, &plan.file_system_id, &plan.access_point_id) {
(StorageMode::Hybrid | StorageMode::Efs, Some(fs), Some(ap)) => Some((fs, ap)), // Task 3: Efs adds /workspace
(StorageMode::Hybrid | StorageMode::Efs, Some(fs), Some(ap)) => Some((fs, ap)),
_ => None,
};
// EFS = Hybrid + `/workspace` on its own access point. Hybrid and
// Ephemeral requests are exactly what they were before EFS mode (a
// test pins their fingerprints).
let workspace = match (&plan.storage, hybrid, &plan.workspace_access_point_id) {
(StorageMode::Efs, Some((fs, _)), Some(ap)) => Some((fs, ap)),
_ => None,
};
@@ -392,6 +405,15 @@ fn build_request(plan: &WorkspacePlan) -> RegisterTaskDefinitionInput {
.build(),
);
}
if workspace.is_some() {
container = container.mount_points(
MountPoint::builder()
.source_volume(WORKSPACE_VOLUME)
.container_path(WORKSPACE_MOUNT_PATH)
.read_only(false)
.build(),
);
}
let mut req = RegisterTaskDefinitionInput::builder()
.family(&plan.family)
@@ -422,29 +444,35 @@ fn build_request(plan: &WorkspacePlan) -> RegisterTaskDefinitionInput {
.map(|(k, v)| Tag::builder().key(k).value(v).build())
.collect(),
));
if let Some((fs, ap)) = hybrid {
req = req.volumes(
Volume::builder()
.name(HOME_VOLUME)
.efs_volume_configuration(
EfsVolumeConfiguration::builder()
.file_system_id(fs)
.transit_encryption(EfsTransitEncryption::Enabled)
.authorization_config(
EfsAuthorizationConfig::builder()
.access_point_id(ap)
.iam(EfsAuthorizationConfigIam::Enabled)
.build(),
)
.build()
.expect(BUILT),
)
.build(),
);
for (name, (fs, ap)) in [(HOME_VOLUME, hybrid), (WORKSPACE_VOLUME, workspace)]
.into_iter()
.filter_map(|(n, v)| v.map(|v| (n, v)))
{
req = req.volumes(efs_volume(name, fs, ap));
}
req.build().expect(BUILT)
}
/// An EFS volume through an access point, IAM-authorised, TLS in transit.
fn efs_volume(name: &str, fs: &str, ap: &str) -> Volume {
Volume::builder()
.name(name)
.efs_volume_configuration(
EfsVolumeConfiguration::builder()
.file_system_id(fs)
.transit_encryption(EfsTransitEncryption::Enabled)
.authorization_config(
EfsAuthorizationConfig::builder()
.access_point_id(ap)
.iam(EfsAuthorizationConfigIam::Enabled)
.build(),
)
.build()
.expect("every required field is set"),
)
.build()
}
// ---------------------------------------------------------------------- API
#[derive(Debug, Clone, PartialEq)]
@@ -593,12 +621,14 @@ pub struct PreparedWorkspace {
/// Exact `family:revision`.
pub task_definition_arn: String,
pub access_point_id: Option<String>,
/// EFS storage's `/workspace` access point.
pub workspace_access_point_id: Option<String>,
/// This start's token, already in the secret.
pub agent_token: String,
pub secret_arn: String,
}
/// Make the project's secret, access point (Hybrid) and task definition
/// Make the project's secret, access points (Hybrid, EFS) and task definition
/// ready. Everything that can be checked locally — placement, sizes, the
/// payload's size and names — is checked before the first write.
pub async fn prepare_workspace<W: WorkspaceApi>(
@@ -652,10 +682,11 @@ pub async fn prepare_workspace<W: WorkspaceApi>(
.map_err(other)?;
let json = serialize_payload(&payload).map_err(other)?;
// Hybrid: the user's own file system, from their onboarding.
let (file_system_id, access_point_id) = match cfg.storage {
StorageMode::Ephemeral => (None, None),
StorageMode::Hybrid | StorageMode::Efs => { // Task 3: Efs adds the workspace access point
// Hybrid and EFS: the user's own file system, from their onboarding.
let (file_system_id, access_point_id, workspace_access_point_id) = match cfg.storage {
StorageMode::Ephemeral => (None, None, None),
StorageMode::Hybrid | StorageMode::Efs => {
let mode = if cfg.storage == StorageMode::Efs { "EFS" } else { "Hybrid" };
let token = user_file_system_token(&env.name, &ok);
let fs = api
.find_file_system(&token)
@@ -663,19 +694,31 @@ pub async fn prepare_workspace<W: WorkspaceApi>(
.filter(|fs| fs.owner.as_deref() == Some(who.user_id.as_str()))
.ok_or_else(|| {
other(format!(
"Your file system in environment \"{}\" was not found. Hybrid storage \
"Your file system in environment \"{}\" was not found. {mode} storage \
needs it: ask an administrator to onboard you there, or use \
Ephemeral storage.",
env.name
))
})?;
let root = access_point_root(&ok, &project.id);
let points = api.access_points(&fs.id).await?;
let ap = match pick_access_point(&points, &fs.id, &root, &who.user_id, &project.id) {
Some(a) => a.id.clone(),
None => api.create_access_point(&fs.id, &root, &tags).await?,
let ensure = |root: String| {
let found = pick_access_point(&points, &fs.id, &root, &who.user_id, &project.id)
.map(|a| a.id.clone());
let (fs_id, tags) = (&fs.id, &tags);
async move {
match found {
Some(id) => Ok(id),
None => api.create_access_point(fs_id, &root, tags).await,
}
}
};
(Some(fs.id), Some(ap))
let ap = ensure(access_point_root(&ok, &project.id)).await?;
let workspace_ap = if cfg.storage == StorageMode::Efs {
Some(ensure(workspace_access_point_root(&ok, &project.id)).await?)
} else {
None
};
(Some(fs.id), Some(ap), workspace_ap)
}
};
@@ -703,6 +746,7 @@ pub async fn prepare_workspace<W: WorkspaceApi>(
secret_keys: payload.keys().cloned().collect(),
file_system_id,
access_point_id: access_point_id.clone(),
workspace_access_point_id: workspace_access_point_id.clone(),
tags,
};
let fingerprint = workspace_fingerprint(&plan);
@@ -729,6 +773,7 @@ pub async fn prepare_workspace<W: WorkspaceApi>(
family: plan.family,
task_definition_arn,
access_point_id,
workspace_access_point_id,
agent_token,
secret_arn,
})
+182 -3
View File
@@ -9,7 +9,7 @@ use crate::aws::environments::EnvironmentInfo;
use crate::aws::identity::CallerIdentity;
use crate::aws::tofu_modules::{
access_point_root, log_stream_prefix, owner_key, project_secret_name, task_family,
user_file_system_token,
user_file_system_token, workspace_access_point_root,
};
use crate::models::project::{Arch, AwsPlacement, AwsWorkspaceConfig, RepoSource, StorageMode};
use crate::models::Project;
@@ -96,8 +96,10 @@ fn sample_plan(storage: StorageMode) -> WorkspacePlan {
"GIT_TOKEN".into(),
"TRIPLEC_AGENT_TOKEN".into(),
],
file_system_id: (storage == StorageMode::Hybrid).then(|| "fs-0123abcd".to_string()),
access_point_id: (storage == StorageMode::Hybrid).then(|| "fsap-0123abcd".to_string()),
file_system_id: (storage != StorageMode::Ephemeral).then(|| "fs-0123abcd".to_string()),
access_point_id: (storage != StorageMode::Ephemeral).then(|| "fsap-0123abcd".to_string()),
workspace_access_point_id: (storage == StorageMode::Efs)
.then(|| "fsap-4567efab".to_string()),
tags: workspace_tags(USER, PROJECT_ID, "dev"),
}
}
@@ -113,6 +115,7 @@ fn names_use_owner_key_and_never_contain_a_colon() {
access_point_root(&ok, PROJECT_ID),
log_stream_prefix(&ok, PROJECT_ID),
user_file_system_token("dev", &ok),
workspace_access_point_root(&ok, PROJECT_ID),
];
for n in &names {
assert!(n.contains(&ok), "{n} lacks the owner key");
@@ -125,6 +128,9 @@ fn names_use_owner_key_and_never_contain_a_colon() {
assert_eq!(names[3], format!("{ok}/{PROJECT_ID}"));
// The onboarding module's `creation_token` (local.name).
assert_eq!(names[4], format!("triple-c-dev-{ok}"));
// A sibling of the home roots, never inside one (Q1).
assert_eq!(names[5], format!("/triple-c-workspaces/{ok}/{PROJECT_ID}"));
assert!(!names[5].starts_with(&format!("{}/", names[2])));
}
#[test]
@@ -144,6 +150,12 @@ fn names_sanitise_a_hostile_project_id() {
!tail.is_empty() && !tail.contains('/') && tail != "." && tail != "..",
"{root}"
);
let wroot = workspace_access_point_root(&ok, id);
assert_eq!(
wroot.strip_prefix(&format!("/triple-c-workspaces/{ok}/")),
Some(tail),
"{wroot}"
);
let secret = project_secret_name("dev", &ok, id);
assert!(!secret.contains(':') && !secret.contains(".."), "{secret}");
assert_eq!(secret.matches('/').count(), 3, "{secret}");
@@ -151,6 +163,7 @@ fn names_sanitise_a_hostile_project_id() {
let long = "x".repeat(500);
assert!(task_family("abcdefghijklmnopqrst", &ok, &long).len() <= 255);
assert!(access_point_root(&ok, &long).len() <= 100);
assert!(workspace_access_point_root(&ok, &long).len() <= 100);
}
// ------------------------------------------------------- task definition
@@ -311,6 +324,84 @@ fn hybrid_mounts_the_access_point_with_iam_and_tls() {
assert_eq!(mounts[0].read_only(), Some(false));
}
/// Captured before EFS mode existed: Hybrid and Ephemeral requests must not
/// change (a changed fingerprint registers a new revision for every project).
#[test]
fn hybrid_and_ephemeral_requests_are_unchanged_by_efs_mode() {
assert_eq!(
workspace_fingerprint(&sample_plan(StorageMode::Hybrid)),
"d6d00b3f3489060c40ff732be8eb8a10e723e26dd5f1ff58345e4c2a307f862d"
);
assert_eq!(
workspace_fingerprint(&sample_plan(StorageMode::Ephemeral)),
"00f248ed315167fe7a1adc0ea5c8bcee328e8a0739a1c4f9ce9ac10270851786"
);
// A stray workspace access point (kept after switching EFS → Hybrid)
// does not reach a Hybrid or Ephemeral request.
for storage in [StorageMode::Hybrid, StorageMode::Ephemeral] {
let mut p = sample_plan(storage);
p.workspace_access_point_id = Some("fsap-stray".into());
assert_eq!(
workspace_fingerprint(&p),
workspace_fingerprint(&sample_plan(storage))
);
}
}
#[test]
fn efs_mounts_home_and_workspace_access_points() {
let req = task_definition_request(&sample_plan(StorageMode::Efs));
let vols = req.volumes();
assert_eq!(vols.len(), 2);
let by_name = |n: &str| vols.iter().find(|v| v.name() == Some(n)).unwrap();
for (name, ap) in [("home", "fsap-0123abcd"), ("workspace", "fsap-4567efab")] {
let efs = by_name(name).efs_volume_configuration().unwrap();
assert_eq!(efs.file_system_id(), "fs-0123abcd");
assert_eq!(efs.transit_encryption(), Some(&EfsTransitEncryption::Enabled));
let auth = efs.authorization_config().unwrap();
assert_eq!(auth.access_point_id(), Some(ap));
assert_eq!(auth.iam(), Some(&EfsAuthorizationConfigIam::Enabled));
assert!(efs.root_directory().is_none() || efs.root_directory() == Some("/"));
}
let mounts: Vec<(&str, &str, Option<bool>)> = req.container_definitions()[0]
.mount_points()
.iter()
.map(|m| {
(
m.source_volume().unwrap(),
m.container_path().unwrap(),
m.read_only(),
)
})
.collect();
assert_eq!(
mounts,
vec![
("home", "/mnt/triple-c-home", Some(false)),
("workspace", "/workspace", Some(false)),
]
);
// Its own fingerprint, and the workspace access point is covered.
let fp = workspace_fingerprint(&sample_plan(StorageMode::Efs));
assert_ne!(fp, workspace_fingerprint(&sample_plan(StorageMode::Hybrid)));
let mut other = sample_plan(StorageMode::Efs);
other.workspace_access_point_id = Some("fsap-other".into());
assert_ne!(workspace_fingerprint(&other), fp);
}
#[test]
fn efs_without_its_workspace_access_point_mounts_nothing_at_workspace() {
// Not a plan `prepare_workspace` makes; the builder must not invent one.
let mut p = sample_plan(StorageMode::Efs);
p.workspace_access_point_id = None;
let req = task_definition_request(&p);
assert!(req
.container_definitions()[0]
.mount_points()
.iter()
.all(|m| m.container_path() != Some("/workspace")));
}
#[test]
fn arm64_sets_the_runtime_platform() {
let mut plan = sample_plan(StorageMode::Ephemeral);
@@ -912,6 +1003,93 @@ async fn an_existing_access_point_is_reused() {
assert_eq!(fake2.created_access_points.lock().unwrap().len(), 1);
}
#[tokio::test]
async fn efs_creates_both_access_points_then_reuses_them_by_root_owner_and_project() {
let fake = Fake::onboarded();
let ok = owner_key(REGION, USER);
let tags = workspace_tags(USER, PROJECT_ID, "dev");
let p = project(StorageMode::Efs);
let first = prepare(&fake, &p, &[]).await.unwrap();
let created = fake.created_access_points.lock().unwrap().clone();
assert_eq!(
created,
vec![
("fs-0123abcd".to_string(), access_point_root(&ok, PROJECT_ID), tags.clone()),
(
"fs-0123abcd".to_string(),
workspace_access_point_root(&ok, PROJECT_ID),
tags.clone()
),
]
);
assert_eq!(first.access_point_id.as_deref(), Some("fsap-new1"));
assert_eq!(first.workspace_access_point_id.as_deref(), Some("fsap-new2"));
{
let reg = fake.registered.lock().unwrap();
let aps: Vec<Option<&str>> = reg[0]
.volumes()
.iter()
.map(|v| {
v.efs_volume_configuration()
.unwrap()
.authorization_config()
.unwrap()
.access_point_id()
})
.collect();
assert_eq!(aps, vec![Some("fsap-new1"), Some("fsap-new2")]);
let secrets = fake.secrets.lock().unwrap();
assert_eq!(payload_map(&secrets[0].2)["TRIPLEC_STORAGE"], "efs");
}
// The second start finds both (and is not fooled by decoys: another
// owner's, another project's, the home root, one being deleted).
let good = AccessPointRef {
id: "fsap-ws".into(),
file_system_id: "fs-0123abcd".into(),
root_path: Some(workspace_access_point_root(&ok, PROJECT_ID)),
owner: Some(USER.into()),
project: Some(PROJECT_ID.into()),
state: Some("available".into()),
};
fake.access_points.lock().unwrap().extend([
AccessPointRef { id: "fsap-foreign".into(), owner: Some(OTHER.into()), ..good.clone() },
AccessPointRef {
id: "fsap-other-project".into(),
project: Some("another".into()),
..good.clone()
},
AccessPointRef { id: "fsap-deleting".into(), state: Some("deleting".into()), ..good.clone() },
AccessPointRef {
id: "fsap-home".into(),
root_path: Some(access_point_root(&ok, PROJECT_ID)),
..good.clone()
},
good,
]);
let second = prepare(&fake, &p, &[]).await.unwrap();
assert_eq!(fake.created_access_points.lock().unwrap().len(), 2);
assert_eq!(second.access_point_id.as_deref(), Some("fsap-home"));
assert_eq!(second.workspace_access_point_id.as_deref(), Some("fsap-ws"));
}
#[tokio::test]
async fn hybrid_never_creates_or_returns_a_workspace_access_point() {
let fake = Fake::onboarded();
let out = prepare(&fake, &project(StorageMode::Hybrid), &[]).await.unwrap();
assert!(out.workspace_access_point_id.is_none());
assert_eq!(fake.created_access_points.lock().unwrap().len(), 1);
assert_eq!(fake.registered.lock().unwrap()[0].volumes().len(), 1);
}
#[tokio::test]
async fn efs_without_the_users_file_system_fails_before_any_write() {
let fake = Fake::default();
let err = prepare(&fake, &project(StorageMode::Efs), &[]).await.unwrap_err();
assert!(err.to_string().contains("EFS storage"), "{err}");
assert_eq!(fake.writes(), 0);
}
#[tokio::test]
async fn ephemeral_touches_no_file_system() {
let fake = Fake::default(); // no file system at all
@@ -1124,3 +1302,4 @@ fn a_secret_pending_deletion_is_recognised() {
assert!(msg.contains("scheduled for deletion"), "{msg}");
assert!(msg.contains("triple-c/dev/abc/p"), "{msg}");
}
+54 -18
View File
@@ -715,7 +715,7 @@ pub async fn remove_project(
// An AWS project's task and resources go first, and a failure keeps the
// project: its record is the only handle on a billed task and its
// secret. Its EFS access point goes only when asked (the files stay on the
// secret. Its EFS access points go only when asked (the files stay on the
// user's own file system until offboarding).
if let Some(project) = state.projects_store.get(&project_id).filter(|p| p.is_aws()) {
let settings = state.settings_store.get();
@@ -1463,7 +1463,7 @@ async fn start_project_container_locked(
// id stored above is the tunnel's endpoint URL, which is what the death
// watch reports a stopped task as.
if project.is_aws() {
if let Some((task_arn, access_point_id, task_definition_arn)) =
if let Some((task_arn, access_point_id, task_definition_arn, workspace_access_point_id)) =
crate::host::tunnels::runtime(&project_id)
{
state.projects_store.set_aws_runtime(
@@ -1471,7 +1471,7 @@ async fn start_project_container_locked(
Some(task_arn),
access_point_id,
Some(task_definition_arn),
project.aws.as_ref().and_then(|a| a.workspace_access_point_id.clone()), // Task 3: from the start
workspace_access_point_id,
)?;
}
}
@@ -1699,24 +1699,37 @@ pub async fn remove_aws_resources(
ProjectHost::for_project(&project)
.remove_aws_resources(&project, &settings, discard_data)
.await?;
state
.projects_store
.set_aws_runtime(&project_id, None, access_point_after_removal(&project, discard_data), None, None)?;
let (access_point_id, workspace_access_point_id) =
access_points_after_removal(&project, discard_data);
state.projects_store.set_aws_runtime(
&project_id,
None,
access_point_id,
None,
workspace_access_point_id,
)?;
state
.projects_store
.get(&project_id)
.ok_or_else(|| format!("Project {} not found", project_id))
}
/// The access point a removal leaves stored: kept when the saved files were
/// kept (it is still there, a later start reuses it and a later removal
/// with `discard_data` deletes it; and while it is stored the project can't
/// move away from it — [`validate_aws_update`]), gone when they were not.
fn access_point_after_removal(project: &Project, discard_data: bool) -> Option<String> {
if discard_data {
return None;
/// The access points (home, EFS `/workspace`) a removal leaves stored: kept
/// when the saved files were kept (they are still there, a later start
/// reuses them and a later removal with `discard_data` deletes them; and
/// while one is stored the project can't move away from it —
/// [`validate_aws_update`]), gone when they were not.
fn access_points_after_removal(
project: &Project,
discard_data: bool,
) -> (Option<String>, Option<String>) {
match project.aws.as_ref() {
Some(a) if !discard_data => (
a.access_point_id.clone(),
a.workspace_access_point_id.clone(),
),
_ => (None, None),
}
project.aws.as_ref().and_then(|a| a.access_point_id.clone())
}
fn check_aws_resources_removable(project: &Project) -> Result<(), String> {
@@ -2712,14 +2725,14 @@ mod tests {
let hosts = vec![host("h1")];
let mut stored = aws_project();
stored.aws.as_mut().unwrap().access_point_id = Some("fsap-1".into());
assert_eq!(access_point_after_removal(&stored, false), Some("fsap-1".into()));
assert_eq!(access_point_after_removal(&stored, true), None);
assert_eq!(access_points_after_removal(&stored, false), (Some("fsap-1".into()), None));
assert_eq!(access_points_after_removal(&stored, true), (None, None));
// What the store holds after a keep-the-files removal still blocks a move.
let mut after = stored.clone();
let a = after.aws.as_mut().unwrap();
a.task_arn = None;
a.task_definition_arn = None;
a.access_point_id = access_point_after_removal(&stored, false);
a.access_point_id = access_points_after_removal(&stored, false).0;
let mut local = after.clone();
local.host_id = None;
local.aws_placement = None;
@@ -2727,10 +2740,33 @@ mod tests {
let e = validate_aws_update(&after, &local, &hosts).unwrap_err();
assert!(e.contains("access point"), "{e}");
// After a discarding removal it can move.
after.aws.as_mut().unwrap().access_point_id = access_point_after_removal(&stored, true);
after.aws.as_mut().unwrap().access_point_id = access_points_after_removal(&stored, true).0;
assert!(validate_aws_update(&after, &local, &hosts).is_ok());
}
#[test]
fn a_removal_keeps_or_drops_both_access_points_together() {
let hosts = vec![host("h1")];
// EFS switched to Hybrid: the /workspace access point is still stored.
let mut stored = aws_project();
let a = stored.aws.as_mut().unwrap();
a.access_point_id = Some("fsap-1".into());
a.workspace_access_point_id = Some("fsap-w".into());
assert_eq!(
access_points_after_removal(&stored, false),
(Some("fsap-1".into()), Some("fsap-w".into()))
);
assert_eq!(access_points_after_removal(&stored, true), (None, None));
// Kept: the stored /workspace access point alone still blocks a move.
let mut after = stored.clone();
after.aws.as_mut().unwrap().access_point_id = None;
let mut local = after.clone();
local.host_id = None;
local.aws_placement = None;
local.aws = None;
assert!(validate_aws_update(&after, &local, &hosts).is_err());
}
#[test]
fn a_project_with_aws_resources_cannot_be_moved_off_its_host() {
let hosts = vec![host("h1"), host("h2")];
+85 -1
View File
@@ -273,6 +273,42 @@ fn link_persistent_home_without_the_mount_changes_nothing() {
assert!(fs::symlink_metadata(home.join(".claude")).unwrap().is_dir());
}
#[test]
fn efs_storage_links_home_state_like_hybrid() {
let script = format!(
"{}\nfor m in hybrid efs ephemeral '' HYBRID efsx; do aws_storage_links_home \"$m\" && echo \"$m:yes\" || echo \"$m:no\"; done\n",
aws_blocks(&["aws_env", "aws_home"])
);
let out = bash(&script, &[], &[], &[]);
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"hybrid:yes\nefs:yes\nephemeral:no\n:no\nHYBRID:no\nefsx:no\n"
);
// The call site asks it, rather than testing for `hybrid` alone (an EFS
// task would otherwise get no home links at all).
let call = ENTRYPOINT
.lines()
.position(|l| l.trim_start().starts_with("link_persistent_home /home/claude"))
.unwrap();
let above = ENTRYPOINT.lines().nth(call - 1).unwrap();
assert_eq!(
above.trim(),
"if [ \"$triplec_aws\" = 1 ] && aws_storage_links_home \"${TRIPLEC_STORAGE:-}\"; then"
);
}
#[test]
fn efs_workspace_check_warns_only_when_workspace_is_not_mounted() {
let tmp = tempfile::tempdir().unwrap();
let script = format!("{}\naws_efs_workspace_check \"$1\"; echo \"rc=$?\"\n", aws_blocks(&["aws_env", "aws_home"]));
let out = bash(&script, &[tmp.path()], &[], &[]);
assert!(text(&out).contains("is not mounted"), "{}", text(&out));
assert!(text(&out).contains("rc=0"), "{}", text(&out));
let out = bash(&script, &[Path::new("/proc")], &[], &[]);
assert!(!text(&out).contains("warning"), "{}", text(&out));
assert!(text(&out).contains("rc=0"), "{}", text(&out));
}
/// `write_claude_json` with the Hybrid mount at `<tmp>/mnt`, in aws mode or not.
fn write_claude_json(tmp: &Path, aws: bool) -> Output {
let mnt = tmp.join("mnt");
@@ -426,6 +462,50 @@ fn clone_repos_clones_skips_existing_and_reports_failures_without_failing() {
);
}
#[test]
fn clone_repos_on_a_persistent_workspace_skips_on_restart_and_redoes_a_clone_cut_short() {
// EFS storage: /workspace outlives the task, so the next start sees
// what the last one left.
let tmp = tempfile::tempdir().unwrap();
let ws = tmp.path().join("workspace");
fs::create_dir_all(&ws).unwrap();
let remote = bare_remote(tmp.path(), "proj");
let json = format!(
r#"[{{"url":"{r}","branch":null,"folder":"a"}},{{"url":"{r}","branch":null,"folder":"b"}}]"#,
r = remote.display()
);
let script = format!("{}\nclone_repos \"$JSON\" \"$1\" \"$2\"\n", aws_blocks(&["aws_env", "aws_repos"]));
let run = |status: &Path| {
fs::create_dir_all(status).unwrap();
let out = bash(&script, &[&ws, status], &[("JSON", &json)], &[]);
assert!(out.status.success(), "{}", text(&out));
(text(&out), fs::read_to_string(status.join("repos")).unwrap())
};
let (_, first) = run(&tmp.path().join("s1"));
assert_eq!(first, "a\tcloning\na\tcloned\nb\tcloning\nb\tcloned\n");
// A finished clone carries no in-progress mark.
for f in ["a", "b"] {
let o = Command::new("git")
.args(["config", "--file"])
.arg(ws.join(f).join(".git/config"))
.args(["--get", "triplec.cloning"])
.output()
.unwrap();
assert!(!o.status.success(), "{f} still marked");
}
// The user's work in a, and b as a clone the last task was killed in
// the middle of (its mark still set, its checkout missing).
fs::write(ws.join("a/mine"), "work").unwrap();
git(&ws.join("b"), &["config", "triplec.cloning", "1"]);
fs::remove_file(ws.join("b/README")).unwrap();
let (log, second) = run(&tmp.path().join("s2"));
assert_eq!(second, "a\texists\nb\tcloning\nb\tcloned\n", "{log}");
assert!(log.contains("cut short"), "{log}");
assert_eq!(fs::read_to_string(ws.join("a/mine")).unwrap(), "work", "never touched");
assert_eq!(fs::read_to_string(ws.join("b/README")).unwrap(), "hello");
}
/// A stand-in `ssh` that records how it was called and fails.
fn fake_ssh(dir: &Path) -> (std::path::PathBuf, std::path::PathBuf) {
let log = dir.join("ssh-calls");
@@ -1196,6 +1276,7 @@ fn docker_mode_never_reaches_the_aws_blocks() {
"aws_hybrid_ssh_dir",
"aws_before_stop",
"start_idle_watch",
"aws_efs_workspace_check",
];
let guarded = |s: &str| s.contains("\"$triplec_aws\" = 1");
let mut seen = 0;
@@ -1211,7 +1292,10 @@ fn docker_mode_never_reaches_the_aws_blocks() {
"unguarded call outside the aws blocks: {line}"
);
}
assert_eq!(seen, 5, "the call sites: Hybrid link, Hybrid ~/.ssh, clone, idle watch, stop");
assert_eq!(
seen, 6,
"the call sites: Hybrid/EFS link, EFS /workspace check, Hybrid ~/.ssh, clone, idle watch, stop"
);
// Clones start in the background *after* the agent: the app gives a
// starting task's agent only seconds to answer.
let pos = |needle: &str| {
+33 -5
View File
@@ -362,6 +362,8 @@ pub struct TaskRecord {
pub task_arn: String,
pub access_point_id: Option<String>,
pub task_definition_arn: Option<String>,
/// EFS storage's `/workspace` access point.
pub workspace_access_point_id: Option<String>,
}
/// A connected task.
@@ -373,6 +375,8 @@ pub struct Started {
/// The access point the task mounts (Hybrid). `None` when an existing
/// task was attached to: the store's value stands.
pub access_point_id: Option<String>,
/// The `/workspace` access point (EFS), like `access_point_id`.
pub workspace_access_point_id: Option<String>,
/// This start ran the task (rather than attaching to a running one).
pub created: bool,
}
@@ -433,13 +437,14 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
.await
.map_err(s)?;
let (task, token, access_point_id, created) = if let Some(task) = existing {
let (task, token, access_point_id, workspace_access_point_id, created) = if let Some(task) = existing {
// Attach: never rotate a running task's token (P2).
log::info!("Project {}: attaching to its running task {}", project.id, task.arn);
(inp.on_task)(Some(&TaskRecord {
task_arn: task.arn.clone(),
access_point_id: None,
task_definition_arn: Some(task.task_definition_arn.clone()),
workspace_access_point_id: None,
}));
let token = read_agent_token(rt, &env.name, &ok, &project.id).await.map_err(s)?;
progress(PROGRESS_WAITING);
@@ -447,7 +452,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
Ok(t) => t,
Err(e) => return Err(with_log_tail(tasks, &logs, &task.arn, e.to_string()).await),
};
(task, token, None, false)
(task, token, None, None, false)
} else {
progress(PROGRESS_PREPARING);
let prepared = prepare_workspace(
@@ -461,7 +466,10 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
)
.await
.map_err(s)?;
if let Some(ap) = &prepared.access_point_id {
for ap in [&prepared.access_point_id, &prepared.workspace_access_point_id]
.into_iter()
.flatten()
{
wait_access_point(rt, ap, inp.access_point_wait).await.map_err(s)?;
}
progress(PROGRESS_STARTING);
@@ -482,6 +490,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
task_arn: start.task.arn.clone(),
access_point_id: prepared.access_point_id.clone(),
task_definition_arn: Some(start.task.task_definition_arn.clone()),
workspace_access_point_id: prepared.workspace_access_point_id.clone(),
}));
return Err(START_RACE.into());
}
@@ -490,6 +499,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
task_arn: arn.clone(),
access_point_id: prepared.access_point_id.clone(),
task_definition_arn: Some(prepared.task_definition_arn.clone()),
workspace_access_point_id: prepared.workspace_access_point_id.clone(),
}));
progress(PROGRESS_WAITING);
let task = match wait_ready(tasks, &env.cluster_arn, &arn, &logs, inp.wait, |_| {}).await {
@@ -502,7 +512,13 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
return Err(msg);
}
};
(task, prepared.agent_token, prepared.access_point_id, true)
(
task,
prepared.agent_token,
prepared.access_point_id,
prepared.workspace_access_point_id,
true,
)
};
progress(PROGRESS_CONNECTING);
@@ -530,6 +546,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
forward,
endpoint,
access_point_id,
workspace_access_point_id,
created,
})
}
@@ -615,6 +632,9 @@ pub async fn ensure_started(
let access_point_id = started
.access_point_id
.or_else(|| project.aws.as_ref().and_then(|a| a.access_point_id.clone()));
let workspace_access_point_id = started
.workspace_access_point_id
.or_else(|| project.aws.as_ref().and_then(|a| a.workspace_access_point_id.clone()));
let ecs = ecs_task(&started.task)?;
if let Some(old) = tunnels::register(
&project.id,
@@ -628,6 +648,7 @@ pub async fn ensure_started(
forward: started.forward,
endpoint: endpoint.clone(),
access_point_id,
workspace_access_point_id,
task_definition_arn: started.task.task_definition_arn.clone(),
},
) {
@@ -651,7 +672,7 @@ pub fn record_task(store: &ProjectsStore, project_id: &str, rec: Option<&TaskRec
Some(r.task_arn.clone()),
r.access_point_id.clone().or(stored.access_point_id),
r.task_definition_arn.clone().or(stored.task_definition_arn),
stored.workspace_access_point_id, // Task 3: from the record
r.workspace_access_point_id.clone().or(stored.workspace_access_point_id),
),
None => store.set_aws_runtime(
project_id,
@@ -860,6 +881,8 @@ pub async fn remove_resources(
project_id: &project.id,
stored_task_arn: aws.and_then(|a| a.task_arn.as_deref()),
stored_access_point_id: aws.and_then(|a| a.access_point_id.as_deref()),
stored_workspace_access_point_id: aws
.and_then(|a| a.workspace_access_point_id.as_deref()),
discard_data,
},
)
@@ -974,6 +997,7 @@ pub async fn reconcile_project<T: TaskApi>(
task_arn: t.arn.clone(),
access_point_id: None,
task_definition_arn: Some(t.task_definition_arn.clone()),
workspace_access_point_id: None,
}),
);
}
@@ -1072,6 +1096,10 @@ async fn reattach(
forward,
endpoint: endpoint.clone(),
access_point_id: project.aws.as_ref().and_then(|a| a.access_point_id.clone()),
workspace_access_point_id: project
.aws
.as_ref()
.and_then(|a| a.workspace_access_point_id.clone()),
task_definition_arn: task.task_definition_arn.clone(),
};
if !reattach_still_wanted(store, &project.id, &task.arn) {
+84 -4
View File
@@ -155,11 +155,11 @@ impl WorkspaceApi for Fake {
async fn create_access_point(
&self,
_fs: &str,
_root: &str,
root: &str,
_tags: &[(String, String)],
) -> Result<String, AwsError> {
self.log("create-ap");
Ok("fsap-new".into())
Ok(if root.starts_with("/triple-c-workspaces/") { "fsap-ws" } else { "fsap-new" }.into())
}
async fn put_project_secret(
&self,
@@ -309,6 +309,76 @@ async fn a_first_start_prepares_runs_waits_and_connects_in_that_order() {
);
}
#[tokio::test]
async fn an_efs_start_waits_for_both_access_points_and_records_them() {
let p = aws_project(StorageMode::Efs);
let fake = Fake { run: Some(task(&p, "new", "RUNNING", true)), ..Default::default() };
let w = who();
let records = Mutex::new(Vec::new());
let on_task = |r: Option<&TaskRecord>| records.lock().unwrap().push(r.cloned());
let started = start_core(&fake, &fake, &fake, &fake, &inputs(&p, &w, &on_task), &|_| {})
.await
.unwrap();
assert_eq!(started.access_point_id.as_deref(), Some("fsap-new"));
assert_eq!(started.workspace_access_point_id.as_deref(), Some("fsap-ws"));
let calls = fake.calls();
let pos = |c: &str| calls.iter().position(|x| x == c).unwrap_or_else(|| panic!("{c}: {calls:?}"));
assert!(pos("ap-state fsap-new") < pos("run"), "{calls:?}");
assert!(pos("ap-state fsap-ws") < pos("run"), "{calls:?}");
let recs = records.into_inner().unwrap();
let rec = recs[0].as_ref().unwrap();
assert_eq!(rec.access_point_id.as_deref(), Some("fsap-new"));
assert_eq!(rec.workspace_access_point_id.as_deref(), Some("fsap-ws"));
// Hybrid waits for one and records none for /workspace.
let p = aws_project(StorageMode::Hybrid);
let fake = Fake { run: Some(task(&p, "new", "RUNNING", true)), ..Default::default() };
let records = Mutex::new(Vec::new());
let on_task = |r: Option<&TaskRecord>| records.lock().unwrap().push(r.cloned());
let started = start_core(&fake, &fake, &fake, &fake, &inputs(&p, &w, &on_task), &|_| {})
.await
.unwrap();
assert_eq!(started.workspace_access_point_id, None);
assert!(!fake.called("ap-state fsap-ws"));
assert_eq!(records.into_inner().unwrap()[0].as_ref().unwrap().workspace_access_point_id, None);
}
#[test]
fn switching_efs_to_hybrid_keeps_the_stored_workspace_access_point() {
let mut p = aws_project(StorageMode::Hybrid);
p.aws.as_mut().unwrap().workspace_access_point_id = Some("fsap-ws".into());
let (_d, store) = store_with(&p);
// A Hybrid start knows no /workspace access point: the stored one stays.
record_task(
&store,
&p.id,
Some(&TaskRecord {
task_arn: "arn:t".into(),
access_point_id: Some("fsap-home".into()),
task_definition_arn: None,
workspace_access_point_id: None,
}),
);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!(a.workspace_access_point_id.as_deref(), Some("fsap-ws"));
record_task(&store, &p.id, None);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!(a.workspace_access_point_id.as_deref(), Some("fsap-ws"));
// An EFS start records its own.
record_task(
&store,
&p.id,
Some(&TaskRecord {
task_arn: "arn:t2".into(),
access_point_id: None,
task_definition_arn: None,
workspace_access_point_id: Some("fsap-ws2".into()),
}),
);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!(a.workspace_access_point_id.as_deref(), Some("fsap-ws2"));
}
#[tokio::test]
async fn a_running_task_is_attached_with_its_own_token_and_nothing_is_rewritten() {
let p = aws_project(StorageMode::Hybrid);
@@ -666,7 +736,12 @@ fn a_start_records_its_task_and_keeps_the_stored_handles_it_does_not_know() {
record_task(
&store,
&p.id,
Some(&TaskRecord { task_arn: "arn:t".into(), access_point_id: None, task_definition_arn: Some("arn:td:2".into()) }),
Some(&TaskRecord {
task_arn: "arn:t".into(),
access_point_id: None,
task_definition_arn: Some("arn:td:2".into()),
workspace_access_point_id: None,
}),
);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!((a.task_arn.as_deref(), a.access_point_id.as_deref(), a.task_definition_arn.as_deref()),
@@ -720,7 +795,12 @@ fn the_log_task_is_the_stored_one_else_the_last_one_a_start_saw() {
record_task(
&store,
&p.id,
Some(&TaskRecord { task_arn: "arn:first".into(), access_point_id: None, task_definition_arn: None }),
Some(&TaskRecord {
task_arn: "arn:first".into(),
access_point_id: None,
task_definition_arn: None,
workspace_access_point_id: None,
}),
);
record_task(&store, &p.id, None);
assert_eq!(log_task_arn(&p).as_deref(), Some("arn:first"), "a cleared ARN still has a log");
+1 -1
View File
@@ -132,7 +132,7 @@ impl ProjectHost {
/// AWS: stop the task and remove the project's resources — task
/// definition revisions, the secret (deleted at once) and, only
/// with `discard_data`, the EFS access point (not its files). Docker: nothing (its state
/// with `discard_data`, the EFS access points, home and EFS-mode `/workspace` (not their files). Docker: nothing (its state
/// goes with [`Self::discard_project_state`]).
pub async fn remove_aws_resources(
&self,
+7 -2
View File
@@ -51,6 +51,8 @@ pub struct LiveTunnel {
/// Runtime handles for the store (`set_aws_runtime`).
pub access_point_id: Option<String>,
pub task_definition_arn: String,
/// EFS storage's `/workspace` access point.
pub workspace_access_point_id: Option<String>,
}
/// Where an endpoint's task is: `(connection, region, cluster, task ARN)`.
@@ -123,13 +125,15 @@ pub fn get_endpoint(project_id: &str) -> Option<AgentEndpoint> {
lock().live.get(project_id).map(|t| t.endpoint.clone())
}
/// `(task ARN, access point id, task definition ARN)` of the project's tunnel.
pub fn runtime(project_id: &str) -> Option<(String, Option<String>, String)> {
/// `(task ARN, access point id, task definition ARN, workspace access point
/// id)` of the project's tunnel.
pub fn runtime(project_id: &str) -> Option<(String, Option<String>, String, Option<String>)> {
lock().live.get(project_id).map(|t| {
(
t.task_arn.clone(),
t.access_point_id.clone(),
t.task_definition_arn.clone(),
t.workspace_access_point_id.clone(),
)
})
}
@@ -334,6 +338,7 @@ pub(crate) mod tests {
endpoint: AgentEndpoint::loopback(port, "tok"),
access_point_id: Some("fsap-1".into()),
task_definition_arn: "arn:td:1".into(),
workspace_access_point_id: None,
}
}
@@ -14,6 +14,14 @@ describe("ConfirmRemoveModal", () => {
expect(onConfirm.mock.calls).toEqual([[{ discardData: false }], [{ discardData: true }]]);
});
it("says both access points go when the workspace kept /workspace on EFS", () => {
render(
<ConfirmRemoveModal projectName="api" aws savedFiles workspaceFiles onConfirm={vi.fn()} onCancel={vi.fn()} />,
);
expect(screen.getByRole("checkbox", { name: /file-system access points/ })).toBeInTheDocument();
expect(screen.getByText(/\/workspace/)).toBeInTheDocument();
});
it("offers no access-point choice for an Ephemeral AWS workspace", () => {
const onConfirm = vi.fn();
render(<ConfirmRemoveModal projectName="api" aws onConfirm={onConfirm} onCancel={vi.fn()} />);
@@ -8,6 +8,8 @@ interface Props {
aws?: boolean;
/** AWS: the workspace may have an EFS access point (offers removing it). */
savedFiles?: boolean;
/** AWS: `/workspace` may be on EFS too (EFS storage, now or before). */
workspaceFiles?: boolean;
onConfirm: (opts: { discardData: boolean }) => void;
onCancel: () => void;
}
@@ -19,6 +21,7 @@ export default function ConfirmRemoveModal({
projectName,
aws = false,
savedFiles = false,
workspaceFiles = false,
onConfirm,
onCancel,
}: Props) {
@@ -61,11 +64,12 @@ export default function ConfirmRemoveModal({
onChange={(e) => setDiscardData(e.target.checked)}
/>
<span>
Also remove the workspace&rsquo;s file-system access point
Also remove the workspace&rsquo;s file-system access points
<span className="block text-xs text-[var(--text-secondary)]">
The saved files themselves (Claude login, history, SSH keys) stay on your own
EFS file system, readable only by your workspace role, until an administrator
offboards you.
The saved files themselves (Claude login, history, SSH keys
{workspaceFiles ? ", and the /workspace files" : ""}) stay on your own EFS file
system, readable only by your workspace role, until an administrator offboards
you.
</span>
</span>
</label>
@@ -11,7 +11,7 @@ import Button from "../../ui/Button";
import OverflowMenu from "../../ui/OverflowMenu";
import ConfirmRemoveModal, { ConfirmForgetAwsModal } from "../ConfirmRemoveModal";
import StopGuardModal from "../StopGuardModal";
import { hasSavedFiles, isAwsProject } from "../../../lib/awsWorkspace";
import { hasSavedFiles, hasWorkspaceFiles, isAwsProject } from "../../../lib/awsWorkspace";
import { AWS_CONNECTION_MISSING, type RemoveProjectOptions } from "../../../lib/types";
import ConfirmResetModal from "../ConfirmResetModal";
import MigrateContainerModal from "../MigrateContainerModal";
@@ -349,6 +349,7 @@ export default function ProjectHome({ projectId, active }: Props) {
projectName={project.name}
aws={aws}
savedFiles={hasSavedFiles(project)}
workspaceFiles={hasWorkspaceFiles(project)}
onCancel={() => setConfirmRemove(false)}
onConfirm={({ discardData }) => {
setConfirmRemove(false);
@@ -131,7 +131,55 @@ describe("HostSection", () => {
p.aws = { ...p.aws!, storage: "ephemeral" };
renderHost(p);
expect(screen.getByText(/Claude login and history are lost when the workspace stops/)).toBeInTheDocument();
expect(screen.getByText(/EFS .* coming later/)).toBeInTheDocument();
expect(screen.queryByText(/coming later/)).toBeNull();
});
it("offers EFS storage with what it costs", async () => {
const p = awsProject();
renderHost(p);
const efs = screen.getByRole("radio", { name: "EFS" });
expect(efs).not.toBeDisabled();
fireEvent.click(efs);
await waitFor(() => expect(save).toHaveBeenCalled());
expect(save.mock.calls[0][0].aws.storage).toBe("efs");
p.aws = { ...p.aws!, storage: "efs" };
renderHost(p);
expect(
screen.getByText("Everything in /workspace survives a stop; git and builds are slower over NFS"),
).toBeInTheDocument();
});
it("says /workspace files stay on their access point after switching away from EFS", () => {
const p = awsProject();
p.aws = {
...p.aws!,
storage: "hybrid",
workspace_access_point_id: "fsap-w",
task_arn: null,
task_definition_arn: null,
access_point_id: null,
};
renderHost(p);
expect(screen.getByRole("note", { name: "EFS files kept" })).toHaveTextContent(
/\/workspace files .* stay on their access point until .*Remove AWS resources/,
);
// It is an AWS resource: removable, and it keeps the project in place.
expect(screen.getByRole("button", { name: "Run on this machine instead" })).toHaveAttribute(
"aria-disabled",
"true",
);
fireEvent.click(screen.getByRole("button", { name: "Remove AWS resources…" }));
const dialog = screen.getByRole("dialog");
expect(within(dialog).getByRole("checkbox", { name: /access points/ })).toBeInTheDocument();
expect(dialog).toHaveTextContent(/\/workspace/);
});
it("does not show the kept-files note on EFS or without a workspace access point", () => {
const p = awsProject();
p.aws = { ...p.aws!, storage: "efs", workspace_access_point_id: "fsap-w" };
renderHost(p);
expect(screen.queryByRole("note", { name: "EFS files kept" })).toBeNull();
});
it("saves repository edits on blur", async () => {
@@ -3,6 +3,7 @@ import type { AwsWorkspaceConfig, HostConnection, Project, RepoSource } from "..
import * as commands from "../../../../lib/tauri-commands";
import { useAppState } from "../../../../store/appState";
import {
EFS_HINT,
EPHEMERAL_WARNING,
FARGATE_CPUS,
defaultAwsWorkspace,
@@ -10,6 +11,7 @@ import {
formatMemory,
memoryError,
hasSavedFiles,
hasWorkspaceFiles,
memoryOptions,
nearestMemory,
} from "../../../../lib/awsWorkspace";
@@ -57,9 +59,19 @@ export default function HostSection({ project, save, disabled }: Props) {
const saveAws = (patch: Partial<AwsWorkspaceConfig>) => save({ aws: { ...aws, ...patch } });
const hasResources = !!(aws.task_arn || aws.access_point_id || aws.task_definition_arn);
// A removal that kept the saved files keeps their access point stored.
const onlyAccessPoint = !!aws.access_point_id && !aws.task_arn && !aws.task_definition_arn;
const hasResources = !!(
aws.task_arn ||
aws.access_point_id ||
aws.workspace_access_point_id ||
aws.task_definition_arn
);
// A removal that kept the saved files keeps their access points stored.
const onlyAccessPoint =
!!(aws.access_point_id || aws.workspace_access_point_id) &&
!aws.task_arn &&
!aws.task_definition_arn;
// Switched away from EFS: its /workspace files are still on their access point.
const keptWorkspaceFiles = aws.storage !== "efs" && !!aws.workspace_access_point_id;
// Not `disabled` (which also allows Error): on AWS, Error can mean a live task.
const stopped = project.status === "stopped";
@@ -196,11 +208,9 @@ export default function HostSection({ project, save, disabled }: Props) {
segments={[
{ value: "ephemeral", label: "Ephemeral", caution: true },
{ value: "hybrid", label: "Hybrid" },
{ value: "efs", label: "EFS" },
]}
/>
<span className="text-xs text-[var(--text-disabled)]">
EFS (everything persists) — coming later
</span>
</div>
{aws.storage === "ephemeral" ? (
<p
@@ -209,17 +219,36 @@ export default function HostSection({ project, save, disabled }: Props) {
>
{EPHEMERAL_WARNING} Push your work to a remote before stopping.
</p>
) : aws.storage === "efs" ? (
<p className="mt-1 text-xs text-[var(--text-secondary)]">
<span>{EFS_HINT}</span>. The Claude login, history and SSH keys are kept on EFS too.
</p>
) : (
<p className="mt-1 text-xs text-[var(--text-secondary)]">
The Claude login, history and SSH keys are kept on EFS between starts; everything
else, repositories included, starts fresh.
</p>
)}
{keptWorkspaceFiles && (
<p
role="note"
aria-label="EFS files kept"
className="mt-2 px-2 py-1.5 text-xs text-[var(--text-secondary)] bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded-[var(--radius-control)]"
>
The /workspace files from when this project used EFS storage stay on their access
point until &ldquo;Remove AWS resources&rdquo; removes it (with the access points
option checked). Switching back to EFS picks them up again.
</p>
)}
</div>
<Field
label="Ephemeral storage (GiB)"
hint="The task's local disk: 21 to 200 GiB. Repositories and builds live here."
hint={
aws.storage === "efs"
? "The task's local disk: 21 to 200 GiB. With EFS storage, /workspace is on EFS instead."
: "The task's local disk: 21 to 200 GiB. Repositories and builds live here."
}
>
{(id) => (
<input
@@ -346,7 +375,7 @@ export default function HostSection({ project, save, disabled }: Props) {
!stopped
? STILL_RUNNING
: onlyAccessPoint
? "The saved files' access point is still on AWS. Remove the AWS resources with \u201cAlso remove the workspace\u2019s file-system access point\u201d first."
? "The saved files' access point is still on AWS. Remove the AWS resources with \u201cAlso remove the workspace\u2019s file-system access points\u201d first."
: "Remove the workspace's AWS resources first, so nothing is left running or billed."
}
onClick={() => void save({ host_id: null, aws_placement: null, aws: null })}
@@ -422,8 +451,11 @@ function RemoveAwsResourcesModal({ project, onClose }: { project: Project; onClo
onChange={(e) => setDiscardData(e.target.checked)}
/>
<span>
Also remove the workspace&rsquo;s file-system access point
Also remove the workspace&rsquo;s file-system access points
<span className="block text-xs text-[var(--text-secondary)]">
{hasWorkspaceFiles(project)
? "Both go: the one for the saved home files and the one for /workspace. "
: ""}
The files stay on your own EFS file system (only your workspace role can read
them) until an administrator offboards you. Left unchecked, the access point
stays too: the next start here reuses it, and the project can&rsquo;t move to
+9
View File
@@ -3,6 +3,7 @@ import {
cleanRepos,
defaultAwsWorkspace,
hasSavedFiles,
hasWorkspaceFiles,
environmentSelectable,
memoryError,
memoryOptions,
@@ -78,4 +79,12 @@ describe("phase 6 settings", () => {
expect(hasSavedFiles({ aws: { ...aws, storage: "ephemeral", workspace_access_point_id: "fsap-w" } })).toBe(true);
expect(hasSavedFiles({ aws: { ...aws, storage: "ephemeral" } })).toBe(false);
});
it("knows when /workspace files may be on EFS", () => {
const aws = defaultAwsWorkspace();
expect(hasWorkspaceFiles({ aws: { ...aws, storage: "efs" } })).toBe(true);
expect(hasWorkspaceFiles({ aws: { ...aws, storage: "hybrid", workspace_access_point_id: "fsap-w" } })).toBe(true);
expect(hasWorkspaceFiles({ aws: { ...aws, storage: "hybrid" } })).toBe(false);
expect(hasWorkspaceFiles({ aws: null })).toBe(false);
});
});
+10
View File
@@ -129,6 +129,16 @@ export function hasSavedFiles(p: Pick<Project, "aws">): boolean {
return a?.storage === "hybrid" || a?.storage === "efs" || !!a?.access_point_id || !!a?.workspace_access_point_id;
}
/** Whether an AWS project may have `/workspace` files on EFS (EFS storage now,
* or its access point left from when it was). */
export function hasWorkspaceFiles(p: Pick<Project, "aws">): boolean {
const a = p.aws;
return a?.storage === "efs" || !!a?.workspace_access_point_id;
}
/** Shown with EFS storage selected. */
export const EFS_HINT = "Everything in /workspace survives a stop; git and builds are slower over NFS";
/** Hosts that only mean something on this machine or its Docker bridge. */
const LOCAL_HOSTS = /^(localhost|127(\.\d{1,3}){3}|0\.0\.0\.0|\[?::1\]?|host\.docker\.internal|172\.17\.0\.1)$/i;
+39 -3
View File
@@ -213,7 +213,9 @@ remap_uid_gid() {
# ~/.claude volume.
find /home/claude \( ! -user claude -o ! -group claude \) -exec chown -h claude:claude {} +
# ── AWS Hybrid storage: persisted home state (plan ruling P4) ───────────────
# ── AWS Hybrid/EFS storage: persisted home state (plan ruling P4) ───────────
# EFS storage is Hybrid plus /workspace on a second access point (mounted by
# the task definition straight at /workspace), so it gets the same home links.
# A Hybrid workspace mounts its EFS access point (POSIX 1000:1000) at
# /mnt/triple-c-home. Mounting it over /home/claude would hide the image's
# Claude Code, cargo and uv — EFS has no Docker-volume "copy the image's
@@ -276,10 +278,31 @@ aws_hybrid_ssh_dir() {
[ ! -L "$triplec_home_mnt" ] && [ ! -L "$want" ] && [ -d "$want" ] || return 1
printf '%s' "$want"
}
# Whether storage mode $1 persists home state (Hybrid, and EFS = Hybrid +
# /workspace on EFS).
aws_storage_links_home() {
case "$1" in
hybrid|efs) return 0 ;;
esac
return 1
}
# EFS storage: /workspace is the access point itself (uid/gid 1000 enforced,
# root acts as 1000 there). Nothing here creates or chowns it; only says so
# when it is missing, since the files would then not survive a stop.
aws_efs_workspace_check() {
mountpoint -q "$1" 2>/dev/null \
|| echo "entrypoint: warning — EFS storage, but $1 is not mounted; its files will not persist"
return 0
}
# <<< aws_home
if [ "$triplec_aws" = 1 ] && [ "${TRIPLEC_STORAGE:-}" = hybrid ]; then
if [ "$triplec_aws" = 1 ] && aws_storage_links_home "${TRIPLEC_STORAGE:-}"; then
link_persistent_home /home/claude "$triplec_home_mnt" claude:claude
fi
if [ "$triplec_aws" = 1 ] && [ "${TRIPLEC_STORAGE:-}" = efs ]; then
aws_efs_workspace_check /workspace
fi
# ── Corporate CA certificates ───────────────────────────────────────────────
# The host's CA material is bind-mounted read-only at /tmp/.host-ca. Triple-C
@@ -641,6 +664,13 @@ chown claude:claude /home/claude/.gitconfig 2>/dev/null || true
# folder is its state), and `done` appears when all are finished. The idle
# watcher counts an unfinished clone as activity; triple-c-wip-push skips a
# folder still `cloning`.
# With EFS storage /workspace outlives the task, so a repository already there
# is skipped on every later start. A clone is marked in progress in its own
# .git/config (`git clone -c triplec.cloning=1`, written before the fetch) and
# unmarked once it succeeds; a repository still marked was cut short (the task
# was killed mid-clone) and is removed and cloned again. A repository the user
# made never carries the mark. Every look at or removal of it runs as the user:
# the tree is theirs.
# >>> aws_repos
# clone_repos json root [status_dir]
clone_repos() {
@@ -650,6 +680,10 @@ clone_repos() {
_clone_status() { [ -z "$status_dir" ] || printf '%s\t%s\n' "$1" "$2" >> "$status_dir/repos"; }
while IFS= read -r -d '' folder && IFS= read -r -d '' url && IFS= read -r -d '' branch; do
dest="$root/$folder"
if [ -e "$dest/.git" ] && [ "$(_triplec_as_user git config --file "$dest/.git/config" --get triplec.cloning 2>/dev/null)" = 1 ]; then
echo "entrypoint: the last clone of $folder was cut short; cloning it again"
_triplec_as_user rm -rf -- "$dest"
fi
if [ -e "$dest/.git" ]; then
echo "entrypoint: /workspace/$folder is already a repository; not cloning"
_clone_status "$folder" exists
@@ -657,7 +691,7 @@ clone_repos() {
fi
existed=0
[ -e "$dest" ] && existed=1
local args=(clone --quiet)
local args=(clone --quiet -c triplec.cloning=1)
[ -n "$branch" ] && args+=(--branch "$branch")
args+=(-- "$url" "$dest")
echo "entrypoint: cloning $folder..."
@@ -671,6 +705,8 @@ clone_repos() {
exec timeout -k 10 "$limit" git "$@"' _ "$limit" "${args[@]}" 2>&1 </dev/null)
rc=$?
if [ "$rc" -eq 0 ]; then
_triplec_as_user git config --file "$dest/.git/config" --unset triplec.cloning \
|| echo "entrypoint: warning — could not unmark $folder's clone; the next start will clone it again"
echo "entrypoint: cloned $folder"
_clone_status "$folder" cloned
continue