Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/azure-cli-core/azure/cli/core/ssl_context_adaptor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import requests.adapters
import ssl
import truststore

class SSLContextAdapter(requests.adapters.HTTPAdapter):
def init_poolmanager(self, *args, **kwargs):
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

kwargs['ssl_context'] = ctx
return super(SSLContextAdapter, self).init_poolmanager(*args, **kwargs)
2 changes: 2 additions & 0 deletions src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ def send_raw_request(cli_ctx, method, url, headers=None, uri_parameters=None, #
import uuid
from requests import Session, Request
from requests.structures import CaseInsensitiveDict
from azure.cli.core.ssl_context_adaptor import SSLContextAdapter

result = CaseInsensitiveDict()
for s in headers or []:
Expand Down Expand Up @@ -1027,6 +1028,7 @@ def send_raw_request(cli_ctx, method, url, headers=None, uri_parameters=None, #

# https://requests.readthedocs.io/en/latest/user/advanced/#prepared-requests
s = Session()
s.mount(url, SSLContextAdapter())
Copy link
Copy Markdown
Member

@jiasli jiasli Dec 19, 2024

Choose a reason for hiding this comment

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

Applying SSLContextAdapter in send_raw_request() will only affect az rest. All other commands that use Azure Python SDK will not benefit from this change. MSAL is not affected either.

There is a similar feature request AzureAD/microsoft-authentication-library-for-python#685 for supporting using certificates from system certificate store for service principal authentication.

req = Request(method=method, url=url, headers=headers, params=uri_parameters, data=body)
prepped = s.prepare_request(req)

Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ semver==2.13.0
six==1.16.0
sshtunnel==0.1.5
tabulate==0.8.9
truststore==0.10.0
urllib3==1.26.19
wcwidth==0.1.7
websocket-client==1.3.1
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ semver==2.13.0
six==1.16.0
sshtunnel==0.1.5
tabulate==0.8.9
truststore==0.10.0
urllib3==1.26.19
wcwidth==0.1.7
websocket-client==1.3.1
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ semver==2.13.0
six==1.16.0
sshtunnel==0.1.5
tabulate==0.8.9
truststore==0.10.0
urllib3==1.26.19
wcwidth==0.1.7
websocket-client==1.3.1
Expand Down