Skip to content

Commit aa4f0f3

Browse files
authored
[Fix] Exclude localhost from hitting proxies for metadata service requests (#877)
## What changes are proposed in this pull request? Exclude localhost from hitting proxies for metadata service requests `requests` package doesn't do it by default. Relevant issue: databricks/databricks-vscode#916 (comment) ## How is this tested? Tested manually by running this code against real metadata service of the logged in databricks vscode extension: ```python import requests import os os.environ["HTTP_PROXY"] = "http://test.com" resp = requests.get("http://127.0.0.1:53468/redacted", timeout=10000, headers={ "X-Databricks-Metadata-Version": "1", "X-Databricks-Host": "https://redacted.databricks.com/" }, proxies={"no_proxy": "localhost,127.0.0.1"}) print(resp.text) ``` The code fails without the no_proxy option
1 parent 95277c8 commit aa4f0f3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

databricks/sdk/credentials_provider.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,18 @@ def __init__(self, cfg: 'Config'):
676676
self.host = cfg.host
677677

678678
def refresh(self) -> Token:
679-
resp = requests.get(self.url,
680-
timeout=self._metadata_service_timeout,
681-
headers={
682-
self.METADATA_SERVICE_VERSION_HEADER: self.METADATA_SERVICE_VERSION,
683-
self.METADATA_SERVICE_HOST_HEADER: self.host
684-
})
679+
resp = requests.get(
680+
self.url,
681+
timeout=self._metadata_service_timeout,
682+
headers={
683+
self.METADATA_SERVICE_VERSION_HEADER: self.METADATA_SERVICE_VERSION,
684+
self.METADATA_SERVICE_HOST_HEADER: self.host
685+
},
686+
proxies={
687+
# Explicitly exclude localhost from being proxied. This is necessary
688+
# for Metadata URLs which typically point to localhost.
689+
"no_proxy": "localhost,127.0.0.1"
690+
})
685691
json_resp: dict[str, Union[str, float]] = resp.json()
686692
access_token = json_resp.get("access_token", None)
687693
if access_token is None:

0 commit comments

Comments
 (0)