Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/azure-cli-core/azure/cli/core/sdk/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import re
import types
import uuid

from azure.core.pipeline.policies import SansIOHTTPPolicy, UserAgentPolicy
from knack.log import get_logger
Expand Down Expand Up @@ -111,7 +112,7 @@ def _acquire_policy_token_request_hook(request):
http_request = request.http_request
if getattr(http_request, 'method', '') == 'GET':
return
ACQUIRE_POLICY_TOKEN_URL = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/acquirePolicyToken?api-version=2025-03-01'
ACQUIRE_POLICY_TOKEN_URL = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/acquirePolicyToken?api-version=2025-11-01'
policy_token = None

from azure.cli.core.azclierror import ServiceError
Expand All @@ -135,10 +136,18 @@ def _acquire_policy_token_request_hook(request):
},
"changeReference": cli_ctx.data.get('_change_reference', None)
}

# Reuse the original request's x-ms-correlation-request-id so the acquirePolicyToken call shares the same correlation ID as the operation it is gating.
headers = ['Content-Type=application/json', 'x-ms-force-sync=true']
correlation_id = http_request.headers.get('x-ms-correlation-request-id')
if not correlation_id:
correlation_id = str(uuid.uuid4())
http_request.headers['x-ms-correlation-request-id'] = correlation_id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why you add the new correlation id to the incoming header when one isn't there. Is it used in creating the token (or for something else)?

@Celinadhh Celinadhh Jun 26, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http_request is the original request (e.g. a storage account delete). If there is no existing correlation-id, we generate the correlation-id in the acquire-policy-token call, and propagate the same one to http_request (storage account delete).

headers.append('x-ms-correlation-request-id={}'.format(correlation_id))

acquire_policy_token_response = send_raw_request(cli_ctx, 'POST',
ACQUIRE_POLICY_TOKEN_URL,
headers=['Content-Type=application/json',
'x-ms-force-sync=true'],
headers=headers,
body=json.dumps(acquire_policy_token_body))
if acquire_policy_token_response.status_code == 200 and acquire_policy_token_response.content:
response_content = json.loads(acquire_policy_token_response.content)
Expand Down
Loading