fix(aws): never let the user record vouch for EC2 names tagged as another owner's

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-16 18:30:41 -08:00
1 parent 8c9ffd4c4c
commit 8fe0810901
2 files changed
+15 -9

No files matched your search

@@ -338,10 +338,11 @@ pub(crate) fn resolve_ec2(
/// R3 (amended): an apply with EC2 capacity would adopt (or fail on) a
/// per-user cluster or Auto Scaling group named `stem` that already exists.
/// Each one found must be the caller's: its `triple-c:owner` tag (the
/// module's default tags) is `owner_id`, or, failing that, the caller's
/// record names the cluster. A half-built capacity of the caller's own (a
/// failed apply that wrote no record yet) is therefore re-applied; one
/// owned by someone else, or untagged, is refused.
/// module's default tags) is `owner_id`, or, for an untagged one only, the
/// caller's record names the cluster. A half-built capacity of the caller's
/// own (a failed apply that wrote no record yet) is therefore re-applied;
/// one tagged as someone else's is always refused (a record can't vouch for
/// it), and an untagged one is refused unless the record names it.
pub(crate) fn ec2_collision_refusal(
stem: &str,
holders: &[NameHolder],
@@ -351,8 +352,10 @@ pub(crate) fn ec2_collision_refusal(
let suffix = format!(":cluster/{stem}");
let recorded_here = recorded.is_some_and(|r| r.cluster_arn.ends_with(&suffix));
for h in holders {
if h.owner.as_deref() == Some(owner_id) || recorded_here {
continue;
match h.owner.as_deref() {
Some(o) if o == owner_id => continue,
None if recorded_here => continue,
_ => {}
}
let whose = if h.owner.is_some() {
"belongs to another onboarding"
@@ -752,10 +752,13 @@ fn ec2_names_held_by_another_owner_are_refused() {
assert!(e.contains("triple-c-user"), "{e}");
let e = ec2_collision_refusal(stem, &[cluster(Some(me)), group(None)], me, None).unwrap_err();
assert!(e.contains("Auto Scaling group") && e.contains("isn't tagged"), "{e}");
// The record naming the cluster is the fallback for an untagged or
// differently tagged one.
// The record naming the cluster is the fallback for an untagged one
// only: one tagged as someone else's is refused even then.
let mine = recorded("dev", "alice", 2);
assert!(ec2_collision_refusal(stem, &[cluster(None), group(Some("x"))], me, Some(&mine)).is_ok());
assert!(ec2_collision_refusal(stem, &[cluster(None), group(None)], me, Some(&mine)).is_ok());
assert!(ec2_collision_refusal(stem, &[cluster(None), group(Some(me))], me, Some(&mine)).is_ok());
let e = ec2_collision_refusal(stem, &[cluster(None), group(Some("x"))], me, Some(&mine)).unwrap_err();
assert!(e.contains("Auto Scaling group") && e.contains("another onboarding"), "{e}");
// A record naming another cluster doesn't help.
assert!(ec2_collision_refusal(stem, &[cluster(None)], me, Some(&recorded("dev", "bob", 1))).is_err());
// A cluster that merely ends in the same text is not the same cluster.