Skip to content
Python

fix: use supported Azure bootstrap assignment scope checks

Rohit Pfca8fb9ab7d9
diff --git a/harness/service-cli/src/deployment_azure.rs b/harness/service-cli/src/deployment_azure.rs
index 4ca52493..457af30b 100644
--- a/harness/service-cli/src/deployment_azure.rs
+++ b/harness/service-cli/src/deployment_azure.rs
@@ -191,8 +191,12 @@ a() {{ az "$@" --subscription '{subscription}' --only-show-errors; }}
[ "$(a account show --query id -o tsv)" = '{subscription}' ] || {{ echo 'Subscription mismatch' >&2; exit 1; }}
[ "$(a account show --query state -o tsv)" = Enabled ] || {{ echo 'Subscription is not enabled' >&2; exit 1; }}
[ "$(a group show --name '{rg}' --query id -o tsv | tr '[:upper:]' '[:lower:]')" = '{scope_lower}' ] || {{ echo 'Existing resource group mismatch' >&2; exit 1; }}
-[ "$(a role definition list --name '{rid}' --scope '{resource}' --query 'length(@)' -o tsv)" = 0 ] || {{ echo 'Generated role already exists; reconcile the original journal, never overwrite it' >&2; exit 1; }}
-[ "$(a role assignment list --scope '{resource}' --all --query 'length([?name==`"{aid}"`])' -o tsv)" = 0 ] || {{ echo 'Generated assignment already exists; reconcile first' >&2; exit 1; }}
+bootstrap_role_count=$(a role definition list --name '{rid}' --scope '{resource}' --query 'length(@)' -o tsv)
+[ "$bootstrap_role_count" = 0 ] || {{ echo 'Generated role already exists; reconcile the original journal, never overwrite it' >&2; exit 1; }}
+# --scope and --all are mutually exclusive in Azure CLI. A failed read must
+# stop here, rather than be misreported as an existing assignment.
+bootstrap_assignment_count=$(a role assignment list --scope '{resource}' --query 'length([?name==`"{aid}"`])' -o tsv)
+[ "$bootstrap_assignment_count" = 0 ] || {{ echo 'Generated assignment already exists; reconcile first' >&2; exit 1; }}
journal_parent=$(cd -- "$(dirname -- "$2")" && pwd)
case "$journal_parent/" in "$root/"*) echo 'Journal must be outside the immutable bundle' >&2; exit 1;; esac
umask 077
diff --git a/harness/service-cli/tests/azure.rs b/harness/service-cli/tests/azure.rs
index 89eff695..f8a3b741 100644
--- a/harness/service-cli/tests/azure.rs
+++ b/harness/service-cli/tests/azure.rs
@@ -361,6 +361,16 @@ fn exported_script_requires_explicit_confirmation_and_refuses_existing_or_wrong_
}
}
#[test]
+fn failed_assignment_read_stops_before_grants_and_is_not_reported_as_a_collision() {
+ let f = Fixture::ready();
+ let r = f.script("assignment-read-fails", "read-failed-journal");
+ assert!(!r.status.success());
+ assert!(String::from_utf8_lossy(&r.stderr).contains("AuthorizationFailed"));
+ assert!(!String::from_utf8_lossy(&r.stderr).contains("already exists"));
+ assert!(!f.path("read-failed-journal").exists());
+ assert!(f.log().iter().all(|a| a[0] != "rest"));
+}
+#[test]
fn exported_script_writes_fixed_scope_receipts_and_never_retries_unknown_mutations() {
let f = Fixture::ready();
let r = f.script("ready", "private journal");
diff --git a/harness/service-cli/tests/fixtures/azure-bootstrap.py b/harness/service-cli/tests/fixtures/azure-bootstrap.py
index ed4f373b..b5f19c39 100644
--- a/harness/service-cli/tests/fixtures/azure-bootstrap.py
+++ b/harness/service-cli/tests/fixtures/azure-bootstrap.py
@@ -80,7 +80,13 @@ if args[:3] == ["role", "definition", "list"]:
assert value("--scope") == scope and value("--name") == ident["roleDefinitionGuid"]
emit(1 if scenario == "existing-role" else 0)
if args[:3] == ["role", "assignment", "list"]:
+ if "--scope" in args and "--all" in args:
+ print("ERROR: group or scope are not required when --all is used", file=sys.stderr)
+ sys.exit(2)
assert value("--scope") == scope
+ if scenario == "assignment-read-fails":
+ print("AuthorizationFailed", file=sys.stderr)
+ sys.exit(1)
emit(0)
if args[:2] == ["provider", "show"]:
provider = value("--namespace")