Skip to content

Commit f0218b3

Browse files
committed
Merge branch 'mi-arc-detection' into release-1.31.1
2 parents 866e4ce + e9b3913 commit f0218b3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

msal/managed_identity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,12 @@ def _scope_to_resource(scope): # This is an experimental reasonable-effort appr
346346
def _get_arc_endpoint():
347347
if "IDENTITY_ENDPOINT" in os.environ and "IMDS_ENDPOINT" in os.environ:
348348
return os.environ["IDENTITY_ENDPOINT"]
349-
if ( # Defined in https://msazure.visualstudio.com/One/_wiki/wikis/One.wiki/233012/VM-Extension-Authoring-for-Arc?anchor=determining-which-endpoint-to-use
350-
sys.platform == "linux" and os.path.exists("/var/opt/azcmagent/bin/himds")
349+
if ( # Defined in https://eng.ms/docs/cloud-ai-platform/azure-core/azure-management-and-platforms/control-plane-bburns/hybrid-resource-provider/azure-arc-for-servers/specs/extension_authoring
350+
sys.platform == "linux" and os.path.exists("/opt/azcmagent/bin/himds")
351351
or sys.platform == "win32" and os.path.exists(os.path.expandvars(
352-
r"%ProgramFiles%\AzureConnectedMachineAgent\himds.exe"))
352+
# Avoid Windows-only "%EnvVar%" syntax so that tests can be run on Linux
353+
r"${ProgramFiles}\AzureConnectedMachineAgent\himds.exe"
354+
))
353355
):
354356
return "http://localhost:40342/metadata/identity/oauth2/token"
355357

tests/test_mi.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,23 @@ def test_machine_learning(self):
347347
"IDENTITY_ENDPOINT": "http://localhost",
348348
"IMDS_ENDPOINT": "http://localhost",
349349
})
350-
def test_arc(self):
350+
def test_arc_by_env_var(self):
351351
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
352352

353+
@patch("msal.managed_identity.os.path.exists", return_value=True)
354+
@patch("msal.managed_identity.sys.platform", new="linux")
355+
def test_arc_by_file_existence_on_linux(self, mocked_exists):
356+
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
357+
mocked_exists.assert_called_with("/opt/azcmagent/bin/himds")
358+
359+
@patch("msal.managed_identity.os.path.exists", return_value=True)
360+
@patch("msal.managed_identity.sys.platform", new="win32")
361+
@patch.dict(os.environ, {"ProgramFiles": "C:\Program Files"})
362+
def test_arc_by_file_existence_on_windows(self, mocked_exists):
363+
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
364+
mocked_exists.assert_called_with(
365+
r"C:\Program Files\AzureConnectedMachineAgent\himds.exe")
366+
353367
@patch.dict(os.environ, {
354368
"AZUREPS_HOST_ENVIRONMENT": "cloud-shell-foo",
355369
})

0 commit comments

Comments
 (0)