Skip to content
Python

fix(azure): frame empty ARM actions and sanitize response errors

Rohit P7d39200ea92c
diff --git a/harness/service-cli/src/deployment_azure_api.rs b/harness/service-cli/src/deployment_azure_api.rs
index a19ca274..b7eb7f1c 100644
--- a/harness/service-cli/src/deployment_azure_api.rs
+++ b/harness/service-cli/src/deployment_azure_api.rs
@@ -140,11 +140,15 @@ impl Azure {
let origin = "https://management.azure.com";
let mut b = self
.http
- .request(method, format!("{origin}{id}?api-version={api}"))
+ .request(method.clone(), format!("{origin}{id}?api-version={api}"))
.bearer_auth(token.as_str())
.header("x-ms-client-request-id", request);
if let Some(body) = body {
b = b.json(body);
+ } else if method == reqwest::Method::POST {
+ // ARM action endpoints (including listClusterUserCredential) reject
+ // bodyless POST without explicit length with a non-JSON HTTP411 page.
+ b = b.header(reqwest::header::CONTENT_LENGTH, "0");
}
let r = b
.send()
@@ -178,7 +182,8 @@ impl Azure {
"Unexpected operation endpoint; reconcile resource instead"
);
}
- let body = bounded(r, 1024 * 1024).await?;
+ let body = bounded(r, 1024 * 1024).await
+ .with_context(|| format!("ARM response body invalid (HTTP {status}); inspect original request, no automatic replay"))?;
Ok(Reply {
status,
etag,
@@ -439,6 +444,42 @@ printf '%s' '{{"tenant":"{tenant}","subscription":"expected-sub","accessToken":"
body.len()
)
}
+ #[tokio::test]
+ async fn empty_arm_post_has_explicit_length_and_non_json_errors_are_sanitized() {
+ let (mut a, log, t) = fixture(vec![
+ Some(response(
+ "200 OK",
+ "Content-Type: application/json\r\n",
+ "{\"kubeconfigs\":[]}",
+ )),
+ Some(response(
+ "411 Length Required",
+ "Content-Type: text/html\r\n",
+ "<html>secret-canary</html>",
+ )),
+ ]);
+ let id="/subscriptions/66666666-7777-4888-8999-aaaaaaaaaaaa/resourceGroups/test/providers/Microsoft.ContainerService/managedClusters/test/listClusterUserCredential";
+ let first = a
+ .arm(Method::POST, id, "2024-10-01", None, "first")
+ .await
+ .unwrap();
+ assert_eq!(first.status, 200);
+ let error = a
+ .arm(Method::POST, id, "2024-10-01", None, "second")
+ .await
+ .err()
+ .unwrap()
+ .to_string();
+ assert!(error.contains("HTTP 411"));
+ assert!(!error.contains("secret-canary"));
+ t.join().unwrap();
+ let requests = log.lock().unwrap();
+ assert_eq!(requests.len(), 2, "No automatic replay on provider error");
+ assert!(requests
+ .iter()
+ .all(|r| r.to_ascii_lowercase().contains("content-length: 0\r\n")));
+ }
+
#[tokio::test]
async fn control_uses_create_only_and_etag_cas_without_secret_headers() {
let (mut a, log, t) = fixture(vec![