fix(aws): copy-at-connect review fixes — lock, ~/.ssh off EFS, secret history

- triple-c-apply-connect: the background re-clone closes the apply lock's
  fd, so a later connect never waits on it; --prepare takes the lock.
- R6: under copy-at-connect Hybrid/EFS no longer link ~/.ssh to EFS; the
  copied keys vanish with the task (UI says so, and that old keys on EFS
  stay until removed).
- R7: a copy-at-connect start that finds credentials still in the secret
  force-deletes it and creates it again (retrying ~30 s while AWS finishes),
  so no AWSPREVIOUS version keeps them.
- TRIPLE_C_CUSTOM_ENV (unsalted fingerprint) left out of the secret.
- Terminals get only the credential pairs (no file reads; keychain off the
  runtime), so a bad SSH/CA file never drops the API keys.
- ConnectBundle values are Zeroizing; UI copy updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-16 08:43:12 -08:00
1 parent 8510797c22
commit 820bfab25c
15 files changed
+502 -59

No files matched your search

@@ -2401,3 +2401,63 @@ fn apply_connect_retries_a_clone_that_started_without_credentials_once_it_is_don
assert!(c.p("ws/late/README").exists());
assert!(!c.p("clone/no-credentials").exists());
}
#[test]
fn a_running_re_clone_never_holds_the_apply_lock_and_prepare_waits_for_an_apply() {
let tmp = tempfile::tempdir().unwrap();
let c = Connect::new(tmp.path());
// A re-clone that takes a while.
let mut lib = fs::read_to_string(c.p("lib.sh")).unwrap();
lib.push_str("\nclone_repos() { sleep 6; }\n");
fs::write(c.p("lib.sh"), lib).unwrap();
assert!(c.run(&["--prepare"]).status.success());
fs::write(c.p("run/repos.json"), r#"[{"url":"x","branch":null,"folder":"bad"}]"#).unwrap();
fs::write(c.p("clone/repos"), "bad\tcloning\nbad\tfailed\n").unwrap();
fs::write(c.p("clone/done"), "").unwrap();
assert!(c.run(&[]).status.success());
assert!(!c.p("clone/done").exists(), "the re-clone is running");
// The next connect goes straight through.
let started = std::time::Instant::now();
assert!(c.run(&["--prepare"]).status.success());
let out = c.run(&[]);
assert!(out.status.success(), "{}", text(&out));
assert!(!text(&out).contains("another apply"), "{}", text(&out));
assert!(started.elapsed() < std::time::Duration::from_secs(4), "{:?}", started.elapsed());
c.wait_done();
// An apply in progress (the lock held) holds a prepare back.
let lock = c.p("shm/apply-connect.lock");
let mut holder = Command::new("flock").arg(&lock).args(["sleep", "2"]).spawn().unwrap();
std::thread::sleep(std::time::Duration::from_millis(300));
fs::write(c.p("shm/connect/marker"), "").ok();
let started = std::time::Instant::now();
assert!(c.run(&["--prepare"]).status.success());
assert!(started.elapsed() >= std::time::Duration::from_millis(1200), "{:?}", started.elapsed());
holder.wait().unwrap();
}
#[test]
fn under_copy_at_connect_hybrid_keeps_ssh_off_efs() {
let tmp = tempfile::tempdir().unwrap();
let (home, mnt) = hybrid_dirs(tmp.path());
fs::create_dir_all(home.join(".ssh")).unwrap();
fs::create_dir_all(home.join(".claude")).unwrap();
let src = tmp.path().join("src");
fs::create_dir_all(&src).unwrap();
fs::write(src.join("id_ed25519"), "KEY").unwrap();
let script = format!(
"{}\ntriplec_aws=1\ntriplec_connect=1\nlink_persistent_home \"$1\" \"$2\" \"\"\nmerge_host_ssh \"$3\"\n",
aws_blocks(&["aws_home", "sync_host_ssh", "merge_host_ssh"])
.replace("/home/claude", home.to_str().unwrap())
.replace("triplec_home_mnt=/mnt/triple-c-home", &format!("triplec_home_mnt='{}'", mnt.display()))
.replace("chown -R claude:claude", ": chown")
);
let out = bash(&script, &[&home, &mnt, &src], &[], &[]);
assert!(out.status.success(), "{}", text(&out));
assert!(text(&out).contains("~/.ssh does not"), "{}", text(&out));
assert!(fs::symlink_metadata(home.join(".claude")).unwrap().file_type().is_symlink());
let ssh = fs::symlink_metadata(home.join(".ssh")).unwrap();
assert!(ssh.is_dir() && !ssh.file_type().is_symlink(), "~/.ssh is a local directory");
assert_eq!(fs::read_to_string(home.join(".ssh/id_ed25519")).unwrap(), "KEY");
assert!(!mnt.join(".ssh").exists(), "nothing written to EFS");
}
+18 -5
View File
@@ -442,11 +442,25 @@ pub(crate) fn workspace_env_from_settings(
project: &Project,
settings: &crate::models::AppSettings,
) -> Result<crate::host::aws_host::AwsEnv, String> {
let shared_claude = super::container::shared_claude_auth(project);
let effective_ca_path =
resolve_with_global(project.ca_cert_path.as_deref(), settings.ca_cert_path.as_deref());
let resolved_ca = ca_certs::resolve(effective_ca_path)?;
let pairs = workspace_env(
let pairs = workspace_env_with_ca(project, settings, resolved_ca.as_ref());
Ok((pairs, resolved_ca))
}
/// [`workspace_env`] resolved from `settings` like
/// [`workspace_env_from_settings`] but with the CA given (`None`: no CA
/// variables) — so nothing is read from disk. The keychain is (the shared
/// Claude token). Copy-at-connect's terminal environment uses it: the
/// credential pairs never depend on the CA.
pub(crate) fn workspace_env_with_ca(
project: &Project,
settings: &crate::models::AppSettings,
resolved_ca: Option<&ResolvedCa>,
) -> Vec<(String, String)> {
let shared_claude = super::container::shared_claude_auth(project);
workspace_env(
project,
&WorkspaceEnvInputs {
global_aws: &settings.global_aws,
@@ -459,11 +473,10 @@ pub(crate) fn workspace_env_from_settings(
global_claude_code_settings: settings.global_claude_code_settings.as_ref(),
default_git_user_name: settings.default_git_user_name.as_deref(),
default_git_user_email: settings.default_git_user_email.as_deref(),
resolved_ca: resolved_ca.as_ref(),
resolved_ca,
shared_claude_token: shared_claude.as_ref().map(|(token, _)| token.as_str()),
},
);
Ok((pairs, resolved_ca))
)
}
#[cfg(test)]