fix(aws): create the secret before reading it; one staging dir per connect
- Copy-at-connect tries CreateSecret first and reads the current value only when the secret exists, so a first start never reads a missing secret (which the owner-tag condition may refuse). - triple-c-apply-connect: --prepare makes and prints a per-connect nonce dir; the app uploads into it and applies exactly that dir, so concurrent connects never mix files. CA files move to a fixed path so an unchanged CA is not reinstalled. - connect.env parsing kept a trailing '=' (base64 padding) — it was dropped. - Pending-deletion errors from GetSecretValue are reported as such; message and doc-comment fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
820bfab25c
commit
262ea041c8
8 files changed
+299
-112
No files matched your search
@@ -8,8 +8,9 @@
|
||||
//! [`workspace_files`](super::workspace_files) the secret would carry) and
|
||||
//! the credential environment pairs (`SECRET_ENV_KEYS` and every custom
|
||||
//! variable, `aws::workspace::credential_pairs`). [`push_connect_bundle`]
|
||||
//! uploads them through the agent, as root, into root-only staging on the
|
||||
//! task's `/dev/shm` tmpfs and runs `triple-c-apply-connect` (container), which
|
||||
//! uploads them through the agent, as root, into this connect's own root-only
|
||||
//! staging dir on the task's `/dev/shm` tmpfs and runs `triple-c-apply-connect
|
||||
//! <nonce>` (container), which
|
||||
//! installs the CA, merges the SSH files, writes the git credential helper
|
||||
//! and re-clones what failed. The terminals the app opens get the pairs in
|
||||
//! their own `ExecSpec.env` ([`terminal_env`]); nothing puts them into the
|
||||
@@ -28,9 +29,8 @@ use crate::models::{AppSettings, Project};
|
||||
|
||||
/// The in-container half (container/triple-c-apply-connect).
|
||||
pub const APPLY_CONNECT: &str = "/usr/local/bin/triple-c-apply-connect";
|
||||
/// Root 0700 on the tmpfs (made by the entrypoint for the agent token).
|
||||
pub const CONNECT_SHM: &str = "/dev/shm/triple-c";
|
||||
/// Staging for the files: `ssh/` and `ca/` under it.
|
||||
/// Staging (root 0700, on the tmpfs the entrypoint made for the agent
|
||||
/// token): each connect gets `<nonce>/` with `ssh/`, `ca/` and `connect.env`.
|
||||
pub const CONNECT_STAGE: &str = "/dev/shm/triple-c/connect";
|
||||
pub const CONNECT_ENV_FILE: &str = "connect.env";
|
||||
/// Every staged file is root 0600.
|
||||
@@ -174,21 +174,34 @@ async fn run_apply<T: ConnectTarget>(t: &T, args: &[&str]) -> Result<String, Str
|
||||
}
|
||||
}
|
||||
|
||||
/// Upload `bundle` and apply it (see the module docs): `--prepare`, the
|
||||
/// files and `connect.env` (root 0600), then the apply.
|
||||
/// `--prepare`'s answer: this connect's nonce, 16 hex digits on the last line.
|
||||
pub(crate) fn parse_nonce(out: &str) -> Result<String, String> {
|
||||
let last = out.lines().rev().map(str::trim).find(|l| !l.is_empty()).unwrap_or_default();
|
||||
if last.len() == 16 && last.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) {
|
||||
Ok(last.to_string())
|
||||
} else {
|
||||
Err(format!("triple-c-apply-connect --prepare gave no connect id:\n{}", tail(out)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Upload `bundle` and apply it (see the module docs): `--prepare` (which
|
||||
/// names this connect's own staging dir), the files and `connect.env` (root
|
||||
/// 0600) into that dir, then the apply of exactly that dir — so two
|
||||
/// connects at once (two machines) never mix their files.
|
||||
pub async fn push_connect_bundle<T: ConnectTarget>(t: &T, bundle: &ConnectBundle) -> Result<(), String> {
|
||||
run_apply(t, &["--prepare"]).await?;
|
||||
let nonce = parse_nonce(&run_apply(t, &["--prepare"]).await?)?;
|
||||
let dir = format!("{CONNECT_STAGE}/{nonce}");
|
||||
for (key, data) in &bundle.files {
|
||||
validate_file_key(key)?;
|
||||
let (kind, name) = key.split_once('/').expect("validated");
|
||||
t.upload_root(&format!("{CONNECT_STAGE}/{kind}"), name, data, STAGED_MODE)
|
||||
t.upload_root(&format!("{dir}/{kind}"), name, data, STAGED_MODE)
|
||||
.await
|
||||
.map_err(|e| format!("Could not copy {key} into the workspace: {e}"))?;
|
||||
}
|
||||
t.upload_root(CONNECT_SHM, CONNECT_ENV_FILE, &connect_env_file(&bundle.env), STAGED_MODE)
|
||||
t.upload_root(&dir, CONNECT_ENV_FILE, &connect_env_file(&bundle.env), STAGED_MODE)
|
||||
.await
|
||||
.map_err(|e| format!("Could not copy the credential variables into the workspace: {e}"))?;
|
||||
let out = run_apply(t, &[]).await?;
|
||||
let out = run_apply(t, &[&nonce]).await?;
|
||||
for line in out.lines().filter(|l| l.contains("warning")) {
|
||||
log::warn!("{line}");
|
||||
}
|
||||
|
||||
@@ -164,6 +164,15 @@ impl WorkspaceApi for Fake {
|
||||
async fn project_secret_value(&self, _name: &str) -> Result<Option<String>, AwsError> {
|
||||
Ok(None)
|
||||
}
|
||||
async fn create_project_secret(
|
||||
&self,
|
||||
n: &str,
|
||||
k: &str,
|
||||
j: &str,
|
||||
t: &[(String, String)],
|
||||
) -> Result<Option<String>, AwsError> {
|
||||
self.put_project_secret(n, k, j, t).await.map(Some)
|
||||
}
|
||||
async fn delete_project_secret(&self, _name: &str) -> Result<(), AwsError> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -959,10 +968,11 @@ mod copy_at_connect {
|
||||
impl ConnectTarget for FakeTarget {
|
||||
async fn exec_root(&self, cmd: Vec<String>) -> Result<(String, i64), String> {
|
||||
self.calls.lock().unwrap().push(format!("exec {}", cmd.join(" ")));
|
||||
if cmd.len() == 1 {
|
||||
if let Some(r) = self.apply_result.lock().unwrap().clone() {
|
||||
return Ok(r);
|
||||
}
|
||||
if cmd.get(1).map(String::as_str) == Some("--prepare") {
|
||||
return Ok(("0123456789abcdef\n".into(), 0));
|
||||
}
|
||||
if let Some(r) = self.apply_result.lock().unwrap().clone() {
|
||||
return Ok(r);
|
||||
}
|
||||
Ok(("triple-c-apply-connect: credentials applied\n".into(), 0))
|
||||
}
|
||||
@@ -994,10 +1004,10 @@ mod copy_at_connect {
|
||||
*t.calls.lock().unwrap(),
|
||||
vec![
|
||||
"exec /usr/local/bin/triple-c-apply-connect --prepare",
|
||||
"upload /dev/shm/triple-c/connect/ssh/id_ed25519",
|
||||
"upload /dev/shm/triple-c/connect/ca/corp.crt",
|
||||
"upload /dev/shm/triple-c/connect.env",
|
||||
"exec /usr/local/bin/triple-c-apply-connect",
|
||||
"upload /dev/shm/triple-c/connect/0123456789abcdef/ssh/id_ed25519",
|
||||
"upload /dev/shm/triple-c/connect/0123456789abcdef/ca/corp.crt",
|
||||
"upload /dev/shm/triple-c/connect/0123456789abcdef/connect.env",
|
||||
"exec /usr/local/bin/triple-c-apply-connect 0123456789abcdef",
|
||||
]
|
||||
);
|
||||
let uploads = t.uploads.lock().unwrap();
|
||||
@@ -1030,6 +1040,14 @@ mod copy_at_connect {
|
||||
assert!(t.uploads.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_well_formed_connect_id_is_used_as_a_path() {
|
||||
assert_eq!(parse_nonce("noise\n0123456789abcdef\n").unwrap(), "0123456789abcdef");
|
||||
for bad in ["", "../../etc/passwd", "0123456789ABCDEF", "0123456789abcde", "0123456789abcdef0"] {
|
||||
assert!(parse_nonce(bad).is_err(), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_bundle_never_shows_its_values() {
|
||||
let shown = format!("{:?}", bundle());
|
||||
|
||||
Reference in new issue
Block a user